页面优化

This commit is contained in:
Dev
2026-10-19 15:46:10 +08:00
parent 44405743bb
commit 6beeeb2383
14 changed files with 229 additions and 120 deletions
+20 -5
View File
@@ -48,7 +48,13 @@ Page({
onShow() {
this.getTabBar().init();
this.refreshRole();
const app = getApp();
const appShowAt = app && app.globalData ? app.globalData.appShowAt : 0;
// 冷启动和从后台回到前台才拉角色;切换 Tab 不重复请求
if (!this._roleLoadedAt || appShowAt !== this._seenAppShowAt) {
this._seenAppShowAt = appShowAt;
this.refreshRole();
}
},
onLoad() {
@@ -64,12 +70,12 @@ Page({
},
onPullDownRefresh() {
this.init();
this.loadHomePage(true);
this.refreshRole();
},
init() {
this.loadHomePage();
this.loadHomePage(false);
},
/**
@@ -77,6 +83,10 @@ Page({
* 入驻审核通过后,用户回到小程序触发 onShow 即可看到「进入接单大厅」入口
*/
refreshRole() {
if (this._roleLoading) {
return Promise.resolve();
}
this._roleLoading = true;
return fetchPerson().then((res) => {
if (res.code === 1 && res.data) {
const role = res.data.role || '';
@@ -87,15 +97,20 @@ Page({
wx.setStorageSync('userInfo', userInfo);
}
}
}).catch((err) => {
console.error('refreshRole failed:', err);
}).then(() => {
this._roleLoading = false;
this._roleLoadedAt = Date.now();
});
},
async loadHomePage() {
async loadHomePage(force = false) {
this.setData({
pageLoading: true,
});
try {
const [configRes, bannerRes] = await Promise.all([fetchConfig(), fetchHomeBanners()]);
const [configRes, bannerRes] = await Promise.all([fetchConfig({ force }), fetchHomeBanners()]);
const next = { pageLoading: false };
if (configRes.code === 1) {
next.tabList = configRes.data.developTypes || [];