From 76c28f8d78be198297a22261be3176cee2c01fa8 Mon Sep 17 00:00:00 2001 From: zhengw <247276359@qq.com> Date: Tue, 10 Mar 2026 11:33:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0onPageLoadInitAuth=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=88=A4=E6=96=AD=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/pages/base/account/account.ts | 34 +++++---- miniprogram/pages/base/customer/customer.ts | 34 +++++---- miniprogram/pages/base/depot/depot.ts | 34 +++++---- miniprogram/pages/base/item/item.ts | 27 ++++--- .../pages/base/orderCategory/orderCategory.ts | 27 ++++--- miniprogram/pages/base/orderStep/orderStep.ts | 34 +++++---- .../processChildConfig/processChildConfig.ts | 22 ++++-- .../processChildConfig.wxml | 2 +- .../pages/base/processConfig/processConfig.ts | 18 +++-- .../pages/base/productType/productType.ts | 34 +++++---- miniprogram/pages/base/supplier/supplier.ts | 34 +++++---- miniprogram/pages/base/workload/workload.ts | 67 +++++++++-------- .../components/page-plugin/page-plugin.ts | 36 ++++----- miniprogram/pages/finance/flow/flow.ts | 35 +++++---- miniprogram/pages/finance/giro/giro.ts | 34 +++++---- .../pages/finance/giroDetail/giroDetail.ts | 42 +++++++---- miniprogram/pages/finance/income/income.ts | 34 +++++---- .../finance/incomeDetail/incomeDetail.ts | 42 +++++++---- miniprogram/pages/finance/outcome/outcome.ts | 34 +++++---- .../finance/outcomeDetail/outcomeDetail.ts | 42 +++++++---- miniprogram/pages/logs/loginLog/loginLog.ts | 53 +++++++------ .../pages/logs/operateLog/operateLog.ts | 35 +++++---- .../pages/manage/department/department.ts | 27 ++++--- miniprogram/pages/manage/group/group.ts | 28 ++++--- .../pages/manage/groupDetail/groupDetail.ts | 75 +++++++++++-------- miniprogram/pages/manage/my/my.ts | 75 +++++++++++-------- miniprogram/pages/manage/staff/staff.ts | 28 ++++--- miniprogram/pages/my/my.ts | 2 + miniprogram/pages/other/batch/batch.ts | 35 +++++---- miniprogram/pages/other/batch/batch.wxml | 2 +- .../pages/other/batchDetail/batchDetail.ts | 35 +++++---- miniprogram/pages/other/goods/goods.ts | 34 ++++++--- .../pages/other/goodsDetail/goodsDetail.ts | 38 ++++++---- miniprogram/pages/other/outbound/outbound.ts | 34 +++++---- .../other/outboundDetail/outboundDetail.ts | 41 ++++++---- miniprogram/pages/other/transfer/transfer.ts | 34 +++++---- .../other/transferDetail/transferDetail.ts | 41 ++++++---- .../processManageDetail.ts | 33 +++++--- miniprogram/utils/https.ts | 14 ++-- miniprogram/utils/subscribe.ts | 12 +-- 40 files changed, 816 insertions(+), 526 deletions(-) diff --git a/miniprogram/pages/base/account/account.ts b/miniprogram/pages/base/account/account.ts index fb9556e..e230350 100644 --- a/miniprogram/pages/base/account/account.ts +++ b/miniprogram/pages/base/account/account.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -27,11 +27,11 @@ Page({ 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; @@ -62,16 +62,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ErpAccount/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpAccount/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderEdit(e: any) { @@ -142,7 +150,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/customer/customer.ts b/miniprogram/pages/base/customer/customer.ts index b34060a..bd70474 100644 --- a/miniprogram/pages/base/customer/customer.ts +++ b/miniprogram/pages/base/customer/customer.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -27,11 +27,11 @@ Page({ 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; @@ -62,16 +62,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ErpCrm/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpCrm/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderEdit(e: any) { @@ -114,7 +122,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/depot/depot.ts b/miniprogram/pages/base/depot/depot.ts index 3d0624d..abc5337 100644 --- a/miniprogram/pages/base/depot/depot.ts +++ b/miniprogram/pages/base/depot/depot.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -27,11 +27,11 @@ Page({ 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; @@ -62,16 +62,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ErpDepot/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpDepot/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderEdit(e: any) { @@ -129,7 +137,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/item/item.ts b/miniprogram/pages/base/item/item.ts index dfc0249..1031ce9 100644 --- a/miniprogram/pages/base/item/item.ts +++ b/miniprogram/pages/base/item/item.ts @@ -1,5 +1,5 @@ import { FinanceItemTypeArr, FinanceItemTypeObj } from '@/utils/config'; -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -30,11 +30,11 @@ Page({ 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; @@ -65,13 +65,20 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ErpFinanceItem/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - // if (list.length == 0 && this.data.params.curr_page > 1) { - // this.getList(this.data.params.curr_page - 1); - // } - this.setData({ count: toNumber(res.data?.count), list: list }); + return new Promise((resolve, reject) => { + post('ErpFinanceItem/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + // if (list.length == 0 && this.data.params.curr_page > 1) { + // this.getList(this.data.params.curr_page - 1); + // } + this.setData({ count: toNumber(res.data?.count), list: list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -130,7 +137,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/orderCategory/orderCategory.ts b/miniprogram/pages/base/orderCategory/orderCategory.ts index 4cf93d9..33ca6f7 100644 --- a/miniprogram/pages/base/orderCategory/orderCategory.ts +++ b/miniprogram/pages/base/orderCategory/orderCategory.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -27,11 +27,11 @@ Page({ 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; @@ -62,13 +62,20 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('OrderCategory/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); - // } - this.setData({ count: toNumber(res.count), list: list }); + return new Promise((resolve, reject) => { + post('OrderCategory/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); + // } + this.setData({ count: toNumber(res.count), list: list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -127,7 +134,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/orderStep/orderStep.ts b/miniprogram/pages/base/orderStep/orderStep.ts index 9d6051e..46ecfc9 100644 --- a/miniprogram/pages/base/orderStep/orderStep.ts +++ b/miniprogram/pages/base/orderStep/orderStep.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -27,11 +27,11 @@ Page({ 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; @@ -62,16 +62,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('OrderStep/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); - // } - this.setData({ - count: toNumber(res.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('OrderStep/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); + // } + this.setData({ + count: toNumber(res.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -128,7 +136,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/processChildConfig/processChildConfig.ts b/miniprogram/pages/base/processChildConfig/processChildConfig.ts index a269b7e..fe76cc8 100644 --- a/miniprogram/pages/base/processChildConfig/processChildConfig.ts +++ b/miniprogram/pages/base/processChildConfig/processChildConfig.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { getAuthInfo, toArray } from '@/utils/util'; Page({ @@ -14,18 +14,24 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { - post('CompanyProcessV2/getChildProcess', { process_id: this.data.process_id }).then( - (res: any) => { - this.setData({ list: toArray(res.data) }); - }, - ); + return new Promise((resolve, reject) => { + post('CompanyProcessV2/getChildProcess', { process_id: this.data.process_id }) + .then((res: any) => { + this.setData({ list: toArray(res.data), isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); + }); }, /** @@ -37,7 +43,7 @@ Page({ wx.setNavigationBarTitle({ title: decodeURIComponent(title) }); } this.data.process_id = process_id; - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/processChildConfig/processChildConfig.wxml b/miniprogram/pages/base/processChildConfig/processChildConfig.wxml index 1bf89a0..69bc89a 100644 --- a/miniprogram/pages/base/processChildConfig/processChildConfig.wxml +++ b/miniprogram/pages/base/processChildConfig/processChildConfig.wxml @@ -3,7 +3,7 @@ + description="提成值: {{item.bonus_value || '未配置'}}"> {{index + 1}} diff --git a/miniprogram/pages/base/processConfig/processConfig.ts b/miniprogram/pages/base/processConfig/processConfig.ts index 966c044..e543627 100644 --- a/miniprogram/pages/base/processConfig/processConfig.ts +++ b/miniprogram/pages/base/processConfig/processConfig.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { getAuthInfo, getDataSet, toArray } from '@/utils/util'; Page({ @@ -13,15 +13,23 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { - post('CompanyProcessV2/getParentProcess').then((res: any) => { - this.setData({ list: toArray(res.data) }); + return new Promise((resolve, reject) => { + post('CompanyProcessV2/getParentProcess') + .then((res: any) => { + this.setData({ list: toArray(res.data), isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onChildProcess(e: any) { @@ -38,7 +46,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad(_options) { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/productType/productType.ts b/miniprogram/pages/base/productType/productType.ts index 5e193ef..4630c31 100644 --- a/miniprogram/pages/base/productType/productType.ts +++ b/miniprogram/pages/base/productType/productType.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -27,11 +27,11 @@ Page({ 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; @@ -62,16 +62,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ProductType/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); - // } - this.setData({ - count: toNumber(res.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ProductType/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); + // } + this.setData({ + count: toNumber(res.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -130,7 +138,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/supplier/supplier.ts b/miniprogram/pages/base/supplier/supplier.ts index 7b48c2c..115f0f4 100644 --- a/miniprogram/pages/base/supplier/supplier.ts +++ b/miniprogram/pages/base/supplier/supplier.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -27,11 +27,11 @@ Page({ 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; @@ -62,16 +62,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ErpCrm/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpCrm/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderEdit(e: any) { @@ -114,7 +122,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/base/workload/workload.ts b/miniprogram/pages/base/workload/workload.ts index 06fef3c..450c7ab 100644 --- a/miniprogram/pages/base/workload/workload.ts +++ b/miniprogram/pages/base/workload/workload.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { toArray, toNumber } from '@/utils/util'; Page({ @@ -14,40 +14,47 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, - init() { - this.getList(); - }, + init() {}, getList() { - post('Index/index') - .then((res: any) => { - const process_count = toArray(res.process_count).filter((el) => { - el.count = toNumber(el.count); - return el.count > 0; - }); - const arr = toArray(res.seven_process_count).filter((el) => { - el.count = toNumber(el.count); - return el.count > 0; - }); + return new Promise((resolve, reject) => { + post('Index/index') + .then((res: any) => { + const process_count = toArray(res.process_count).filter((el) => { + el.count = toNumber(el.count); + return el.count > 0; + }); + const arr = toArray(res.seven_process_count).filter((el) => { + el.count = toNumber(el.count); + return el.count > 0; + }); - const map = new Map(); - arr.forEach((el) => { - if (!map.has(el.date)) { - map.set(el.date, []); - } - map.get(el.date).push(el); + const map = new Map(); + arr.forEach((el) => { + if (!map.has(el.date)) { + map.set(el.date, []); + } + map.get(el.date).push(el); + }); + // console.log([...map.values()]); + this.setData({ + seven_process_count: [...map.values()], + process_count: process_count, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }) + .finally(() => { + wx.stopPullDownRefresh(); }); - // console.log([...map.values()]); - this.setData({ - seven_process_count: [...map.values()], - process_count: process_count, - }); - }) - .finally(() => { - wx.stopPullDownRefresh(); - }); + }); }, /** @@ -64,7 +71,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/components/page-plugin/page-plugin.ts b/miniprogram/pages/components/page-plugin/page-plugin.ts index 65f757a..9d386a0 100644 --- a/miniprogram/pages/components/page-plugin/page-plugin.ts +++ b/miniprogram/pages/components/page-plugin/page-plugin.ts @@ -1,7 +1,7 @@ import { base, defaultAvatarUrl } from '@/utils/config'; import { login } from '@/utils/https'; import { Subscribe } from '@/utils/subscribe'; -import { isArray, setStorage } from '@/utils/util'; +import { getCurrentPageRoute, isArray } from '@/utils/util'; // import { IStorage } from "@/utils/storage"; // const app = getApp(); @@ -10,26 +10,26 @@ import { isArray, setStorage } from '@/utils/util'; Component({ options: { addGlobalClass: true }, properties: { - isLogin: Boolean, - loading: Boolean, + // isLogin: Boolean, + // loading: Boolean, isAuth: null, customStyle: null, hasTabBar: null, }, - // attached() { - // this.setData({ isLogin: getStorage("isLogin") == 1 }); - - // console.log("attached"); - // Subscribe.on("isLogin", getCurrentPageRoute(), () => { - // this.setData({ isLogin: getStorage("isLogin") == 1 }); - // console.log("监听到 isLogin 变化:"); - // }); - // }, - // detached() { - // console.log("detached"); - // Subscribe.off("isLogin", getCurrentPageRoute()); - // }, + attached() { + // this.setData({ isLogin: getStorage('isLogin') == 1 }); + // console.log('attached'); + Subscribe.on('isLogin', getCurrentPageRoute(), (data: any) => { + // console.log(data); + this.setData({ isLogin: data, loading: false }); + // console.log('监听到 isLogin 变化:'); + }); + }, + detached() { + // console.log('detached'); + Subscribe.off('isLogin', getCurrentPageRoute()); + }, data: { avatarUrl: defaultAvatarUrl, @@ -39,14 +39,14 @@ Component({ companyList: [], encryptedData: '', iv: '', + isLogin: false, + loading: true, }, methods: { handleLogin(e: any) { this.triggerEvent('handleLogin', e.detail); }, getPhoneNumberToast() { - setStorage('isLogin', 1); - Subscribe.set('isLogin', 'zzzuz'); wx.showToast({ title: '请先勾选协议', icon: 'none' }); }, changeAgreementCheck(event: any) { diff --git a/miniprogram/pages/finance/flow/flow.ts b/miniprogram/pages/finance/flow/flow.ts index 03927da..58c4455 100644 --- a/miniprogram/pages/finance/flow/flow.ts +++ b/miniprogram/pages/finance/flow/flow.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -35,11 +35,12 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); + this.getData(); }, searchChange(e: any) { @@ -87,16 +88,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ErpAccount/flow', 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: list, - }); + return new Promise((resolve, reject) => { + post('ErpAccount/flow', 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: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -137,7 +146,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/finance/giro/giro.ts b/miniprogram/pages/finance/giro/giro.ts index 6d019bb..b1da790 100644 --- a/miniprogram/pages/finance/giro/giro.ts +++ b/miniprogram/pages/finance/giro/giro.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -32,11 +32,11 @@ Page({ 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; @@ -78,16 +78,24 @@ Page({ } else { delete temp.process_state; } - - post('ErpFinance/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpFinance/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderDetail(e: any) { @@ -135,7 +143,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/finance/giroDetail/giroDetail.ts b/miniprogram/pages/finance/giroDetail/giroDetail.ts index a5c40fe..cc4a687 100644 --- a/miniprogram/pages/finance/giroDetail/giroDetail.ts +++ b/miniprogram/pages/finance/giroDetail/giroDetail.ts @@ -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,25 +29,12 @@ 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('ErpFinance/info', temp).then((res: any) => { - const data = toObject(res.data); - const info = toObject(data.info); - wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); - this.setData({ - detail: toArray(info.rows), - info: info, - }); - }); post('ErpFinance/fileList', temp).then((res: any) => { this.setData({ files: toArray(res.data).map((el) => { @@ -59,6 +46,29 @@ Page({ }); }); }, + + getList() { + this.setData({ params: this.data.params }); + const temp = cloneLite(this.data.params); + return new Promise((resolve, reject) => { + post('ErpFinance/info', temp) + .then((res: any) => { + const data = toObject(res.data); + const info = toObject(data.info); + wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); + this.setData({ + detail: toArray(info.rows), + info: info, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); + }); + }, onPreview(e: any) { const data = getDataSet(e); const index = data.index; @@ -78,7 +88,7 @@ Page({ onLoad(options) { const { head_id } = options; this.data.params.head_id = head_id; - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/finance/income/income.ts b/miniprogram/pages/finance/income/income.ts index aae7058..7901fc4 100644 --- a/miniprogram/pages/finance/income/income.ts +++ b/miniprogram/pages/finance/income/income.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -32,11 +32,11 @@ Page({ 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; @@ -78,16 +78,24 @@ Page({ } else { delete temp.process_state; } - - post('ErpFinance/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpFinance/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderDetail(e: any) { @@ -135,7 +143,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/finance/incomeDetail/incomeDetail.ts b/miniprogram/pages/finance/incomeDetail/incomeDetail.ts index a5c40fe..cc4a687 100644 --- a/miniprogram/pages/finance/incomeDetail/incomeDetail.ts +++ b/miniprogram/pages/finance/incomeDetail/incomeDetail.ts @@ -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,25 +29,12 @@ 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('ErpFinance/info', temp).then((res: any) => { - const data = toObject(res.data); - const info = toObject(data.info); - wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); - this.setData({ - detail: toArray(info.rows), - info: info, - }); - }); post('ErpFinance/fileList', temp).then((res: any) => { this.setData({ files: toArray(res.data).map((el) => { @@ -59,6 +46,29 @@ Page({ }); }); }, + + getList() { + this.setData({ params: this.data.params }); + const temp = cloneLite(this.data.params); + return new Promise((resolve, reject) => { + post('ErpFinance/info', temp) + .then((res: any) => { + const data = toObject(res.data); + const info = toObject(data.info); + wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); + this.setData({ + detail: toArray(info.rows), + info: info, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); + }); + }, onPreview(e: any) { const data = getDataSet(e); const index = data.index; @@ -78,7 +88,7 @@ Page({ onLoad(options) { const { head_id } = options; this.data.params.head_id = head_id; - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/finance/outcome/outcome.ts b/miniprogram/pages/finance/outcome/outcome.ts index c7d1b49..d980d81 100644 --- a/miniprogram/pages/finance/outcome/outcome.ts +++ b/miniprogram/pages/finance/outcome/outcome.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -32,11 +32,11 @@ Page({ 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; @@ -78,16 +78,24 @@ Page({ } else { delete temp.process_state; } - - post('ErpFinance/list', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpFinance/list', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderDetail(e: any) { @@ -135,7 +143,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/finance/outcomeDetail/outcomeDetail.ts b/miniprogram/pages/finance/outcomeDetail/outcomeDetail.ts index a5c40fe..cc4a687 100644 --- a/miniprogram/pages/finance/outcomeDetail/outcomeDetail.ts +++ b/miniprogram/pages/finance/outcomeDetail/outcomeDetail.ts @@ -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,25 +29,12 @@ 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('ErpFinance/info', temp).then((res: any) => { - const data = toObject(res.data); - const info = toObject(data.info); - wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); - this.setData({ - detail: toArray(info.rows), - info: info, - }); - }); post('ErpFinance/fileList', temp).then((res: any) => { this.setData({ files: toArray(res.data).map((el) => { @@ -59,6 +46,29 @@ Page({ }); }); }, + + getList() { + this.setData({ params: this.data.params }); + const temp = cloneLite(this.data.params); + return new Promise((resolve, reject) => { + post('ErpFinance/info', temp) + .then((res: any) => { + const data = toObject(res.data); + const info = toObject(data.info); + wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); + this.setData({ + detail: toArray(info.rows), + info: info, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); + }); + }, onPreview(e: any) { const data = getDataSet(e); const index = data.index; @@ -78,7 +88,7 @@ Page({ onLoad(options) { const { head_id } = options; this.data.params.head_id = head_id; - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/logs/loginLog/loginLog.ts b/miniprogram/pages/logs/loginLog/loginLog.ts index e627fbb..da41328 100644 --- a/miniprogram/pages/logs/loginLog/loginLog.ts +++ b/miniprogram/pages/logs/loginLog/loginLog.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -19,16 +19,17 @@ Page({ list: [] as any[], count: 0, 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; @@ -59,26 +60,34 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('Log/loginList', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list.map((el) => { - el.address = ''; - if (el.detail) { - const obj = JSON.parse(el.detail); - const arr = ['province', 'city'] - .map((key) => obj[key]) // 取出字段值 - .filter(Boolean); - el.address = arr.length ? arr.join(',') : ''; + return new Promise((resolve, reject) => { + post('Log/loginList', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); } - return el; - }), - }); + this.setData({ + count: toNumber(res.data?.count), + list: list.map((el) => { + el.address = ''; + if (el.detail) { + const obj = JSON.parse(el.detail); + const arr = ['province', 'city'] + .map((key) => obj[key]) // 取出字段值 + .filter(Boolean); + el.address = arr.length ? arr.join(',') : ''; + } + return el; + }), + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -96,7 +105,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/logs/operateLog/operateLog.ts b/miniprogram/pages/logs/operateLog/operateLog.ts index bf003e3..0002002 100644 --- a/miniprogram/pages/logs/operateLog/operateLog.ts +++ b/miniprogram/pages/logs/operateLog/operateLog.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -19,16 +19,17 @@ Page({ list: [] as any[], count: 0, 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; @@ -59,16 +60,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('Log/operateList', temp).then((res: any) => { - const list = toArray(res.data?.list); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.data?.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('Log/operateList', temp) + .then((res: any) => { + const list = toArray(res.data?.list); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.data?.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -86,7 +95,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/manage/department/department.ts b/miniprogram/pages/manage/department/department.ts index 3c987fa..905e155 100644 --- a/miniprogram/pages/manage/department/department.ts +++ b/miniprogram/pages/manage/department/department.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -30,11 +30,11 @@ Page({ 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; @@ -76,13 +76,20 @@ Page({ } else { delete temp.process_state; } - - post('Departments/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); - } - this.setData({ list: list }); + return new Promise((resolve, reject) => { + post('Departments/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); + } + this.setData({ list: list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -113,7 +120,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/manage/group/group.ts b/miniprogram/pages/manage/group/group.ts index 9d7f587..4c805bf 100644 --- a/miniprogram/pages/manage/group/group.ts +++ b/miniprogram/pages/manage/group/group.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -25,16 +25,17 @@ Page({ { value: '2', 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; @@ -76,13 +77,20 @@ Page({ } else { delete temp.process_state; } - - post('Groups/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); - } - this.setData({ list: list }); + return new Promise((resolve, reject) => { + post('Groups/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); + } + this.setData({ list: list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onGroupTap(e: any) { @@ -122,7 +130,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/manage/groupDetail/groupDetail.ts b/miniprogram/pages/manage/groupDetail/groupDetail.ts index c3859d7..097ce3e 100644 --- a/miniprogram/pages/manage/groupDetail/groupDetail.ts +++ b/miniprogram/pages/manage/groupDetail/groupDetail.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { getAuthInfo, toArray } from '@/utils/util'; Page({ @@ -8,53 +8,62 @@ Page({ data: { list: [] as any[], group_id: '', + 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() { - post('Groups/getGrpRights', { group_id: this.data.group_id }).then((res: any) => { - const list = toArray(res.right_tree); - const rights = `${res.rights || ''}`.split(','); - this.data.list.length = 0; + return new Promise((resolve, reject) => { + post('Groups/getGrpRights', { group_id: this.data.group_id }) + .then((res: any) => { + const list = toArray(res.right_tree); + const rights = `${res.rights || ''}`.split(','); + this.data.list.length = 0; - toArray(list).forEach((menu) => { - const arr: any[] = []; - toArray(menu.children).forEach((menu2) => { - let flag = false; - toArray(menu2.children).forEach((fun) => { - fun.web_checked = rights.includes(`${fun.function_id}`); - if (fun.web_checked) { - flag = true; + toArray(list).forEach((menu) => { + const arr: any[] = []; + toArray(menu.children).forEach((menu2) => { + let flag = false; + toArray(menu2.children).forEach((fun) => { + fun.web_checked = rights.includes(`${fun.function_id}`); + if (fun.web_checked) { + flag = true; + } + }); + + if (flag) { + arr.push({ + menu_ch_name: menu2.menu_ch_name, + menu_id: menu2.menu_id, + functions: toArray(menu2.children), + }); + } + }); + if (arr.length) { + this.data.list.push({ + menu_ch_name: menu.menu_ch_name, + menu_id: menu.menu_id, + children: arr, + }); } }); - - if (flag) { - arr.push({ - menu_ch_name: menu2.menu_ch_name, - menu_id: menu2.menu_id, - functions: toArray(menu2.children), - }); - } + // console.log(this.data.list); + this.setData({ list: this.data.list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); }); - if (arr.length) { - this.data.list.push({ - menu_ch_name: menu.menu_ch_name, - menu_id: menu.menu_id, - children: arr, - }); - } - }); - // console.log(this.data.list); - this.setData({ list: this.data.list }); }); }, @@ -65,7 +74,7 @@ Page({ this.data.group_id = `${options.group_id}`; wx.setNavigationBarTitle({ title: `${decodeURIComponent(`${options.name}`)} 权限` }); - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/manage/my/my.ts b/miniprogram/pages/manage/my/my.ts index 540a25f..3f059d0 100644 --- a/miniprogram/pages/manage/my/my.ts +++ b/miniprogram/pages/manage/my/my.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { getAuthInfo, toArray } from '@/utils/util'; Page({ @@ -7,53 +7,62 @@ 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() { - post('Groups/myAuth').then((res: any) => { - const list = toArray(res.right_tree); - const rights = `${res.rights || ''}`.split(','); - this.data.list.length = 0; + return new Promise((resolve, reject) => { + post('Groups/myAuth') + .then((res: any) => { + const list = toArray(res.right_tree); + const rights = `${res.rights || ''}`.split(','); + this.data.list.length = 0; - toArray(list).forEach((menu) => { - const arr: any[] = []; - toArray(menu.children).forEach((menu2) => { - let flag = false; - toArray(menu2.children).forEach((fun) => { - fun.web_checked = rights.includes(`${fun.function_id}`); - if (fun.web_checked) { - flag = true; + toArray(list).forEach((menu) => { + const arr: any[] = []; + toArray(menu.children).forEach((menu2) => { + let flag = false; + toArray(menu2.children).forEach((fun) => { + fun.web_checked = rights.includes(`${fun.function_id}`); + if (fun.web_checked) { + flag = true; + } + }); + + if (flag) { + arr.push({ + menu_ch_name: menu2.menu_ch_name, + menu_id: menu2.menu_id, + functions: toArray(menu2.children), + }); + } + }); + if (arr.length) { + this.data.list.push({ + menu_ch_name: menu.menu_ch_name, + menu_id: menu.menu_id, + children: arr, + }); } }); - - if (flag) { - arr.push({ - menu_ch_name: menu2.menu_ch_name, - menu_id: menu2.menu_id, - functions: toArray(menu2.children), - }); - } + // console.log(this.data.list); + this.setData({ list: this.data.list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); }); - if (arr.length) { - this.data.list.push({ - menu_ch_name: menu.menu_ch_name, - menu_id: menu.menu_id, - children: arr, - }); - } - }); - // console.log(this.data.list); - this.setData({ list: this.data.list }); }); }, @@ -61,7 +70,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad(_options) { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/manage/staff/staff.ts b/miniprogram/pages/manage/staff/staff.ts index 1b94d83..e55b664 100644 --- a/miniprogram/pages/manage/staff/staff.ts +++ b/miniprogram/pages/manage/staff/staff.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -31,16 +31,17 @@ Page({ user_id: wx.getStorageSync('user_id'), depOption: [] as any[], groupsOption: [] 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(); this.getOrderStep(); }, searchChange(e: any) { @@ -106,13 +107,20 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('Users/getStaff', 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: list }); + return new Promise((resolve, reject) => { + post('Users/getStaff', 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: list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onReinstatedStaff(e: any) { @@ -170,7 +178,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/my/my.ts b/miniprogram/pages/my/my.ts index edd8f3a..70467fe 100644 --- a/miniprogram/pages/my/my.ts +++ b/miniprogram/pages/my/my.ts @@ -1,5 +1,6 @@ import { base } from '@/utils/config'; import { checkSesskey, loginStatusPage, post } from '@/utils/https'; +import { Subscribe } from '@/utils/subscribe'; import { getStorage, toObject } from '@/utils/util'; Page({ @@ -59,6 +60,7 @@ Page({ complete: (res: any) => { if (res.confirm) { post('Applet/loginOut').then(() => { + Subscribe.set('isLogin', false); this.setData({ isLogin: false }); checkSesskey({ showLoading: false, showError: false }) .then(() => {}) diff --git a/miniprogram/pages/other/batch/batch.ts b/miniprogram/pages/other/batch/batch.ts index a2d0c0a..b1aa8c5 100644 --- a/miniprogram/pages/other/batch/batch.ts +++ b/miniprogram/pages/other/batch/batch.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -28,11 +28,12 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); + this.getData(); }, searchChange(e: any) { @@ -86,16 +87,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('GoodsBatch/goodsBatchList', 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: list, - }); + return new Promise((resolve, reject) => { + post('GoodsBatch/goodsBatchList', 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: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -124,7 +133,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/other/batch/batch.wxml b/miniprogram/pages/other/batch/batch.wxml index 5e69add..ebe5b4c 100644 --- a/miniprogram/pages/other/batch/batch.wxml +++ b/miniprogram/pages/other/batch/batch.wxml @@ -32,9 +32,9 @@ {{ item.batch_no }} - + diff --git a/miniprogram/pages/other/batchDetail/batchDetail.ts b/miniprogram/pages/other/batchDetail/batchDetail.ts index 026acb6..643e7ef 100644 --- a/miniprogram/pages/other/batchDetail/batchDetail.ts +++ b/miniprogram/pages/other/batchDetail/batchDetail.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -26,11 +26,12 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); + this.getData(); }, searchChange(e: any) { @@ -74,16 +75,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('GoodsBatch/getBatchLogList', 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: list, - }); + return new Promise((resolve, reject) => { + post('GoodsBatch/getBatchLogList', 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: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -96,7 +105,7 @@ Page({ if (title) { wx.setNavigationBarTitle({ title }); } - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/other/goods/goods.ts b/miniprogram/pages/other/goods/goods.ts index 747cafe..a11d2ce 100644 --- a/miniprogram/pages/other/goods/goods.ts +++ b/miniprogram/pages/other/goods/goods.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -28,11 +28,12 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); + this.getData(); }, searchChange(e: any) { @@ -134,15 +135,24 @@ Page({ if (!temp.goods_class) { delete temp.goods_class; } - post('ErpGoods/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); - } - this.setData({ - count: toNumber(res.count), - list: list, - }); + return new Promise((resolve, reject) => { + post('ErpGoods/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); + } + this.setData({ + count: toNumber(res.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -180,7 +190,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad(_options) { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/other/goodsDetail/goodsDetail.ts b/miniprogram/pages/other/goodsDetail/goodsDetail.ts index c979e2f..cf1760b 100644 --- a/miniprogram/pages/other/goodsDetail/goodsDetail.ts +++ b/miniprogram/pages/other/goodsDetail/goodsDetail.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -28,11 +28,11 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getGoodsAttr(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getGoodsAttr(); }, searchChange(e: any) { const key = getDataSet(e).key; @@ -57,19 +57,27 @@ Page({ this.getList(); }, getGoodsAttr() { - post('GoodsAttr/list').then((res: any) => { - this.data.goodsSubAttr = {}; - toArray(res?.data?.list).forEach((el) => { - toArray(el.sub_attr).forEach((ell) => { - this.data.goodsSubAttr[ell.attr_id] = { - ...ell, - p_attr_name: el.attr_name, - }; + return new Promise((resolve, reject) => { + post('GoodsAttr/list') + .then((res: any) => { + this.data.goodsSubAttr = {}; + toArray(res?.data?.list).forEach((el) => { + toArray(el.sub_attr).forEach((ell) => { + this.data.goodsSubAttr[ell.attr_id] = { + ...ell, + p_attr_name: el.attr_name, + }; + }); + }); + // console.log(this.data.goodsSubAttr); + this.setData({ goodsSubAttr: this.data.goodsSubAttr, isLogin: true }); + this.getList(); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); }); - }); - // console.log(this.data.goodsSubAttr); - this.setData({ goodsSubAttr: this.data.goodsSubAttr }); - this.getList(); }); }, getList() { @@ -109,7 +117,7 @@ Page({ if (title) { wx.setNavigationBarTitle({ title: decodeURIComponent(title) }); } - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getGoodsAttr()); }, /** diff --git a/miniprogram/pages/other/outbound/outbound.ts b/miniprogram/pages/other/outbound/outbound.ts index fb3f53a..c9f9c63 100644 --- a/miniprogram/pages/other/outbound/outbound.ts +++ b/miniprogram/pages/other/outbound/outbound.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -33,11 +33,11 @@ Page({ 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; @@ -79,16 +79,24 @@ Page({ } else { delete temp.process_state; } - - 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); - } - this.setData({ - count: toNumber(res.count), - list: list, - }); + return new Promise((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); + } + this.setData({ + count: toNumber(res.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderDetail(e: any) { @@ -142,7 +150,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/other/outboundDetail/outboundDetail.ts b/miniprogram/pages/other/outboundDetail/outboundDetail.ts index 7535ba6..f2c1774 100644 --- a/miniprogram/pages/other/outboundDetail/outboundDetail.ts +++ b/miniprogram/pages/other/outboundDetail/outboundDetail.ts @@ -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,29 +29,38 @@ 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('ErpDepot/info', temp).then((res: any) => { - const info = toObject(res.info); - wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); - this.setData({ - files: toArray(res.files).map((el) => { - el._file_type = getFileType(el.file_name); - el.file_path = `${OSSBaseUrl}${el.file_path}`; - el._file_size = formatFileSize(el.file_size); - return el; - }), - detail: toArray(res.rows), - info: info, - }); + return new Promise((resolve, reject) => { + post('ErpDepot/info', temp) + .then((res: any) => { + const info = toObject(res.info); + wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); + this.setData({ + files: toArray(res.files).map((el) => { + el._file_type = getFileType(el.file_name); + el.file_path = `${OSSBaseUrl}${el.file_path}`; + el._file_size = formatFileSize(el.file_size); + return el; + }), + detail: toArray(res.rows), + info: info, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onPreview(e: any) { @@ -73,7 +82,7 @@ Page({ onLoad(options) { const { head_id } = options; this.data.params.head_id = head_id; - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/other/transfer/transfer.ts b/miniprogram/pages/other/transfer/transfer.ts index 268201c..a5425ec 100644 --- a/miniprogram/pages/other/transfer/transfer.ts +++ b/miniprogram/pages/other/transfer/transfer.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -32,11 +32,11 @@ Page({ 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; @@ -78,16 +78,24 @@ Page({ } else { delete temp.process_state; } - - 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); - } - this.setData({ - count: toNumber(res.count), - list: list, - }); + return new Promise((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); + } + this.setData({ + count: toNumber(res.count), + list: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderDetail(e: any) { @@ -135,7 +143,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/other/transferDetail/transferDetail.ts b/miniprogram/pages/other/transferDetail/transferDetail.ts index 7535ba6..f2c1774 100644 --- a/miniprogram/pages/other/transferDetail/transferDetail.ts +++ b/miniprogram/pages/other/transferDetail/transferDetail.ts @@ -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,29 +29,38 @@ 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('ErpDepot/info', temp).then((res: any) => { - const info = toObject(res.info); - wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); - this.setData({ - files: toArray(res.files).map((el) => { - el._file_type = getFileType(el.file_name); - el.file_path = `${OSSBaseUrl}${el.file_path}`; - el._file_size = formatFileSize(el.file_size); - return el; - }), - detail: toArray(res.rows), - info: info, - }); + return new Promise((resolve, reject) => { + post('ErpDepot/info', temp) + .then((res: any) => { + const info = toObject(res.info); + wx.setNavigationBarTitle({ title: `${info.bill_no} 详情` }); + this.setData({ + files: toArray(res.files).map((el) => { + el._file_type = getFileType(el.file_name); + el.file_path = `${OSSBaseUrl}${el.file_path}`; + el._file_size = formatFileSize(el.file_size); + return el; + }), + detail: toArray(res.rows), + info: info, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onPreview(e: any) { @@ -73,7 +82,7 @@ Page({ onLoad(options) { const { head_id } = options; this.data.params.head_id = head_id; - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/produce/processManageDetail/processManageDetail.ts b/miniprogram/pages/produce/processManageDetail/processManageDetail.ts index 4b9cff6..3f12db0 100644 --- a/miniprogram/pages/produce/processManageDetail/processManageDetail.ts +++ b/miniprogram/pages/produce/processManageDetail/processManageDetail.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -30,11 +30,11 @@ Page({ 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; @@ -64,15 +64,24 @@ Page({ getList(curr: number = 1) { this.data.params.curr_page = curr; this.setData({ params: this.data.params }); - post('CompanyProcessV2/processOrd', this.data.params).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: list, - }); + return new Promise((resolve, reject) => { + post('CompanyProcessV2/processOrd', this.data.params) + .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: list, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, confirmDialog() { @@ -113,7 +122,7 @@ Page({ title: decodeURIComponent(options.title || ''), }); this.data.params.process_id = `${options.process_id || ''}`; - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/utils/https.ts b/miniprogram/utils/https.ts index f2d7b3e..33c3444 100644 --- a/miniprogram/utils/https.ts +++ b/miniprogram/utils/https.ts @@ -3,6 +3,7 @@ * YangXB 2021.11.24 * */ import { base, http } from './config'; +import { Subscribe } from './subscribe'; import { getStorage, isArray, setStorage, toArray, toastError } from './util'; /** * 请求 @@ -44,12 +45,11 @@ const request = (url: string, options: any, config = { showLoading: true, showEr resolve(request.data); } else { if (config.showError != false) { - wx.showToast({ - title: request.data.err_msg, - icon: 'none', - }); + wx.showToast({ title: request.data.err_msg, icon: 'none' }); } if (request.data.err_code == 110000) { + Subscribe.set('isLogin', false); + // const currentPage = getCurrentPage(); // console.log(currentPage); // if ( @@ -147,6 +147,7 @@ export const loginStatus = () => { setStorage('auth_info', res.auth_info); setStorage('session_id', res.session_id); getUsersConfigList(); + Subscribe.set('isLogin', true); resolve(res); }) .catch((err: any) => { @@ -155,7 +156,9 @@ export const loginStatus = () => { if (isArray(res.data)) { post('Applet/loginOut').then(() => { checkSesskey({ showLoading: false, showError: false }) - .then(() => {}) + .then(() => { + Subscribe.set('isLogin', false); + }) .catch((err) => { console.log('checkSesskey', err); }); @@ -201,6 +204,7 @@ export const onPageLoadInitAuth = ( initFun() .then((_res) => { // console.log('onPageLoadInitAuth', res); + Subscribe.set('isLogin', true); that.setData({ isLogin: true, loading: false }); that.init?.(); }) diff --git a/miniprogram/utils/subscribe.ts b/miniprogram/utils/subscribe.ts index 14599cf..6f7d76c 100644 --- a/miniprogram/utils/subscribe.ts +++ b/miniprogram/utils/subscribe.ts @@ -9,8 +9,8 @@ function triggerEvent(key: string, data: any) { }); } // 也可以触发一个通用的 'change' 事件 - if (listeners["change"]) { - listeners["change"].forEach((callback: any) => { + if (listeners['change']) { + listeners['change'].forEach((callback: any) => { callback({ key, data }); }); } @@ -45,15 +45,15 @@ export const Subscribe = { * @param functionKey 唯一的函数key(用于取消订阅的) * @param callback 回调函数 */ - on(key: string, functionKey: string, callback: () => void) { + on(key: string, functionKey: string, callback: (data: any) => void) { if (!listeners[key]) { listeners[key] = []; } - if (typeof callback == "function") { - (callback as IFun)["$$functionKey"] = functionKey; + if (typeof callback == 'function') { + (callback as IFun)['$$functionKey'] = functionKey; listeners[key].push(callback); } else { - console.log("订阅事件 callback 必须是函数"); + console.log('订阅事件 callback 必须是函数'); } },