From 38cd76c5f05fd55855038e2d393074e27909c63d Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期五, 28 三月 2025 15:28:01 +0800 Subject: [PATCH] 剩余页面登录迁移 --- pages/digitalCourses/index.js | 113 +++++++++++++++++++++++++++++++++----------------------- 1 files changed, 66 insertions(+), 47 deletions(-) diff --git a/pages/digitalCourses/index.js b/pages/digitalCourses/index.js index a99fbbf..204a643 100644 --- a/pages/digitalCourses/index.js +++ b/pages/digitalCourses/index.js @@ -1,4 +1,7 @@ // pages/digitalCourses/index.js +import { + loginInfo +} from '../../assets/js/login'; const app = getApp() import { setSessionGuid, @@ -21,7 +24,7 @@ activeItem: null, loading: false, contentLoading: false, - noData:false, + noData: false, shoppingCartGetId: [], sorter: { value: "*", @@ -68,7 +71,8 @@ }); } this.getCourseTypeListList() - this.getShoppingCartList() + const token = wx.getStorageSync(app.config.tokenKey) + if (token) this.getShoppingCartList() }, /** @@ -175,6 +179,9 @@ }, getCourseList(item) { + this.setData({ + noData: false, + }) let searchObj = {} let sort = {} // // 鎼滅储妗� @@ -231,10 +238,11 @@ } } app.MG.store.getProductList(obj).then((res) => { - if(!res.datas.length) { + if (!res.datas.length) { return this.setData({ - noData:true, - contentLoading:false + noData: true, + courseList: [], + contentLoading: false }) } res.datas.forEach(item => { @@ -284,55 +292,66 @@ }) }, addCart(e) { - const { - item - } = e.currentTarget.dataset; - wx.showToast({ - title: "寤鸿涓�", - icon: 'none', - duration: 1000 - }) - if (wx.getStorageSync(app.config.tokenKey)) { - let query = { - start: 0, - size: 999, - filterList: [], - searchList: [] - } - try { - if ( - this.data.shoppingCartGetId.includes( - item.defaultSaleMethodId - ) - ) { - wx.showToast({ - title: "璇ヤ功宸插湪璐墿杞︼紝璇峰嬁閲嶅娣诲姞绌�", - icon: 'none', - duration: 1000 - }) - } else { - let query = { - requests: [{ - saleMethodId: item.defaultSaleMethodId, - storeEventId: null, - agentCode: '鏁板瓧璇剧▼' - }] - } - const addRes = app.MG.store.addShoppingCart(query) - if (addRes) { + const addFun = () => { + const { + item + } = e.currentTarget.dataset; + wx.showToast({ + title: "寤鸿涓�", + icon: 'none', + duration: 1000 + }) + if (wx.getStorageSync(app.config.tokenKey)) { + let query = { + start: 0, + size: 999, + filterList: [], + searchList: [] + } + try { + if ( + this.data.shoppingCartGetId.includes( + item.defaultSaleMethodId + ) + ) { wx.showToast({ - title: "娣诲姞鎴愬姛", - icon: 'success', + title: "璇ヨ绋嬪凡鍦ㄨ喘鐗╄溅锛岃鍕块噸澶嶆坊鍔�", + icon: 'none', duration: 1000 }) + } else { + let query = { + requests: [{ + saleMethodId: item.defaultSaleMethodId, + storeEventId: null, + agentCode: '鏁板瓧璇剧▼' + }] + } + const addRes = app.MG.store.addShoppingCart(query) + if (addRes) { + wx.showToast({ + title: "娣诲姞鎴愬姛", + icon: 'success', + duration: 1000 + }) + } + this.getShoppingCartList() } - this.getShoppingCartList() + } catch (error) { + console.error('鍑洪敊浜嗭細', error) } - } catch (error) { - console.error('鍑洪敊浜嗭細', error) } } - + const token = wx.getStorageSync(app.config.tokenKey) + if (token) { + addFun() + } else { + loginInfo(app, (data) => { + if (data) { + this.getShoppingCartList() + } + }) + } }, }) \ No newline at end of file -- Gitblit v1.9.1