-
-
@@ -28,16 +48,16 @@ export default {
this.list = list
},
deep: true,
- immediate: true
+ immediate: true,
},
- isOpen: {
+ /* isOpen: {
handler(val) {
if (val) {
}
},
deep: true
- }
+ } */
},
data() {
return {
@@ -50,39 +70,47 @@ export default {
computed: {},
-
methods: {
beforeRead(file) {
- const supportedFormats = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'jpg', 'png', 'jpeg'];
+ const supportedFormats = [
+ 'pdf',
+ 'doc',
+ 'docx',
+ 'xls',
+ 'xlsx',
+ 'jpg',
+ 'png',
+ 'jpeg',
+ ]
// 获取文件扩展名
- console.log('file....', file);
+ console.log('file....', file)
if (Array.isArray(file)) {
for (let index = 0; file < file.length; index++) {
- const element = file[index];
- const fileExtension = element.name.split('.').pop().toLowerCase();
+ const element = file[index]
+ const fileExtension = element.name.split('.').pop().toLowerCase()
// 检查文件格式是否支持
if (!supportedFormats.includes(fileExtension)) {
this.$fm('只允许上传PDF、Word、Excel、JPG、PNG和JPEG格式的文件!')
- return false;
+ return false
}
}
} else {
- const fileExtension = file.name.split('.').pop().toLowerCase();
+ const fileExtension = file.name.split('.').pop().toLowerCase()
// 检查文件格式是否支持
if (!supportedFormats.includes(fileExtension)) {
this.$fm('只允许上传PDF、Word、Excel、JPG、PNG和JPEG格式的文件!')
- return false;
+ return false
}
}
- return true;
+ return true
},
handleToShow(item) {
this.$emit('onShow')
this.$router.push({
path: '/fileShow',
query: {
- url: item.url
- }
+ url: item.url,
+ },
})
},
handleDel(index) {
@@ -92,40 +120,43 @@ export default {
uploadFile(params) {
return new Promise((resolve, reject) => {
let FormDatas = new FormData()
- FormDatas.append('file', params.file);
- FormDatas.append('path', params.file.name);
- uploadFileApi(FormDatas).then((res) => {
- resolve({
- name: params.file.name,
- url: res.data
- });
- }).catch((err) => {
- reject(err)
- })
- });
+ FormDatas.append('file', params.file)
+ FormDatas.append('path', params.file.name)
+ uploadFileApi(FormDatas)
+ .then((res) => {
+ resolve({
+ name: params.file.name,
+ url: res.data.url,
+ })
+ })
+ .catch((err) => {
+ reject(err)
+ })
+ })
},
uploadFiles(fileList) {
- let promises = fileList.map((item) => this.uploadFile(item));
- return Promise.all(promises);
+ let promises = fileList.map((item) => this.uploadFile(item))
+ return Promise.all(promises)
},
handleAfterRead(list) {
let newList = Array.isArray(list) ? list : [list]
this.$loading(true, 'file')
- this.uploadFiles(newList).then((res) => {
- (res || []).map(item => {
- this.list.push(item)
+ this.uploadFiles(newList)
+ .then((res) => {
+ ;(res || []).map((item) => {
+ this.list.push(item)
+ })
+ this.$loading(false, 'file')
+ this.$emit('onConfirm', this.list)
+ })
+ .catch(() => {
+ this.$loading(false, 'file')
+ this.$fm('文件上传失败!')
})
- this.$loading(false, 'file')
- this.$emit('onConfirm', this.list)
- }).catch(() => {
- this.$loading(false, 'file')
- this.$fm('文件上传失败!')
- })
// console.log('list...', list);
- }
- }
+ },
+ },
}
-