修改启动白屏

This commit is contained in:
tangxinyue 2026-04-29 14:28:18 +08:00
parent f3be53fe2f
commit 1601a3e4ae
2 changed files with 40 additions and 19 deletions

View File

@ -29,7 +29,7 @@ export function createApp() {
app.config.globalProperties.$system = plus.os.name; app.config.globalProperties.$system = plus.os.name;
// #endif // #endif
app.config.globalProperties.$systemInfo = systemInfo app.config.globalProperties.$systemInfo = systemInfo
uni.setStorageSync('version', '1.0.4.sp17') uni.setStorageSync('version', '1.0.4.sp21')
app.config.globalProperties.$version = uni.getStorageSync('version') app.config.globalProperties.$version = uni.getStorageSync('version')
app.use(globalMethods); app.use(globalMethods);
return { return {

View File

@ -1,9 +1,9 @@
<template> <template>
<view class="container" :style="{ height: data.windowHeight + 'px' }"> <view class="container" :style="{ height: data.windowHeight + 'px' }">
<image class="index-bg-img" :style="{ width: windowWidth + 'px' }" src="/static/image/index/index-bg.png" <image v-if="isReady" class="index-bg-img" :style="{ width: windowWidth + 'px' }"
mode="widthFix"> src="/static/image/index/index-bg.png" mode="widthFix">
</image> </image>
<view class="nav-bar-box" :style="{ backgroundColor: data.navBarBgColor }"> <view v-if="isReady" class="nav-bar-box" :style="{ backgroundColor: data.navBarBgColor }">
<view class="status-box" :style="{ height: statusBarHeight + 'px' }"></view> <view class="status-box" :style="{ height: statusBarHeight + 'px' }"></view>
<view class="nav-box"> <view class="nav-box">
<view class="left-box" @click="exit" @tap="exit" @touchstart.stop="exit"> <view class="left-box" @click="exit" @tap="exit" @touchstart.stop="exit">
@ -15,7 +15,7 @@
</view> </view>
</view> </view>
<view class="content-box" :style="{ height: windowHeight + 'px' }"> <view v-if="isReady" class="content-box" :style="{ height: windowHeight + 'px' }">
<scroll-view scroll-y="true" class="scroll-view" <scroll-view scroll-y="true" class="scroll-view"
:style="{ height: (windowHeight - statusBarHeight - 44) + 'px', marginTop: (statusBarHeight + 44) + 'px' }" :style="{ height: (windowHeight - statusBarHeight - 44) + 'px', marginTop: (statusBarHeight + 44) + 'px' }"
@scroll="handleScroll"> @scroll="handleScroll">
@ -39,7 +39,7 @@
:src="`/static/image/index/${userInfo.vip > 1 ? (userInfo.vip == 3 ? 'lifetime-vip-bg' : 'vip-bg') : 'no-vip-bg'}.png`" :src="`/static/image/index/${userInfo.vip > 1 ? (userInfo.vip == 3 ? 'lifetime-vip-bg' : 'vip-bg') : 'no-vip-bg'}.png`"
mode=""></image> mode=""></image>
<view class="user-info-box" :style="{ width: (windowWidth - 32) + 'px' }"> <view class="user-info-box" :style="{ width: (windowWidth - 32) + 'px' }">
<image class="user-avatar" :src="userInfo.avater"></image> <image v-if="userInfo.avater" class="user-avatar" :src="userInfo.avater"></image>
<view class="user-info"> <view class="user-info">
<view class="name-box"> <view class="name-box">
<text class="phone-text">ID{{ userInfo.user_id }}</text> <text class="phone-text">ID{{ userInfo.user_id }}</text>
@ -161,12 +161,11 @@ import {
} from '@dcloudio/uni-app'; } from '@dcloudio/uni-app';
onReady(() => { onReady(() => {
// NVUE 挂载极快,但给它 100~200ms 的喘息让原生视图确认渲染
setTimeout(() => { setTimeout(() => {
// #ifdef APP-PLUS // #ifdef APP-PLUS
plus.navigator.closeSplashscreen(); plus.navigator.closeSplashscreen();
// #endif // #endif
}, 150); }, 500);
}); });
// 内部埋点方法 // 内部埋点方法
@ -292,10 +291,11 @@ const otherList = [{
] ]
const data = reactive({ const data = reactive({
isReady: false,
navBarBgColor: 'transparent', navBarBgColor: 'transparent',
statusBarHeight: 0, statusBarHeight: 0,
windowWidth: 0, windowWidth: 390, // 防0导致初次Weex负数高度白屏崩溃
windowHeight: 0, windowHeight: 844, // 防0导致初次Weex负数高度白屏崩溃
userInfo: {}, userInfo: {},
videoHelpList: [], videoHelpList: [],
noticeInfo: {}, noticeInfo: {},
@ -305,6 +305,7 @@ const data = reactive({
}) })
const { const {
isReady,
statusBarHeight, statusBarHeight,
windowWidth, windowWidth,
windowHeight, windowHeight,
@ -336,21 +337,41 @@ onLoad(async () => {
data.vision = uni.getStorageSync('version') data.vision = uni.getStorageSync('version')
}) })
const updateSystemSize = () => {
try {
const systemInfo = uni.getSystemInfoSync();
// 防止安卓宿主中首次热更新进入短暂状态下获取宽高均为0导致的白屏bug
if (systemInfo.windowHeight > 0 && systemInfo.windowWidth > 0) {
data.statusBarHeight = systemInfo.statusBarHeight;
data.windowWidth = systemInfo.windowWidth;
data.windowHeight = systemInfo.windowHeight;
// 针对部分小米/底层ROM的顽疾
// 强制延迟挂载超重DOM让其宿主完全完成测绘后再放入节点避免Weex渲染主线程卡死白屏
setTimeout(() => {
data.isReady = true;
}, 300);
} else {
// 未获取到正常宽高,延迟再次进行重试
setTimeout(updateSystemSize, 100);
}
} catch (error) {
setTimeout(updateSystemSize, 100);
}
}
onShow(() => { onShow(() => {
// 启动时获取数据 // 启动时获取数据
fetchUserData() fetchUserData()
// 每次显示时刷新数据 // 每次显示时刷新数据
setUserData() setUserData()
// 获取系统信息 // 循环检测更新真实屏幕宽高
const systemInfo = uni.getSystemInfoSync(); updateSystemSize();
data.statusBarHeight = systemInfo.statusBarHeight;
data.windowWidth = systemInfo.windowWidth;
data.windowHeight = systemInfo.windowHeight;
// #ifdef APP-PLUS // #ifdef APP-PLUS
util.setAndroidSystemBarColor('#F0F4F9')
setTimeout(() => { setTimeout(() => {
plus.navigator.setStatusBarStyle("dark"); // util.setAndroidSystemBarColor('#F0F4F9');
}, 500) // plus.navigator.setStatusBarStyle("dark");
}, 800);
// #endif // #endif
}) })
@ -434,7 +455,7 @@ const setUserData = () => {
const userInfoData = storage.get("userInfo") const userInfoData = storage.get("userInfo")
data.userInfo = userInfoData || { data.userInfo = userInfoData || {
user_id: '加载中...', user_id: '加载中...',
avater: '/static/default-avatar.png', avater: '',
vip: 0, vip: 0,
vip_expire: '' vip_expire: ''
} }