ÎļþÃû´Ó ruoyi-ui/src/components/ImageUpload/index.vue ÐÞ¸Ä |
| | |
| | | <!-- ä¸ä¼ æä»¶å°è£
--> |
| | | <template> |
| | | <div class="component-upload-image"> |
| | | <el-upload |
| | |
| | | <!-- ä¸ä¼ æç¤º --> |
| | | <div class="el-upload__tip" slot="tip" v-if="showTip"> |
| | | 请ä¸ä¼ |
| | | <template v-if="fileSize"> 大å°ä¸è¶
è¿ <b style="color: #f56c6c">{{ fileSize }}MB</b> </template> |
| | | <template v-if="fileType"> æ ¼å¼ä¸º <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template> |
| | | <template v-if="fileSize"> |
| | | 大å°ä¸è¶
è¿ <b style="color: #f56c6c">{{ fileSize }}MB</b> |
| | | </template> |
| | | <template v-if="fileType"> |
| | | æ ¼å¼ä¸º <b style="color: #f56c6c">{{ fileType.join("/") }}</b> |
| | | </template> |
| | | çæä»¶ |
| | | </div> |
| | | |
| | |
| | | // æ¯å¦æ¾ç¤ºæç¤º |
| | | isShowTip: { |
| | | type: Boolean, |
| | | default: true |
| | | } |
| | | default: true, |
| | | }, |
| | | }, |
| | | data() { |
| | | return { |
| | |
| | | headers: { |
| | | Authorization: "Bearer " + getToken(), |
| | | }, |
| | | fileList: [] |
| | | fileList: [], |
| | | }; |
| | | }, |
| | | watch: { |
| | |
| | | handler(val) { |
| | | if (val) { |
| | | // é¦å
å°å¼è½¬ä¸ºæ°ç» |
| | | const list = Array.isArray(val) ? val : this.value.split(','); |
| | | const list = Array.isArray(val) ? val : this.value.split(","); |
| | | // ç¶åå°æ°ç»è½¬ä¸ºå¯¹è±¡æ°ç» |
| | | this.fileList = list.map(item => { |
| | | this.fileList = list.map((item) => { |
| | | if (typeof item === "string") { |
| | | if (item.indexOf(this.baseUrl) === -1) { |
| | | item = { name: this.baseUrl + item, url: this.baseUrl + item }; |
| | |
| | | } |
| | | }, |
| | | deep: true, |
| | | immediate: true |
| | | } |
| | | immediate: true, |
| | | }, |
| | | }, |
| | | computed: { |
| | | // æ¯å¦æ¾ç¤ºæç¤º |
| | |
| | | if (file.name.lastIndexOf(".") > -1) { |
| | | fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1); |
| | | } |
| | | isImg = this.fileType.some(type => { |
| | | isImg = this.fileType.some((type) => { |
| | | if (file.type.indexOf(type) > -1) return true; |
| | | if (fileExtension && fileExtension.indexOf(type) > -1) return true; |
| | | return false; |
| | |
| | | } |
| | | |
| | | if (!isImg) { |
| | | this.$modal.msgError(`æä»¶æ ¼å¼ä¸æ£ç¡®, 请ä¸ä¼ ${this.fileType.join("/")}å¾çæ ¼å¼æä»¶!`); |
| | | this.$modal.msgError( |
| | | `æä»¶æ ¼å¼ä¸æ£ç¡®, 请ä¸ä¼ ${this.fileType.join("/")}å¾çæ ¼å¼æä»¶!` |
| | | ); |
| | | return false; |
| | | } |
| | | if (this.fileSize) { |
| | |
| | | }, |
| | | // å é¤å¾ç |
| | | handleDelete(file) { |
| | | const findex = this.fileList.map(f => f.name).indexOf(file.name); |
| | | const findex = this.fileList.map((f) => f.name).indexOf(file.name); |
| | | if(findex > -1) { |
| | | this.fileList.splice(findex, 1); |
| | | this.$emit("input", this.listToString(this.fileList)); |
| | |
| | | strs += list[i].url.replace(this.baseUrl, "") + separator; |
| | | } |
| | | } |
| | | return strs != '' ? strs.substr(0, strs.length - 1) : ''; |
| | | } |
| | | } |
| | | return strs != "" ? strs.substr(0, strs.length - 1) : ""; |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | <style scoped lang="scss"> |
| | |
| | | transition: all 0s; |
| | | } |
| | | |
| | | ::v-deep .el-list-enter, .el-list-leave-active { |
| | | ::v-deep .el-list-enter, |
| | | .el-list-leave-active { |
| | | opacity: 0; |
| | | transform: translateY(0); |
| | | } |
| | | </style> |
| | | |