|
@@ -42,6 +42,7 @@
|
|
import {isIos,isWX,isQQ} from '../utils/tools';
|
|
import {isIos,isWX,isQQ} from '../utils/tools';
|
|
import api from '../utils/api.js';
|
|
import api from '../utils/api.js';
|
|
import $ from 'jquery';
|
|
import $ from 'jquery';
|
|
|
|
+import {mapState} from 'vuex';
|
|
export default {
|
|
export default {
|
|
name: 'UploadImg',
|
|
name: 'UploadImg',
|
|
data() {
|
|
data() {
|
|
@@ -54,6 +55,11 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
props: ['item', 'moduleType', 'imgList','num'],
|
|
props: ['item', 'moduleType', 'imgList','num'],
|
|
|
|
+ computed:{
|
|
|
|
+ ...mapState({
|
|
|
|
+ imgUpList: state => state.diagnose.imgFile,
|
|
|
|
+ }),
|
|
|
|
+ },
|
|
mounted() {
|
|
mounted() {
|
|
this.imgs = this.imgList; //回读
|
|
this.imgs = this.imgList; //回读
|
|
this.imgLen = Object.keys(this.imgList).length;
|
|
this.imgLen = Object.keys(this.imgList).length;
|
|
@@ -72,19 +78,58 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- saveAllImage() {
|
|
|
|
|
|
+ async saveAllImage() {
|
|
let n = this.num;
|
|
let n = this.num;
|
|
|
|
+ let uploadFail = false;
|
|
|
|
+ const data = await this.uploadImgs(this.$store.state.diagnose.imgFile).then((res)=>{
|
|
|
|
+ let data = res.data;
|
|
|
|
+ if (data.code == 0) {//图片提交成功再保存数据
|
|
|
|
+ this.saveImgs(data);
|
|
|
|
+ } else {//提交失败提示
|
|
|
|
+ this.$emit('warning',data.msg);
|
|
|
|
+ uploadFail=true;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if(uploadFail){ //上传失败,暂停
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
if(Object.keys(this.imgs).length===0){
|
|
if(Object.keys(this.imgs).length===0){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
this.$emit("updataResult",this.item,{val:this.imgs,valp:this.imgs},++n);
|
|
this.$emit("updataResult",this.item,{val:this.imgs,valp:this.imgs},++n);
|
|
},
|
|
},
|
|
- /*handleUpload() {
|
|
|
|
- const inp = this.$refs.inp;
|
|
|
|
- if(this.flag){
|
|
|
|
- inp.click();
|
|
|
|
|
|
+ uploadImgs() {
|
|
|
|
+ const imgList = this.imgUpList;
|
|
|
|
+ return new Promise((resolve,reject)=>{
|
|
|
|
+ let formData = new FormData();
|
|
|
|
+ if (imgList.length > 0) {//有图片先上传图片
|
|
|
|
+ for (let i = 0; i < imgList.length; i++) {
|
|
|
|
+ let pageFile = imgList[i].file;
|
|
|
|
+ formData.append('upfiles', imgList[i].file);
|
|
|
|
+ formData.append('type', imgList[i].type);
|
|
|
|
+ }
|
|
|
|
+ api.uploadImageThums(formData).then((res) => {//获取图片
|
|
|
|
+ resolve(res)
|
|
|
|
+ }).catch((err)=>{
|
|
|
|
+ this.$emit('warning','上传失败,请稍后重试!');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ saveImgs(data){
|
|
|
|
+ const imgList = this.imgUpList;
|
|
|
|
+ let reportList = [];
|
|
|
|
+ let result = data.data;
|
|
|
|
+ for(let i = 0;i < result.length;i++){
|
|
|
|
+ let obg = {}
|
|
|
|
+ obg.originalImage = result[i].url+'?width='+imgList[i].imgWidth+'&height='+imgList[i].imgHeight
|
|
|
|
+ obg.originalName = result[i].original
|
|
|
|
+ obg.orderNum = i+1
|
|
|
|
+ obg.type = result[i].type
|
|
|
|
+ reportList.push(obg)
|
|
}
|
|
}
|
|
- },*/
|
|
|
|
|
|
+ this.$store.commit("setUploadImgs",reportList);
|
|
|
|
+ },
|
|
delImg(key) {
|
|
delImg(key) {
|
|
let obj = this.imgs;
|
|
let obj = this.imgs;
|
|
delete (obj[key]);
|
|
delete (obj[key]);
|
|
@@ -125,7 +170,7 @@ export default {
|
|
that.imgLen++;
|
|
that.imgLen++;
|
|
// 将图片信息存到store
|
|
// 将图片信息存到store
|
|
that.$store.commit('setImgFile', { type: that.moduleType, pId: that.item.id, key: key, file: uploadFile,imgWidth:imgWidth, imgHeight:imgHeight})
|
|
that.$store.commit('setImgFile', { type: that.moduleType, pId: that.item.id, key: key, file: uploadFile,imgWidth:imgWidth, imgHeight:imgHeight})
|
|
- that.$store.commit('setImgSrc', { key: key, src: uploadSrc, type: that.moduleType })
|
|
|
|
|
|
+ that.$store.commit('setImgSrc', { key: key, src: uploadSrc, type: that.moduleType });
|
|
that.$previewRefresh(); //异步获取的图片需要刷新下
|
|
that.$previewRefresh(); //异步获取的图片需要刷新下
|
|
}
|
|
}
|
|
// that.$refs.inp.value = '';
|
|
// that.$refs.inp.value = '';
|