From a9abe435bdc23bda340c84f45deb363eccf907a7 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期二, 02 四月 2024 10:06:17 +0800 Subject: [PATCH] 个人中心 --- packageDomain/pages/teacherCertification/index.js | 198 ++++++++++++++++++++++++++++--------------------- 1 files changed, 114 insertions(+), 84 deletions(-) diff --git a/packageDomain/pages/teacherCertification/index.js b/packageDomain/pages/teacherCertification/index.js index c245a0a..afaf20a 100644 --- a/packageDomain/pages/teacherCertification/index.js +++ b/packageDomain/pages/teacherCertification/index.js @@ -1,8 +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({ /** @@ -40,16 +45,25 @@ editState: true, reasonTxt: "", reasonTxtShow: false, + skeletonLoding: true, }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad() { + //鑾峰彇鑱岀О this.getpositionalTitle(); this.getAgreement(); - - if (wx.getStorageSync(app.config.tokenKey)) { + // 妫�鏌ョ櫥褰曠姸鎬� + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + loginInfo(app, (data) => { + if (data) { + this.getUserRole() + } + }) + } else { this.getUserRole() } }, @@ -86,64 +100,51 @@ if (res) { this.getType() this.setData({ - userId: res.userId + userId: res.userId, + skeletonLoding: true, }) + 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 ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name, + icon: nickNameData && JSON.parse(nickNameData.data).icon ? JSON.parse(nickNameData.data).icon : 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 ? JSON.parse(nickNameData.data).nickName : WeChatInfo.name, + icon: nickNameData && JSON.parse(nickNameData.data).icon ? 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 ? wechatInfo.name : studentInfo.nickName, - 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'] }).then((res) => { - console.log(res) this.setData({ worksInfo: res[0].cmsTypeLinks[0].children, }) this.newGetTeacherInfo() }) + }, + //鑾峰彇鏁欏笀鐘舵�� newGetTeacherInfo() { + let that = this; const data = { start: 0, size: 10, @@ -156,23 +157,22 @@ } app.MG.ugc.getTopicMessageList(data).then((res) => { try { - this.setData({ + that.setData({ imgPics: [], }) - const resData = res.datas.find((i) => i.appUserCreator.userId === this.data.userId) + const resData = res.datas.find((i) => i.appUserCreator.userId === that.data.userId) if (resData) { if (resData.state == 'WaitAudit') { - this.setData({ + that.setData({ editState: false, }) } else { - this.setData({ + that.setData({ editState: true, }) } - let info = getTopicMsgCmsItemFile(this.data.worksInfo, resData.cmsItemDataList) - console.log(info) - this.setData({ + let info = getTopicMsgCmsItemFile(that.data.worksInfo, resData.cmsItemDataList) + that.setData({ 'teacherInfo.fullName': info.fullName, 'teacherInfo.schoolName': info.schoolName, 'teacherInfo.positionalTitle': info.positionalTitle, @@ -187,48 +187,53 @@ topicId: resData.id, topicMessageList: resData.cmsItemDataList, teachText: info.positionalTitle, + skeletonLoding: false, }) if (resData.feedBack != null) { - this.setData({ + that.setData({ reasonTxt: JSON.parse(resData.feedBack).reason, }) } - if (this.data.teacherInfo.relevantCertificates.length > 0) { + if (that.data.teacherInfo.relevantCertificates.length > 0) { let arr = []; - if (typeof this.data.teacherInfo.relevantCertificates == 'object') { - this.data.teacherInfo.relevantCertificates.forEach((ele) => { + if (typeof that.data.teacherInfo.relevantCertificates == 'object') { + that.data.teacherInfo.relevantCertificates.forEach((ele) => { let imgObj = { 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({ + that.setData({ imgPics: arr, }); }) } else { let imgObj = { - md5: this.data.teacherInfo.relevantCertificates, + md5: that.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=` + that.data.teacherInfo.relevantCertificates, + imgUrl: app.config.requestCtx + `/file/GetPreViewImage?md5=` + that.data.teacherInfo.relevantCertificates, } arr.push(imgObj); - this.setData({ + that.setData({ imgPics: arr, }); } } + } else { + that.setData({ + skeletonLoding: false, + }); } - } catch (error) { - } + } catch (error) {} }) }, - + //鑾峰彇鑱岀О getpositionalTitle() { const data = { refCodes: ['positionalTitle'] @@ -296,14 +301,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) { @@ -314,7 +323,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({ @@ -325,7 +336,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({ @@ -335,7 +348,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,13 +362,20 @@ // 涓婁紶鍥剧墖浜嬩欢 chooseImg(e) { var that = this; + if (that.data.imgPics.length == 4) { + wx.showToast({ + title: "宸ヤ綔璇佹枃浠朵笉瓒呰繃5涓紒", + icon: 'none', + duration: 1000, + }) + return + } wx.chooseMedia({ - // count: 1, // 榛樿9 + count: 1, sizeType: ['original', 'compressed'], // 鍙互鎸囧畾鏄師鍥捐繕鏄帇缂╁浘锛岄粯璁や簩鑰呴兘鏈� sourceType: ['album', 'camera'], // 鍙互鎸囧畾鏉ユ簮鏄浉鍐岃繕鏄浉鏈猴紝榛樿浜岃�呴兘鏈� success: function (res) { // 杩斿洖閫夊畾鐓х墖鐨勬湰鍦版枃浠惰矾寰勫垪琛紝tempFilePath涔熷彲浠ヤ綔涓篿mg鏍囩鐨剆rc灞炴�ф樉绀哄浘鐗� - console.log(res.tempFiles[0], 12); wx.getFileSystemManager().readFile({ filePath: res.tempFiles[0].tempFilePath, //閫夋嫨鍥剧墖杩斿洖鐨勭浉瀵硅矾寰� // encoding: 'binary', //缂栫爜鏍煎紡 @@ -387,14 +409,14 @@ data: data.buffer, success(res1) { if (res1.statusCode == 200) { - resolve(res1.data); if (res1.data) { + resolve(res1.data); + if (res1.data) { let arr = []; let imgObj = { md5: md5, linkType: 'LinkFile', linkProtectType: 'Public', - url: - app.config.requestCtx + `/file/GetPreViewImage?md5=` + md5, + url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + md5, imgUrl: res.tempFiles[0].tempFilePath } arr = [...that.data.imgPics, ...[imgObj]]; @@ -448,7 +470,6 @@ }) }, onChange() { - console.log(this.data.teacherInfo.agree, 12) if (this.data.teacherInfo.agree) { this.setData({ 'teacherInfo.agree': false, @@ -472,11 +493,22 @@ reasonTxtShow: e.detail.visible }); }, + onCloseProtocol() { + this.setData({ + protocolShow: false, + }); + }, //鏌ョ湅涓洪�氳繃鍘熷洜 previewReason() { this.setData({ reasonTxtShow: true, + }); + }, + + onCloseReasonTxt() { + this.setData({ + reasonTxtShow: false, }); }, @@ -522,7 +554,7 @@ }) return } - if (that.data.teacherInfo.relevantCertificates.length == 0) { + if (that.data.imgPics.length == 0) { wx.showToast({ title: "璇蜂笂浼犲伐浣滆瘉锛�", icon: 'none', @@ -538,7 +570,6 @@ that.data.teacherInfo, that.data.imgPics ); - console.log(dataRequests, 4) const data = { description: '', icon: '', @@ -558,13 +589,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) { @@ -575,7 +604,8 @@ icon: 'none', duration: 1000, }) - that.newGetTeacherInfo() + that.getUserRole() + // that.newGetTeacherInfo() } }) } @@ -595,13 +625,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(() => { @@ -611,7 +639,8 @@ icon: 'none', duration: 1000, }) - that.newGetTeacherInfo() + // that.newGetTeacherInfo() + that.getUserRole() } }) }) @@ -630,14 +659,15 @@ * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { + if (wx.getStorageSync(app.config.tokenKey)) { + this.getUserRole() + } }, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ - onReachBottom() { - - }, + onReachBottom() {}, /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� -- Gitblit v1.9.1