添加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

@@ -82,7 +82,7 @@ Component({
this.triggerEvent('handleLogin', false);
});
} else {
wx.showToast({ title: e.detail.errMsg, icon: 'none' });
// wx.showToast({ title: e.detail.errMsg, icon: 'none' });
}
},
login2(e: any) {

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) => {
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 });
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();
}
},
/**
* 页面上拉触底事件的处理函数

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import { getAuthInfo, getDataSet, showModal, sleep, toArray, toastSuccess } from '@/utils/util';
Page({
@@ -7,26 +7,34 @@ Page({
*/
data: {
list: [] as any[],
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
getList() {
return new Promise<void>((resolve, reject) => {
post('Orders/getLiteOrders')
.then((res: any) => {
const list = toArray(res.data);
this.setData({ list });
this.setData({ list, isLogin: true });
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
})
.finally(() => {
wx.stopPullDownRefresh();
});
});
},
onOrderToTop(e: any) {
const data = getDataSet(e);
@@ -55,7 +63,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
formatFileSize,
@@ -29,17 +29,19 @@ Page({
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
getList() {
this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params);
post('Orders/saleDetail', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('Orders/saleDetail', temp)
.then((res: any) => {
this.setData({
info: toObject(res.info),
files: toArray(res.files).map((el) => {
@@ -49,6 +51,13 @@ Page({
return el;
}),
detail: toArray(res.detail),
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -72,7 +81,7 @@ Page({
const { order_no } = options;
this.data.params.order_no = order_no;
wx.setNavigationBarTitle({ title: `${order_no} 详情` });
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
SaleOrderProcessStateOption,
PayedStateOption,
@@ -59,11 +59,11 @@ Page({
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
this.getOrderStep();
},
searchChange(e: any) {
@@ -116,8 +116,9 @@ Page({
} else {
delete temp.process_state;
}
post('Orders/list', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('Orders/list', temp)
.then((res: any) => {
const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1);
@@ -126,6 +127,13 @@ Page({
count: toNumber(res.count),
list: list,
amount: toObject(res.amount),
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -192,7 +200,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import { formatTime, getAuthInfo, getDataSet, isArray, toArray, toObject } from '@/utils/util';
import { voiceRequest } from '@/utils/voiceUtil';
@@ -67,6 +67,7 @@ Page({
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getExecProcess();
}
},
backChange(e: any) {
@@ -110,7 +111,9 @@ Page({
this.getProcessName();
},
getExecProcess() {
post('CompanyProcessV2/getProcessByCode').then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('CompanyProcessV2/getProcessByCode')
.then((res: any) => {
this.data.processItems = toArray(res.data);
if (this.data.processItems.length == 1) {
this.data.selectedProcessCode = this.data.processItems[0].process_code;
@@ -120,6 +123,13 @@ Page({
}
this.setData({
processItems: this.data.processItems,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -139,7 +149,6 @@ Page({
process_code: code,
logType: logType || 0,
});
this.getExecProcess();
},
voiceChange(event: any) {
this.setData({
@@ -340,7 +349,7 @@ Page({
loading: true,
voice: wx.getStorageSync('processEntryVoice') == 'false' ? false : true,
});
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getExecProcess());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import { SaleOrderProcessStateOption } from '@/utils/config';
import {
cloneLite,
@@ -22,16 +22,17 @@ Page({
saleOrderProcessStateOption: SaleOrderProcessStateOption,
sort: [{ label: '创建日期', value: 'create_date' }],
detail: { show: false, title: '', data: [] as any[] },
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
searchChange(e: any) {
const key = getDataSet(e).key;
@@ -67,13 +68,20 @@ Page({
} else {
delete temp.process_state;
}
post('ProduceOrder/getListV2', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ProduceOrder/getListV2', temp)
.then((res: any) => {
const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1);
}
this.setData({ count: toNumber(res.count), list });
this.setData({ count: toNumber(res.count), list, isLogin: true });
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -115,7 +123,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import { getAuthInfo, getDataSet, toArray } from '@/utils/util';
Page({
@@ -25,26 +25,33 @@ Page({
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
getList() {
return new Promise<void>((resolve, reject) => {
post('CompanyProcessV2/getAllProcessNum')
.then((res: any) => {
this.setData({ process: toArray(res.data) });
this.setData({ process: toArray(res.data), isLogin: true });
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
})
.finally(() => {
wx.stopPullDownRefresh();
});
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -29,16 +29,17 @@ Page({
{ value: 4, label: '无需结算' },
],
sort: [{ label: '创建日期', value: 'create_date' }],
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
searchChange(e: any) {
const key = getDataSet(e).key;
@@ -74,8 +75,9 @@ Page({
} else {
delete temp.pay_state;
}
post('ErpDepot/depotHeadList', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotHeadList', temp)
.then((res: any) => {
const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1);
@@ -83,6 +85,13 @@ Page({
this.setData({
count: toNumber(res.count),
list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -131,7 +140,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
formatFileSize,
@@ -24,22 +24,25 @@ Page({
info: {} as any,
files: [] as any,
detail: [] as any,
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
getList() {
this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params);
post('ErpDepot/info', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ErpDepot/info', temp)
.then((res: any) => {
const info = toObject(res.info);
wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` });
this.setData({
@@ -51,6 +54,13 @@ Page({
}),
detail: toArray(res.rows),
info: info,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -73,7 +83,7 @@ Page({
onLoad(options) {
const { head_id } = options;
this.data.params.head_id = head_id;
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -30,16 +30,17 @@ Page({
{ value: 3, label: '完成结算' },
{ value: 4, label: '无需结算' },
],
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
searchChange(e: any) {
const key = getDataSet(e).key;
@@ -70,8 +71,9 @@ Page({
this.data.params.curr_page = curr;
this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params);
post('ErpDepot/depotHeadList', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotHeadList', temp)
.then((res: any) => {
const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1);
@@ -79,6 +81,13 @@ Page({
this.setData({
count: toNumber(res.count),
list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -133,7 +142,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
formatFileSize,
@@ -24,22 +24,25 @@ Page({
info: {} as any,
files: [] as any,
detail: [] as any,
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
getList() {
this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params);
post('ErpDepot/info', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ErpDepot/info', temp)
.then((res: any) => {
const info = toObject(res.info);
wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` });
this.setData({
@@ -51,6 +54,13 @@ Page({
}),
detail: toArray(res.rows),
info: info,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -73,7 +83,7 @@ Page({
onLoad(options) {
const { head_id } = options;
this.data.params.head_id = head_id;
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -28,16 +28,17 @@ Page({
{ value: 3, label: '完成入库' },
],
sort: [{ label: '创建日期', value: 'create_date' }],
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
searchChange(e: any) {
const key = getDataSet(e).key;
@@ -74,7 +75,9 @@ Page({
delete temp.states;
}
post('ErpDepot/depotHeadList', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotHeadList', temp)
.then((res: any) => {
const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1);
@@ -82,6 +85,13 @@ Page({
this.setData({
count: toNumber(res.count),
list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -136,7 +146,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
formatFileSize,
@@ -24,22 +24,25 @@ Page({
info: {} as any,
files: [] as any,
detail: [] as any,
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
getList() {
this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params);
post('ErpDepot/info', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ErpDepot/info', temp)
.then((res: any) => {
const info = toObject(res.info);
wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` });
this.setData({
@@ -51,6 +54,13 @@ Page({
}),
detail: toArray(res.rows),
info: info,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -73,7 +83,7 @@ Page({
onLoad(options) {
const { head_id } = options;
this.data.params.head_id = head_id;
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -28,16 +28,17 @@ Page({
// { value: 3, label: '完成入库' },
// ],
sort: [{ label: '创建日期', value: 'create_date' }],
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
searchChange(e: any) {
const key = getDataSet(e).key;
@@ -73,8 +74,9 @@ Page({
// } else {
// delete temp.states;
// }
post('ErpDepot/depotHeadList', temp).then((res: any) => {
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotHeadList', temp)
.then((res: any) => {
const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1);
@@ -82,6 +84,13 @@ Page({
this.setData({
count: toNumber(res.count),
list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
@@ -140,7 +149,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
},
/**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https';
import { onPageLoadInitAuth, post } from '@/utils/https';
import {
cloneLite,
formatFileSize,
@@ -24,24 +24,23 @@ Page({
info: {} as any,
files: [] as any,
detail: [] as any,
isLogin: false,
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
this.getList();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
},
getList() {
this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params);
post('ErpDepot/depotItemList', temp).then((res: any) => {
this.setData({ detail: toArray(res.data) });
});
post('ErpDepot/fileList', { head_id: temp.head_id }).then((res: any) => {
this.setData({
files: toArray(res.data).map((el) => {
@@ -52,6 +51,18 @@ Page({
}),
});
});
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotItemList', temp)
.then((res: any) => {
this.setData({ detail: toArray(res.data), isLogin: true });
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
});
});
},
onPreview(e: any) {
const data = getDataSet(e);
@@ -78,10 +89,10 @@ Page({
const record = toObject(res.data);
wx.setNavigationBarTitle({ title: `${record.bill_no} 详情` });
this.setData({ info: record });
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
});
} else {
loginStatusPage(this);
onPageLoadInitAuth(this, () => this.getList());
}
},

View File

@@ -3,15 +3,7 @@
* YangXB 2021.11.24
* */
import { base, http } from './config';
import {
getCurrentPage,
getStorage,
goIndexPage,
isArray,
setStorage,
toArray,
toastError,
} from './util';
import { getStorage, isArray, setStorage, toArray, toastError } from './util';
/**
* 请求
*/
@@ -58,15 +50,15 @@ const request = (url: string, options: any, config = { showLoading: true, showEr
});
}
if (request.data.err_code == 110000) {
const currentPage = getCurrentPage();
console.log(currentPage);
if (
!['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes(
currentPage.route,
)
) {
goIndexPage();
}
// const currentPage = getCurrentPage();
// console.log(currentPage);
// if (
// !['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes(
// currentPage.route,
// )
// ) {
// goIndexPage();
// }
}
reject(request.data);
}
@@ -197,6 +189,28 @@ export const loginStatusPage = (that: WechatMiniprogram.Page.Instance<any, any>)
});
};
/**
* 页面初始化
*/
export const onPageLoadInitAuth = (
that: WechatMiniprogram.Page.Instance<any, any>,
initFun: () => Promise<void>,
) => {
if (typeof initFun == 'function') {
that.setData({ loading: true });
initFun()
.then((_res) => {
// console.log('onPageLoadInitAuth', res);
that.setData({ isLogin: true, loading: false });
that.init?.();
})
.catch((_res) => {
// console.log('onPageLoadInitAuth catch', res);
that.setData({ isLogin: false, loading: false });
});
}
};
/**
*
* @param {*} config { showLoading: true, showError: true }