|
|
@@ -7,11 +7,12 @@
|
|
|
:file-list="fileList"
|
|
|
:show-file-list="true"
|
|
|
:limit="limit"
|
|
|
+ :on-change="handleChange"
|
|
|
:on-error="handleUploadError"
|
|
|
:on-exceed="handleExceed"
|
|
|
:on-success="handleUploadSuccess"
|
|
|
:on-preview="handlePictureCardPreview"
|
|
|
- :before-remove="beforeRemove"
|
|
|
+ :on-remove="handleRemove"
|
|
|
list-type="picture-card"
|
|
|
class="upload-file-uploader"
|
|
|
ref="upload"
|
|
|
@@ -26,34 +27,9 @@
|
|
|
<div class="el-upload__tips" slot="tip" v-if="showTip">
|
|
|
*建议尺寸800x800像素,大小10M以下
|
|
|
</div>
|
|
|
- <el-dialog :visible.sync="dialogVisible">
|
|
|
+ <el-dialog append-to-body :visible.sync="dialogVisible">
|
|
|
<img width="100%" :src="dialogImageUrl" alt="" />
|
|
|
</el-dialog>
|
|
|
- <!-- 文件列表 -->
|
|
|
- <!-- <transition-group
|
|
|
- class="upload-file-list el-upload-list el-upload-list--text"
|
|
|
- name="el-fade-in-linear"
|
|
|
- tag="ul"
|
|
|
- >
|
|
|
- <li
|
|
|
- :key="file.uid"
|
|
|
- class="el-upload-list__item ele-upload-list__item-content"
|
|
|
- v-for="(file, index) in fileList"
|
|
|
- >
|
|
|
- <el-link
|
|
|
- :href="`${baseUrl}${file.url}`"
|
|
|
- :underline="false"
|
|
|
- target="_blank"
|
|
|
- >
|
|
|
- <span class="el-icon-document"> {{ getFileName(file.name) }} </span>
|
|
|
- </el-link>
|
|
|
- <div class="ele-upload-list__item-content-action">
|
|
|
- <el-link :underline="false" @click="handleDelete(index)" type="danger"
|
|
|
- >删除</el-link
|
|
|
- >
|
|
|
- </div>
|
|
|
- </li>
|
|
|
- </transition-group> -->
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -62,9 +38,13 @@ import { getToken } from "@/utils/auth";
|
|
|
|
|
|
export default {
|
|
|
name: "FileUpload",
|
|
|
+ model: {
|
|
|
+ prop: "flies",
|
|
|
+ event: "changeFlie",
|
|
|
+ },
|
|
|
props: {
|
|
|
// 值
|
|
|
- value: [String, Object, Array],
|
|
|
+ flies: [String, Object, Array],
|
|
|
// 数量限制
|
|
|
limit: {
|
|
|
type: Number,
|
|
|
@@ -73,7 +53,7 @@ export default {
|
|
|
// 大小限制(MB)
|
|
|
fileSize: {
|
|
|
type: Number,
|
|
|
- default: 5,
|
|
|
+ default: 10,
|
|
|
},
|
|
|
// 文件类型, 例如['png', 'jpg', 'jpeg'] ["doc", "xls", "ppt", "txt", "pdf"],
|
|
|
fileType: {
|
|
|
@@ -92,23 +72,19 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- baseUrl: process.env.VUE_APP_BASE_API,
|
|
|
- uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
|
|
|
- headers: {
|
|
|
- Authorization: "Bearer " + getToken(),
|
|
|
- },
|
|
|
fileList: [],
|
|
|
+ upload_List: [],
|
|
|
dialogVisible: false,
|
|
|
dialogImageUrl: "",
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
|
- value: {
|
|
|
+ flies: {
|
|
|
handler(val) {
|
|
|
if (val) {
|
|
|
let temp = 1;
|
|
|
// 首先将值转为数组
|
|
|
- const list = Array.isArray(val) ? val : this.value.split(",");
|
|
|
+ const list = Array.isArray(val) ? val : this.flies.split(",");
|
|
|
// 然后将数组转为对象数组
|
|
|
this.fileList = list.map((item) => {
|
|
|
if (typeof item === "string") {
|
|
|
@@ -117,6 +93,7 @@ export default {
|
|
|
item.uid = item.uid || new Date().getTime() + temp++;
|
|
|
return item;
|
|
|
});
|
|
|
+ this.upload_List = JSON.parse(JSON.stringify(this.fileList));
|
|
|
} else {
|
|
|
this.fileList = [];
|
|
|
return [];
|
|
|
@@ -133,19 +110,31 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
- beforeRemove(file, fileList) {
|
|
|
- console.log(file, fileList);
|
|
|
- this.fileList = fileList;
|
|
|
+ handleChange(file, fileList) {
|
|
|
+ this.fileList = JSON.parse(JSON.stringify(fileList));
|
|
|
+ },
|
|
|
+ handleRemove(file, fileList) {
|
|
|
+ this.fileList = JSON.parse(JSON.stringify(fileList));
|
|
|
+ this.upload_List.forEach((item, index) => {
|
|
|
+ if (item.uid == file.uid) {
|
|
|
+ this.upload_List.splice(index, 1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.$emit("changeFlie", JSON.parse(JSON.stringify(this.upload_List)));
|
|
|
},
|
|
|
handlePictureCardPreview(file) {
|
|
|
this.dialogImageUrl = file.url;
|
|
|
this.dialogVisible = true;
|
|
|
},
|
|
|
- requestUpload(file) {
|
|
|
+ requestUpload({ file }) {
|
|
|
this.$upload.upload(file, 0).then((res) => {
|
|
|
const url = this.$methodsTools.splitImgHost(res);
|
|
|
- this.fileList.push({ name: url, url: url });
|
|
|
- this.$emit("input", this.listToString(this.fileList));
|
|
|
+ this.upload_List.push({
|
|
|
+ name: file.name,
|
|
|
+ url: url,
|
|
|
+ uid: file.uid,
|
|
|
+ });
|
|
|
+ this.$emit("changeFlie", JSON.parse(JSON.stringify(this.upload_List)));
|
|
|
});
|
|
|
},
|
|
|
// 上传前校检格式和大小
|
|
|
@@ -192,11 +181,6 @@ export default {
|
|
|
this.fileList.push({ name: res.fileName, url: res.fileName });
|
|
|
this.$emit("input", this.listToString(this.fileList));
|
|
|
},
|
|
|
- // 删除文件
|
|
|
- handleDelete(index) {
|
|
|
- this.fileList.splice(index, 1);
|
|
|
- this.$emit("input", this.listToString(this.fileList));
|
|
|
- },
|
|
|
// 获取文件名称
|
|
|
getFileName(name) {
|
|
|
if (name.lastIndexOf("/") > -1) {
|
|
|
@@ -205,62 +189,23 @@ export default {
|
|
|
return "";
|
|
|
}
|
|
|
},
|
|
|
- // 对象转成指定字符串分隔
|
|
|
- listToString(list, separator) {
|
|
|
- let strs = "";
|
|
|
- separator = separator || ",";
|
|
|
- for (let i in list) {
|
|
|
- strs += list[i].url + separator;
|
|
|
- }
|
|
|
- return strs != "" ? strs.substr(0, strs.length - 1) : "";
|
|
|
- },
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
-.upload-file-uploader {
|
|
|
- margin-bottom: 5px;
|
|
|
-}
|
|
|
-.upload-file-list .el-upload-list__item {
|
|
|
- border: 1px solid #e4e7ed;
|
|
|
- line-height: 2;
|
|
|
- margin-bottom: 10px;
|
|
|
- position: relative;
|
|
|
-}
|
|
|
-.upload-file-list .ele-upload-list__item-content {
|
|
|
- display: flex;
|
|
|
- justify-content: space-between;
|
|
|
- align-items: center;
|
|
|
- color: inherit;
|
|
|
-}
|
|
|
-.ele-upload-list__item-content-action .el-link {
|
|
|
- margin-right: 10px;
|
|
|
-}
|
|
|
-// .uploladBtn {
|
|
|
-// width: 72px;
|
|
|
-// height: 72px;
|
|
|
-// background: #f5f6f7;
|
|
|
-// border-radius: 8px;
|
|
|
-// font-size: 20px;
|
|
|
-// }
|
|
|
.el-upload__tips {
|
|
|
color: #999999;
|
|
|
font-size: 12px;
|
|
|
height: 0;
|
|
|
margin-bottom: 20px;
|
|
|
}
|
|
|
-/deep/ .el-upload--picture-card {
|
|
|
- width: 72px;
|
|
|
- height: 72px;
|
|
|
- background: #f5f6f7;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- justify-content: center;
|
|
|
-}
|
|
|
/deep/ {
|
|
|
- .upload-file-uploader {
|
|
|
- display: flex;
|
|
|
+ .el-upload--picture-card {
|
|
|
+ width: 72px;
|
|
|
+ height: 72px;
|
|
|
+ background: #f5f6f7;
|
|
|
+ line-height: 72px;
|
|
|
}
|
|
|
.el-upload-list {
|
|
|
.el-upload-list__item {
|