diff --git a/miniprogram/pages/components/page-plugin/page-plugin.ts b/miniprogram/pages/components/page-plugin/page-plugin.ts index 2c3ee36..65f757a 100644 --- a/miniprogram/pages/components/page-plugin/page-plugin.ts +++ b/miniprogram/pages/components/page-plugin/page-plugin.ts @@ -82,7 +82,7 @@ Component({ this.triggerEvent('handleLogin', false); }); } else { - wx.showToast({ title: e.detail.errMsg, icon: 'none' }); + // wx.showToast({ title: e.detail.errMsg, icon: 'none' }); } }, login2(e: any) { diff --git a/miniprogram/pages/index/index.json b/miniprogram/pages/index/index.json index d99667d..dbb4bf4 100644 --- a/miniprogram/pages/index/index.json +++ b/miniprogram/pages/index/index.json @@ -5,5 +5,6 @@ "tab-bar-plugin": "/pages/components/tab-bar-plugin/tab-bar-plugin", "pagination-plugin": "/pages/components/pagination-plugin/pagination-plugin", "search-popup": "/pages/components/search-popup/search-popup" - } + }, + "enablePullDownRefresh": true } diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts index 8fcd6ec..c12edfc 100644 --- a/miniprogram/pages/index/index.ts +++ b/miniprogram/pages/index/index.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { post, onPageLoadInitAuth } from '@/utils/https'; import { menuConfig } from '@/utils/menuConfig'; import { getDataSet, toArray, toObject } from '@/utils/util'; @@ -55,6 +55,7 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getIndex(); } }, init() { @@ -76,7 +77,6 @@ Page({ }); } }); - this.getIndex(); this.setData({ authInfo: this.data.authInfo, menuList: this.data.menuList, @@ -84,12 +84,23 @@ Page({ }); }, getIndex() { - post('Index/index', {}).then((res: any) => { - const block = toArray(res?.block); - if (block.length % 2 != 0) { - block.push({ value: '', name: '工作量查看', unit: '' }); - } - this.setData({ block }); + return new Promise((resolve, reject) => { + post('Index/index', {}) + .then((res: any) => { + const block = toArray(res?.block); + if (block.length % 2 != 0) { + block.push({ value: '', name: '工作量查看', unit: '' }); + } + this.setData({ block, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }) + .finally(() => { + wx.stopPullDownRefresh(); + }); }); }, onBlockNavTo(e: any) { @@ -118,7 +129,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getIndex()); wx.hideHomeButton(); }, @@ -135,7 +146,13 @@ Page({ /** * 页面相关事件处理函数--监听用户下拉动作 */ - onPullDownRefresh() {}, + onPullDownRefresh() { + if (this.data.isLogin) { + this.getIndex(); + } else { + wx.stopPullDownRefresh(); + } + }, /** * 页面上拉触底事件的处理函数 diff --git a/miniprogram/pages/orders/orderSort/orderSort.ts b/miniprogram/pages/orders/orderSort/orderSort.ts index c268f11..689ab72 100644 --- a/miniprogram/pages/orders/orderSort/orderSort.ts +++ b/miniprogram/pages/orders/orderSort/orderSort.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { getAuthInfo, getDataSet, showModal, sleep, toArray, toastSuccess } from '@/utils/util'; Page({ @@ -7,26 +7,34 @@ Page({ */ data: { list: [] as any[], + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { - post('Orders/getLiteOrders') - .then((res: any) => { - const list = toArray(res.data); - this.setData({ list }); - }) - .finally(() => { - wx.stopPullDownRefresh(); - }); + return new Promise((resolve, reject) => { + post('Orders/getLiteOrders') + .then((res: any) => { + const list = toArray(res.data); + this.setData({ list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }) + .finally(() => { + wx.stopPullDownRefresh(); + }); + }); }, onOrderToTop(e: any) { const data = getDataSet(e); @@ -55,7 +63,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/orders/ordersList/orderDetail/orderDetail.ts b/miniprogram/pages/orders/ordersList/orderDetail/orderDetail.ts index d367473..951be06 100644 --- a/miniprogram/pages/orders/ordersList/orderDetail/orderDetail.ts +++ b/miniprogram/pages/orders/ordersList/orderDetail/orderDetail.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,27 +29,36 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - post('Orders/saleDetail', temp).then((res: any) => { - this.setData({ - info: toObject(res.info), - 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.detail), - }); + return new Promise((resolve, reject) => { + post('Orders/saleDetail', temp) + .then((res: any) => { + this.setData({ + info: toObject(res.info), + 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.detail), + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onPreview(e: any) { @@ -72,7 +81,7 @@ Page({ const { order_no } = options; this.data.params.order_no = order_no; wx.setNavigationBarTitle({ title: `${order_no} 详情` }); - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/orders/ordersList/ordersList.ts b/miniprogram/pages/orders/ordersList/ordersList.ts index c487fc4..5797ac5 100644 --- a/miniprogram/pages/orders/ordersList/ordersList.ts +++ b/miniprogram/pages/orders/ordersList/ordersList.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { SaleOrderProcessStateOption, PayedStateOption, @@ -59,11 +59,11 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); this.getOrderStep(); }, searchChange(e: any) { @@ -116,17 +116,25 @@ Page({ } else { delete temp.process_state; } - - post('Orders/list', temp).then((res: any) => { - const list = toArray(res.data); - if (list.length == 0 && this.data.params.curr_page > 1) { - this.getList(this.data.params.curr_page - 1); - } - this.setData({ - count: toNumber(res.count), - list: list, - amount: toObject(res.amount), - }); + return new Promise((resolve, reject) => { + post('Orders/list', temp) + .then((res: any) => { + const list = toArray(res.data); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.count), + list: list, + amount: toObject(res.amount), + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, onOrderPay(e: any) { @@ -192,7 +200,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/processEntry/processEntry.ts b/miniprogram/pages/processEntry/processEntry.ts index edb1450..f4b4088 100644 --- a/miniprogram/pages/processEntry/processEntry.ts +++ b/miniprogram/pages/processEntry/processEntry.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { formatTime, getAuthInfo, getDataSet, isArray, toArray, toObject } from '@/utils/util'; import { voiceRequest } from '@/utils/voiceUtil'; @@ -67,6 +67,7 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getExecProcess(); } }, backChange(e: any) { @@ -110,17 +111,26 @@ Page({ this.getProcessName(); }, getExecProcess() { - post('CompanyProcessV2/getProcessByCode').then((res: any) => { - this.data.processItems = toArray(res.data); - if (this.data.processItems.length == 1) { - this.data.selectedProcessCode = this.data.processItems[0].process_code; - this.getProcessName(); - } else { - this.getProcessName(); - } - this.setData({ - processItems: this.data.processItems, - }); + return new Promise((resolve, reject) => { + post('CompanyProcessV2/getProcessByCode') + .then((res: any) => { + this.data.processItems = toArray(res.data); + if (this.data.processItems.length == 1) { + this.data.selectedProcessCode = this.data.processItems[0].process_code; + this.getProcessName(); + } else { + this.getProcessName(); + } + this.setData({ + processItems: this.data.processItems, + isLogin: true, + }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, init() { @@ -139,7 +149,6 @@ Page({ process_code: code, logType: logType || 0, }); - this.getExecProcess(); }, voiceChange(event: any) { this.setData({ @@ -340,7 +349,7 @@ Page({ loading: true, voice: wx.getStorageSync('processEntryVoice') == 'false' ? false : true, }); - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getExecProcess()); }, /** diff --git a/miniprogram/pages/produce/orderTask/orderTask.ts b/miniprogram/pages/produce/orderTask/orderTask.ts index f29d94d..3925566 100644 --- a/miniprogram/pages/produce/orderTask/orderTask.ts +++ b/miniprogram/pages/produce/orderTask/orderTask.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { SaleOrderProcessStateOption } from '@/utils/config'; import { cloneLite, @@ -22,16 +22,17 @@ Page({ saleOrderProcessStateOption: SaleOrderProcessStateOption, sort: [{ label: '创建日期', value: 'create_date' }], detail: { show: false, title: '', data: [] as any[] }, + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, searchChange(e: any) { const key = getDataSet(e).key; @@ -67,13 +68,20 @@ Page({ } else { delete temp.process_state; } - - post('ProduceOrder/getListV2', temp).then((res: any) => { - 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 }); + return new Promise((resolve, reject) => { + post('ProduceOrder/getListV2', temp) + .then((res: any) => { + const list = toArray(res.data); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ count: toNumber(res.count), list, isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); }); }, @@ -115,7 +123,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/produce/processManage/processManage.ts b/miniprogram/pages/produce/processManage/processManage.ts index c636de2..dd1d654 100644 --- a/miniprogram/pages/produce/processManage/processManage.ts +++ b/miniprogram/pages/produce/processManage/processManage.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({ @@ -25,26 +25,33 @@ Page({ this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { - post('CompanyProcessV2/getAllProcessNum') - .then((res: any) => { - this.setData({ process: toArray(res.data) }); - }) - .finally(() => { - wx.stopPullDownRefresh(); - }); + return new Promise((resolve, reject) => { + post('CompanyProcessV2/getAllProcessNum') + .then((res: any) => { + this.setData({ process: toArray(res.data), isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }) + .finally(() => { + wx.stopPullDownRefresh(); + }); + }); }, /** * 生命周期函数--监听页面加载 */ onLoad() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/purchase/backOrder/backOrder.ts b/miniprogram/pages/purchase/backOrder/backOrder.ts index ee81c51..c5299fd 100644 --- a/miniprogram/pages/purchase/backOrder/backOrder.ts +++ b/miniprogram/pages/purchase/backOrder/backOrder.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -29,16 +29,17 @@ Page({ { value: 4, label: '无需结算' }, ], sort: [{ label: '创建日期', value: 'create_date' }], + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, searchChange(e: any) { const key = getDataSet(e).key; @@ -74,16 +75,24 @@ Page({ } else { delete temp.pay_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); + }); }); }, onOrderDel(e: any) { @@ -131,7 +140,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/purchase/backOrderDetail/backOrderDetail.ts b/miniprogram/pages/purchase/backOrderDetail/backOrderDetail.ts index 7535ba6..a93b472 100644 --- a/miniprogram/pages/purchase/backOrderDetail/backOrderDetail.ts +++ b/miniprogram/pages/purchase/backOrderDetail/backOrderDetail.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, @@ -24,34 +24,44 @@ Page({ info: {} as any, files: [] as any, detail: [] as any, + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - post('ErpDepot/info', temp).then((res: any) => { - 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 +83,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/purchase/buyInOrder/buyInOrder.ts b/miniprogram/pages/purchase/buyInOrder/buyInOrder.ts index 466f775..4429453 100644 --- a/miniprogram/pages/purchase/buyInOrder/buyInOrder.ts +++ b/miniprogram/pages/purchase/buyInOrder/buyInOrder.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -30,16 +30,17 @@ Page({ { value: 3, label: '完成结算' }, { value: 4, label: '无需结算' }, ], + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, searchChange(e: any) { const key = getDataSet(e).key; @@ -70,16 +71,24 @@ Page({ this.data.params.curr_page = curr; this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - - post('ErpDepot/depotHeadList', temp).then((res: any) => { - 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); + }); }); }, onOrderDel(e: any) { @@ -133,7 +142,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/purchase/buyInOrderDetail/buyInOrderDetail.ts b/miniprogram/pages/purchase/buyInOrderDetail/buyInOrderDetail.ts index 7535ba6..a93b472 100644 --- a/miniprogram/pages/purchase/buyInOrderDetail/buyInOrderDetail.ts +++ b/miniprogram/pages/purchase/buyInOrderDetail/buyInOrderDetail.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, @@ -24,34 +24,44 @@ Page({ info: {} as any, files: [] as any, detail: [] as any, + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - post('ErpDepot/info', temp).then((res: any) => { - 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 +83,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/purchase/buyOrder/buyOrder.ts b/miniprogram/pages/purchase/buyOrder/buyOrder.ts index b8ef0a9..32b878f 100644 --- a/miniprogram/pages/purchase/buyOrder/buyOrder.ts +++ b/miniprogram/pages/purchase/buyOrder/buyOrder.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -28,16 +28,17 @@ Page({ { value: 3, label: '完成入库' }, ], sort: [{ label: '创建日期', value: 'create_date' }], + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, searchChange(e: any) { const key = getDataSet(e).key; @@ -74,15 +75,24 @@ Page({ delete temp.states; } - 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); + }); }); }, onOrderDel(e: any) { @@ -136,7 +146,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/purchase/buyOrderDetail/buyOrderDetail.ts b/miniprogram/pages/purchase/buyOrderDetail/buyOrderDetail.ts index 7535ba6..a93b472 100644 --- a/miniprogram/pages/purchase/buyOrderDetail/buyOrderDetail.ts +++ b/miniprogram/pages/purchase/buyOrderDetail/buyOrderDetail.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, @@ -24,34 +24,44 @@ Page({ info: {} as any, files: [] as any, detail: [] as any, + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - post('ErpDepot/info', temp).then((res: any) => { - 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 +83,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/purchase/requestOrder/requestOrder.ts b/miniprogram/pages/purchase/requestOrder/requestOrder.ts index 3f6b1e3..b4b68ff 100644 --- a/miniprogram/pages/purchase/requestOrder/requestOrder.ts +++ b/miniprogram/pages/purchase/requestOrder/requestOrder.ts @@ -1,4 +1,4 @@ -import { loginStatusPage, post } from '@/utils/https'; +import { onPageLoadInitAuth, post } from '@/utils/https'; import { cloneLite, getAuthInfo, @@ -28,16 +28,17 @@ Page({ // { value: 3, label: '完成入库' }, // ], sort: [{ label: '创建日期', value: 'create_date' }], + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, searchChange(e: any) { const key = getDataSet(e).key; @@ -73,16 +74,24 @@ Page({ // } else { // delete temp.states; // } - - 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) { @@ -140,7 +149,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }, /** diff --git a/miniprogram/pages/purchase/requestOrderDetail/requestOrderDetail.ts b/miniprogram/pages/purchase/requestOrderDetail/requestOrderDetail.ts index 829707b..885f74e 100644 --- a/miniprogram/pages/purchase/requestOrderDetail/requestOrderDetail.ts +++ b/miniprogram/pages/purchase/requestOrderDetail/requestOrderDetail.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, @@ -24,24 +24,23 @@ Page({ info: {} as any, files: [] as any, detail: [] as any, + isLogin: false, }, handleLogin(e: any) { this.setData({ isLogin: e.detail }); if (e.detail) { this.init(); + this.getList(); } }, init() { this.setData({ authInfo: getAuthInfo() }); - this.getList(); }, getList() { this.setData({ params: this.data.params }); const temp = cloneLite(this.data.params); - post('ErpDepot/depotItemList', temp).then((res: any) => { - this.setData({ detail: toArray(res.data) }); - }); + post('ErpDepot/fileList', { head_id: temp.head_id }).then((res: any) => { this.setData({ files: toArray(res.data).map((el) => { @@ -52,6 +51,18 @@ Page({ }), }); }); + + return new Promise((resolve, reject) => { + post('ErpDepot/depotItemList', temp) + .then((res: any) => { + this.setData({ detail: toArray(res.data), isLogin: true }); + resolve(res); + }) + .catch((res) => { + this.setData({ isLogin: false }); + reject(res); + }); + }); }, onPreview(e: any) { const data = getDataSet(e); @@ -78,10 +89,10 @@ Page({ const record = toObject(res.data); wx.setNavigationBarTitle({ title: `${record.bill_no} 详情` }); this.setData({ info: record }); - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); }); } else { - loginStatusPage(this); + onPageLoadInitAuth(this, () => this.getList()); } }, diff --git a/miniprogram/utils/https.ts b/miniprogram/utils/https.ts index 18124b9..f2d7b3e 100644 --- a/miniprogram/utils/https.ts +++ b/miniprogram/utils/https.ts @@ -3,15 +3,7 @@ * YangXB 2021.11.24 * */ import { base, http } from './config'; -import { - getCurrentPage, - getStorage, - goIndexPage, - isArray, - setStorage, - toArray, - toastError, -} from './util'; +import { getStorage, isArray, setStorage, toArray, toastError } from './util'; /** * 请求 */ @@ -58,15 +50,15 @@ const request = (url: string, options: any, config = { showLoading: true, showEr }); } if (request.data.err_code == 110000) { - const currentPage = getCurrentPage(); - console.log(currentPage); - if ( - !['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes( - currentPage.route, - ) - ) { - goIndexPage(); - } + // const currentPage = getCurrentPage(); + // console.log(currentPage); + // if ( + // !['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes( + // currentPage.route, + // ) + // ) { + // goIndexPage(); + // } } reject(request.data); } @@ -197,6 +189,28 @@ export const loginStatusPage = (that: WechatMiniprogram.Page.Instance) }); }; +/** + * 页面初始化 + */ +export const onPageLoadInitAuth = ( + that: WechatMiniprogram.Page.Instance, + initFun: () => Promise, +) => { + 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 }