From 1daa00227f03bc3a370dc1311b7166df17368929 Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期三, 20 三月 2024 16:15:46 +0800 Subject: [PATCH] Merge refs/remotes/origin/master into refs/heads/master --- pages/home/home.js | 11 packageDomain/pages/sampleBookList/index.wxml | 4 packageDomain/pages/sampleBookList/index.wxss | 48 + pages/testLogin/index.js | 2 pages/personalCenter/components/user-center-card/index.wxml | 38 packageDomain/pages/teacherCertification/index.js | 371 ++++++++++-- pages/personalCenter/components/user-center-card/index.wxss | 17 pages/personalCenter/index.wxml | 25 packageDomain/pages/teacherCertification/index.wxss | 64 + utils/formdata/mimeMap.js | 346 +++++++++++ packageDomain/pages/teacherCertification/index.wxml | 57 + assets/js/middleGround/api/file.js | 12 assets/js/middleGround/api/job.js | 2 pages/personalCenter/index.wxss | 23 packageDomain/pages/sampleBookList/index.js | 138 +++- pages/home/home.wxml | 5 pages/personalCenter/index.js | 168 ++++- pages/home/home.wxss | 28 packagePersonal/pages/userSetting/index.wxml | 2 packagePersonal/pages/userSetting/index.wxss | 1 pages/personalCenter/index.json | 3 pages/personalCenter/components/user-center-card/index.js | 3 packageDomain/pages/sampleBookList/applicationForm/index.js | 48 utils/formdata/index.js | 145 ++++ packagePersonal/pages/userSetting/index.js | 66 ++ packageDomain/pages/sampleBookList/applicationForm/index.wxml | 5 app.json | 3 assets/js/toolClass.js | 115 +- packagePersonal/pages/userSetting/index.json | 3 packageDomain/pages/teacherCertification/index.json | 3 30 files changed, 1,445 insertions(+), 311 deletions(-) diff --git a/app.json b/app.json index 294a29e..c3c65c8 100644 --- a/app.json +++ b/app.json @@ -40,7 +40,8 @@ "pages/sampleBooks/index", "pages/personalCenter/publishBooks/index", "pages/feedBack/index", - "pages/aboutUs/index" + "pages/aboutUs/index", + "pages/userSetting/index" ] }, { diff --git a/assets/js/middleGround/api/file.js b/assets/js/middleGround/api/file.js index 5edfbd4..918ae65 100644 --- a/assets/js/middleGround/api/file.js +++ b/assets/js/middleGround/api/file.js @@ -36,10 +36,14 @@ }, //涓婁紶鏂囦欢 upload(data) { + console.log(data) return request({ url: "/file/api/ApiUpload", method: "post", - data + header: { + 'content-type': data.contentType, + }, + data: data.buffer, }); }, @@ -71,13 +75,13 @@ }, // 鎵归噺涓嬭浇get - getDownloadFiles (params) { + getDownloadFiles(params) { return request({ url: '/file/api/ApiGetDownloadFiles', method: 'GET', responseType: 'blob', - headers:{ - 'md5s':params + headers: { + 'md5s': params } }); } diff --git a/assets/js/middleGround/api/job.js b/assets/js/middleGround/api/job.js index 2f30f78..97f9df3 100644 --- a/assets/js/middleGround/api/job.js +++ b/assets/js/middleGround/api/job.js @@ -14,7 +14,7 @@ }, newSession(data) { - let token = wx.getStorageSync(config.tokenKey) ? wx.getStorageSync(config.tokenKey) : '' + let token = wx.getStorageSync(tokenKey) ? wx.getStorageSync(tokenKey) : '' return request({ url: token ? "/job/api/AppUserNewSession" : "/job/api/NewSession", method: "post", diff --git a/assets/js/toolClass.js b/assets/js/toolClass.js index 0cbb183..c173046 100644 --- a/assets/js/toolClass.js +++ b/assets/js/toolClass.js @@ -203,46 +203,71 @@ } export function UpdateworksDataBytool(initData, res, value, linkList) { - let arr = [] + let arr = []; + let newArr = []; for (let i = 0; i < initData.length; i++) { - const ele = initData[i] + const ele = initData[i]; for (let j = 0; j < res.length; j++) { - const item = res[j] + const item = res[j]; if (item.sequenceNum == ele.sequenceNum) { - item.refCode = ele.typeField.refCode + item.refCode = ele.typeField.refCode; } } } - res.forEach((item) => { - const obj = { - baseType: item.baseType, - order: 0, - id: item.id, - typeFieldId: item.fieldId, - sequenceNum: item.sequenceNum, - setDataAndFileLinkListRequest: [] - } - for (let k in value) { - if (item.refCode === k) { - if (typeof value[k] == 'object') { - obj.strValue = JSON.stringify(value[k][0]) - obj.setDataAndFileLinkListRequest = linkList - } else { - if (obj.baseType === 'String') { - obj.strValue = value[k] + '' - } else if (obj.baseType === 'Text') { - obj.textValue = value[k] + '' + initData.forEach((citem) => { + const updateOldData = res.find((f) => f.sequenceNum == citem.sequenceNum); + if (updateOldData) { + const obj = { + baseType: citem.typeField.baseType, + order: 0, + id: updateOldData.id, + typeFieldId: citem.typeField.id, + sequenceNum: citem.sequenceNum, + setDataAndFileLinkListRequest: [], + }; + for (let k in value) { + if (citem.typeField.refCode === k) { + if (typeof value[k] == "object" && k != "region") { + obj.strValue = JSON.stringify(linkList); + obj.setDataAndFileLinkListRequest = linkList; + } else if (typeof value[k] == "object" && k == "region") { + obj.strValue = value[k]?.join("/"); + obj.setDataAndFileLinkListRequest = [{ area: value[k] }]; } else { - obj.strValue = value[k] + '' + obj.strValue = value[k].toString(); } } } + if (obj.strValue) { + arr.push(obj); + } + } else { + const newObj = { + baseType: citem.typeField.baseType, + order: 0, + typeFieldId: citem.typeField.id, + sequenceNum: citem.sequenceNum, + setDataAndFileLinkListRequest: [], + }; + for (let k in value) { + if (citem.typeField.refCode === k) { + if (typeof value[k] == "object") { + newObj.strValue = JSON.stringify(linkList); + newObj.setDataAndFileLinkListRequest = linkList; + } else { + newObj.strValue = value[k].toString(); + } + } + } + if (newObj.strValue) { + newArr.push(newObj); + } } - // if (obj.strValue) { - arr.push(obj) - // } - }) - return arr + }); + return { + updateData: arr, + newData: newArr, + }; } export function download(url) { @@ -294,36 +319,12 @@ return uuid.join('') } -export function getFileMd5(file, chunkSize) { +export function getFileMd5(file) { return new Promise((resolve, reject) => { - let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice - let chunks = Math.ceil(file.size / chunkSize) - let currentChunk = 0 let spark = new SparkMD5.ArrayBuffer() - let fileReader = new FileReader() - fileReader.onload = function (e) { - spark.append(e.target.result) - currentChunk++ - if (currentChunk < chunks) { - loadNext() - } else { - const md5 = spark.end() - resolve(md5) - } - } - fileReader.onerror = function (e) { - reject(e) - } - - function loadNext() { - let start = currentChunk * chunkSize - let end = start + chunkSize - if (end > file.size) { - end = file.size - } - fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)) - } - loadNext() + spark.append(file) + const md5 = spark.end(false) + resolve(md5) }) } diff --git a/packageDomain/pages/sampleBookList/applicationForm/index.js b/packageDomain/pages/sampleBookList/applicationForm/index.js index 8cd51e5..92d0e54 100644 --- a/packageDomain/pages/sampleBookList/applicationForm/index.js +++ b/packageDomain/pages/sampleBookList/applicationForm/index.js @@ -36,26 +36,22 @@ }) if (this.data.userInfo.role == 'Teacher') { this.setData({ - teacherInfo: { - schoolName: JSON.parse(this.data.userInfo.data).schoolName, - courseName: JSON.parse(this.data.userInfo.data).courseName, - }, - contactInfo: { - fullName: JSON.parse(this.data.userInfo.data).fullName, - phone: JSON.parse(this.data.userInfo.data).phone, - detailedAddress: JSON.parse(this.data.userInfo.data).detailedAddress - } + 'teacherInfo.schoolName': JSON.parse(this.data.userInfo.data).schoolName, + 'teacherInfo.courseName': JSON.parse(this.data.userInfo.data).courseName, + 'contactInfo.fullName': JSON.parse(this.data.userInfo.data).fullName, + 'contactInfo.phone': JSON.parse(this.data.userInfo.data).phone, + 'contactInfo.detailedAddress': JSON.parse(this.data.userInfo.data).detailedAddress, }) } if (wx.getStorageSync("paperBookList")) { this.setData({ - paperBookList: JSON.parse(wx.getStorageSync("paperBookList")), - bookList: JSON.parse(wx.getStorageSync("paperBookList")) + paperBookList: wx.getStorageSync("paperBookList"), + bookList: wx.getStorageSync("paperBookList") }) } if (wx.getStorageSync("electronicBookList")) { this.setData({ - electronicBookList: JSON.parse(wx.getStorageSync("electronicBookList")) + electronicBookList: wx.getStorageSync("electronicBookList") }) } this.getSelectBookCount(); @@ -90,9 +86,7 @@ app.MG.resource.getCmsTypeByRefCode({ refCodes: ['jsek_electronicSampleBook'] }).then((res) => { this.setData({ description: res[0].description, - teacherInfo: { - workInfo: res[0].cmsTypeLinks[0].children - }, + 'teacherInfo.workInfo': res[0].cmsTypeLinks[0].children, }) }) }, @@ -104,9 +98,7 @@ if (res && res.length > 0) { this.setData({ description: res[0].description, - teacherInfo: { - workInfo: res[0].cmsTypeLinks[0].children - }, + 'teacherInfo.workInfo': res[0].cmsTypeLinks[0].children, }) } }) @@ -173,7 +165,7 @@ } applyInfo = { ticketRefCodeOrGuid: 'electronicSampleBookapplyNum', - roleId: userStore.userInfo.roleId, + roleId: that.data.userInfo.roleId, refType: 'applyBook' } } else { @@ -257,25 +249,27 @@ success: function (res) { if (res.confirm) { if (that.data.active == '1') { - that.data.electronicBookList.forEach((obj, index) => { + let eList = that.data.electronicBookList; + eList.forEach((obj, index) => { if (obj.id == item.id) { - that.data.electronicBookList.splice(index, 1); + eList.splice(index, 1); } }) that.setData({ - bookList: that.data.electronicBookList + bookList: eList }) - wx.setStorageSync("electronicBookList", that.data.electronicBookList); + wx.setStorageSync("electronicBookList", eList); } else { - that.data.paperBookList.forEach((obj, index) => { + let pList = that.data.paperBookList; + pList.forEach((obj, index) => { if (obj.id == item.id) { - that.data.paperBookList.splice(index, 1); + pList.splice(index, 1); } }) that.setData({ - bookList: this.data.paperBookList + bookList: pList }) - wx.setStorageSync("paperBookList", that.data.paperBookList); + wx.setStorageSync("paperBookList", pList); } } else if (res.cancel) { } diff --git a/packageDomain/pages/sampleBookList/applicationForm/index.wxml b/packageDomain/pages/sampleBookList/applicationForm/index.wxml index 3ce83ea..c6ea8b8 100644 --- a/packageDomain/pages/sampleBookList/applicationForm/index.wxml +++ b/packageDomain/pages/sampleBookList/applicationForm/index.wxml @@ -16,10 +16,11 @@ <t-cell title="宸︽粦鍗曟搷浣�" note="杈呭姪淇℃伅" bordered="{{false}}"> <view class="listItem flex"> <view class="specialSubject-img"> - <image src="{{item.icon}}" mode="aspectFill" class="img" /> + <image src="{{item.icon}}" mode="aspectFill" class="img" wx:if="{{item.icon}}" /> + <image src="/static/images/default-book-img.png" mode="aspectFill" class="img" wx:else="" /> </view> <view class="body-info"> - <view class="name">{{item.name}}</view> + <view class="name">{{item.title}}</view> <view class="author">浣滆�咃細{{item.author}}</view> <view class="author">ISBN:{{item.isbn}}</view> <view class="author">鍑虹増鏃堕棿:{{item.publicationDate}}</view> diff --git a/packageDomain/pages/sampleBookList/index.js b/packageDomain/pages/sampleBookList/index.js index 30be704..c43b0aa 100644 --- a/packageDomain/pages/sampleBookList/index.js +++ b/packageDomain/pages/sampleBookList/index.js @@ -63,6 +63,7 @@ electronicBookList: [], //鏍蜂功鍗曠數瀛愪功 paperBookCount: 0, //绾歌川涔﹀墿浣欐鏁� ebookCount: 0, //鐢靛瓙涔﹀墿浣欐鏁� + num: 0, }, /** @@ -117,7 +118,7 @@ }) } this.getIconTypeList(); - this.getBookList(false); + // 鑾峰彇閲嶇偣椤圭洰 this.getProjectList('bookClassification'); //鏂板舰鎬佹暀鏉� @@ -133,14 +134,18 @@ } if (wx.getStorageSync("paperBookList")) { this.setData({ - paperBookList: wx.getStorageSync("paperBookList") + paperBookList: wx.getStorageSync("paperBookList"), }) } if (wx.getStorageSync("electronicBookList")) { this.setData({ - electronicBookList: wx.getStorageSync("electronicBookList") + electronicBookList: wx.getStorageSync("electronicBookList"), }) } + this.setData({ + num: this.data.paperBookList.length + this.data.electronicBookList.length + }) + this.getBookList(false); }, /** @@ -299,7 +304,6 @@ this.setData({ 'newTextBook.options': options, }); - console.log('閲嶇偣椤圭洰', this.data.newTextBook); } }); }, @@ -389,6 +393,7 @@ }) }) } + if (that.data.alreadyElectronicBookList.length > 0) { that.data.alreadyElectronicBookList.forEach((eBook) => { eBook.content.forEach((eBookItem) => { @@ -546,7 +551,6 @@ }, // 鎼滅储鍥句功 searchBook(e) { - console.log(e.detail.value); this.setData({ searchValue: e.detail.value, }); @@ -572,13 +576,15 @@ } } app.MG.ugc.getTopicMessageList(data).then((res) => { + let list = []; res.datas.map((item) => { if (item.content) { item.content = JSON.parse(item.content) } + list.push(item) }) this.setData({ - alreadyPaperBookList: res.datas, + alreadyPaperBookList: list, }); }) }, @@ -596,27 +602,30 @@ } app.MG.ugc.getTopicMessageList(data).then((res) => { let list = [] - res.datas.map((item) => { - if (item.feedBack) { - item.feedBack = JSON.parse(item.feedBack) - if (item.feedBack.endDate) { - let times = new Date(item.feedBack.endDate + ' 23:59:59').getTime() - let currentDate = new Date().getTime() - if (times < currentDate) { - item.isExpiry = true + if (res.datas.length > 0) { + res.datas.map((item) => { + if (item.feedBack) { + item.feedBack = JSON.parse(item.feedBack) + if (item.feedBack.endDate) { + let times = new Date(item.feedBack.endDate + ' 23:59:59').getTime() + let currentDate = new Date().getTime() + if (times < currentDate) { + item.isExpiry = true + } } } - } - if (item.content) { - item.content = JSON.parse(item.content) - } - if (item.state != 'Reject') { - list.push(item) - } - }) - this.setData({ - alreadyElectronicBookList: list, - }); + if (item.content) { + item.content = JSON.parse(item.content) + } + if (item.state != 'Reject') { + list.push(item) + } + }) + this.setData({ + alreadyElectronicBookList: list, + }); + this.getBookList(false); + } }) }, @@ -681,12 +690,12 @@ }) return } - if (item.paperChecked) { - if (this.data.paperBookList.length > 0) { - this.data.paperBookList.forEach((obj, index) => { + let pList = this.data.paperBookList; + if (pList.length > 0) { + pList.forEach((obj, index) => { if (obj.id == item.id) { - this.data.paperBookList.splice(index, 1); + pList.splice(index, 1); } }) } @@ -703,7 +712,11 @@ icon: 'none', duration: 1000, }) - wx.setStorageSync("paperBookList", JSON.stringify(this.data.paperBookList)); + this.setData({ + paperBookList: pList, + num: pList.length + this.data.electronicBookList.length + }) + wx.setStorageSync("paperBookList", JSON.stringify(pList)); return } if (role == 'Teacher') { @@ -757,10 +770,11 @@ return } if (item.electronChecked) { - if (this.data.electronicBookList) { - this.data.electronicBookList.forEach((obj, index) => { + let eList = this.data.electronicBookList; + if (eList.length > 0) { + eList.forEach((obj, index) => { if (obj.id == item.id) { - this.data.electronicBookList.splice(index, 1); + eList.splice(index, 1); } }) } @@ -777,7 +791,11 @@ icon: 'none', duration: 1000, }) - wx.setStorageSync("electronicBookList", JSON.stringify(this.data.electronicBookList)); + this.setData({ + electronicBookList: eList, + num: eList.length + this.data.paperBookList.length + }) + wx.setStorageSync("electronicBookList", eList); return } if (role == 'Teacher') { @@ -830,6 +848,8 @@ } }) } + } else { + item.electronChecked = false } }, getSelectBookCount(item) { @@ -889,16 +909,28 @@ duration: 1000, }) this.setData({ - electronicBookList: [...this.data.electronicBookList, ...[item]] + electronicBookList: [...this.data.electronicBookList, ...[itemAttr]], + num: this.data.electronicBookList.length + this.data.paperBookList.length }) - wx.setStorageSync("electronicBookList", JSON.stringify(this.data.electronicBookList)); + wx.setStorageSync("electronicBookList", this.data.electronicBookList); } else { + let list = this.data.electronicBookList; + list.forEach((obj, index) => { + if (obj.id == item.id) { + list.splice(index, 1); + } + }) item.electronChecked = false wx.showToast({ - title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�", + title: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�", icon: "none", duration: 1000, }) + this.setData({ + electronicBookList: list, + num: list.length + this.data.paperBookList.length + }) + wx.setStorageSync("electronicBookList", list); } } else { wx.showToast({ @@ -907,9 +939,10 @@ duration: 1000, }) this.setData({ - electronicBookList: [...this.data.electronicBookList, ...[item]] + electronicBookList: [itemAttr], + num: 1 + this.data.paperBookList.length }) - wx.setStorageSync("electronicBookList", JSON.stringify(this.data.electronicBookList)); + wx.setStorageSync("electronicBookList", [itemAttr]); } } else { item.electronChecked = false @@ -945,17 +978,28 @@ duration: 1000, }) this.setData({ - paperBookList: [...this.data.paperBookList, ...[item]] + paperBookList: [...this.data.paperBookList, ...[itemAttr]], + num: this.data.paperBookList.lenght + this.data.electronicBookList.length }) - wx.setStorageSync("paperBookList", JSON.stringify(this.data.paperBookList)); - console.log(this.data.paperBookList, "3") + wx.setStorageSync("paperBookList", this.data.paperBookList); } else { + let list = this.data.paperBookList; + list.forEach((obj, index) => { + if (obj.id == item.id) { + list.splice(index, 1); + } + }) item.paperChecked = false wx.showToast({ - title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�", - icon: 'none', + title: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�", + icon: "none", duration: 1000, }) + this.setData({ + paperChecked: list, + num: list.length + this.data.electronicBookList.length + }) + wx.setStorageSync("paperBookList", list); } } else { item.paperChecked = true; @@ -965,10 +1009,10 @@ duration: 1000, }) this.setData({ - paperBookList: [item] + paperBookList: [itemAttr], + num: 1 + this.data.electronicBookList.length }) - wx.setStorageSync("paperBookList", JSON.stringify(this.data.paperBookList)); - console.log(this.data.paperBookList, "4") + wx.setStorageSync("paperBookList", [itemAttr]); } } else { item.paperChecked = false diff --git a/packageDomain/pages/sampleBookList/index.wxml b/packageDomain/pages/sampleBookList/index.wxml index f1d6070..06be016 100644 --- a/packageDomain/pages/sampleBookList/index.wxml +++ b/packageDomain/pages/sampleBookList/index.wxml @@ -11,7 +11,7 @@ <view class="header-scroll"> <scroll-view scroll-x scroll-with-animation='true' class="srcolbox"> <t-dropdown-menu> - <t-dropdown-item label="鎬诲垎绫�" options="{{iconList.options}}" value="{{iconList.value}}" optionsColumns="2" bindchange="onChangeIcon" arrow-icon="" /> + <t-dropdown-item label="鎬诲垎绫�" options="{{iconList.options}}" default-value="{{iconList.value}}" optionsColumns="2" bindchange="onChangeIcon" arrow-icon="" /> <t-dropdown-item label="涓�绾�" options="{{stairList.options}}" value="{{stairList.value}}" optionsColumns="2" bindchange="onChangeStair" arrow-icon="" /> <t-dropdown-item label="浜岀骇" options="{{secondList.options}}" optionsColumns="2" multiple value="{{secondList.value}}" bind:confirm="onConfirmSecond" bind:change="onChangeSecond" /> </t-dropdown-menu> @@ -70,6 +70,6 @@ <view class="applyBox" bindtap="goApply"> <view class="box"> <t-image src="/static/images/home/yangshuForm.png" mode="heightFix" class="img" /> - <view class="num">{{num}}</view> + <view class="num" wx:if="{{num > 0}}">{{num}}</view> </view> </view> \ No newline at end of file diff --git a/packageDomain/pages/sampleBookList/index.wxss b/packageDomain/pages/sampleBookList/index.wxss index e1317d1..ed8578b 100644 --- a/packageDomain/pages/sampleBookList/index.wxss +++ b/packageDomain/pages/sampleBookList/index.wxss @@ -45,6 +45,19 @@ white-space: nowrap; } +.srcolbox .t-button--primary { + border-radius: 50rpx !important; + background: #FF6C00 !important; + border: none; +} + +.srcolbox .t-button--light { + background: #fff !important; + border-radius: 50rpx !important; + color: #545C63 !important; + border: 2rpx solid #979797 !important; +} + .t-dropdown-menu:after, .t-dropdown-menu::after { height: 0px; @@ -74,10 +87,20 @@ border-radius: 40rpx 40rpx 0 0; } +.t-radio__title { + font-size: 28rpx !important; +} + .t-dropdown-menu__item--active, .t-radio__icon--checked, -.t-checkbox__icon--checked { - color: #FF6C00 !important +.t-checkbox__icon--checked, +.t-radio__title--checked, +.t-checkbox__title--checked { + color: #FF6C00 !important; +} + +.srcolbox .t-checkbox--checked { + background-color: #FFECDE !important; } .t-checkbox__icon--disabled { @@ -85,7 +108,7 @@ } .t-radio--block { - padding: 20rpx !important; + padding: 10rpx !important; } .t-radio__border { @@ -245,16 +268,33 @@ height: 184rpx; position: fixed; bottom: 20%; - right: 20rpx; + right: 0; } .applyBox .box { width: 184rpx; height: 184rpx; color: #fff; + position: relative; } .applyBox .box .t-image { width: 100%; height: 100%; +} + +.num { + background-color: #FD3D16; + color: #fff; + border: 2rpx solid #FFFFFF; + font-size: 24rpx; + line-height: 30rpx; + font-weight: 400; + width: 48rpx; + height: 32rpx; + text-align: center; + border-radius: 9px; + position: absolute; + top: 30rpx; + left: 118rpx; } \ No newline at end of file diff --git a/packageDomain/pages/teacherCertification/index.js b/packageDomain/pages/teacherCertification/index.js index c1b9a7e..812abdc 100644 --- a/packageDomain/pages/teacherCertification/index.js +++ b/packageDomain/pages/teacherCertification/index.js @@ -1,6 +1,7 @@ const app = getApp(); 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'; Page({ /** @@ -30,11 +31,14 @@ topicId: "", worksInfo: [], userId: '', - fileList: [], + imgPics: [], + file: "", + imgs: [], protocolTxt: '', //鏁欏笀鍗忚 protocolShow: false, editState: true, - reasonTxt: "" + reasonTxt: "", + reasonTxtShow: false, }, /** @@ -123,7 +127,7 @@ role: 'Student' } } - wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo)); + wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); } }) }, @@ -152,7 +156,7 @@ app.MG.ugc.getTopicMessageList(data).then((res) => { try { this.setData({ - fileList: [], + imgPics: [], }) const resData = res.datas.find((i) => i.appUserCreator.userId === this.data.userId) if (resData) { @@ -166,9 +170,10 @@ }) } let info = getTopicMsgCmsItemFile(this.data.worksInfo, resData.cmsItemDataList) + console.log(info) this.setData({ 'teacherInfo.fullName': info.fullName, - 'teacherInfo.schoolName ': info.schoolName, + 'teacherInfo.schoolName': info.schoolName, 'teacherInfo.positionalTitle': info.positionalTitle, 'teacherInfo.courseName': info.courseName, 'teacherInfo.phone': info.phone, @@ -179,7 +184,8 @@ 'teacherInfo.agree': true, 'teacherInfo.state': resData.state, topicId: resData.id, - topicMessageList: resData.cmsItemDataList + topicMessageList: resData.cmsItemDataList, + teachText: info.positionalTitle, }) if (resData.feedBack != null) { this.setData({ @@ -187,15 +193,19 @@ }) } if (this.data.teacherInfo.relevantCertificates.length > 0) { + let arr = []; if (typeof this.data.teacherInfo.relevantCertificates == 'object') { this.data.teacherInfo.relevantCertificates.forEach((ele) => { let imgObj = { md5: ele.file.md5, linkType: 'LinkFile', linkProtectType: 'Public', - url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + ele.file.md5 + url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + ele.md5 } - this.data.fileList.push(imgObj) + arr.push(imgObj); + this.setData({ + imgPics: arr, + }); }) } else { let imgObj = { @@ -205,9 +215,13 @@ url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + this.data.teacherInfo.relevantCertificates } - this.data.fileList.push(imgObj) + arr.push(imgObj); + this.setData({ + imgPics: arr, + }); } } + } } catch (error) { } @@ -253,6 +267,31 @@ } }) }, + //瀛︽牎鍚嶇О + 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() { @@ -279,6 +318,7 @@ if (phoneError === isPhoneNumber) { this.setData({ phoneError: !isPhoneNumber, + "teacherInfo.phone": e.detail.value, }); } }, @@ -289,6 +329,7 @@ if (telphoneError === isPhoneNumber) { this.setData({ telphoneError: !isPhoneNumber, + "teacherInfo.telphone": e.detail.value, }); } }, @@ -298,69 +339,115 @@ if (emailError === isPhoneNumber) { this.setData({ emailError: !isPhoneNumber, + "teacherInfo.email": e.detail.value, }); } }, - handleAdd(e) { - const { fileList } = this.data; - console.log(e) - const { files } = e.detail; - // 鏂规硶2锛氭瘡娆¢�夋嫨鍥剧墖閮戒笂浼狅紝灞曠ず姣忔涓婁紶鍥剧墖鐨勮繘搴� - files.forEach(file => { - this.onUpload(file) - }) - }, - onUpload(file) { - console.log(file, '123') - const isLt2M = (0.5 * file.size) / 1024 / 1024 < 0.5 - if (!isLt2M) { - wx.showToast({ - title: "涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 500KB!", - icon: 'none', - duration: 1000, - }) - return reject() - } - const FileName = file.name.split('.')[0] - const Extension = file.name.split('.')[1] - const FileType = file.type - let size = 1024 - tool.getFileMd5(file, size * 1024).then((e) => { - if (!this.data.fileList.find((item) => item.md5 == e)) { - const imgData = new FormData() - imgData.append('Md5', e) - imgData.append('FileName', FileName) - imgData.append('Extension', Extension) - imgData.append('FileType', FileType) - imgData.append('MetaData', null) - imgData.append('file', file) - app.MG.file.upload(imgData).then(() => { - this.data.fileList.push({ - md5: e, - linkType: 'LinkFile', - linkProtectType: 'Public', - name: FileName, - type: FileType, - url: app.config.requestCtx + `/file/GetPreViewImage?md5=` + e - }) + // 涓婁紶鍥剧墖浜嬩欢 + chooseImg(e) { + var that = this; + wx.chooseMedia({ + // count: 1, // 榛樿9 + 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]]; + + that.setData({ + imgPics: arr, + }); + } + } else { + reject('杩愯鏃堕敊璇�,璇风◢鍚庡啀璇�'); + } + } + }) + }) + } else { + wx.showToast({ + title: "褰撳墠鏂囦欢宸蹭笂浼狅紝璇峰嬁閲嶅鎿嶄綔锛�", + icon: 'none', + duration: 1000, + }) + } }) - } else { - ElMessage.error('褰撳墠鏂囦欢宸蹭笂浼狅紝璇峰嬁閲嶅鎿嶄綔锛�') } - }) - .catch((e) => { - console.error(e) - }) - }, - handleRemove(e) { - const { index } = e.detail; - const { fileList } = this.data; - fileList.splice(index, 1); - this.setData({ - fileList, }); }, + // 鍒犻櫎鍥剧墖 + 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() { + console.log(this.data.teacherInfo.agree, 12) + if (this.data.teacherInfo.agree) { + this.setData({ + 'teacherInfo.agree': false, + }); + } else { + this.setData({ + 'teacherInfo.agree': true, + }); + } }, //鏌ョ湅鏁欏笀璁よ瘉鏈嶅姟 @@ -372,7 +459,161 @@ onVisibleChange(e) { this.setData({ protocolShow: e.detail.visible, + reasonTxtShow: e.detail.visible }); + }, + + //鏌ョ湅涓洪�氳繃鍘熷洜 + previewReason() { + this.setData({ + reasonTxtShow: true, + }); + }, + + 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.relevantCertificates.length == 0) { + wx.showToast({ + title: "璇蜂笂浼犲伐浣滆瘉锛�", + icon: 'none', + duration: 1000, + }) + return + } + console.log(that.data.teacherInfo.fullName) + 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 + ); + console.log(dataRequests, 4) + 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.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() + } + }) + }) + } + } else { + wx.showToast({ + title: "璇峰悓鎰忋�婃暀甯堣璇佹湇鍔℃潯娆俱�嬶紒", + icon: 'none', + duration: 1000, + }) + } }, diff --git a/packageDomain/pages/teacherCertification/index.json b/packageDomain/pages/teacherCertification/index.json index f773807..965b59d 100644 --- a/packageDomain/pages/teacherCertification/index.json +++ b/packageDomain/pages/teacherCertification/index.json @@ -7,6 +7,7 @@ "t-input": "tdesign-miniprogram/input/input", "t-upload": "tdesign-miniprogram/upload/upload", "t-popup": "tdesign-miniprogram/popup/popup", - "t-checkbox": "tdesign-miniprogram/checkbox/checkbox" + "t-checkbox": "tdesign-miniprogram/checkbox/checkbox", + "t-image": "tdesign-miniprogram/image/image" } } \ No newline at end of file diff --git a/packageDomain/pages/teacherCertification/index.wxml b/packageDomain/pages/teacherCertification/index.wxml index ef9addf..da571aa 100644 --- a/packageDomain/pages/teacherCertification/index.wxml +++ b/packageDomain/pages/teacherCertification/index.wxml @@ -9,57 +9,61 @@ <text class="yes" wx:if="{{teacherInfo.state == 'Normal'}}">宸茶璇�</text> <text class="no" wx:if="{{teacherInfo.state == 'Reject'}}">宸查┏鍥�</text> <text class="wait" wx:if="{{teacherInfo.state == ''}}">寰呰璇�</text> + <view class="reasonTxt" bindtap="previewReason" wx:if="{{teacherInfo.state == 'Reject'}}">鏌ョ湅鍘熷洜</view> </view> </view> <view class="from-item"> <view class="label"> 瀛︽牎锛� </view> <view class="item-content"> - <t-input placeholder="璇疯緭鍏ュ鏍�" borderless value="{{teacherInfo.schoolName}}" disabled="{{!editState}}" /> + <t-input placeholder="璇疯緭鍏ュ鏍�" borderless value="{{teacherInfo.schoolName}}" disabled="{{!editState}}" bindchange="onSchoolNameInput" /> </view> </view> <view class="from-item"> <view class="label"> 鐪熷疄濮撳悕锛� </view> <view class="item-content"> - <t-input placeholder="璇疯緭鍏ョ湡瀹炲鍚�" borderless value="{{teacherInfo.fullName}}" disabled="{{!editState}}" /> + <t-input placeholder="璇疯緭鍏ョ湡瀹炲鍚�" borderless value="{{teacherInfo.fullName}}" disabled="{{!editState}}" bindchange="onFullNameInput" /> </view> </view> <view class="from-item"> <view class="label"> 鑱岀О锛� </view> - <view class="item-content"> + <view class="item-content state" wx:if="{{editState}}"> <t-cell arrow note="{{teachText}}" bind:click="onTeachPicker" /> - <t-picker visible="{{teachVisible}}" default-value="{{teacherInfo.positionalTitle}}" title="閫夋嫨鑱岀О" cancelBtn="鍙栨秷" confirmBtn="纭" bindchange="onPickerChange" bindcancel="onPickerCancel"> + <t-picker visible="{{teachVisible}}" value="{{teacherInfo.positionalTitle}}" title="閫夋嫨鑱岀О" cancelBtn="鍙栨秷" confirmBtn="纭" bindchange="onPickerChange" bindcancel="onPickerCancel"> <t-picker-item options="{{teachPosts}}" /> </t-picker> + </view> + <view class="item-content" wx:if="{{!editState}}"> + <t-cell arrow note="{{teachText}}" /> </view> </view> <view class="from-item"> <view class="label"> 浠绘暀璇剧▼锛� </view> <view class="item-content"> - <t-input placeholder="璇疯緭鍏ヤ换鏁欒绋�" borderless value="{{teacherInfo.courseName}}" /> + <t-input placeholder="璇疯緭鍏ヤ换鏁欒绋�" borderless value="{{teacherInfo.courseName}}" bindchange="onCourseNameInput" disabled="{{!editState}}" /> </view> </view> <view class="from-item"> <view class="label"> 鎵嬫満鍙凤細 </view> <view class="item-content"> - <t-input placeholder="杈撳叆鎵嬫満鍙风爜" borderless value="{{teacherInfo.phone}}" type="number" tips="{{phoneError ? '鎵嬫満鍙疯緭鍏ヤ笉姝g‘' : ''}}" bindchange="onPhoneInput" /> + <t-input placeholder="杈撳叆鎵嬫満鍙风爜" borderless value="{{teacherInfo.phone}}" type="number" tips="{{phoneError ? '鎵嬫満鍙疯緭鍏ヤ笉姝g‘' : ''}}" bindchange="onPhoneInput" disabled="{{!editState}}" /> </view> </view> <view class="from-item"> <view class="label"> 搴ф満锛� </view> <view class="item-content"> - <t-input placeholder="杈撳叆搴ф満鍙�" borderless value="{{teacherInfo.telphone}}" type="number" tips="{{telphoneError ? '搴ф満鍙疯緭鍏ヤ笉姝g‘' : ''}}" bindchange="onTelphoneInput" /> + <t-input placeholder="杈撳叆搴ф満鍙�" borderless value="{{teacherInfo.telphone}}" type="number" tips="{{telphoneError ? '搴ф満鍙疯緭鍏ヤ笉姝g‘' : ''}}" bindchange="onTelphoneInput" disabled="{{!editState}}" /> </view> </view> <view class="from-item"> <view class="label"> 閭锛� </view> <view class="item-content"> - <t-input placeholder="杈撳叆閭" borderless value="{{teacherInfo.email}}" type="number" tips="{{emailError ? '閭杈撳叆涓嶆纭�' : ''}}" bindchange="onEmailInput" /> + <t-input placeholder="杈撳叆閭" borderless value="{{teacherInfo.email}}" type="number" tips="{{emailError ? '閭杈撳叆涓嶆纭�' : ''}}" bindchange="onEmailInput" disabled="{{!editState}}" /> </view> </view> <view class="from-item"> <view class="label"> 璇︾粏鍦板潃锛� </view> <view class="item-content"> - <t-input placeholder="璇疯緭鍏ヨ缁嗗湴鍧�" borderless value="{{teacherInfo.detailedAddress}}" /> + <t-input placeholder="璇疯緭鍏ヨ缁嗗湴鍧�" borderless value="{{teacherInfo.detailedAddress}}" bindchange="onAddressInput" disabled="{{!editState}}" /> </view> </view> </view> @@ -67,9 +71,15 @@ <view class="from-item"> <view class="label"> 鍦ㄨ亴鏁欏笀宸ヤ綔璇侊細 </view> <view class="imageBox"> - <view class="wrapper"> - <t-upload mediaType="{{['image']}}" files="{{fileList}}" bind:add="handleAdd" bind:remove="handleRemove"> - </t-upload> + <view class="weui-uploader"> + <view class='pics' wx:for="{{imgPics}}" wx:for-item="item" wx:key="*this"> + <image class='weui-uploader__img' src="{{item.url}}" data-index="{{index}}" mode="aspectFill" bindtap="previewImg"> + <icon type='cancel' class="delete-btn" data-index="{{index}}" catchtap="deleteImg"></icon> + </image> + </view> + <view class="tp_cont {{tj_ycang?'':'hide'}}" bindtap="chooseImg" wx:if="{{editState}}"> + <view class="tp_add">+</view> + </view> </view> </view> <view class="fileTip"> @@ -78,16 +88,23 @@ </view> </view> <view class="protocolBox"> - <t-checkbox label="" icon="rectangle" default-checked="{{teacherInfo.agree}}" bind:change="onChange" /> + <t-checkbox label="" icon="rectangle" checked="{{teacherInfo.agree}}" bind:change="onChange" disabled="{{!editState}}" /> <text class="wait" bind:tap="viewContent">銆婃暀甯堣璇佹湇鍔℃潯娆俱��</text> </view> - <view class="btn-area"> - <button class="submit" formType="submit">鎻愪氦</button> + <view class="btn-area" wx:if="{{editState}}"> + <button class="submit" bindtap="submit">鎻愪氦</button> </view> </view> - <t-popup visible="{{protocolShow}}" bind:visible-change="onVisibleChange" placement="center" close-btn> - <view class="block"> - <rich-text space="emsp" nodes="{{protocolTxt}}" class="content" /> - </view> - </t-popup> + <view class="popupBox"> + <t-popup visible="{{protocolShow}}" bind:visible-change="onVisibleChange" placement="center" close-btn> + <view class="block"> + <rich-text space="emsp" nodes="{{protocolTxt}}" class="content" /> + </view> + </t-popup> + <t-popup visible="{{reasonTxtShow}}" bind:visible-change="onVisibleChange" placement="center" close-btn> + <view class="reasonBlock"> + {{reasonTxt}} + </view> + </t-popup> + </view> </view> \ No newline at end of file diff --git a/packageDomain/pages/teacherCertification/index.wxss b/packageDomain/pages/teacherCertification/index.wxss index e3571cd..43206bf 100644 --- a/packageDomain/pages/teacherCertification/index.wxss +++ b/packageDomain/pages/teacherCertification/index.wxss @@ -48,13 +48,19 @@ } .from-item .item-content { - width: 56%; + width: 75%; border: 2rpx solid #D9D9D9; padding: 10rpx; } .from-item .stateBox { padding: 10rpx; + display: flex; +} + +.reasonTxt { + margin-left: 40rpx; + color: #ff6d00; } .from-item .t-input { @@ -78,7 +84,12 @@ .t-cell__note { justify-content: flex-start !important; display: block !important; + font-size: 28rpx !important; /* width: 300rpx; */ +} + +.state .t-cell__note { + color: #333 !important; } .t-input__wrap .t-input__content, @@ -117,10 +128,6 @@ padding: 20rpx; } -.wrapper { - width: 100%; -} - .fileTip { font-size: 24rpx; color: #949494; @@ -145,11 +152,11 @@ color: #ff6c00 !important; } -.t-popup { +.popupBox .t-popup { width: 80% !important; } -.t-popup__content { +.popupBox .t-popup__content { padding: 40rpx 10rpx !important; padding-top: 80rpx !important; } @@ -157,6 +164,13 @@ .block { height: 450px !important; overflow: auto !important; +} + +.reasonBlock { + height: 450px !important; + overflow: auto !important; + font-size: 28rpx; + line-height: 48rpx; } .btn-area { @@ -169,4 +183,40 @@ background: #ff6c00; color: #fff; border-radius: 50rpx; +} + +/* 涓婁紶鍥剧墖鏍峰紡 */ +.weui-uploader { + height: 152rpx; +} + +.tp_add { + width: 152rpx; + height: 152rpx; + border-radius: 10rpx; + opacity: 1; + border: 2rpx dashed #999999; + display: flex; + justify-content: center; + align-items: center; + font-size: 59rpx; +} + +.pics { + float: left; + position: relative; + margin-right: 15px; +} + +.pics image { + width: 152rpx; + height: 152rpx; +} + +.delete-btn { + width: 20rpx; + height: 20rpx; + position: absolute; + top: -15rpx; + right: -5rpx; } \ No newline at end of file diff --git a/packagePersonal/pages/userSetting/index.js b/packagePersonal/pages/userSetting/index.js new file mode 100644 index 0000000..110615f --- /dev/null +++ b/packagePersonal/pages/userSetting/index.js @@ -0,0 +1,66 @@ +// packagePersonal/pages/userSetting/index.js +Page({ + + /** + * 椤甸潰鐨勫垵濮嬫暟鎹� + */ + data: { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 + */ + onLoad(options) { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 + */ + onReady() { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず + */ + onShow() { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 + */ + onHide() { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 + */ + onUnload() { + + }, + + /** + * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 + */ + onPullDownRefresh() { + + }, + + /** + * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� + */ + onReachBottom() { + + }, + + /** + * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/packagePersonal/pages/userSetting/index.json b/packagePersonal/pages/userSetting/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/packagePersonal/pages/userSetting/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/packagePersonal/pages/userSetting/index.wxml b/packagePersonal/pages/userSetting/index.wxml new file mode 100644 index 0000000..1b6bbbf --- /dev/null +++ b/packagePersonal/pages/userSetting/index.wxml @@ -0,0 +1,2 @@ +<!--packagePersonal/pages/userSetting/index.wxml--> +<text>packagePersonal/pages/userSetting/index.wxml</text> diff --git a/packagePersonal/pages/userSetting/index.wxss b/packagePersonal/pages/userSetting/index.wxss new file mode 100644 index 0000000..42e75dd --- /dev/null +++ b/packagePersonal/pages/userSetting/index.wxss @@ -0,0 +1 @@ +/* packagePersonal/pages/userSetting/index.wxss */ \ No newline at end of file diff --git a/pages/home/home.js b/pages/home/home.js index bfe983c..f534823 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -4,6 +4,8 @@ const app = getApp() Page({ data: { + barHeight: '', + navBarHeight: '', searchVal: '', isWhite: false, backUrl: null, @@ -36,6 +38,13 @@ }, onLoad(options) { + const systInfo = wx.getSystemInfoSync(); + const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 + const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� + this.setData({ + barHeight: systInfo.statusBarHeight, + navBarHeight: navBarHeight, + }); if (options.backUrl) { let backUrl = JSON.parse(decodeURIComponent(options.backUrl)); if (backUrl.options) { @@ -149,7 +158,7 @@ getBannerList() { const list = [] app.MG.resource.getItem({ - path: 'jsek_banner\\jsek_homeBanner', + path: 'jsek_banner\\jsek_homeBannerApplet', fields: { jsek_link: [] }, paging: { start: 0, size: 9 } }).then(res => { diff --git a/pages/home/home.wxml b/pages/home/home.wxml index 21fbf69..baecdb0 100644 --- a/pages/home/home.wxml +++ b/pages/home/home.wxml @@ -1,7 +1,8 @@ <view style="text-align: center; color: #b9b9b9" wx:if="{{pageLoading}}"> <t-loading theme="circular" size="40rpx" text="鍔犺浇涓�..." inherit-color /> </view> -<view class="background {{ isWhite ? 'white':''}}"> + +<view class="background {{ isWhite ? 'white':''}}" style="padding-top: {{barHeight}}px"> <text class="text">浜笀E璇�</text> </view> <view class="home-page-header"> @@ -195,7 +196,7 @@ </view> <view class="body-info"> <view class="name">{{item.name}}</view> - <view class="author">{{item.author}}</view> + <!-- <view class="author">{{item.author}}</view> --> </view> </view> </view> diff --git a/pages/home/home.wxss b/pages/home/home.wxss index 422c185..67cd4ed 100644 --- a/pages/home/home.wxss +++ b/pages/home/home.wxss @@ -15,6 +15,7 @@ top: 0; left: 0; height: 80rpx; + line-height: 80rpx; z-index: 3; text-align: center; padding-top: 110rpx; @@ -152,7 +153,7 @@ .body-info .name { font-size: 30rpx; - height: 88rpx; + height: 80rpx; color: #333333; font-weight: bold; line-height: 40rpx; @@ -173,6 +174,17 @@ font-size: 26rpx; display: flex; justify-content: space-between; + display: -webkit-box; + /* 浣跨敤寮规�х洅瀛愬竷灞�妯″瀷 */ + -webkit-line-clamp: 1; + /* 鎺у埗鏂囨湰鐨勮鏁� */ + -webkit-box-orient: vertical; + /* 璁剧疆鐩掑瓙鐨勫瓙鍏冪礌鎺掑垪鏂瑰悜 */ + overflow: hidden; + /* 瓒呭嚭閮ㄥ垎闅愯棌 */ + text-overflow: ellipsis; + /* 瓒呭嚭閮ㄥ垎鏄剧ず鐪佺暐鍙� */ + white-space: normal; } .body-info .price { @@ -241,7 +253,7 @@ } .listBox2 .booksListItemBox { - width: calc(100%/3 - 30rpx); + width: calc(100%/3 - 32rpx); margin-bottom: 30rpx; margin-right: 45rpx; } @@ -360,10 +372,16 @@ height: 80rpx; width: 188rpx; color: #333333; - line-height: 30rpx; - overflow: hidden; - text-overflow: ellipsis; + line-height: 40rpx; display: -webkit-box; + /* 浣跨敤寮规�х洅瀛愬竷灞�妯″瀷 */ -webkit-line-clamp: 2; + /* 鎺у埗鏂囨湰鐨勮鏁� */ -webkit-box-orient: vertical; + /* 璁剧疆鐩掑瓙鐨勫瓙鍏冪礌鎺掑垪鏂瑰悜 */ + overflow: hidden; + /* 瓒呭嚭閮ㄥ垎闅愯棌 */ + text-overflow: ellipsis; + /* 瓒呭嚭閮ㄥ垎鏄剧ず鐪佺暐鍙� */ + white-space: normal; } \ No newline at end of file diff --git a/pages/personalCenter/components/user-center-card/index.js b/pages/personalCenter/components/user-center-card/index.js index 47593c4..21481f1 100644 --- a/pages/personalCenter/components/user-center-card/index.js +++ b/pages/personalCenter/components/user-center-card/index.js @@ -31,5 +31,8 @@ gotoUserEditPage() { this.triggerEvent('gotoUserEditPage'); }, + editUserType() { + this.triggerEvent('editUserType'); + }, }, }); diff --git a/pages/personalCenter/components/user-center-card/index.wxml b/pages/personalCenter/components/user-center-card/index.wxml index 60d1830..60cff21 100644 --- a/pages/personalCenter/components/user-center-card/index.wxml +++ b/pages/personalCenter/components/user-center-card/index.wxml @@ -3,7 +3,9 @@ <block wx:if="{{currAuthStep === AuthStepType.ONE}}"> <view class="user-center-card__header" bind:tap="gotoUserEditPage"> <t-avatar image="{{userInfo.avatarUrl || defaultAvatarUrl}}" class="user-center-card__header__avatar" /> - <view class="user-center-card__header__name">{{'璇风櫥褰�'}}</view> + <view> + <view class="user-center-card__header__name">{{'璇风櫥褰�'}}</view> + </view> <view class="setting" bind:tap="gotoUserEditPage"> <image src="/static/images/personal/setting.png" mode="heightFix" class="img" /> <text>璁剧疆</text> @@ -13,21 +15,37 @@ <!-- 宸茬櫥褰曚絾鏈巿鏉冪敤鎴蜂俊鎭儏鍐� --> <block wx:if="{{currAuthStep === AuthStepType.TWO}}"> <view class="user-center-card__header"> - <t-avatar image="{{userInfo.avatarUrl || defaultAvatarUrl}}" class="user-center-card__header__avatar" /> - <view class="user-center-card__header__name">{{userInfo.nickName || '寰俊鐢ㄦ埛'}}</view> - <!-- 闇�瑕佹巿鏉冪敤鎴蜂俊鎭紝閫氳繃slot娣诲姞寮圭獥 --> - <view class="user-center-card__header__transparent" wx:if="{{isNeedGetUserInfo}}"> - <slot name="getUserInfo" /> + <t-avatar image="{{userInfo.icon || defaultAvatarUrl}}" class="user-center-card__header__avatar" /> + <view> + <view class="user-center-card__header__name">{{userInfo.fullName || '寰俊鐢ㄦ埛'}}</view> + <view class="userTypeBox"> + <text>{{userInfo.userType}}</text> + <text class="edit" bindtap="editUserType">淇敼</text> + </view> </view> + <!-- 涓嶉渶瑕佹巿鏉冪敤鎴蜂俊鎭紝浠嶇劧瑙﹀彂gotoUserEditPage浜嬩欢 --> - <view class="user-center-card__header__transparent" bind:tap="gotoUserEditPage" wx:else></view> + <view class="setting" bind:tap="gotoUserEditPage"> + <image src="/static/images/personal/setting.png" mode="heightFix" class="img" /> + <text>璁剧疆</text> + </view> </view> </block> <!-- 宸茬櫥褰曚笖宸茬粡鎺堟潈鐢ㄦ埛淇℃伅鐨勬儏鍐� --> <block wx:if="{{currAuthStep === AuthStepType.THREE}}"> - <view class="user-center-card__header" bind:tap="gotoUserEditPage"> - <t-avatar t-class="avatar" mode="aspectFill" class="user-center-card__header__avatar" image="{{userInfo.avatarUrl || defaultAvatarUrl}}" /> - <view class="user-center-card__header__name">{{userInfo.nickName || '寰俊鐢ㄦ埛'}}</view> + <view class="user-center-card__header"> + <t-avatar t-class="avatar" mode="aspectFill" class="user-center-card__header__avatar" image="{{userInfo.icon || defaultAvatarUrl}}" /> + <view> + <view class="user-center-card__header__name">{{userInfo.fullName || '寰俊鐢ㄦ埛'}}</view> + <view class="userTypeBox"> + <text>{{userInfo.userType}}</text> + <text bindtap="editUserType">淇敼</text> + </view> + </view> + <view class="setting" bind:tap="gotoUserEditPage"> + <image src="/static/images/personal/setting.png" mode="heightFix" class="img" /> + <text>璁剧疆</text> + </view> </view> </block> </view> \ No newline at end of file diff --git a/pages/personalCenter/components/user-center-card/index.wxss b/pages/personalCenter/components/user-center-card/index.wxss index cee02f2..d618c8b 100644 --- a/pages/personalCenter/components/user-center-card/index.wxss +++ b/pages/personalCenter/components/user-center-card/index.wxss @@ -9,7 +9,7 @@ margin-top: 160rpx; margin-bottom: 30rpx; margin-left: 20rpx; - height: 96rpx; + height: 120rpx; line-height: 48rpx; display: flex; justify-content: flex-start; @@ -19,8 +19,8 @@ } .user-center-card__header__avatar { - width: 96rpx; - height: 96rpx; + width: 120rpx; + height: 120rpx; border-radius: 48rpx; overflow: hidden; } @@ -34,6 +34,17 @@ margin-right: 16rpx; } +.userTypeBox { + margin-left: 24rpx; + font-size: 28rpx; + padding-top: 15rpx; +} + +.edit { + margin-left: 20rpx; + color: #ff6d00; +} + .user-center-card__header__transparent { position: absolute; left: 0; diff --git a/pages/personalCenter/index.js b/pages/personalCenter/index.js index cda03ed..1ecdbf5 100644 --- a/pages/personalCenter/index.js +++ b/pages/personalCenter/index.js @@ -77,21 +77,37 @@ type: 'contact', } ]; +const userTypeList = [ + { + lable: '涓亴鏁欏笀', + value: 'vocSchoolTeachers' + }, + { + lable: '楂樿亴鏁欏笀', + value: 'vocCollegeTeachers' + }, + { + lable: '鏅�氶珮鏍℃暀甯�', + value: 'ordUniversityTeachers' + }, + { + lable: '鍏朵粬璇昏��', + value: 'otherReaders' + } +]; Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { + barHeight: '', + navBarHeight: '', isWhite: false, - show: false, - userInfo: { - avatarUrl: - 'https://we-retail-static-1300977798.cos.ap-guangzhou.myqcloud.com/retail-ui/components-exp/avatar/avatar-1.jpg', - nickName: 'TDesign', - phoneNumber: '13438358888', - }, + userInfo: {}, currAuthStep: 1, + userTypeActive: '', + userTypeList, teacherState: { state: '', reasonTxt: '', @@ -99,56 +115,108 @@ integral: 0, menuData, moreMenu, - moreMenu1 + moreMenu1, + visible: false, }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ - onLoad(options) { - console.log(options); - }, - - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず - */ - onShow() { - if (wx.getStorageSync(app.config.userInfoKey)) { + onLoad() { + const systInfo = wx.getSystemInfoSync(); + const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 + const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� + this.setData({ + barHeight: systInfo.statusBarHeight, + navBarHeight: navBarHeight, + }); + if (wx.getStorageSync(app.config.tokenKey)) { this.setData({ - show: true, - userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)) - }) - - if (typeof this.getTabBar === 'function' && this.getTabBar()) { - this.getTabBar().setData({ - selected: 4 //杩欎釜鏁板瓧鏄綋鍓嶉〉闈㈠湪tabBar涓璴ist鏁扮粍鐨勭储寮� - }) - } - this.getTeacherInfo() + currAuthStep: 2, + }); + this.getUserInfo() } else { + this.setData({ + currAuthStep: 1, + }); wx.navigateTo({ url: "/pages/testLogin/index", }); } + }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 - */ - onHide() { - this.setData({ - show: false - }) + onShow() { + }, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { - this.init(); + this.getUserInfo() }, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ onReachBottom() { + }, + // 鑾峰彇鐧诲綍鐢ㄦ埛韬唤 + getUserInfo() { + app.MG.identity.getCurrentAppUser().then(res => { + // 鐢ㄦ埛淇℃伅浼樺厛绾э細鏁欏笀璁よ瘉 > 寰俊 > 瀛︾敓锛堟敞鍐屾椂榛樿锛� + if (res) { + //鑾峰彇鐢ㄦ埛绫诲瀷 + let userTypeData = res.infoList.find((item) => item.type == 'userType') + let type = ""; + if (userTypeData) { + this.data.userTypeActive = JSON.parse(userTypeData.data).userType; + type = userTypeList.find((item) => item.value === this.data.userTypeActive)?.lable; + } else { + type = '-' + } + let defaultUser = {}; + let teacherRole = res.roleLinks.find((item) => item.role.refCode == 'teacher') + let teacherInfos = res.infoList.find((item) => item.type == 'teacherInfo') + let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword') + let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); + if (teacherRole && teacherInfos) { + defaultUser = { + ...teacherInfos, + fullName: teacherInfos.fullName, + icon: teacherInfos.icon, + userId: res.userId, + role: 'Teacher', + roleId: teacherRole.role.id, + userType: type + } + this.setData({ + currAuthStep: 2, + }); + + } else if (WeChatInfo) { + defaultUser = { + ...WeChatInfo, + fullName: WeChatInfo.name, + icon: WeChatInfo.icon, + userId: res.userId, + userType: type + } + this.setData({ + currAuthStep: 3, + }); + } else if (secretData) { + defaultUser = { + fullName: secretData.credential, + icon: "", + userId: res.userId, + userType: type + } + } + this.setData({ + userInfo: defaultUser + }) + this.getTeacherInfo() + wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo)); + } + }); }, //鏁欏笀淇℃伅 getTeacherInfo() { @@ -163,7 +231,6 @@ } } app.MG.ugc.getTopicMessageList(data).then((res) => { - console.log(this.data.userInfo, "userInfo") const resData = res.datas.find((i) => i.appUserCreator.userId == this.data.userInfo.userId) if (resData) { this.setData({ @@ -179,6 +246,26 @@ toCertification() { wx.navigateTo({ url: "/packageDomain/pages/teacherCertification/index", + }); + }, + //淇敼鐢ㄦ埛绫诲瀷 + editUserType() { + console.log(44) + if (!this.data.visible) { + this.setData({ + visible: true, + }); + } + }, + onVisibleChange(e) { + this.setData({ + visible: e.detail.visible, + }); + }, + //璁剧疆 + gotoUserEditPage() { + wx.navigateTo({ + url: "/packagePersonal/pages/userSetting/index", }); }, @@ -203,13 +290,6 @@ * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� */ onShareAppMessage() { - - }, - - onPageScroll(e) { - this.setData({ - isWhite: e.scrollTop > 50 ? true : false - }) }, //璺宠浆鍏充簬鎴戜滑鍜岃仈绯绘垜浠� diff --git a/pages/personalCenter/index.json b/pages/personalCenter/index.json index a7c0c31..98d959b 100644 --- a/pages/personalCenter/index.json +++ b/pages/personalCenter/index.json @@ -3,7 +3,8 @@ "navigationStyle": "custom", "usingComponents": { "t-user-center-card": "./components/user-center-card/index", - "t-image": "tdesign-miniprogram/image/image" + "t-image": "tdesign-miniprogram/image/image", + "t-popup": "tdesign-miniprogram/popup/popup" }, "enablePullDownRefresh": true } \ No newline at end of file diff --git a/pages/personalCenter/index.wxml b/pages/personalCenter/index.wxml index c1a6791..e5396f0 100644 --- a/pages/personalCenter/index.wxml +++ b/pages/personalCenter/index.wxml @@ -1,12 +1,12 @@ -<view class="background {{ isWhite ? 'white':''}}"> +<view style="width: 100%; height: {{barHeight}}px;"></view> +<view class="background {{ isWhite ? 'white':''}}" style="padding-top: {{barHeight}}px"> <text class="text">涓汉涓績</text> </view> <view class="home-page"> <view class="bg"> <image src="/static/images/personal/my-bg.png" mode="heightFix" class="image" /> </view> - <!-- <image class="background" src="/static/images/personal/my-bg.png" mode="heightFix" /> --> - <t-user-center-card userInfo="{{userInfo}}" isPhoneHide="{{true}}" name-class="custom-name-class" phone-class="custom-phone-class" avatar-class="customer-avatar-class" currAuthStep="{{currAuthStep}}" bind:gotoUserEditPage="gotoUserEditPage" /> + <t-user-center-card userInfo="{{userInfo}}" isPhoneHide="{{true}}" name-class="custom-name-class" phone-class="custom-phone-class" avatar-class="customer-avatar-class" currAuthStep="{{currAuthStep}}" bind:gotoUserEditPage="gotoUserEditPage" bind:editUserType="editUserType" /> <view class="content-wrapper"> <view class="topBox"> <view class="teacherBox"> @@ -46,8 +46,8 @@ <text>鏇村鍔熻兘</text> </view> <view class="domainList1"> - <view wx:for="{{moreMenu}}" wx:for-item="item" wx:for-index="index" wx:key="index" bindtap="toPages" data-info="{{item}}" class="listItem" > - <view class="icon" > + <view wx:for="{{moreMenu}}" wx:for-item="item" wx:for-index="index" wx:key="index" bindtap="toPages" data-info="{{item}}" class="listItem"> + <view class="icon"> <t-image src="{{item.icon}}" mode="heightFix" class="img" /> </view> <view class="label"> @@ -67,4 +67,19 @@ </view> </view> </view> + <t-popup visible="{{visible}}" bind:visible-change="onVisibleChange" placement="bottom"> + <view class="block"> + <view class="header"> + <view class="title">璇烽�夋嫨鎮ㄧ殑鐢ㄦ埛绫诲瀷</view> + </view> + <view class="body"> + <view wx:for="{{userTypeList}}" wx:for-item="item" wx:for-index="index" wx:key="index" data-info="{{item}}" bindtap="tabUserTypeClick" :class="item.value == userTypeActive ? 'activeItem item hover' : 'item hover'"> + {{ item.lable }} + </view> + </view> + <view class="footer"> + <button class="submit" bindtap="submit">鎻愪氦</button> + </view> + </view> + </t-popup> </view> \ No newline at end of file diff --git a/pages/personalCenter/index.wxss b/pages/personalCenter/index.wxss index 6668928..058000d 100644 --- a/pages/personalCenter/index.wxss +++ b/pages/personalCenter/index.wxss @@ -10,9 +10,9 @@ top: 0; left: 0; height: 80rpx; + line-height: 80rpx; z-index: 3; text-align: center; - padding-top: 60rpx; font-size: 36rpx; } @@ -136,4 +136,25 @@ line-height: 40rpx; text-align: center; margin-top: 20rpx; +} + +.block { + width: 100vw; + height: 240px; + background: #fff; + border-top-left-radius: 16rpx; + border-top-right-radius: 16rpx; +} + +.header { + display: flex; + align-items: center; + height: 116rpx; +} + +.title { + flex: 1; + text-align: center; + font-weight: 600; + font-size: 36rpx; } \ No newline at end of file diff --git a/pages/testLogin/index.js b/pages/testLogin/index.js index fdcb3c4..4c0e7be 100644 --- a/pages/testLogin/index.js +++ b/pages/testLogin/index.js @@ -77,7 +77,7 @@ } else if (secretData) { defaultUser = { nickName: secretData.credential, - avatarUrl: "../../static/images/index/tab.png", + avatarUrl: "", userId: res.userId } } diff --git a/utils/formdata/index.js b/utils/formdata/index.js new file mode 100644 index 0000000..a786861 --- /dev/null +++ b/utils/formdata/index.js @@ -0,0 +1,145 @@ +import mimeMap from './mimeMap' + +function FormData(){ + let fileManager = wx.getFileSystemManager(); + let data = {}; + let files = []; + + this.append = (name, value)=>{ + data[name] = value; + return true; + } + + this.appendFile = (name, path)=>{ + let buffer = fileManager.readFileSync(path); + if(Object.prototype.toString.call(buffer).indexOf("ArrayBuffer") < 0){ + return false; + } + files.push({ + name: name, + buffer: buffer, + fileName: getFileNameFromPath(path) + }); + return true; + } + + this.getData = ()=>convert(data, files) +} + +function getFileNameFromPath(path){ + let idx=path.lastIndexOf("/"); + return path.substr(idx+1); +} + +function convert(data, files){ + let boundaryKey = 'wxmpFormBoundary' + randString(); // 鏁版嵁鍒嗗壊绗︼紝涓�鑸槸闅忔満鐨勫瓧绗︿覆 + let boundary = '--' + boundaryKey; + let endBoundary = boundary + '--'; + + let postArray = []; + //鎷兼帴鍙傛暟 + if(data && Object.prototype.toString.call(data) == "[object Object]"){ + for(let key in data){ + postArray = postArray.concat(formDataArray(boundary, key, data[key])); + } + } + //鎷兼帴鏂囦欢 + if(files && Object.prototype.toString.call(files) == "[object Array]"){ + for(let i in files){ + let file = files[i]; + postArray = postArray.concat(formDataArray(boundary, file.name, file.buffer, file.fileName)); + } + } + //缁撳熬 + let endBoundaryArray = []; + for (var i = 0; i < endBoundary.length; i++) { // 鏈�鍚庡彇鍑虹粨鏉焍oundary鐨刢harCode + endBoundaryArray.push(...endBoundary.utf8CodeAt(i)); + } + postArray = postArray.concat(endBoundaryArray); + return { + contentType: 'multipart/form-data; boundary=' + boundaryKey, + buffer: new Uint8Array(postArray).buffer + } +} + +function randString() { + let res = ""; + for (let i = 0; i < 17; i++) { + let n = parseInt(Math.random() * 62); + if (n <= 9) { + res += n; + } + else if (n <= 35) { + res += String.fromCharCode(n + 55); + } + else { + res += String.fromCharCode(n + 61); + } + } + return res; +} + +function formDataArray(boundary, name, value, fileName){ + let dataString = ''; + let isFile = !!fileName; + + dataString += boundary + '\r\n'; + dataString += 'Content-Disposition: form-data; name="' + name + '"'; + if (isFile){ + dataString += '; filename="' + fileName + '"' + '\r\n'; + dataString += 'Content-Type: ' + getFileMime(fileName) + '\r\n\r\n'; + } + else{ + dataString += '\r\n\r\n'; + dataString += value; + } + + var dataArray = []; + for (var i = 0; i < dataString.length; i++) { // 鍙栧嚭鏂囨湰鐨刢harCode锛�10杩涘埗锛� + dataArray.push(...dataString.utf8CodeAt(i)); + } + + if (isFile) { + let fileArray = new Uint8Array(value); + dataArray = dataArray.concat(Array.prototype.slice.call(fileArray)); + } + dataArray.push(..."\r".utf8CodeAt()); + dataArray.push(..."\n".utf8CodeAt()); + + return dataArray; +} + +function getFileMime(fileName){ + let idx = fileName.lastIndexOf("."); + let mime = mimeMap[fileName.substr(idx)]; + return mime?mime:"application/octet-stream" +} + +String.prototype.utf8CodeAt = function(i) { + var str = this; + var out = [], p = 0; + var c = str.charCodeAt(i); + if (c < 128) { + out[p++] = c; + } else if (c < 2048) { + out[p++] = (c >> 6) | 192; + out[p++] = (c & 63) | 128; + } else if ( + ((c & 0xFC00) == 0xD800) && (i + 1) < str.length && + ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00)) { + // Surrogate Pair + c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF); + out[p++] = (c >> 18) | 240; + out[p++] = ((c >> 12) & 63) | 128; + out[p++] = ((c >> 6) & 63) | 128; + out[p++] = (c & 63) | 128; + } else { + out[p++] = (c >> 12) | 224; + out[p++] = ((c >> 6) & 63) | 128; + out[p++] = (c & 63) | 128; + } + return out; +}; + + +export default FormData; \ No newline at end of file diff --git a/utils/formdata/mimeMap.js b/utils/formdata/mimeMap.js new file mode 100644 index 0000000..f3d2c0f --- /dev/null +++ b/utils/formdata/mimeMap.js @@ -0,0 +1,346 @@ +const mimeMap = { + "0.001": "application/x-001", + "0.323": "text/h323", + "0.907": "drawing/907", + ".acp": "audio/x-mei-aac", + ".aif": "audio/aiff", + ".aiff": "audio/aiff", + ".asa": "text/asa", + ".asp": "text/asp", + ".au": "audio/basic", + ".awf": "application/vnd.adobe.workflow", + ".bmp": "application/x-bmp", + ".c4t": "application/x-c4t", + ".cal": "application/x-cals", + ".cdf": "application/x-netcdf", + ".cel": "application/x-cel", + ".cg4": "application/x-g4", + ".cit": "application/x-cit", + ".cml": "text/xml", + ".cmx": "application/x-cmx", + ".crl": "application/pkix-crl", + ".csi": "application/x-csi", + ".cut": "application/x-cut", + ".dbm": "application/x-dbm", + ".dcd": "text/xml", + ".der": "application/x-x509-ca-cert", + ".dib": "application/x-dib", + ".doc": "application/msword", + ".drw": "application/x-drw", + ".dwf": "Model/vnd.dwf", + ".dwg": "application/x-dwg", + ".dxf": "application/x-dxf", + ".emf": "application/x-emf", + ".ent": "text/xml", + ".eps": "application/x-ps", + ".etd": "application/x-ebx", + ".fax": "image/fax", + ".fif": "application/fractals", + ".frm": "application/x-frm", + ".gbr": "application/x-gbr", + ".gif": "image/gif", + ".gp4": "application/x-gp4", + ".hmr": "application/x-hmr", + ".hpl": "application/x-hpl", + ".hrf": "application/x-hrf", + ".htc": "text/x-component", + ".html": "text/html", + ".htx": "text/html", + ".ico": "image/x-icon", + ".iff": "application/x-iff", + ".igs": "application/x-igs", + ".img": "application/x-img", + ".isp": "application/x-internet-signup", + ".java": "java/*", + ".jpe": "image/jpeg", + ".jpeg": "image/jpeg", + ".jpg": "application/x-jpg", + ".jsp": "text/html", + ".lar": "application/x-laplayer-reg", + ".lavs": "audio/x-liquid-secure", + ".lmsff": "audio/x-la-lms", + ".ltr": "application/x-ltr", + ".m2v": "video/x-mpeg", + ".m4e": "video/mpeg4", + ".man": "application/x-troff-man", + ".mdb": "application/msaccess", + ".mfp": "application/x-shockwave-flash", + ".mhtml": "message/rfc822", + ".mid": "audio/mid", + ".mil": "application/x-mil", + ".mnd": "audio/x-musicnet-download", + ".mocha": "application/x-javascript", + ".mp1": "audio/mp1", + ".mp2v": "video/mpeg", + ".mp4": "video/mpeg4", + ".mpd": "application/vnd.ms-project", + ".mpeg": "video/mpg", + ".mpga": "audio/rn-mpeg", + ".mps": "video/x-mpeg", + ".mpv": "video/mpg", + ".mpw": "application/vnd.ms-project", + ".mtx": "text/xml", + ".net": "image/pnetvue", + ".nws": "message/rfc822", + ".out": "application/x-out", + ".p12": "application/x-pkcs12", + ".p7c": "application/pkcs7-mime", + ".p7r": "application/x-pkcs7-certreqresp", + ".pc5": "application/x-pc5", + ".pcl": "application/x-pcl", + ".pdf": "application/pdf", + ".pdx": "application/vnd.adobe.pdx", + ".pgl": "application/x-pgl", + ".pko": "application/vnd.ms-pki.pko", + ".plg": "text/html", + ".plt": "application/x-plt", + ".png": "application/x-png", + ".ppa": "application/vnd.ms-powerpoint", + ".pps": "application/vnd.ms-powerpoint", + ".ppt": "application/x-ppt", + ".prf": "application/pics-rules", + ".prt": "application/x-prt", + ".ps": "application/postscript", + ".pwz": "application/vnd.ms-powerpoint", + ".ra": "audio/vnd.rn-realaudio", + ".ras": "application/x-ras", + ".rdf": "text/xml", + ".red": "application/x-red", + ".rjs": "application/vnd.rn-realsystem-rjs", + ".rlc": "application/x-rlc", + ".rm": "application/vnd.rn-realmedia", + ".rmi": "audio/mid", + ".rmm": "audio/x-pn-realaudio", + ".rms": "application/vnd.rn-realmedia-secure", + ".rmx": "application/vnd.rn-realsystem-rmx", + ".rp": "image/vnd.rn-realpix", + ".rsml": "application/vnd.rn-rsml", + ".rtf": "application/msword", + ".rv": "video/vnd.rn-realvideo", + ".sat": "application/x-sat", + ".sdw": "application/x-sdw", + ".slb": "application/x-slb", + ".slk": "drawing/x-slk", + ".smil": "application/smil", + ".snd": "audio/basic", + ".sor": "text/plain", + ".spl": "application/futuresplash", + ".ssm": "application/streamingmedia", + ".stl": "application/vnd.ms-pki.stl", + ".sty": "application/x-sty", + ".swf": "application/x-shockwave-flash", + ".tg4": "application/x-tg4", + ".tif": "image/tiff", + ".tiff": "image/tiff", + ".top": "drawing/x-top", + ".tsd": "text/xml", + ".uin": "application/x-icq", + ".vcf": "text/x-vcard", + ".vdx": "application/vnd.visio", + ".vpg": "application/x-vpeg005", + ".vsd": "application/x-vsd", + ".vst": "application/vnd.visio", + ".vsw": "application/vnd.visio", + ".vtx": "application/vnd.visio", + ".wav": "audio/wav", + ".wb1": "application/x-wb1", + ".wb3": "application/x-wb3", + ".wiz": "application/msword", + ".wk4": "application/x-wk4", + ".wks": "application/x-wks", + ".wma": "audio/x-ms-wma", + ".wmf": "application/x-wmf", + ".wmv": "video/x-ms-wmv", + ".wmz": "application/x-ms-wmz", + ".wpd": "application/x-wpd", + ".wpl": "application/vnd.ms-wpl", + ".wr1": "application/x-wr1", + ".wrk": "application/x-wrk", + ".ws2": "application/x-ws", + ".wsdl": "text/xml", + ".xdp": "application/vnd.adobe.xdp", + ".xfd": "application/vnd.adobe.xfd", + ".xhtml": "text/html", + ".xls": "application/x-xls", + ".xml": "text/xml", + ".xq": "text/xml", + ".xquery": "text/xml", + ".xsl": "text/xml", + ".xwd": "application/x-xwd", + ".sis": "application/vnd.symbian.install", + ".x_t": "application/x-x_t", + ".apk": "application/vnd.android.package-archive", + "0.301": "application/x-301", + "0.906": "application/x-906", + ".a11": "application/x-a11", + ".ai": "application/postscript", + ".aifc": "audio/aiff", + ".anv": "application/x-anv", + ".asf": "video/x-ms-asf", + ".asx": "video/x-ms-asf", + ".avi": "video/avi", + ".biz": "text/xml", + ".bot": "application/x-bot", + ".c90": "application/x-c90", + ".cat": "application/vnd.ms-pki.seccat", + ".cdr": "application/x-cdr", + ".cer": "application/x-x509-ca-cert", + ".cgm": "application/x-cgm", + ".class": "java/*", + ".cmp": "application/x-cmp", + ".cot": "application/x-cot", + ".crt": "application/x-x509-ca-cert", + ".css": "text/css", + ".dbf": "application/x-dbf", + ".dbx": "application/x-dbx", + ".dcx": "application/x-dcx", + ".dgn": "application/x-dgn", + ".dll": "application/x-msdownload", + ".dot": "application/msword", + ".dtd": "text/xml", + ".dwf": "application/x-dwf", + ".dxb": "application/x-dxb", + ".edn": "application/vnd.adobe.edn", + ".eml": "message/rfc822", + ".epi": "application/x-epi", + ".eps": "application/postscript", + ".exe": "application/x-msdownload", + ".fdf": "application/vnd.fdf", + ".fo": "text/xml", + ".g4": "application/x-g4", + ".tif": "image/tiff", + ".gl2": "application/x-gl2", + ".hgl": "application/x-hgl", + ".hpg": "application/x-hpgl", + ".hqx": "application/mac-binhex40", + ".hta": "application/hta", + ".htm": "text/html", + ".htt": "text/webviewhtml", + ".icb": "application/x-icb", + ".ico": "application/x-ico", + ".ig4": "application/x-g4", + ".iii": "application/x-iphone", + ".ins": "application/x-internet-signup", + ".IVF": "video/x-ivf", + ".jfif": "image/jpeg", + ".jpe": "application/x-jpe", + ".jpg": "image/jpeg", + ".js": "application/x-javascript", + ".la1": "audio/x-liquid-file", + ".latex": "application/x-latex", + ".lbm": "application/x-lbm", + ".ls": "application/x-javascript", + ".m1v": "video/x-mpeg", + ".m3u": "audio/mpegurl", + ".mac": "application/x-mac", + ".math": "text/xml", + ".mdb": "application/x-mdb", + ".mht": "message/rfc822", + ".mi": "application/x-mi", + ".midi": "audio/mid", + ".mml": "text/xml", + ".mns": "audio/x-musicnet-stream", + ".movie": "video/x-sgi-movie", + ".mp2": "audio/mp2", + ".mp3": "audio/mp3", + ".mpa": "video/x-mpg", + ".mpe": "video/x-mpeg", + ".mpg": "video/mpg", + ".mpp": "application/vnd.ms-project", + ".mpt": "application/vnd.ms-project", + ".mpv2": "video/mpeg", + ".mpx": "application/vnd.ms-project", + ".mxp": "application/x-mmxp", + ".nrf": "application/x-nrf", + ".odc": "text/x-ms-odc", + ".p10": "application/pkcs10", + ".p7b": "application/x-pkcs7-certificates", + ".p7m": "application/pkcs7-mime", + ".p7s": "application/pkcs7-signature", + ".pci": "application/x-pci", + ".pcx": "application/x-pcx", + ".pdf": "application/pdf", + ".pfx": "application/x-pkcs12", + ".pic": "application/x-pic", + ".pl": "application/x-perl", + ".pls": "audio/scpls", + ".png": "image/png", + ".pot": "application/vnd.ms-powerpoint", + ".ppm": "application/x-ppm", + ".ppt": "application/vnd.ms-powerpoint", + ".pr": "application/x-pr", + ".prn": "application/x-prn", + ".ps": "application/x-ps", + ".ptn": "application/x-ptn", + ".r3t": "text/vnd.rn-realtext3d", + ".ram": "audio/x-pn-realaudio", + ".rat": "application/rat-file", + ".rec": "application/vnd.rn-recording", + ".rgb": "application/x-rgb", + ".rjt": "application/vnd.rn-realsystem-rjt", + ".rle": "application/x-rle", + ".rmf": "application/vnd.adobe.rmf", + ".rmj": "application/vnd.rn-realsystem-rmj", + ".rmp": "application/vnd.rn-rn_music_package", + ".rmvb": "application/vnd.rn-realmedia-vbr", + ".rnx": "application/vnd.rn-realplayer", + ".rpm": "audio/x-pn-realaudio-plugin", + ".rt": "text/vnd.rn-realtext", + ".rtf": "application/x-rtf", + ".sam": "application/x-sam", + ".sdp": "application/sdp", + ".sit": "application/x-stuffit", + ".sld": "application/x-sld", + ".smi": "application/smil", + ".smk": "application/x-smk", + ".sol": "text/plain", + ".spc": "application/x-pkcs7-certificates", + ".spp": "text/xml", + ".sst": "application/vnd.ms-pki.certstore", + ".stm": "text/html", + ".svg": "text/xml", + ".tdf": "application/x-tdf", + ".tga": "application/x-tga", + ".tif": "application/x-tif", + ".tld": "text/xml", + ".torrent": "application/x-bittorrent", + ".txt": "text/plain", + ".uls": "text/iuls", + ".vda": "application/x-vda", + ".vml": "text/xml", + ".vsd": "application/vnd.visio", + ".vss": "application/vnd.visio", + ".vst": "application/x-vst", + ".vsx": "application/vnd.visio", + ".vxml": "text/xml", + ".wax": "audio/x-ms-wax", + ".wb2": "application/x-wb2", + ".wbmp": "image/vnd.wap.wbmp", + ".wk3": "application/x-wk3", + ".wkq": "application/x-wkq", + ".wm": "video/x-ms-wm", + ".wmd": "application/x-ms-wmd", + ".wml": "text/vnd.wap.wml", + ".wmx": "video/x-ms-wmx", + ".wp6": "application/x-wp6", + ".wpg": "application/x-wpg", + ".wq1": "application/x-wq1", + ".wri": "application/x-wri", + ".ws": "application/x-ws", + ".wsc": "text/scriptlet", + ".wvx": "video/x-ms-wvx", + ".xdr": "text/xml", + ".xfdf": "application/vnd.adobe.xfdf", + ".xls": "application/vnd.ms-excel", + ".xlw": "application/x-xlw", + ".xpl": "audio/scpls", + ".xql": "text/xml", + ".xsd": "text/xml", + ".xslt": "text/xml", + ".x_b": "application/x-x_b", + ".sisx": "application/vnd.symbian.install", + ".ipa": "application/vnd.iphone", + ".xap": "application/x-silverlight-app", + ".zip": "application/x-zip-compressed", +} +export default mimeMap; \ No newline at end of file -- Gitblit v1.9.1