From b0e2bf29dd96e7100f06b27997a6d4c6c3630374 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期一, 02 九月 2024 20:16:44 +0800 Subject: [PATCH] ceshi --- pages/digitalCourses/digitalCoursesDetails/index.js | 317 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 284 insertions(+), 33 deletions(-) diff --git a/pages/digitalCourses/digitalCoursesDetails/index.js b/pages/digitalCourses/digitalCoursesDetails/index.js index 4ede1be..775c89b 100644 --- a/pages/digitalCourses/digitalCoursesDetails/index.js +++ b/pages/digitalCourses/digitalCoursesDetails/index.js @@ -1,5 +1,8 @@ // pages/digitalCourses/digitalCoursesDetails/index.js const app = getApp() +import SparkMD5 from 'spark-md5' +import FormData from '../../../utils/formdata/index.js'; +import Wxml2Canvas from 'wxml2canvas'; import { worksDataBytool } from "../../../assets/js/toolClass.js"; @@ -50,7 +53,14 @@ onlineQuestioningClick: { name: "/static/images/digitalCourses/tiwen-click@2x.png" }, - + testResourceClickIocn: { + name: "/static/images/digitalTextbooks/link-t-click@3x.png", + }, + testResourceIocn: { + name: "/static/images/digitalTextbooks/link-t@3x.png", + }, + relationTextBook: null, + isTextBookBuy: false, dialogBox: false, lecturerList: [], selectActive: 'learn', @@ -80,9 +90,15 @@ isLearn: false, isTest: false, userInfo: { - fullName: '' //鍚嶇О + fullName: '', //鍚嶇О + userPicture: '' //鐢宠璇佷功鐢ㄦ埛鍥剧墖 }, - publishingUnit: '' + pictureMd5: '', + publishingUnit: '', + pubCertificateHide: true, + cbzsImg: '', //鍑虹増璇佷功base64 + rzzsImg: '' //璁よ瘉璇佷功base64 + }, formatDate(dateString) { if (!dateString) { @@ -140,7 +156,7 @@ this.digitalCoursesDetailsGet(options.id) this.getPlayerList() this.getType() - this.getCertificateList() + }, /** @@ -203,7 +219,6 @@ this.setData({ playerList: JSON.parse(res[0].value) }) - console.log(this.data.playerList, "playerList") } }) }, @@ -246,7 +261,6 @@ } } app.MG.store.getProductDetail(query).then(async res => { - console.log(res); if (res.datas.purchasedSaleMethodIdList.includes(res.datas.defaultSaleMethodId)) { this.setData({ isBuy: true @@ -293,7 +307,8 @@ } }) } - + this.getAboutBook(res.datas.productLinkInfo[res.datas.productLinkInfo.length - 1].LinkPath) + this.getCertificateList() this.setData({ lecturerList: lecturer, digitalsData: res.datas, @@ -329,9 +344,12 @@ this.setData({ tabValue: value }) - console.log(this.data.tabValue); + if (this.data.tabValue == 1) { + this.saveAsImage() + } if (this.data.tabValue == 2) { this.getResource() + this.getRelationBook() } if (this.data.tabValue == 3) { this.selectComponent("#note").getNoteList(); @@ -342,7 +360,6 @@ }, selectChange(event) { - console.log(event) const value = event.target.dataset.value this.setData({ selectActive: value @@ -561,6 +578,118 @@ } } }, + + //鑾峰彇鍏宠仈瀛愬晢鍝�/鏁板瓧鏁欐潗 + getRelationBook() { + app.MG.store.getProductList({ + path: '*', + storeInfo: app.config.digitalCourses, + mainProductId: this.data.digitalsData.id, + queryType: 'Related', // 鏌ヨ绫诲瀷锛� Related锛氭煡璇㈠叧鑱斿晢鍝侊紱SubProduct: 鏌ヨ瀛愬晢鍝侊紱 + paging: { + start: 0, + size: 1 + }, + fields: { + author: [], + publicationDate: [], + isbn: [], + content: [], + Creator: [], + probationPage: [] + } + }) + .then((res) => { + this.setData({ + relationTextBook: res.datas[0] + }) + if (this.data.relationTextBook.purchasedSaleMethodIdList.includes(this.data.relationTextBook.defaultSaleMethodId)) { + this.setData({ + isTextBookBuy: true + }) + } else { + this.setData({ + isTextBookBuy: false + }) + } + }) + }, + + readTextBook() { + wx.navigateTo({ + url: '/pages/digitalCourses/digitalCoursesDetails/components/digitalRead/index?refCode=' + this.data.relationTextBook.refCode + '&tryPageCount=' + this.data.relationTextBook.probationPage + '&isTextBookBuy=' + this.data.isTextBookBuy + }) + }, + + //鍦ㄧ嚎娴嬭瘯鎴戠殑鏀惰棌銆佹垜鐨勯敊棰� + goMycollect(e) { + const answertype = e.currentTarget.dataset.answertype; + const token = wx.getStorageSync("jsek-token"); + if (!token) { + return wx.getUserProfile({ + desc: "鐢ㄦ埛鐧诲綍", + success: (res) => { + console.log(res); + }, + }); + } + wx.navigateTo({ + url: `/packageBookService/pages/bookServices/examination/examination?bookId=${ + this.data.digitalsData.id + }&rootCmsItemId=${this.data.digitalsData.rootCmsItemId}&answerTitle=${ + answertype == "collectQuestion" ? "鎴戠殑鏀惰棌" : "鎴戠殑閿欓" + }&answerType=${answertype}&storeInfo=${app.config.digitalCourses}`, + }); + }, + + // 鑾峰彇鐩稿叧璇剧▼ + getAboutBook(path) { + let query = { + path, + queryType: '*', + coverSize: { + width: 260 + }, + paging: { + start: 0, + size: 9 + }, + fields: { + author: [], + publicationDate: [] + } + } + app.MG.store.getProductList(query).then(res => { + const Arr = res.datas.filter( + (item) => item.id != this.data.digitalsData.id + ); + let bookArr = [] + if (Arr.length) { + if (Arr.length > 9) { + for (var i = 0; i < 9; i++) { + var _num = Math.floor(Math.random() * Arr.length) + var mm = Arr[_num] + Arr.splice(_num, 1) + bookArr.push(mm) + } + } else { + bookArr = Arr + } + bookArr.forEach(item => { + if (item.icon == '') { + item.icon = '/static/images/default-book-img.png' + } + }) + this.setData({ + relatedBookData: bookArr + }) + } else { + this.setData({ + relatedBookData: [] + }) + } + }) + }, //瀛︿範绗旇 //鍦ㄧ嚎鎻愰棶 // 鍥句功娣诲姞璐墿杞� @@ -631,7 +760,6 @@ // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉 const res = await app.MG.store.initOrder(query); // 鑾峰彇璁㈠崟鍙峰苟璧嬪�肩粰 orderNumber.value - console.log(res, 'res456'); bookOrdersId = res.orderNumber; // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪 if (bookOrdersId) { @@ -656,9 +784,7 @@ url, }); } - } else { - console.log(222); - } + } else {} } else { wx.showToast({ title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", @@ -679,7 +805,50 @@ }); }, //鐢宠璇佷功 + async saveAsImage() { + let query = wx.createSelectorQuery().in(this); + query.select("#pubCertificate").boundingClientRect(); + query.exec(function (res) { + console.log("View 鐨勪俊鎭細", res[0]); + }); + console.log(value, 123) + let drawImage = new Wxml2Canvas({ + element: 'pubCertificate', // canvas鑺傜偣鐨刬d, + obj: that, // 鍦ㄧ粍浠朵腑浣跨敤鏃讹紝闇�瑕佷紶鍏ュ綋鍓嶇粍浠剁殑this + width: this.width * 2, // 瀹介珮 + height: this.height * 2, + background: '#fff', // 榛樿鑳屾櫙鑹� + progress(percent) { // 缁樺埗杩涘害 + }, + finish(url) { + console.log("鍒涘缓鐨勫浘鐗�", url); + }, + error(res) { + console.log(res); + // uni.hideLoading() + // 鐢诲け璐ョ殑鍘熷洜 + } + }, this); + // const canvas = Wxml2Canvas.wxmlToCanvas(value); + // // 杞崲涓哄浘鐗� + // const img = Wxml2Canvas.canvasToTempImage(canvas); + // const path = Wxml2Canvas.canvasToTempFilePath(canvas); + // console.log(canvas) + // Wxml2Canvas(value).then((canvas) => { + // const img = canvas.toDataURL('image/png') + // this.setData({ + // cbzsImg: img, + // }) + // }) + // Wxml2Canvas(textCertificate.value).then((canvas1) => { + // const img1 = canvas1.toDataURL('image/png') + // rzzsImg.value = img1 + // }) + this.setData({ + pubCertificateHide: false, + }) + }, //鑾峰彇瀛楁 getType() { app.MG.resource.getCmsTypeByRefCode({ @@ -711,18 +880,21 @@ }) } }) + }) }, + + onCertificate() { - // if (!this.data.isBuy) { - // wx.showToast({ - // title: "璇峰厛璐拱锛屼綋楠屽畬鏁存湇鍔�", - // icon: "none", - // duration: 1000, - // }); - // return false - // } + if (!this.data.isBuy) { + wx.showToast({ + title: "璇峰厛璐拱锛屼綋楠屽畬鏁存湇鍔�", + icon: "none", + duration: 1000, + }); + return false + } // if (!this.data.isLearn) { // wx.showToast({ // title: "鎮ㄧ殑瀛︿範浠诲姟杩樻湭瀹屾垚锛屾殏涓嶈兘鐢宠璇佷功锛屽姞娌瑰摝锛�", @@ -731,14 +903,14 @@ // }); // return false // } - // if (this.data.isCertificate && this.data.isCertificate.state == 'WaitAudit') { - // wx.showToast({ - // title: "鎮ㄧ敵璇风殑璇佷功姝e湪瀹℃牳涓�", - // 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({ @@ -763,13 +935,93 @@ "userInfo.fullName": e.detail.value, }); }, + uploadPicture() { + var that = this; + wx.chooseMedia({ + count: 1, // 榛樿9 + sizeType: ['original', 'compressed'], // 鍙互鎸囧畾鏄師鍥捐繕鏄帇缂╁浘锛岄粯璁や簩鑰呴兘鏈� + sourceType: ['album', 'camera'], // 鍙互鎸囧畾鏉ユ簮鏄浉鍐岃繕鏄浉鏈猴紝榛樿浜岃�呴兘鏈� + success: function (res) { + wx.getFileSystemManager().readFile({ + filePath: res.tempFiles[0].tempFilePath, //閫夋嫨鍥剧墖杩斿洖鐨勭浉瀵硅矾寰� + // encoding: 'binary', //缂栫爜鏍煎紡 + success: ress => { + //鎴愬姛鐨勫洖璋� + let spark = new SparkMD5.ArrayBuffer(); + spark.append(ress.data); + let md5 = spark.end(false); + let formData = new FormData(); + formData.append('Md5', md5); + formData.append('FileName', md5); + formData.append('FileType', res.tempFiles[0].fileType); + formData.appendFile("file", res.tempFiles[0].tempFilePath); + const data = formData.getData(); + let _token = wx.getStorageSync(app.config.tokenKey); + let header = {}; + if (_token == null) { + header["Authorization"] = `Basic ${Base64.encode(website.clientId + ":" + website.clientSecret)}`; + } else { + header["Authorization"] = `Bearer ` + _token; + } + new Promise((resolve, reject) => { + wx.request({ + url: app.config.requestCtx + '/file/api/ApiUpload', + method: 'POST', + header: { + 'content-type': data.contentType, + ...header + }, + data: data.buffer, + success(res) { + if (res.statusCode == 200) { + resolve(res.data); + if (res.data) { + that.setData({ + 'userInfo.userPicture': app.config.requestCtx + `/file/GetPreViewImage?md5=` + md5, + pictureMd5: md5 + }); + } + } else { + reject('杩愯鏃堕敊璇�,璇风◢鍚庡啀璇�'); + } + } + }) + }) + } + }) + } + }); + }, + confirmM() { if (this.data.userInfo.fullName) { + if (this.data.pictureMd5 == '') { + wx.showToast({ + title: "璇蜂笂浼犵収鐗�", + icon: "none", + duration: 1000, + }); + return false + } let data = {} + let bookInfo = { + bookId: this.data.digitalsData.id, + icon: this.data.digitalsData.icon, + courseLeader: this.data.digitalsData.courseLeader, + name: this.data.digitalsData.name, + ISBN: this.data.digitalsData.isbn, + affiliatedUnit: this.data.digitalsData.affiliatedUnit, + publicationDate: this.data.digitalsData.publicationDate, + classHours: this.data.digitalsData.classHours, + lecturerList: this.data.lecturerList.length > 0 ? + this.data.lecturerList[0].name : this.data.digitalsData.courseLeader, + userPicture: this.data.pictureMd5, + certificate: this.data.rzzsImg + } data = { topicIdOrRefCode: 'applyCourseCertificate', name: this.data.userInfo.fullName, - content: JSON.stringify(this.data.digitalsData), + content: JSON.stringify(bookInfo), state: 'WaitAudit', cmsTypeRefCode: 'jsek_courseCertificate', type: 'applyCourse', @@ -866,14 +1118,14 @@ //璇佷功鏌ョ湅 onClick1() { this.setData({ - images: ['/static/images/certificate/cbzs.jpg'], + images: ['https://jsek.bnuic.com/home/certificate/szkc.jpg'], showIndex: true, visible: true, }) }, onClick2() { this.setData({ - images: ['/static/images/certificate/rzzs.jpg'], + images: ['https://jsek.bnuic.com/home/certificate/kczs.jpg'], showIndex: true, visible: true, }) @@ -882,7 +1134,6 @@ const { trigger } = e.detail; - console.log(trigger); this.setData({ visible: false, }); -- Gitblit v1.9.1