Browse Source

新增价值条和报错提示

master
liaoxinyu 3 weeks ago
parent
commit
226b20120a
  1. 2
      src/api/member.js
  2. 104
      src/components/UploadImg.vue
  3. 3
      src/i18n/en.json
  4. 3
      src/i18n/tw.json

2
src/api/member.js

@ -85,7 +85,7 @@ class Member {
* @param {FormData} data * @param {FormData} data
*/ */
static uploadImage(data) { static uploadImage(data) {
return server.post(`/uploadImage`, data); return server.post(`/uploadImage`, data,{config:{loading:false}});
} }
/** /**

104
src/components/UploadImg.vue

@ -1,25 +1,35 @@
<template> <template>
<div class="d-flex align-items-end"> <div>
<button v-if="type=='file'" class="btn btn-light btn-sm change-file-button"> <div class="d-flex align-items-end">
{{file&&file.name||$t('common.selectFile')}} <button v-if="type=='file'" class="btn btn-light btn-sm change-file-button">
<input type="file" class="file" :required="required" :placeholder="placeholder" ref="file" @change="change" /> {{file&&file.name||$t('common.selectFile')}}
</button> <input type="file" class="file" :required="required" :placeholder="placeholder" ref="file" @change="change" />
<div v-else class="el-upload-dragger mr-2 flex-shrink-0"> </button>
<label> <div v-else class="el-upload-dragger mr-2 flex-shrink-0">
<input type="file" class="file" :required="required" :placeholder="placeholder" ref="file" @change="change" /> <label>
<img class="img" v-if="uploadImg" :src="imgFilter(uploadImg)" alt /> <input type="file" class="file" :required="required" :placeholder="placeholder" ref="file" @change="change" />
<template v-else> <img class="img" v-if="uploadImg" :src="imgFilter(uploadImg)" alt />
<i class="el-icon-upload"></i> <template v-else>
<slot name="text"></slot> <i class="el-icon-upload"></i>
</template> <slot name="text"></slot>
</label> </template>
</div> </label>
<div v-if="file"> </div>
<p>{{file.name}}</p> <div v-if="file">
<!-- <button class="btn upload-btn btn-sm btn-primary" @click="upload" v-if="!value">{{$t('common.upload')}}</button> --> <p>{{file.name}}</p>
<!-- v-else --> <!-- <button class="btn upload-btn btn-sm btn-primary" @click="upload" v-if="!value">{{$t('common.upload')}}</button> -->
<button class="btn upload-btn btn-sm btn-danger" @click="del" >{{$t('common.delete')}}</button> <!-- v-else -->
</div> <button class="btn upload-btn btn-sm btn-danger" @click="del" >{{$t('common.delete')}}</button>
</div>
</div>
<el-progress
style="width:300px"
v-if="boll"
:percentage="uploadProgress"
:status="uploadStatus"
:stroke-width="10"
class="my-2"
></el-progress>
</div> </div>
</template> </template>
<script> <script>
@ -30,7 +40,12 @@ export default {
return { return {
file: undefined, file: undefined,
uploadImg: "", uploadImg: "",
isLoad: false isLoad: false,
uploadProgress: 0, //
uploadStatus: null,//
progressInterval: null,
boll:false,
continueUploading:true
}; };
}, },
watch:{ watch:{
@ -48,6 +63,10 @@ export default {
}, },
methods: { methods: {
del() { del() {
this.uploadProgress = 0;
this.uploadStatus = null;
this.boll = false
this.file = undefined; this.file = undefined;
this.$emit("input", undefined); this.$emit("input", undefined);
this.$refs.file.value='' this.$refs.file.value=''
@ -60,6 +79,9 @@ export default {
} }
}, },
change(ev) { change(ev) {
this.uploadProgress = 0;
this.uploadStatus = null;
let file = this.$refs.file.files[0]; let file = this.$refs.file.files[0];
let ele = this.$refs.file; let ele = this.$refs.file;
@ -68,8 +90,7 @@ export default {
allowSize:this.allowSize|| 5, // M allowSize:this.allowSize|| 5, // M
allowType: ["image/png", "image/jpg", "image/jpeg", "image/pdf"] allowType: ["image/png", "image/jpg", "image/jpeg", "image/pdf"]
}; };
utils utils.upload(option)
.upload(option)
.then(result => { .then(result => {
if (result.isIMG) { if (result.isIMG) {
// //
@ -90,11 +111,44 @@ export default {
}); });
}, },
upload() { upload() {
this.uploadStatus = null //
this.uploadProgress = 0 //
this.boll = true
clearInterval(this.progressInterval); //
this.progressInterval = setInterval(() => {
if (this.uploadProgress < 100&&this.continueUploading) {
this.uploadProgress += Math.floor(Math.random() * 3) + 1;
setTimeout(() => {
this.continueUploading = false;
// 3
setTimeout(() => {
this.continueUploading = true;
}, 3000); // 30003
}, 1000);
}
}, 50);
let data = new FormData(); let data = new FormData();
data.append("image", this.file); data.append("image", this.file);
Member.uploadImage(data).then(res => { Member.uploadImage(data).then(res => {
this.$emit("input", res.path); this.$emit("input", res.path);
}); // 2
if(res.path){
setTimeout(() => {
this.uploadStatus = 'success'
this.uploadProgress = 100
clearInterval(this.progressInterval); //
setTimeout(() => {
this.boll = false
},3000)
}, 2000)
}
}).catch(err => {
this.uploadStatus = 'exception'
this.uploadProgress = 100
this.$message.error(this.$t('common.uploadfailed'));
});
} }
} }
}; };

3
src/i18n/en.json

@ -219,7 +219,8 @@
"footerTips4": "Restricted Areas: Unable to provide services to residents of specific countries / regions, such as Israel and the Islamic Republic of China", "footerTips4": "Restricted Areas: Unable to provide services to residents of specific countries / regions, such as Israel and the Islamic Republic of China",
"learn":"Learn", "learn":"Learn",
"GraphicValidation": "Graphical Verification", "GraphicValidation": "Graphical Verification",
"c12": "Rejection Information" "c12": "Rejection Information",
"uploadfailed": "Upload failed, please upload again."
}, },
"exchange": { "exchange": {
"search": "Search", "search": "Search",

3
src/i18n/tw.json

@ -220,7 +220,8 @@
"footerTips4": "受限地區:無法為特定國家/地區的居民提供服務,例如:以色列和伊斯蘭共和國", "footerTips4": "受限地區:無法為特定國家/地區的居民提供服務,例如:以色列和伊斯蘭共和國",
"learn":"學院", "learn":"學院",
"GraphicValidation": "圖形驗證", "GraphicValidation": "圖形驗證",
"c12": "駁回信息" "c12": "駁回信息",
"uploadfailed": "上傳失敗,請重新上傳"
}, },
"exchange": { "exchange": {
"search": "搜索", "search": "搜索",

Loading…
Cancel
Save