From ccf200b60ad213343a13d36c17c5ee5ac5cd7b7a Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期三, 27 三月 2024 20:19:45 +0800 Subject: [PATCH] 样书等 --- packageDomain/pages/teacherCertification/index.js | 259 ++++++++++++++++++++++++++++----------------------- 1 files changed, 143 insertions(+), 116 deletions(-) diff --git a/packageDomain/pages/teacherCertification/index.js b/packageDomain/pages/teacherCertification/index.js index 812abdc..4079d7d 100644 --- a/packageDomain/pages/teacherCertification/index.js +++ b/packageDomain/pages/teacherCertification/index.js @@ -1,7 +1,13 @@ const app = getApp(); +import SparkMD5 from 'spark-md5' import tool from "../../../assets/js/toolClass.js"; -import { getTopicMsgCmsItemFile } from '../../../assets/js/middleGround/tool.js'; +import { + getTopicMsgCmsItemFile +} from '../../../assets/js/middleGround/tool.js'; import FormData from '../../../utils/formdata/index.js'; +import { + loginInfo +} from '../../../assets/js/login'; Page({ /** @@ -45,10 +51,21 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad() { + //鑾峰彇鑱岀О this.getpositionalTitle(); this.getAgreement(); - if (wx.getStorageSync(app.config.tokenKey)) { + this.getUserRole() + } + // 妫�鏌ョ櫥褰曠姸鎬� + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + loginInfo(app, (data) => { + if (data) { + this.getUserRole() + } + }) + } else { this.getUserRole() } }, @@ -87,50 +104,35 @@ this.setData({ userId: res.userId }) + let nickNameData = res.infoList.find((item) => item.type == 'nickName') let teacherRole = res.roleLinks.find((item) => item.role.refCode == 'teacher') let teacherInfos = res.infoList.find((item) => item.type == 'teacherInfo') - let wechatInfo = res.infoList.find((item) => item.type == 'WeChat') - let studentInfo = res.infoList.find((item) => item.type == 'Default') - let phoneInfo = res.secretList.find((item) => item.type == 'MobilePhone') - let emailInfo = res.secretList.find((item) => item.type == 'EMail') + let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); let defaultUser = {}; if (teacherRole && teacherInfos) { defaultUser = { ...teacherInfos, - nickName: teacherInfos.fullName, - avatarUrl: teacherInfos.icon, + nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : teacherInfos.name, + icon: nickNameData ? JSON.parse(nickNameData.data).icon : WeChatInfo ? WeChatInfo.icon : '', userId: res.userId, - phoneNumber: phoneInfo?.credential, - Email: emailInfo ? emailInfo.credential : JSON.parse(teacherInfos.data).email, role: 'Teacher', - roleId: teacherRole.role.id + roleId: teacherRole.role.id, } - } else if (wechatInfo) { + } else if (WeChatInfo) { defaultUser = { - ...wechatInfo, - nickName: wechatInfo.name, - avatarUrl: wechatInfo.icon, + ...WeChatInfo, + nickName: nickNameData ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name, + icon: nickNameData ? JSON.parse(nickNameData.data).icon : WeChatInfo.icon, userId: res.userId, - phoneNumber: phoneInfo?.credential, - Email: emailInfo?.credential, - role: 'Student' } - } else if (studentInfo) { - defaultUser = { - ...studentInfo, - nickName: wechatInfo.name, - avatarUrl: wechatInfo.icon, - userId: res.userId, - phoneNumber: phoneInfo?.credential, - Email: emailInfo?.credential, - role: 'Student' - } + } wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); } }) }, + //鑾峰彇瀛楁 getType() { app.MG.resource.getCmsTypeByRefCode({ refCodes: ['jsek_teacherCertification'] @@ -142,6 +144,7 @@ this.newGetTeacherInfo() }) }, + //鑾峰彇鏁欏笀鐘舵�� newGetTeacherInfo() { const data = { start: 0, @@ -170,7 +173,6 @@ }) } let info = getTopicMsgCmsItemFile(this.data.worksInfo, resData.cmsItemDataList) - console.log(info) this.setData({ 'teacherInfo.fullName': info.fullName, 'teacherInfo.schoolName': info.schoolName, @@ -200,7 +202,8 @@ md5: ele.file.md5, linkType: 'LinkFile', linkProtectType: 'Public', - url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + ele.md5 + url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + ele.md5, + imgUrl: ele.file.imgUrl } arr.push(imgObj); this.setData({ @@ -212,8 +215,8 @@ md5: this.data.teacherInfo.relevantCertificates, linkType: 'LinkFile', linkProtectType: 'Public', - url: - app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates + url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates, + imgUrl: app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates, } arr.push(imgObj); this.setData({ @@ -223,11 +226,10 @@ } } - } catch (error) { - } + } catch (error) {} }) }, - + //鑾峰彇鑱岀О getpositionalTitle() { const data = { refCodes: ['positionalTitle'] @@ -295,14 +297,18 @@ //閫夋嫨鑱岀О onTeachPicker() { - this.setData({ teachVisible: true }); + this.setData({ + teachVisible: true + }); }, onPickerChange(e) { - const { value, label } = e.detail; + const { + label + } = e.detail; this.setData({ teachVisible: false, teachText: label[0], - 'teacherInfo.positionalTitle': value.join[0], + 'teacherInfo.positionalTitle': label[0], }); }, onPickerCancel(e) { @@ -313,7 +319,9 @@ }, //杈撳叆鎵嬫満鍙� onPhoneInput(e) { - const { phoneError } = this.data; + const { + phoneError + } = this.data; const isPhoneNumber = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(e.detail.value); if (phoneError === isPhoneNumber) { this.setData({ @@ -324,7 +332,9 @@ }, //杈撳叆搴ф満 onTelphoneInput(e) { - const { telphoneError } = this.data; + const { + telphoneError + } = this.data; const isPhoneNumber = /^0\d{2}-\d{8}$|^0\d{3}-\d{7}$/.test(e.detail.value); if (telphoneError === isPhoneNumber) { this.setData({ @@ -334,7 +344,9 @@ } }, onEmailInput(e) { - const { emailError } = this.data; + const { + emailError + } = this.data; const isPhoneNumber = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(e.detail.value); if (emailError === isPhoneNumber) { this.setData({ @@ -347,68 +359,76 @@ chooseImg(e) { var that = this; wx.chooseMedia({ - // count: 1, // 榛樿9 + count: 1, sizeType: ['original', 'compressed'], // 鍙互鎸囧畾鏄師鍥捐繕鏄帇缂╁浘锛岄粯璁や簩鑰呴兘鏈� sourceType: ['album', 'camera'], // 鍙互鎸囧畾鏉ユ簮鏄浉鍐岃繕鏄浉鏈猴紝榛樿浜岃�呴兘鏈� success: function (res) { // 杩斿洖閫夊畾鐓х墖鐨勬湰鍦版枃浠惰矾寰勫垪琛紝tempFilePath涔熷彲浠ヤ綔涓篿mg鏍囩鐨剆rc灞炴�ф樉绀哄浘鐗� - console.log(res.tempFiles[0]) - tool.getFileMd5(res.tempFiles[0]).then((e) => { - console.log(e, 4) - if (!that.data.imgPics.find((item) => item.md5 == e)) { - let formData = new FormData(); - formData.append('Md5', e); - formData.append('FileName', e); - 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) { - let arr = []; - let imgObj = { - md5: e, - linkType: 'LinkFile', - linkProtectType: 'Public', - url: - app.config.requestCtx + `/file/GetPreViewImage?md5=` + e - } - arr = [...that.data.imgPics, ...[imgObj]]; + 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); + if (!that.data.imgPics.find((item) => item.md5 == md5)) { + 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(res1) { + if (res1.statusCode == 200) { + resolve(res1.data); + if (res1.data) { + let arr = []; + let imgObj = { + md5: md5, + linkType: 'LinkFile', + linkProtectType: 'Public', + url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + md5, + imgUrl: res.tempFiles[0].tempFilePath + } + arr = [...that.data.imgPics, ...[imgObj]]; - that.setData({ - imgPics: arr, - }); + that.setData({ + imgPics: arr, + }); + } + } else { + reject('杩愯鏃堕敊璇�,璇风◢鍚庡啀璇�'); } - } else { - reject('杩愯鏃堕敊璇�,璇风◢鍚庡啀璇�'); } - } + }) }) - }) - } else { - wx.showToast({ - title: "褰撳墠鏂囦欢宸蹭笂浼狅紝璇峰嬁閲嶅鎿嶄綔锛�", - icon: 'none', - duration: 1000, - }) + } else { + wx.showToast({ + title: "褰撳墠鏂囦欢宸蹭笂浼狅紝璇峰嬁閲嶅鎿嶄綔锛�", + icon: 'none', + duration: 1000, + }) + } } }) + } }); }, @@ -438,7 +458,6 @@ }) }, onChange() { - console.log(this.data.teacherInfo.agree, 12) if (this.data.teacherInfo.agree) { this.setData({ 'teacherInfo.agree': false, @@ -462,11 +481,22 @@ reasonTxtShow: e.detail.visible }); }, + onCloseProtocol() { + this.setData({ + protocolShow: false, + }); + }, //鏌ョ湅涓洪�氳繃鍘熷洜 previewReason() { this.setData({ reasonTxtShow: true, + }); + }, + + onCloseReasonTxt() { + this.setData({ + reasonTxtShow: false, }); }, @@ -512,7 +542,7 @@ }) return } - if (that.data.teacherInfo.relevantCertificates.length == 0) { + if (that.data.imgPics.length == 0) { wx.showToast({ title: "璇蜂笂浼犲伐浣滆瘉锛�", icon: 'none', @@ -520,7 +550,6 @@ }) return } - console.log(that.data.teacherInfo.fullName) if (that.data.teacherInfo.agree) { if (that.data.topicMessageList.length > 0) { let dataRequests = tool.UpdateworksDataBytool( @@ -529,7 +558,6 @@ that.data.teacherInfo, that.data.imgPics ); - console.log(dataRequests, 4) const data = { description: '', icon: '', @@ -549,13 +577,11 @@ delete basicInfo.worksInfo delete basicInfo.state const userInfo = { - requests: [ - { - data: JSON.stringify(basicInfo), - name: that.data.teacherInfo.fullName + '', - type: 'newTeacherInfo' - } - ] + requests: [{ + data: JSON.stringify(basicInfo), + name: that.data.teacherInfo.fullName + '', + type: 'newTeacherInfo' + }] } app.MG.identity.setAppUserInfo(userInfo).then((res) => { if (res) { @@ -566,7 +592,8 @@ icon: 'none', duration: 1000, }) - that.newGetTeacherInfo() + that.getUserRole() + // that.newGetTeacherInfo() } }) } @@ -586,13 +613,11 @@ delete basicInfo.worksInfo delete basicInfo.state const userInfo = { - requests: [ - { - data: JSON.stringify(basicInfo), - name: that.data.teacherInfo.fullName + '', - type: 'teacherInfo' - } - ] + requests: [{ + data: JSON.stringify(basicInfo), + name: that.data.teacherInfo.fullName + '', + type: 'teacherInfo' + }] } app.MG.identity.setAppUserInfo(userInfo).then((res) => { app.MG.ugc.newTopicMessage(data).then(() => { @@ -602,7 +627,8 @@ icon: 'none', duration: 1000, }) - that.newGetTeacherInfo() + // that.newGetTeacherInfo() + that.getUserRole() } }) }) @@ -621,14 +647,15 @@ * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { + if (wx.getStorageSync(app.config.tokenKey)) { + this.getUserRole() + } }, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ - onReachBottom() { - - }, + onReachBottom() {}, /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� -- Gitblit v1.9.1