添加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); this.triggerEvent('handleLogin', false);
}); });
} else { } else {
wx.showToast({ title: e.detail.errMsg, icon: 'none' }); // wx.showToast({ title: e.detail.errMsg, icon: 'none' });
} }
}, },
login2(e: any) { login2(e: any) {

View File

@@ -5,5 +5,6 @@
"tab-bar-plugin": "/pages/components/tab-bar-plugin/tab-bar-plugin", "tab-bar-plugin": "/pages/components/tab-bar-plugin/tab-bar-plugin",
"pagination-plugin": "/pages/components/pagination-plugin/pagination-plugin", "pagination-plugin": "/pages/components/pagination-plugin/pagination-plugin",
"search-popup": "/pages/components/search-popup/search-popup" "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 { menuConfig } from '@/utils/menuConfig';
import { getDataSet, toArray, toObject } from '@/utils/util'; import { getDataSet, toArray, toObject } from '@/utils/util';
@@ -55,6 +55,7 @@ Page({
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getIndex();
} }
}, },
init() { init() {
@@ -76,7 +77,6 @@ Page({
}); });
} }
}); });
this.getIndex();
this.setData({ this.setData({
authInfo: this.data.authInfo, authInfo: this.data.authInfo,
menuList: this.data.menuList, menuList: this.data.menuList,
@@ -84,12 +84,23 @@ Page({
}); });
}, },
getIndex() { getIndex() {
post('Index/index', {}).then((res: any) => { return new Promise<void>((resolve, reject) => {
post('Index/index', {})
.then((res: any) => {
const block = toArray(res?.block); const block = toArray(res?.block);
if (block.length % 2 != 0) { if (block.length % 2 != 0) {
block.push({ value: '', name: '工作量查看', unit: '' }); 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) { onBlockNavTo(e: any) {
@@ -118,7 +129,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
loginStatusPage(this); onPageLoadInitAuth(this, () => this.getIndex());
wx.hideHomeButton(); 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'; import { getAuthInfo, getDataSet, showModal, sleep, toArray, toastSuccess } from '@/utils/util';
Page({ Page({
@@ -7,26 +7,34 @@ Page({
*/ */
data: { data: {
list: [] as any[], list: [] as any[],
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
getList() { getList() {
return new Promise<void>((resolve, reject) => {
post('Orders/getLiteOrders') post('Orders/getLiteOrders')
.then((res: any) => { .then((res: any) => {
const list = toArray(res.data); const list = toArray(res.data);
this.setData({ list }); this.setData({ list, isLogin: true });
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}) })
.finally(() => { .finally(() => {
wx.stopPullDownRefresh(); wx.stopPullDownRefresh();
}); });
});
}, },
onOrderToTop(e: any) { onOrderToTop(e: any) {
const data = getDataSet(e); const data = getDataSet(e);
@@ -55,7 +63,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
loginStatusPage(this); onPageLoadInitAuth(this, () => this.getList());
}, },
/** /**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config'; import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https'; import { onPageLoadInitAuth, post } from '@/utils/https';
import { import {
cloneLite, cloneLite,
formatFileSize, formatFileSize,
@@ -29,17 +29,19 @@ Page({
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
getList() { getList() {
this.setData({ params: this.data.params }); this.setData({ params: this.data.params });
const temp = cloneLite(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({ this.setData({
info: toObject(res.info), info: toObject(res.info),
files: toArray(res.files).map((el) => { files: toArray(res.files).map((el) => {
@@ -49,6 +51,13 @@ Page({
return el; return el;
}), }),
detail: toArray(res.detail), 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; const { order_no } = options;
this.data.params.order_no = order_no; this.data.params.order_no = order_no;
wx.setNavigationBarTitle({ title: `${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 { import {
SaleOrderProcessStateOption, SaleOrderProcessStateOption,
PayedStateOption, PayedStateOption,
@@ -59,11 +59,11 @@ Page({
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
this.getOrderStep(); this.getOrderStep();
}, },
searchChange(e: any) { searchChange(e: any) {
@@ -116,8 +116,9 @@ Page({
} else { } else {
delete temp.process_state; delete temp.process_state;
} }
return new Promise<void>((resolve, reject) => {
post('Orders/list', temp).then((res: any) => { post('Orders/list', temp)
.then((res: any) => {
const list = toArray(res.data); const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) { if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1); this.getList(this.data.params.curr_page - 1);
@@ -126,6 +127,13 @@ Page({
count: toNumber(res.count), count: toNumber(res.count),
list: list, list: list,
amount: toObject(res.amount), amount: toObject(res.amount),
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -192,7 +200,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { 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 { formatTime, getAuthInfo, getDataSet, isArray, toArray, toObject } from '@/utils/util';
import { voiceRequest } from '@/utils/voiceUtil'; import { voiceRequest } from '@/utils/voiceUtil';
@@ -67,6 +67,7 @@ Page({
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getExecProcess();
} }
}, },
backChange(e: any) { backChange(e: any) {
@@ -110,7 +111,9 @@ Page({
this.getProcessName(); this.getProcessName();
}, },
getExecProcess() { 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); this.data.processItems = toArray(res.data);
if (this.data.processItems.length == 1) { if (this.data.processItems.length == 1) {
this.data.selectedProcessCode = this.data.processItems[0].process_code; this.data.selectedProcessCode = this.data.processItems[0].process_code;
@@ -120,6 +123,13 @@ Page({
} }
this.setData({ this.setData({
processItems: this.data.processItems, processItems: this.data.processItems,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -139,7 +149,6 @@ Page({
process_code: code, process_code: code,
logType: logType || 0, logType: logType || 0,
}); });
this.getExecProcess();
}, },
voiceChange(event: any) { voiceChange(event: any) {
this.setData({ this.setData({
@@ -340,7 +349,7 @@ Page({
loading: true, loading: true,
voice: wx.getStorageSync('processEntryVoice') == 'false' ? false : 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 { SaleOrderProcessStateOption } from '@/utils/config';
import { import {
cloneLite, cloneLite,
@@ -22,16 +22,17 @@ Page({
saleOrderProcessStateOption: SaleOrderProcessStateOption, saleOrderProcessStateOption: SaleOrderProcessStateOption,
sort: [{ label: '创建日期', value: 'create_date' }], sort: [{ label: '创建日期', value: 'create_date' }],
detail: { show: false, title: '', data: [] as any[] }, detail: { show: false, title: '', data: [] as any[] },
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
searchChange(e: any) { searchChange(e: any) {
const key = getDataSet(e).key; const key = getDataSet(e).key;
@@ -67,13 +68,20 @@ Page({
} else { } else {
delete temp.process_state; delete temp.process_state;
} }
return new Promise<void>((resolve, reject) => {
post('ProduceOrder/getListV2', temp).then((res: any) => { post('ProduceOrder/getListV2', temp)
.then((res: any) => {
const list = toArray(res.data); const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) { if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(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() { 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'; import { getAuthInfo, getDataSet, toArray } from '@/utils/util';
Page({ Page({
@@ -25,26 +25,33 @@ Page({
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
getList() { getList() {
return new Promise<void>((resolve, reject) => {
post('CompanyProcessV2/getAllProcessNum') post('CompanyProcessV2/getAllProcessNum')
.then((res: any) => { .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(() => { .finally(() => {
wx.stopPullDownRefresh(); wx.stopPullDownRefresh();
}); });
});
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad() { 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 { import {
cloneLite, cloneLite,
getAuthInfo, getAuthInfo,
@@ -29,16 +29,17 @@ Page({
{ value: 4, label: '无需结算' }, { value: 4, label: '无需结算' },
], ],
sort: [{ label: '创建日期', value: 'create_date' }], sort: [{ label: '创建日期', value: 'create_date' }],
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
searchChange(e: any) { searchChange(e: any) {
const key = getDataSet(e).key; const key = getDataSet(e).key;
@@ -74,8 +75,9 @@ Page({
} else { } else {
delete temp.pay_state; delete temp.pay_state;
} }
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotHeadList', temp).then((res: any) => { post('ErpDepot/depotHeadList', temp)
.then((res: any) => {
const list = toArray(res.data); const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) { if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1); this.getList(this.data.params.curr_page - 1);
@@ -83,6 +85,13 @@ Page({
this.setData({ this.setData({
count: toNumber(res.count), count: toNumber(res.count),
list: list, list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -131,7 +140,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
loginStatusPage(this); onPageLoadInitAuth(this, () => this.getList());
}, },
/** /**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config'; import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https'; import { onPageLoadInitAuth, post } from '@/utils/https';
import { import {
cloneLite, cloneLite,
formatFileSize, formatFileSize,
@@ -24,22 +24,25 @@ Page({
info: {} as any, info: {} as any,
files: [] as any, files: [] as any,
detail: [] as any, detail: [] as any,
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
getList() { getList() {
this.setData({ params: this.data.params }); this.setData({ params: this.data.params });
const temp = cloneLite(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); const info = toObject(res.info);
wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` });
this.setData({ this.setData({
@@ -51,6 +54,13 @@ Page({
}), }),
detail: toArray(res.rows), detail: toArray(res.rows),
info: info, info: info,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -73,7 +83,7 @@ Page({
onLoad(options) { onLoad(options) {
const { head_id } = options; const { head_id } = options;
this.data.params.head_id = head_id; 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 { import {
cloneLite, cloneLite,
getAuthInfo, getAuthInfo,
@@ -30,16 +30,17 @@ Page({
{ value: 3, label: '完成结算' }, { value: 3, label: '完成结算' },
{ value: 4, label: '无需结算' }, { value: 4, label: '无需结算' },
], ],
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
searchChange(e: any) { searchChange(e: any) {
const key = getDataSet(e).key; const key = getDataSet(e).key;
@@ -70,8 +71,9 @@ Page({
this.data.params.curr_page = curr; this.data.params.curr_page = curr;
this.setData({ params: this.data.params }); this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params); const temp = cloneLite(this.data.params);
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotHeadList', temp).then((res: any) => { post('ErpDepot/depotHeadList', temp)
.then((res: any) => {
const list = toArray(res.data); const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) { if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1); this.getList(this.data.params.curr_page - 1);
@@ -79,6 +81,13 @@ Page({
this.setData({ this.setData({
count: toNumber(res.count), count: toNumber(res.count),
list: list, list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -133,7 +142,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
loginStatusPage(this); onPageLoadInitAuth(this, () => this.getList());
}, },
/** /**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config'; import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https'; import { onPageLoadInitAuth, post } from '@/utils/https';
import { import {
cloneLite, cloneLite,
formatFileSize, formatFileSize,
@@ -24,22 +24,25 @@ Page({
info: {} as any, info: {} as any,
files: [] as any, files: [] as any,
detail: [] as any, detail: [] as any,
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
getList() { getList() {
this.setData({ params: this.data.params }); this.setData({ params: this.data.params });
const temp = cloneLite(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); const info = toObject(res.info);
wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` });
this.setData({ this.setData({
@@ -51,6 +54,13 @@ Page({
}), }),
detail: toArray(res.rows), detail: toArray(res.rows),
info: info, info: info,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -73,7 +83,7 @@ Page({
onLoad(options) { onLoad(options) {
const { head_id } = options; const { head_id } = options;
this.data.params.head_id = head_id; 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 { import {
cloneLite, cloneLite,
getAuthInfo, getAuthInfo,
@@ -28,16 +28,17 @@ Page({
{ value: 3, label: '完成入库' }, { value: 3, label: '完成入库' },
], ],
sort: [{ label: '创建日期', value: 'create_date' }], sort: [{ label: '创建日期', value: 'create_date' }],
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
searchChange(e: any) { searchChange(e: any) {
const key = getDataSet(e).key; const key = getDataSet(e).key;
@@ -74,7 +75,9 @@ Page({
delete temp.states; 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); const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) { if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1); this.getList(this.data.params.curr_page - 1);
@@ -82,6 +85,13 @@ Page({
this.setData({ this.setData({
count: toNumber(res.count), count: toNumber(res.count),
list: list, list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -136,7 +146,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
loginStatusPage(this); onPageLoadInitAuth(this, () => this.getList());
}, },
/** /**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config'; import { OSSBaseUrl } from '@/utils/config';
import { loginStatusPage, post } from '@/utils/https'; import { onPageLoadInitAuth, post } from '@/utils/https';
import { import {
cloneLite, cloneLite,
formatFileSize, formatFileSize,
@@ -24,22 +24,25 @@ Page({
info: {} as any, info: {} as any,
files: [] as any, files: [] as any,
detail: [] as any, detail: [] as any,
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
getList() { getList() {
this.setData({ params: this.data.params }); this.setData({ params: this.data.params });
const temp = cloneLite(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); const info = toObject(res.info);
wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` });
this.setData({ this.setData({
@@ -51,6 +54,13 @@ Page({
}), }),
detail: toArray(res.rows), detail: toArray(res.rows),
info: info, info: info,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -73,7 +83,7 @@ Page({
onLoad(options) { onLoad(options) {
const { head_id } = options; const { head_id } = options;
this.data.params.head_id = head_id; 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 { import {
cloneLite, cloneLite,
getAuthInfo, getAuthInfo,
@@ -28,16 +28,17 @@ Page({
// { value: 3, label: '完成入库' }, // { value: 3, label: '完成入库' },
// ], // ],
sort: [{ label: '创建日期', value: 'create_date' }], sort: [{ label: '创建日期', value: 'create_date' }],
isLogin: false,
}, },
handleLogin(e: any) { handleLogin(e: any) {
this.setData({ isLogin: e.detail }); this.setData({ isLogin: e.detail });
if (e.detail) { if (e.detail) {
this.init(); this.init();
this.getList();
} }
}, },
init() { init() {
this.setData({ authInfo: getAuthInfo() }); this.setData({ authInfo: getAuthInfo() });
this.getList();
}, },
searchChange(e: any) { searchChange(e: any) {
const key = getDataSet(e).key; const key = getDataSet(e).key;
@@ -73,8 +74,9 @@ Page({
// } else { // } else {
// delete temp.states; // delete temp.states;
// } // }
return new Promise<void>((resolve, reject) => {
post('ErpDepot/depotHeadList', temp).then((res: any) => { post('ErpDepot/depotHeadList', temp)
.then((res: any) => {
const list = toArray(res.data); const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) { if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1); this.getList(this.data.params.curr_page - 1);
@@ -82,6 +84,13 @@ Page({
this.setData({ this.setData({
count: toNumber(res.count), count: toNumber(res.count),
list: list, list: list,
isLogin: true,
});
resolve(res);
})
.catch((res) => {
this.setData({ isLogin: false });
reject(res);
}); });
}); });
}, },
@@ -140,7 +149,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
loginStatusPage(this); onPageLoadInitAuth(this, () => this.getList());
}, },
/** /**

View File

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

View File

@@ -3,15 +3,7 @@
* YangXB 2021.11.24 * YangXB 2021.11.24
* */ * */
import { base, http } from './config'; import { base, http } from './config';
import { import { getStorage, isArray, setStorage, toArray, toastError } from './util';
getCurrentPage,
getStorage,
goIndexPage,
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) { if (request.data.err_code == 110000) {
const currentPage = getCurrentPage(); // const currentPage = getCurrentPage();
console.log(currentPage); // console.log(currentPage);
if ( // if (
!['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes( // !['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes(
currentPage.route, // currentPage.route,
) // )
) { // ) {
goIndexPage(); // goIndexPage();
} // }
} }
reject(request.data); 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 } * @param {*} config { showLoading: true, showError: true }