From b97bfcb85b2ded3b1f380e9a98b54b836faabba5 Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期五, 28 三月 2025 14:26:35 +0800 Subject: [PATCH] 除过数字教材外的页面的登录迁移 --- pages/digitalCourses/digitalCoursesDetails/index.js | 310 +++++++++++++++++++++++++-------------------------- 1 files changed, 153 insertions(+), 157 deletions(-) diff --git a/pages/digitalCourses/digitalCoursesDetails/index.js b/pages/digitalCourses/digitalCoursesDetails/index.js index 942e574..36a5698 100644 --- a/pages/digitalCourses/digitalCoursesDetails/index.js +++ b/pages/digitalCourses/digitalCoursesDetails/index.js @@ -13,6 +13,7 @@ loginInfo } from '../../../assets/js/login'; import wxbarcode from 'wxbarcode' + Page({ /** @@ -166,24 +167,20 @@ bookId: options.id, bookPath: parentPath.join('\\') }) - const token = wx.getStorageSync(app.config.tokenKey) - if (!token) { - loginInfo(app, (data) => { - if (data) { - this.digitalCoursesDetailsGet(options.id) - this.getPlayerList() - this.getType() - } else {} - }) - } this.digitalCoursesDetailsGet(options.id) this.getPlayerList() this.getType() - // this.setData({ - // userName: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).name, - // }) }, - + logInFun(callback) { + loginInfo(app, (data) => { + if (data) { + this.digitalCoursesDetailsGet(options.id) + this.getPlayerList() + this.getType() + callback() + } + }) + }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ @@ -831,48 +828,57 @@ //瀛︿範绗旇 //鍦ㄧ嚎鎻愰棶 // 鍥句功娣诲姞璐墿杞� - async addBookShopcCar() { - if (!this.data.expire) { - const shoppingCartGetId = []; - let query = { - start: 0, - size: 9999, - filterList: [], - searchList: [], - }; - const res = await app.MG.store.getShoppingCartProductList(query); - res.datas.forEach((item) => { - shoppingCartGetId.push(item.saleMethod.id); - }); - const determine = shoppingCartGetId.some( - (item) => item == this.data.digitalsData.defaultSaleMethodId - ); - if (!determine) { + addBookShopcCar() { + const addFun = async () => { + if (!this.data.expire) { + const shoppingCartGetId = []; let query = { - requests: [{ - saleMethodId: this.data.digitalsData.defaultSaleMethodId, - storeEventId: null, - agentCode: "鐢靛瓙涔�", - }, ], + start: 0, + size: 9999, + filterList: [], + searchList: [], }; - const addRes = app.MG.store.addShoppingCart(query); - this.showSuccessToast(); + const res = await app.MG.store.getShoppingCartProductList(query); + res.datas.forEach((item) => { + shoppingCartGetId.push(item.saleMethod.id); + }); + const determine = shoppingCartGetId.some( + (item) => item == this.data.digitalsData.defaultSaleMethodId + ); + if (!determine) { + let query = { + requests: [{ + saleMethodId: this.data.digitalsData.defaultSaleMethodId, + storeEventId: null, + agentCode: "鐢靛瓙涔�", + }, ], + }; + const addRes = app.MG.store.addShoppingCart(query); + this.showSuccessToast(); + } else { + Toast({ + context: this, + selector: "#t-toast", + message: "璇ヨ绋嬪凡鍦ㄨ喘鐗╄溅锛岃鍕块噸澶嶆坊鍔�", + theme: "warning", + direction: "column", + }); + } } else { - Toast({ - context: this, - selector: "#t-toast", - message: "璇ヨ绋嬪凡鍦ㄨ喘鐗╄溅锛岃鍕块噸澶嶆坊鍔�", - theme: "warning", - direction: "column", + wx.showToast({ + title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", + icon: "none", + duration: 1000, }); } - } else { - wx.showToast({ - title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", - icon: "none", - duration: 1000, - }); } + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + this.logInFun(() => {}) + } else { + addFun() + } + }, showSuccessToast() { Toast({ @@ -886,51 +892,60 @@ //璐拱鎸夐挳 async buyBtn() { - if (!this.data.expire) { - let bookOrdersId = ""; - let query = { - remarks: "鐢靛瓙涔�", - requests: [{ - saleMethodId: this.data.digitalsData.defaultSaleMethodId, - count: 1, - }, ], - }; - // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉 - const res = await app.MG.store.initOrder(query); - // 鑾峰彇璁㈠崟鍙峰苟璧嬪�肩粰 orderNumber.value - bookOrdersId = res.orderNumber; - // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪 - if (bookOrdersId) { - if (this.data.digitalsData.price == "0.00") { - app.MG.store - .confirmOrder({ - orderNum: bookOrdersId, - }) - .then((res) => { - if (res) { - this.digitalCoursesDetailsGet(this.data.digitalsData.id); - wx.showToast({ - title: "棰嗗彇鎴愬姛", - icon: "none", - duration: 1000, - }); - this.digitalCoursesDetailsGet(this.data.bookId); - } + const buyFun = async () => { + if (!this.data.expire) { + let bookOrdersId = ""; + let query = { + remarks: "鐢靛瓙涔�", + requests: [{ + saleMethodId: this.data.digitalsData.defaultSaleMethodId, + count: 1, + }, ], + }; + // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉 + const res = await app.MG.store.initOrder(query); + // 鑾峰彇璁㈠崟鍙峰苟璧嬪�肩粰 orderNumber.value + bookOrdersId = res.orderNumber; + // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪 + if (bookOrdersId) { + if (this.data.digitalsData.price == "0.00") { + app.MG.store + .confirmOrder({ + orderNum: bookOrdersId, + }) + .then((res) => { + if (res) { + this.digitalCoursesDetailsGet(this.data.digitalsData.id); + wx.showToast({ + title: "棰嗗彇鎴愬姛", + icon: "none", + duration: 1000, + }); + this.digitalCoursesDetailsGet(this.data.bookId); + } + }); + } else { + const url = "/pages/cart/paymentPage/index?orderNumber=" + bookOrdersId + '&onNorderSaleMethod=' + res.saleMethodLinks[0].orderSaleMethod.id; + wx.navigateTo({ + url, }); - } else { - const url = "/pages/cart/paymentPage/index?orderNumber=" + bookOrdersId + '&onNorderSaleMethod=' + res.saleMethodLinks[0].orderSaleMethod.id; - wx.navigateTo({ - url, - }); - } - } else {} - } else { - wx.showToast({ - title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", - icon: "none", - duration: 1000, - }); + } + } else {} + } else { + wx.showToast({ + title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", + icon: "none", + duration: 1000, + }); + } } + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + this.logInFun(() => {}) + } else { + buyFun() + } + }, @@ -1097,40 +1112,48 @@ }, onCertificate() { - if (!this.data.isBuy) { - wx.showToast({ - title: "璇峰厛璐拱锛屼綋楠屽畬鏁存湇鍔�", - icon: "none", - duration: 1000, + const cateFun = () => { + if (!this.data.isBuy) { + wx.showToast({ + title: "璇峰厛璐拱锛屼綋楠屽畬鏁存湇鍔�", + icon: "none", + duration: 1000, + }); + return false + } + if (!this.data.isLearn) { + wx.showToast({ + title: "鎮ㄧ殑瀛︿範浠诲姟杩樻湭瀹屾垚锛屾殏涓嶈兘鐢宠璇佷功锛屽姞娌瑰摝锛�", + icon: "none", + duration: 1000, + }); + return false + } + if (this.data.isCertificate && this.data.isCertificate.state == 'WaitAudit') { + wx.showToast({ + title: "鎮ㄧ敵璇风殑璇佷功姝e湪瀹℃牳涓�", + icon: "none", + duration: 1000, + }); + return false + } + var page = getCurrentPages().pop(); // 鑾峰彇褰撳墠椤甸潰瀹炰緥 + page.setData({ + // 鍔ㄦ�佽缃姝㈡粴鍔ㄧ殑鏍峰紡 + disableScrollStyle: 'overflow: hidden;' }); - return false + this.setData({ + dialogBox: true, + scrollJudge: '' + }) } - if (!this.data.isLearn) { - wx.showToast({ - title: "鎮ㄧ殑瀛︿範浠诲姟杩樻湭瀹屾垚锛屾殏涓嶈兘鐢宠璇佷功锛屽姞娌瑰摝锛�", - icon: "none", - duration: 1000, - }); - return false - } - if (this.data.isCertificate && this.data.isCertificate.state == 'WaitAudit') { - wx.showToast({ - title: "鎮ㄧ敵璇风殑璇佷功姝e湪瀹℃牳涓�", - icon: "none", - duration: 1000, - }); - return false + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + this.logInFun(() => {}) + } else { + cateFun() } - var page = getCurrentPages().pop(); // 鑾峰彇褰撳墠椤甸潰瀹炰緥 - page.setData({ - // 鍔ㄦ�佽缃姝㈡粴鍔ㄧ殑鏍峰紡 - disableScrollStyle: 'overflow: hidden;' - }); - this.setData({ - dialogBox: true, - scrollJudge: '' - }) }, closeDialog() { this.setData({ @@ -1317,40 +1340,7 @@ } }, setCoolect() { - // 棣栭〉娴嬭瘯鐧诲綍鍔熻兘锛屽悗缁敞閲� - // 妫�鏌ョ櫥褰曠姸鎬� - const token = wx.getStorageSync(app.config.tokenKey) - if (!token) { - loginInfo(app, (data) => { - // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋� - if (data) { - if (this.data.digitalsData.isFavourite) { - app.MG.store - .delProductLink({ - productIds: [this.data.digitalsData.id], - linkType: 'Favoriteclass' - }) - .then(() => { - this.setData({ - "digitalsData.isFavourite": false - }) - }) - } else { - let params = { - productIds: [this.data.digitalsData.id], - linkType: 'Favoriteclass' - } - app.MG.store.addProductLink(params).then((res) => { - this.setData({ - "digitalsData.isFavourite": true - }) - }) - } - } else { - // 鍑虹幇閿欒锛岃繑鍥瀎alse - } - }) - } else { + const collectFun = () => { if (this.data.digitalsData.isFavourite) { app.MG.store .delProductLink({ @@ -1374,6 +1364,12 @@ }) } } + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + this.logInFun(() => {}) + } else { + collectFun() + } }, //璇佷功鏌ョ湅 -- Gitblit v1.9.1