From aff8d054df4a638f399dc8f15d98c19b9c9aa785 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期二, 29 四月 2025 10:11:25 +0800 Subject: [PATCH] 扫码视频播放 --- packageDomain/pages/teacherCertification/index.js | 729 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 722 insertions(+), 7 deletions(-) diff --git a/packageDomain/pages/teacherCertification/index.js b/packageDomain/pages/teacherCertification/index.js index 358d636..df343fc 100644 --- a/packageDomain/pages/teacherCertification/index.js +++ b/packageDomain/pages/teacherCertification/index.js @@ -1,17 +1,63 @@ +const app = getApp(); +import SparkMD5 from 'spark-md5' +import tool from "../../../assets/js/toolClass.js"; +import { + getTopicMsgCmsItemFile +} from '../../../assets/js/middleGround/tool.js'; +import FormData from '../../../utils/formdata/index.js'; +import { + loginInfo +} from '../../../assets/js/login'; Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { - + teacherInfo: { + schoolName: '', //瀛︽牎鍚嶇О + fullName: '', //濮撳悕 + positionalTitle: '', //鑱岀О + courseName: '', //浠昏鏁欑▼ + phone: '', //鑱旂郴鐢佃瘽 + telphone: '', //搴ф満 + email: '', //鑱旂郴閭 + detailedAddress: '', //閫氳鍦板潃 + relevantCertificates: [], //鐩稿叧璇佷欢 + state: '', //瀹℃牳鐘舵�侀粯璁ゅ緟瀹℃牳 + agree: false + }, + teachPosts: [], + teachText: '', + teachVisible: false, + phoneError: false, + telphoneError: false, + emailError: false, + topicMessageList: [], + topicId: "", + worksInfo: [], + userId: '', + imgPics: [], + file: "", + imgs: [], + protocolTxt: '', //鏁欏笀鍗忚 + protocolShow: false, + editState: true, + reasonTxt: "", + reasonTxtShow: false, + skeletonLoding: true, + isIos: wx.getSystemInfoSync().platform === 'ios', + keyboardHeight: 0 }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ - onLoad(options) { - console.log(options); + onLoad() { + //鑾峰彇鑱岀О + this.getpositionalTitle(); + this.getAgreement(); + }, /** @@ -25,6 +71,21 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { + // 妫�鏌ョ櫥褰曠姸鎬� + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + loginInfo(app, (data) => { + if (data) { + this.getUserRole() + } else { + wx.switchTab({ + url: '/pages/home/home', + }) + } + }) + } else { + this.getUserRole() + } }, @@ -41,20 +102,674 @@ onUnload() { }, + getUserRole() { + app.MG.identity.getCurrentAppUser().then((res) => { + if (res) { + this.getType() + this.setData({ + 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 defaultUser = {}; + if (teacherRole && teacherInfos) { + defaultUser = { + ...teacherInfos, + nickName: nickNameData && JSON.parse(nickNameData.data).nickName ? JSON.parse(nickNameData.data).nickName : WeChatInfo ? WeChatInfo.name : '', + icon: nickNameData && JSON.parse(nickNameData.data).icon != "" ? JSON.parse(nickNameData.data).icon : WeChatInfo ? WeChatInfo.icon : '', + userId: res.userId, + role: 'Teacher', + roleId: teacherRole.role.id, + } + + } else if (WeChatInfo) { + defaultUser = { + ...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, + } + } + wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); + } + }) + }, + //鑾峰彇瀛楁 + getType() { + app.MG.resource.getCmsTypeByRefCode({ + refCodes: ['jsek_teacherCertification'] + }).then((res) => { + this.setData({ + worksInfo: res[0].cmsTypeLinks[0].children, + }) + this.newGetTeacherInfo() + }) + }, + + + //鑾峰彇鏁欏笀鐘舵�� + newGetTeacherInfo() { + let that = this; + const data = { + start: 0, + size: 10, + topicIdOrRefCode: 'teacherRoleApproval', + appRefCode: app.config.appRefCode, + sort: { + type: 'Desc', + field: 'CreateDate' + } + } + app.MG.ugc.getTopicMessageList(data).then((res) => { + try { + that.setData({ + imgPics: [], + }) + const resData = res.datas.find((i) => i.appUserCreator.userId === that.data.userId) + if (resData) { + if (resData.state == 'WaitAudit') { + that.setData({ + editState: false, + }) + } else { + that.setData({ + editState: true, + }) + } + let info = getTopicMsgCmsItemFile(that.data.worksInfo, resData.cmsItemDataList) + that.setData({ + 'teacherInfo.fullName': info.fullName, + 'teacherInfo.schoolName': info.schoolName, + 'teacherInfo.positionalTitle': info.positionalTitle, + 'teacherInfo.courseName': info.courseName, + 'teacherInfo.phone': info.phone, + 'teacherInfo.telphone': info.telphone ? info.telphone : '', + 'teacherInfo.email': info.email, + 'teacherInfo.detailedAddress': info.detailedAddress ? info.detailedAddress : '', + 'teacherInfo.relevantCertificates': info.relevantCertificates, + 'teacherInfo.agree': true, + 'teacherInfo.state': resData.state, + topicId: resData.id, + topicMessageList: resData.cmsItemDataList, + teachText: info.positionalTitle, + skeletonLoding: false, + }) + if (resData.feedBack != null) { + that.setData({ + reasonTxt: JSON.parse(resData.feedBack).reason, + }) + } + if (that.data.teacherInfo.relevantCertificates.length > 0) { + let arr = []; + 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, + imgUrl: ele.file.imgUrl + } + arr.push(imgObj); + that.setData({ + imgPics: arr, + }); + }) + } else { + let imgObj = { + md5: that.data.teacherInfo.relevantCertificates, + linkType: 'LinkFile', + linkProtectType: 'Public', + 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); + that.setData({ + imgPics: arr, + }); + } + } + + } else { + that.setData({ + skeletonLoding: false, + }); + } + } catch (error) {} + }) + }, + //鑾峰彇鑱岀О + getpositionalTitle() { + const data = { + refCodes: ['positionalTitle'] + } + app.MG.store.getProductTypeField(data).then((res) => { + try { + let list = res[0] + let options = JSON.parse(list.config).option + options.forEach((item) => { + item.label = item.name; + }) + this.setData({ + teachPosts: options, + }) + } catch (error) { + + } + }) + }, + 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_teacherCertificationAgreement') + this.setData({ + protocolTxt: data ? data.content : '鏆傛棤鍗忚', + }) + } catch (error) { + this.setData({ + protocolTxt: '鏆傛棤鍗忚', + }) + } + }) + }, + //瀛︽牎鍚嶇О + onSchoolNameInput(e) { + this.setData({ + "teacherInfo.schoolName": e.detail.value, + }); + }, + //濮撳悕 + onFullNameInput(e) { + this.setData({ + "teacherInfo.fullName": e.detail.value, + }); + }, + // 浠绘暀璇剧▼ + onCourseNameInput(e) { + this.setData({ + "teacherInfo.courseName": e.detail.value, + }); + }, + //璇︾粏鍦板潃 + onAddressInput(e) { + this.setData({ + "teacherInfo.detailedAddress": e.detail.value, + }); + }, + + + //閫夋嫨鑱岀О + onTeachPicker() { + this.setData({ + teachVisible: true + }); + }, + onPickerChange(e) { + const { + label + } = e.detail; + this.setData({ + teachVisible: false, + teachText: label[0], + 'teacherInfo.positionalTitle': label[0], + }); + }, + onPickerCancel(e) { + this.setData({ + 'teacherInfo.positionalTitle': '', + teachVisible: false, + }); + }, + //杈撳叆鎵嬫満鍙� + onPhoneInput(e) { + const { + phoneError + } = this.data; + if (e.detail.value) { + 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({ + phoneError: !isPhoneNumber, + "teacherInfo.phone": e.detail.value, + }); + } + } else { + this.setData({ + phoneError: false, + }); + } + }, + //杈撳叆搴ф満 + onTelphoneInput(e) { + const { + telphoneError + } = this.data; + if (e.detail.value) { + const isPhoneNumber = /^0\d{2}-\d{8}$|^0\d{3}-\d{7}$/.test(e.detail.value); + if (telphoneError === isPhoneNumber) { + this.setData({ + telphoneError: !isPhoneNumber, + "teacherInfo.telphone": e.detail.value, + }); + } + } else { + this.setData({ + telphoneError: false, + }); + } + }, + onEmailInput(e) { + const { + emailError + } = this.data; + if (e.detail.value) { + 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({ + emailError: !isPhoneNumber, + "teacherInfo.email": e.detail.value, + }); + } + } else { + this.setData({ + emailError: false, + }); + } + }, + // 涓婁紶鍥剧墖浜嬩欢 + chooseImg(e) { + var that = this; + if (that.data.imgPics.length == 4) { + wx.showToast({ + title: "宸ヤ綔璇佹枃浠朵笉瓒呰繃5涓紒", + icon: 'none', + duration: 1000, + }) + return + } + wx.chooseMedia({ + count: 1, + sizeType: ['original', 'compressed'], // 鍙互鎸囧畾鏄師鍥捐繕鏄帇缂╁浘锛岄粯璁や簩鑰呴兘鏈� + sourceType: ['album', 'camera'], // 鍙互鎸囧畾鏉ユ簮鏄浉鍐岃繕鏄浉鏈猴紝榛樿浜岃�呴兘鏈� + success: function (res) { + // 杩斿洖閫夊畾鐓х墖鐨勬湰鍦版枃浠惰矾寰勫垪琛紝tempFilePath涔熷彲浠ヤ綔涓篿mg鏍囩鐨剆rc灞炴�ф樉绀哄浘鐗� + 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, + }); + } + } else { + reject('杩愯鏃堕敊璇�,璇风◢鍚庡啀璇�'); + } + } + }) + }) + } else { + wx.showToast({ + title: "褰撳墠鏂囦欢宸蹭笂浼狅紝璇峰嬁閲嶅鎿嶄綔锛�", + icon: 'none', + duration: 1000, + }) + } + } + }) + + } + }); + }, + // 鍒犻櫎鍥剧墖 + deleteImg(e) { + var imgs = this.data.imgPics; + var index = e.currentTarget.dataset.index; + imgs.splice(index, 1); + this.setData({ + imgPics: imgs + }); + }, + // 棰勮鐜板満鍥剧墖 + previewImg(e) { + //鑾峰彇褰撳墠鍥剧墖鐨勪笅鏍� + var index = e.currentTarget.dataset.index; + //鎵�鏈夊浘鐗� + let imgs = []; + this.data.imgPics.forEach(item => { + imgs.push(item.url) + }) + wx.previewImage({ + //褰撳墠鏄剧ず鍥剧墖 + current: imgs[index], + //鎵�鏈夊浘鐗� + urls: imgs + }) + }, + onChange() { + if (this.data.teacherInfo.agree) { + this.setData({ + 'teacherInfo.agree': false, + }); + } else { + this.setData({ + 'teacherInfo.agree': true, + }); + } + + }, + //鏌ョ湅鏁欏笀璁よ瘉鏈嶅姟 + viewContent() { + this.setData({ + protocolShow: true, + }); + }, + onVisibleChange(e) { + this.setData({ + protocolShow: e.detail.visible, + reasonTxtShow: e.detail.visible + }); + }, + onCloseProtocol() { + this.setData({ + protocolShow: false, + }); + }, + + //鏌ョ湅涓洪�氳繃鍘熷洜 + previewReason() { + this.setData({ + reasonTxtShow: true, + }); + }, + + onCloseReasonTxt() { + this.setData({ + reasonTxtShow: false, + }); + }, + + submit() { + let that = this; + if (!that.data.teacherInfo.schoolName) { + wx.showToast({ + title: "璇峰~鍐欏鏍″悕绉帮紒", + icon: 'none', + duration: 1000, + }) + return + } + if (!that.data.teacherInfo.fullName) { + wx.showToast({ + title: "璇峰~鍐欑湡瀹炲鍚嶏紒", + icon: 'none', + duration: 1000, + }) + return + } + if (!that.data.teacherInfo.courseName) { + wx.showToast({ + title: "璇峰~鍐欎换鏁欒绋嬶紒", + icon: 'none', + duration: 1000, + }) + return + } + if (!that.data.teacherInfo.phone) { + wx.showToast({ + title: "璇峰~鍐欒仈绯荤數璇濓紒", + icon: 'none', + duration: 1000, + }) + return + } + if (!that.data.teacherInfo.email) { + wx.showToast({ + title: "璇峰~鍐欓偖绠憋紒", + icon: 'none', + duration: 1000, + }) + return + } + if (!that.data.teacherInfo.detailedAddress) { + wx.showToast({ + title: "璇峰~鍐欒缁嗗湴鍧�锛�", + icon: 'none', + duration: 1000, + }) + return + } + if (that.data.imgPics.length == 0) { + wx.showToast({ + title: "璇蜂笂浼犲伐浣滆瘉锛�", + icon: 'none', + duration: 1000, + }) + return + } + if (that.data.teacherInfo.agree) { + if (that.data.topicMessageList.length > 0) { + let dataRequests = tool.UpdateworksDataBytool( + that.data.worksInfo, + that.data.topicMessageList, + that.data.teacherInfo, + that.data.imgPics + ); + const data = { + description: '', + icon: '', + id: that.data.topicId, + topicIdOrRefCode: 'teacherRoleApproval', + name: that.data.teacherInfo.fullName + '', + content: '', + state: 'WaitAudit', + type: 'teacherRegister', + newDataRequests: dataRequests.newData, + updateDataRequests: dataRequests.updateData, + delDataRequest: { + ids: [] + } + } + let basicInfo = JSON.parse(JSON.stringify(that.data.teacherInfo)) + delete basicInfo.worksInfo + delete basicInfo.state + const userInfo = { + requests: [{ + data: JSON.stringify(basicInfo), + name: that.data.teacherInfo.fullName + '', + type: 'newTeacherInfo' + }] + } + app.MG.identity.setAppUserInfo(userInfo).then((res) => { + if (res) { + app.MG.ugc.updateTopicMessage(data).then(() => { + if (res !== false) { + wx.showToast({ + title: "鎻愪氦鎴愬姛锛佽绛夊緟瀹℃牳...", + icon: 'none', + duration: 1000, + }) + that.getUserRole() + // that.newGetTeacherInfo() + } + }) + } + }) + } else { + const data = { + topicIdOrRefCode: 'teacherRoleApproval', + name: that.data.teacherInfo.fullName + '', + content: '', + state: 'WaitAudit', + type: 'teacherRegister', + cmsTypeRefCode: 'jsek_teacherCertification', + newDataListRequest: tool.worksDataBytool(that.data.worksInfo, that.data.teacherInfo, that.data.imgPics) + } + + let basicInfo = JSON.parse(JSON.stringify(that.data.teacherInfo)) + delete basicInfo.worksInfo + delete basicInfo.state + const userInfo = { + 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(() => { + if (res !== false) { + wx.showToast({ + title: "鎻愪氦鎴愬姛锛佽绛夊緟瀹℃牳...", + icon: 'none', + duration: 1000, + }) + // that.newGetTeacherInfo() + that.getUserRole() + } + }) + }) + } + } else { + wx.showToast({ + title: "璇峰悓鎰忋�婃暀甯堣璇佹湇鍔℃潯娆俱�嬶紒", + icon: 'none', + duration: 1000, + }) + } + + }, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { - + if (wx.getStorageSync(app.config.tokenKey)) { + this.getUserRole() + } + }, + // 鐩戝惉椤甸潰杞敭鐩樺脊璧锋墜鍔ㄦ帹鍔ㄩ〉闈� + bindkeyboardheightchange(e) { + // 鍙ios 澶勭悊 + if (!this.data.isIos === 'ios') { + return + } + // 閿洏楂樺害 + const height = e.detail.height; + const className = e.target.dataset.class; + if (height === 0) { + this.scrollToInput(0); + return; + } + try { + this.createSelectorQuery() + .select(`.${className}`) + .boundingClientRect((res) => { + // 鍙娇鐢ㄧ獥鍙i珮搴� + const windowHeight = wx.getSystemInfoSync().windowHeight; + // 闄ゅ幓閿洏鐨勫墿浣欓珮搴� + let restHeight = windowHeight - height; + // 鍏冪礌宸︿笅瑙掑潗鏍� + let bottom = res.bottom; + // 鍙湁褰撳厓绱犺杞敭鐩樿鐩栫殑鏃跺�欐墠涓婃帹椤甸潰 + if (bottom <= restHeight) return; + // 鐜伴樁娈甸渶瑕佹粴鍔ㄧ殑澶у皬 + let scrollTop = bottom - restHeight; + this.scrollToInput(height, scrollTop); + }) + .exec(); + } catch (error) {} }, + // 鑾峰彇椤甸潰婊氬姩鏉′綅缃� + getScrollOffset() { + return new Promise((resolve) => { + try { + wx.createSelectorQuery() + .selectViewport() + .scrollOffset((res) => { + resolve(res.scrollTop); + }) + .exec(); + } catch (error) { + resolve(0); + } + }); + }, + + // 鐩戝惉椤甸潰杞敭鐩樺脊璧锋墜鍔ㄦ帹鍔ㄩ〉闈� + scrollToInput(keyboardHeight, scrollTop) { + this.setData({ + keyboardHeight, + }); + if (scrollTop) { + try { + this.getScrollOffset().then((lastScrollTop) => { + wx.pageScrollTo({ + // 濡傛灉宸茬粡瀛樺湪婊氬姩锛屽湪姝ゅ熀纭�涓婄户缁粴 + scrollTop: lastScrollTop ? lastScrollTop + scrollTop : scrollTop, + duration: 300, + }); + }); + } catch (error) {} + } + }, + changeParam(e) { + this.scrollToInput(0); + }, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ - onReachBottom() { - - }, + onReachBottom() {}, /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� -- Gitblit v1.9.1