12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <template>
- <div>
- <el-upload
- ref="upload"
- class="upload"
- multiple
- :file-list="fileList"
- :action="uploadFileUrl"
- :headers="headers"
- :on-change="handleChange"
- :on-remove="handleRemove"
- :before-remove="beforeRemove"
- :on-success="handleUploadSuccess"
- >
-
- <el-button size="small" type="primary">点击上传</el-button>
- </el-upload>
- </div>
- </template>
- <script>
- import { getToken } from "@/utils/auth";
- import { listFileBusinessId, delFile } from "@/api/system/file";
- export default {
- props: {
- },
- data() {
- return {
- fileList: [],
- uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload",
- headers: {
- Authorization: "Bearer " + getToken(),
- },
- };
- },
- mounted() {
- if (this.id) {
- this.getListFileBusinessId(this.id);
- }
- },
- methods: {
-
- getListFileBusinessId(id) {
- if (id) {
- listFileBusinessId(id).then((response) => {
- if (response.data.length > 0) {
- let list = response.data;
- for (let i in list) {
- list[i].name = list[i].newUploadName;
- }
- this.fileList = list;
- }
- });
- }
- },
- handleChange(file, fileList) {
-
- },
- handleRemove(file, fileList) {
- this.fileList = fileList;
- if (file.id) {
- const id = file.id;
- delFile(id).then((response) => {
-
- this.$emit("getFileList", this.fileList);
- });
- }
- },
- beforeRemove(file, fileList) {
- return this.$confirm(`确定移除 ${file.name}?`);
- },
- handleUploadSuccess(res, file, fileList) {
- let that = this;
- if (fileList.every((item) => item.status == "success")) {
- fileList.map((item) => {
- if (item.response) {
- item.response.file.name = item.response.file.newUploadName;
- this.fileList.push(item.response.file);
- that.$emit("getFileList", this.fileList);
- }
- });
- }
- },
- },
- };
- </script>
|