优化启动页

This commit is contained in:
zhouyanli
2026-08-17 15:31:17 +08:00
parent 9d5310e4a7
commit cb885dc1f2
8 changed files with 88 additions and 24 deletions

View File

@@ -1,11 +1,11 @@
<template>
<view class="content-class">
<template v-if="isLoggedIn">
<!-- 顶部渐变背景层 -->
<view class="bg-gradient"></view>
<!-- 页面内容区 -->
<view class="page-content">
<!-- 粘性顶部区域(状态栏 + 导航栏 + 小区选择) -->
<view class="sticky-header">
<!-- 状态栏占位 -->
<view class="status_bar" :style="{ height: statusBarHeight + 'px' }"></view>
@@ -118,12 +118,14 @@
</view>
</view>
</view>
</template>
<view v-else class="launch-placeholder"></view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad, onUnload, onShow } from '@dcloudio/uni-app'
import { onLoad, onUnload, onShow, onReady } from '@dcloudio/uni-app'
import {
getCurrentVillage,
getTodayInspection,
@@ -136,7 +138,10 @@ import { usePermStore } from '@/stores/usePermStore'
const permStore = usePermStore()
// 首次加载标记:onLoad 和 onShow 在首次进入时都会触发,用此标记避免重复请求
// 登录状态:未登录时启动跳引导页
const isLoggedIn = ref(!!uni.getStorageSync('token'))
// 首次加载标记
const hasInit = ref(false)
// banner 缓存 key 和缓存时长(30分钟)
@@ -302,7 +307,6 @@ const handleFunctionClick = item => {
}
// 获取当前小区
const currentVillageData = () => {
// 先重置,避免新账号无小区时仍显示旧账号的小区
currentCommunity.value = '请先绑定房屋'
getCurrentVillage()
.then(res => {
@@ -313,7 +317,9 @@ const currentVillageData = () => {
getNoticeData()
}
})
.catch(() => {})
.catch(() => {
currentCommunity.value = '请先绑定房屋'
})
}
// 获取今日巡检数据
const getInspectionData = () => {
@@ -339,17 +345,16 @@ const getInspectionData = () => {
}
// 获取消息通知
const getNoticeData = () => {
getNewNoticeData()
.then(res => {
if (res.code === 200 && res.data) {
noticeText.value = res.data.notice || ''
} else {
noticeText.value = '暂无公告'
getNewNoticeData().then(res => {
const notice = res.code === 200 && res.data ? (res.data.notice || '') : '暂无公告'
// 仅在内容真正变化时才更新
if (noticeText.value !== notice) {
noticeText.value = notice
}
})
.catch(() => {})
}
// 获取bannar图(带缓存:30分钟内优先用缓存,请求成功后更新缓存)
// 获取bannar图
function getbannarData(forceRefresh = false) {
// 非强制刷新时,优先读缓存
if (!forceRefresh) {
@@ -414,6 +419,7 @@ const slelctHomeData = data => {
}
onShow(() => {
if (!isLoggedIn.value) return
if (!hasInit.value) {
// 首次加载:onLoad 已触发过核心数据请求,这里只补 onLoad 没调的和需要每次都刷新的
hasInit.value = true
@@ -434,11 +440,33 @@ onShow(() => {
})
onLoad(() => {
// 未登录:登录过→登录页;首次下载→引导页
if (!isLoggedIn.value) {
const hasShowGuide = uni.getStorageSync('hasShowGuide')
uni.hideTabBar({ animation: false })
uni.reLaunch({
url: hasShowGuide ? '/pageSubPack/loginSub/pwd-login' : '/pages/guide/guide',
animationType: 'none',
animationDuration: 0
})
return
}
// 已登录:确保 tabBar 显示(未登录启动时曾被 hideTabBar 隐藏,switchTab 不会自动恢复)
uni.showTabBar({ animation: false })
uni.$on('confirm', slelctHomeData)
currentVillageData()
getInspectionData()
})
onReady(() => {
// 已登录:首页即最终页,渲染完成后关闭启动屏(未登录由引导页 onReady 关闭)
if (isLoggedIn.value) {
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen()
// #endif
}
})
onUnload(() => {
uni.$off('confirm', slelctHomeData)
})
@@ -465,6 +493,12 @@ onUnload(() => {
position: relative;
}
/* 未登录启动占位:背景与引导页一致,过渡不闪烁 */
.launch-placeholder {
min-height: 100vh;
background: linear-gradient(to bottom, #e2f0ff, #f6faff);
}
/* 顶部渐变背景 - 增加高度确保覆盖粘性头部区域 */
.bg-gradient {
position: absolute;