添加onPageLoadInitAuth函数判断登录

This commit is contained in:
zhengw
2026-03-09 17:20:17 +08:00
parent 9033acc56d
commit 511d29281e
18 changed files with 368 additions and 209 deletions

View File

@@ -5,5 +5,6 @@
"tab-bar-plugin": "/pages/components/tab-bar-plugin/tab-bar-plugin",
"pagination-plugin": "/pages/components/pagination-plugin/pagination-plugin",
"search-popup": "/pages/components/search-popup/search-popup"
}
},
"enablePullDownRefresh": true
}

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { post, onPageLoadInitAuth } from '@/utils/https';
import { menuConfig } from '@/utils/menuConfig';
import { getDataSet, toArray, toObject } from '@/utils/util';
@@ -55,6 +55,7 @@ Page({
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getIndex();
}
},
init() {
@@ -76,7 +77,6 @@ Page({
});
}
});
this.getIndex();
this.setData({
authInfo: this.data.authInfo,
menuList: this.data.menuList,
@@ -84,12 +84,23 @@ Page({
});
},
getIndex() {
post('Index/index', {}).then((res: any) => {
const block = toArray(res?.block);
if (block.length % 2 != 0) {
block.push({ value: '', name: '工作量查看', unit: '' });
}
this.setData({ block });
return new Promise<void>((resolve, reject) => {
post('Index/index', {})
.then((res: any) => {
const block = toArray(res?.block);
if (block.length % 2 != 0) {
block.push({ value: '', name: '工作量查看', unit: '' });
}
this.setData({ block, isLogin: true });
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
})
.finally(() => {
wx.stopPullDownRefresh();
});
});
},
onBlockNavTo(e: any) {
@@ -118,7 +129,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getIndex());
wx.hideHomeButton();
},
@@ -135,7 +146,13 @@ Page({
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
onPullDownRefresh() {
if (this.data.isLogin) {
this.getIndex();
} else {
wx.stopPullDownRefresh();
}
},
/**
* 页面上拉触底事件的处理函数