From 8dc4e50769a7ebc5f0a3d766f61aa08b8f23b772 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期五, 06 九月 2024 11:23:21 +0800 Subject: [PATCH] login --- packageBookService/pages/bookServices/detail/index.js | 321 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 286 insertions(+), 35 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js index 4214b0e..ac1c263 100644 --- a/packageBookService/pages/bookServices/detail/index.js +++ b/packageBookService/pages/bookServices/detail/index.js @@ -4,12 +4,16 @@ import { loginInfo } from "../../../../assets/js/login"; +import FormData from '../../../../utils/formdata/index.js'; const app = getApp(); Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { + // 杩涢〉闈㈤粯璁ゅ垏鎹� 灞曞紑鐨刬d + // defaultactiveTeachid 鏁欏璧勬簮 + // defaultactiveLearnid 浜戝涔� bookId: "", barHeight: "", navBarHeight: "", @@ -157,7 +161,17 @@ showIndex: '', successOrderNumber: '', applicationState: '', // 鐢靛瓙鏍蜂功鐢宠鐘舵�� - + dialogBox: false, + resourceInfo: { + resourceName: '', + fileType: '', + description: '', + agree: false + }, + fileList: [], + isShowUp: true, + protocolShow: false, + protocolTxt: '' }, resetTree: function (e) { @@ -184,13 +198,22 @@ id: options.id, name: options.name, storeInfo: options.storeInfo, + }, }); wx.setNavigationBarTitle({ title: options.name, }) + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + loginInfo(app, (data) => { + if (data) {} else {} + }) + } + this.getBookInfo(options.id); // this.getResourceClass(); // 鑾峰彇璧勬簮鎵�灞炲垎绫� + const token = wx.getStorageSync(app.config.tokenKey); if (token) { this.getShoppingCartProductGet(); @@ -205,6 +228,15 @@ // 鑾峰彇鐢宠娆℃暟 this.getSelectPaperBookCount(); this.getSelectBookCount(); + } + if (options.tabValue) { + this.setData({ + tabValue: options.tabValue, + }); + const checkData = this.data.cmsDatas.find( + (item) => item.refCode == options.tabValue + ); + this.getResourceDataList(checkData) } }, @@ -376,6 +408,7 @@ dangdangLink: [], weidianLink: [], content: [], + catalogue: [], authorIntroduction: [], // isApplyPaperBook: [], // isApplyEBook: [], @@ -704,7 +737,7 @@ e.detail.label == "浜戞祴璇�" ) { const checkData = this.data.cmsDatas.find( - (item) => item.refCode == e.detail.value + (item) => item.refCode == this.data.tabValue ); if (!this.data.resourceClassList.length) this.getResourceClass() if (checkData) { @@ -807,7 +840,7 @@ }, // 鎵佸钩鍖栨暟鎹浆鎹ree - getTreeList(rootList, pathLength, newArr, path, addNum) { + getTreeList(rootList, pathLength, newArr, path) { for (const item of rootList) { // 姝ゅ鍘熸湰 item.productLinkPath.length == pathLength 浣� productLinkPath 闀垮害涓埆涔﹀瓨鍦�4銆�5浣嶄氦閿� if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) { @@ -825,7 +858,7 @@ } // newArr.push(item) // 鍦ㄦ彃鍏ヨ繃绋嬩腑瀵规暟鎹繘琛屾帓搴� - newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item, addNum) + newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) // 鎻掕繘鏁扮粍鍚� 浠庡師鏁版嵁涓垹闄� rootList = rootList.filter(nitem => nitem.id != item.id) } @@ -835,7 +868,7 @@ for (const i of newArr) { i.children = [] let addnum1 = i.productLinkPath.length - path.length == 6 ? 6 : 7 - this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath, addnum1) + this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath) if (i.children.length == 0) { delete i.children } @@ -860,9 +893,9 @@ }, // 鎺掑簭鏁扮粍 鎸夌収productLinkPath - insertAndSortObjectsByProductLinkPath(array, newObj, addNum) { + insertAndSortObjectsByProductLinkPath(array, newObj) { // 鏌ユ壘鏂板璞″簲璇ユ彃鍏ョ殑浣嶇疆 - let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - addNum, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - addNum, obj.productLinkPath.length))); + let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.lastIndexOf('\\') + 1, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.lastIndexOf('\\') + 1, obj.productLinkPath.length))); // 濡傛灉娌℃湁鎵惧埌鍚堥�傜殑浣嶇疆锛屽垯鏀惧湪鏁扮粍鏈熬 if (insertIndex === -1) { insertIndex = array.length; @@ -872,10 +905,10 @@ // 娴嬭瘯6 姝e紡5 // 瀵规暟缁勮繘琛屾帓搴� array.sort((a, b) => { - if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) { + if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) { return -1; } - if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) { + if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) { return 1; } // a must be equal to b @@ -973,19 +1006,17 @@ }) } } - const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 14 ? 8 : 6 + const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6 const num = query.cmsPath.length + addNum - this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\', addNum) + this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\') list = this.ensureTreeConsistency(list) list = this.changeResourceChildren(list) - console.log('淇敼鍚�', list); let result = []; if (type.refCode == "jsek_teachingResources") { this.findChildIds(list, result); - const newUSeList = this.deleteTreeData(list, result) - console.log('鏍戝墧闄�', result, newUSeList); - console.log('鏍戝姞涓�', this.increaseTreeData(list, newUSeList, 16094)); - + // const newUSeList = this.deleteTreeData(list, result) + // console.log('鏍戝墧闄�', result, newUSeList); + // console.log('鏍戝姞涓�', this.increaseTreeData(list, newUSeList, 16094)); this.setData({ openTeachids: result, loading: false, @@ -1089,9 +1120,9 @@ let list = [] // 娴嬭瘯 6浣�// 姝e紡 5浣�// 娴嬭瘯璋冪敤浼�20锛屽唴閮�7 姝e紡璋冪敤浼�17 鍐呴儴浼�6 - const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 14 ? 8 : 6 + const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6 const num = query.cmsPath.length + addNum - that.getTreeList(data, num, list, '\\', addNum) + that.getTreeList(data, num, list, '\\') list = that.ensureTreeConsistency(list) that.findChildIds(list[0].children, result); that.setData({ @@ -2512,9 +2543,11 @@ let resultList = [] for (let index = 0; index < list.length; index++) { const item = list[index]; - for (let cindex = 0; cindex < item.children.length; cindex++) { - const citem = item.children[cindex]; - citem.children = [] + if (item.children.length > 0) { + for (let cindex = 0; cindex < item.children.length; cindex++) { + const citem = item.children[cindex]; + citem.children = [] + } } resultList.push(item) } @@ -2527,32 +2560,250 @@ }, // 浼犻�抜ds锛屽皢闇�瑕佸睍寮�鐨刬d鐨刢hildren 璧嬪�� increaseTreeData(treeList, list, openid) { - let num = 0; // let useData = treeList.find(item => item.id == openid) for (let index = 0; index < treeList.length; index++) { const item = treeList[index]; if (item.id == openid && num >= 3) { - debugger let useArr = item.children ? item.children : [] - changeList(list, openid, useArr) + this.changeList(list, openid, useArr) } else { num += 1 this.increaseTreeData(item.children, list, openid) } } - // 閫掑綊鍓嶄袱灞傦紝鎵惧嚭闇�瑕佸睍寮�鐨� - const changeList = (isList, id, childrenList) => { - for (let dindex = 0; dindex < isList.length; dindex++) { - const ditem = isList[cindex]; - if (ditem.id == id) { - diitem.children = childrenList - return true - } else { - changeList(ditem.children, id, childrenList) - } + + }, + // 閫掑綊鍓嶄袱灞傦紝鎵惧嚭闇�瑕佸睍寮�鐨� + changeList(isList, id, childrenList) { + for (let dindex = 0; dindex < isList.length; dindex++) { + const ditem = isList[dindex]; + if (ditem.id == id) { + ditem.children = childrenList + return true + } else { + this.changeList(ditem.children, id, childrenList) } } - return list + return childrenList + }, + uploadFile(e) { + console.log(123) + this.setData({ + dialogBox: true, + isShowUp: true + }); + }, + closeDialog() { + this.setData({ + dialogBox: false, + }); + }, + onCloseProtocol() { + this.setData({ + protocolShow: false, + }); + }, + onVisibleChange(e) { + this.setData({ + protocolShow: e.detail.visible, + }); + }, + //鏌ョ湅鍗忚 + getAgreement() { + let query = { + path: 'jsek_protocol', + fields: { + content: [], + } + } + app.MG.resource.getItem(query).then((res) => { + try { + + const data = res.datas.find((e) => e.refCode == 'jsek_authorizationAndConsentLetter') + this.setData({ + protocolTxt: data && data.content ? data.content : '鏆傛棤鍗忚', + protocolShow: true + }); + } catch (error) { + this.setData({ + protocolTxt: '鏆傛棤鍗忚', + protocolShow: true, + }); + } + }) + + }, + onNameInput(e) { + console.log(e.detail.value) + this.setData({ + 'resourceInfo.resourceName': e.detail.value, + }); + }, + onFileTypeInput(e) { + this.setData({ + 'resourceInfo.fileType': e.detail.value, + }); + }, + textareaChange(e) { + this.setData({ + 'resourceInfo.description': e.detail.value, + }); + }, + onChange() { + if (this.data.resourceInfo.agree) { + this.setData({ + 'resourceInfo.agree': false, + }); + } else { + this.setData({ + 'resourceInfo.agree': true, + }); + } + }, + uploadPicture() { + var that = this; + wx.chooseMessageFile({ + count: 1, + type: 'file', + success(res) { + const isLt2M = res.tempFiles[0].size / 1024 / 1024 < 50 + if (!isLt2M) { + return wx.showToast({ + title: "涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 50MB!", + icon: "none", + duration: 1000, + }); + } + const FileName = res.tempFiles[0].name.split('.')[0] + const Extension = res.tempFiles[0].name.split('.')[1] + var medioType = '' + const audioData = ['mp3', 'mp3'] + const videoData = ['mp4', 'avi'] + const pdfData = ['pdf'] + const Compression = ['rar', 'zip'] + const pictureData = ['jpg', 'png'] + if (audioData.indexOf(Extension) > -1) { + medioType = '闊抽' + } else if (videoData.indexOf(Extension) > -1) { + medioType = '瑙嗛' + } else if (pdfData.indexOf(Extension) > -1) { + medioType = 'PDF' + } else if (Compression.indexOf(Extension) > -1) { + medioType = '璧勬簮鍖�' + } else if (pictureData.indexOf(Extension) > -1) { + medioType = '鍥剧墖' + } else { + medioType = '鍏朵粬' + } + wx.getFileSystemManager().getFileInfo({ + filePath: res.tempFiles[0].path, //閫夋嫨鍥剧墖杩斿洖鐨勭浉瀵硅矾寰� + // encoding: 'binary', //缂栫爜鏍煎紡 + success: ress => { + //鎴愬姛鐨勫洖璋� + let md5 = ress.digest; + let formData = new FormData(); + formData.append('Md5', md5); + formData.append('FileName', FileName); + formData.append('FileType', res.tempFiles[0].type); + formData.appendFile("file", res.tempFiles[0].path); + 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(res1) { + resolve(res1.data); + if (res1.data) { + let file = [{ + name: res.tempFiles[0].name, + md5: md5, + type: medioType, + FileType: Extension + }] + that.setData({ + "resourceInfo.resourceName": FileName, + "resourceInfo.fileType": medioType, + fileList: file, + isShowUp: false + }) + } + } + }) + }) + } + }) + } + }) + + }, + handleRemove(e) { + console.log(e) + let md5 = e.currentTarget.dataset.md5 + for (let i = 0; i < this.data.fileList.length; i++) { + if (this.data.fileList.md5 == md5) { + this.data.fileList.splice(i, 1) + } + } + this.setData({ + isShowUp: true, + }); + }, + confirmM() { + if (this.data.resourceInfo.resourceName == '') { + return wx.showToast({ + icon: "error", + title: "璇峰~鍐欒祫婧愬悕绉�", + }); + } + if (this.data.resourceInfo.fileType == '') { + return wx.showToast({ + icon: "error", + title: "璇峰~鍐欒祫婧愮被鍨�", + }); + } + + if (!this.data.fileList.length) { + return wx.showToast({ + icon: "error", + title: "璇蜂笂浼犺祫婧愭枃浠�", + }); + } + if (!this.data.resourceInfo.agree) { + return wx.showToast({ + icon: "none", + title: "璇峰悓鎰忋�婃巿鏉冨悓鎰忎功銆嬶紒", + }); + } + let query = { + topicIdOrRefCode: "uploadFiles", + name: this.data.bookDetail.name, + content: JSON.stringify(JSON.parse(JSON.stringify(this.data.fileList))), + type: 'UserSubmit', + description: this.data.resourceInfo.description, + cmsTypeRefCode: '', + newDataListRequest: [] + } + app.MG.ugc.newTopicMessage(query).then((res) => { + wx.showToast({ + icon: "success", + title: "璇蜂笂浼犺祫婧愭枃浠�", + }); + this.setData({ + dialogBox: false, + }); + }) } }) \ No newline at end of file -- Gitblit v1.9.1