From 575e9983d9cbbf99ea317035b88c2d8daf4232ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E7=90=AA?= Date: Thu, 18 Aug 2022 17:37:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=94=9F=E4=BF=A1=E6=81=AF=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LearunApp-2.2.0/common/mixins.js | 15 + .../learun-mpui/learun-ui-mp/upload.vue | 79 ++++- .../components/upload-file.vue | 300 ++++++++++++++++++ .../LearunApp-2.2.0/config.js | 7 +- .../pages/MealCardRunTab/list.vue | 5 +- .../LearunApp-2.2.0/pages/welcome/list.vue | 25 +- 6 files changed, 410 insertions(+), 21 deletions(-) create mode 100644 Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/mixins.js b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/mixins.js index 403dc9c31..8fe797283 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/mixins.js +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/common/mixins.js @@ -263,6 +263,12 @@ export default { return this.handleResult(err, res) }, + + async HTTP_UPLOAD2(url,filePath, formData) { + const [err, res] = await this.UPLOAD(url, filePath, formData) + + return this.handleResult(err, res) + }, // 封装的文件下载,集成了验证信息 // 返回临时文件路径或 null @@ -654,6 +660,7 @@ export default { title: '登录状态无效,正在跳转到登录页…', icon: 'none' }) + return null this.CLEAR_GLOBAL() uni.reLaunch({ url: '/pages/login' @@ -673,6 +680,14 @@ export default { return null } + if(result.data.code != 200){ + uni.hideLoading() + uni.showToast({ + title: result.data.info, + icon: 'none' + }) + return null + } return result.data.data }, diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-mpui/learun-ui-mp/upload.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-mpui/learun-ui-mp/upload.vue index d5c17cdb0..f615e5f06 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-mpui/learun-ui-mp/upload.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/learun-mpui/learun-ui-mp/upload.vue @@ -3,14 +3,13 @@ - @@ -90,8 +89,26 @@ export default { }, uploadImage(){ - // 单图上传 多图没写 + // let array = + // function apiFn(item){ + // return this.HTTP_POST('StuInfoFresh/savePhoto', postData, '图片上传失败!').then((data) => { + // if (data) { + // reslove([{ + // url:data.Url, + // id:data.AnnexesFileId + // }]) + // }else{ + // reject('图片上传失败!') + // } + // }) + // } + // return this.promiseAllLimit(5,array,apiFn) + // 单图上传 return new Promise(async (reslove,reject)=>{ + let hasNotUpdatedList = this.imgList.every(item=>item.id) + if(hasNotUpdatedList){ + reslove(this.imgList) + } if(this.imgList.length){ var postData = { Base64Url: await this.imgToBase64(this.imgList[0].url) @@ -110,11 +127,59 @@ export default { reslove("") } }) - + }, + + /** + * @description 控制promise.all并发数量 + * @param limit 并发数 + * @param array 参数列表 + * @param apiFn 执行函数 + * @returns {Promise[]>} + */ + async promiseAllLimit(limit, array, apiFn) { + const ret = [] // 用于存放所有的promise实例 + const executing = [] // 用于存放目前正在执行的promise + for (const item of array) { + const p = apiFn(item) + ret.push(p) + if (limit <= array.length) { + // then回调中,当这个promise状态变为fulfilled后,将其从正在执行的promise列表executing中删除 + const e = p.then(() => executing.splice(executing.indexOf(e), 1)) + executing.push(e) + if (executing.length >= limit) { + // 一旦正在执行的promise列表数量等于限制数,就使用Promise.race等待某一个promise状态发生变更, + // 状态变更后,就会执行上面then的回调,将该promise从executing中删除, + // 然后再进入到下一次for循环,生成新的promise进行补充 + await Promise.race(executing) + } + } + } + return Promise.all(ret) + }, + + validate(array){ + // let type = array.every(item=>{ + // return item.type && item.type.substring(0,6) == "image/" + // }) + // if(!type){ + // this.TOAST('文件类型错误'); + // return false + // } + let size = array.every(item=>{ + return item.size && item.size <= 10 * 1024 * 1024 + }) + if(!size){ + this.TOAST('文件大小不得超过10M'); + return false + } + return true }, imgToBase64(url){ return new Promise((resolve,reject)=>{ + if(!url){ + resolve("") + } var canvas = document.createElement('canvas'), ctx = canvas.getContext('2d'), img = new Image; @@ -152,8 +217,8 @@ export default { viewImg(index) { uni.previewImage({ - urls: this.imgList, - current: this.imgList[index], + urls: this.imgList.map(item=>item.id?this.CONFIG('webHost')+item.url:item.url), + current: this.imgList[index].id?this.CONFIG('webHost')+this.imgList[index].url:this.imgList[index].url, }); }, diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue new file mode 100644 index 000000000..f10c9e3f2 --- /dev/null +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/upload-file.vue @@ -0,0 +1,300 @@ + + + + + diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js index 6b208c6b5..826a1fd3c 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/config.js @@ -22,12 +22,13 @@ export default { // ], "apiHost": [ // "http://localhost:31173/" - "http://192.168.10.58:8012/" + "http://192.168.10.85:8088/" ], + "webHost":"http://192.168.10.85:8087/", // 开发环境下自动填充登录账号密码,与接口地址一一对应,只在开发环境下显示 "devAccount": [ - // 20201130230 - { username: "420528200606205026", password: "www.qj.com" } + // 20201130230 21364200000400266 老师 420528196310072253 学生 420528200606205026 + { username: "420528200507261428", password: "www.qj.com" } ], //是否分布式部署 指WebApi与Web不在一台服务器 "isDistributed":true, diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/MealCardRunTab/list.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/MealCardRunTab/list.vue index 4a7742b8e..bafee7915 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/MealCardRunTab/list.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/MealCardRunTab/list.vue @@ -14,7 +14,7 @@ - {{item.bigGroup}} + {{item.bigGroup}}{{item.smallGroup?"-"+item.smallGroup:""}} 餐次:{{item.seg||"--"}} @@ -231,7 +231,8 @@ this.multipleData.StartTime = this.dateRange.start this.multipleData.EndTime = this.dateRange.end } else{ - + this.multipleData.StartTime = "" + this.multipleData.EndTime = "" } // console.log(this.dateRange,"==========") diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/welcome/list.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/welcome/list.vue index c0ef8e316..26773f034 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/welcome/list.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/welcome/list.vue @@ -63,7 +63,9 @@ - 保存 + 附件 + + 保存 @@ -71,11 +73,16 @@ import moment from 'moment'; import get from 'lodash/get'; import set from 'lodash/set'; +import uploadFile from '@/components/upload-file.vue' export default { + components:{ + uploadFile, + }, data() { return { photo:[], - uploadVisiable:true, + fileList:[], + uploadVisiable:false, imgSrc: '', scheme: { PartyFaceNo: { @@ -141,8 +148,10 @@ export default { _this.queryData.StuInfoFreshFamilyEntities = _this.COPY(res.StuInfoFreshFamilyList); _this.queryData.StuInfoFreshEmergePeopleEntities = _this.COPY(res.StuInfoFreshEmergePeopleList); _this.queryData.ID = res.StuInfoFreshEntity.ID; + _this.queryData.Photo = res.StuInfoFreshEntity.Photo; - _this.photo = [{url:res.StuInfoFreshEntity.Photo}]; + _this.photo = [{url:res.StuInfoFreshEntity.Url,id:res.StuInfoFreshEntity.Photo}]; + _this.fileList = res.StuInfoFreshEntity.FilesList _this.refreshComponent() _this.queryData.telephone = res.StuInfoFreshEntity.telephone; _this.queryData.FamilyAddress = res.StuInfoFreshEntity.FamilyAddress; @@ -150,16 +159,14 @@ export default { // _this.imgSrc = this.API.slice(0,-1) + res.Url; }); }, - async tapBtn() { + async submit() { this.LOADING('正在提交数据…'); let res = await this.$refs["upload"].uploadImage() - if(res){ - this.queryData.Photo = res[0]["AnnexesFileId"]; + if(res&&res.length){ + this.queryData.Photo = res[0]["id"]; } - console.log(this.queryData) - this.HTTP_GET('StuInfoFresh/saveStuInfoFresh', this.queryData, '加载数据时出错').then(res => { + this.HTTP_GET('StuInfoFresh/saveStuInfoFresh', this.queryData).then(res => { this.HIDE_LOADING(); - // console.log(res); if (res) { this.TOAST('保存成功'); }