|
@@ -1,17 +1,6 @@
|
|
|
<template>
|
|
|
<div id="c-upload">
|
|
|
- <el-upload
|
|
|
- v-if="url"
|
|
|
- ref="upload"
|
|
|
- :action="url"
|
|
|
- :limit="limit"
|
|
|
- :accept="accept"
|
|
|
- :file-list="list"
|
|
|
- :list-type="listType"
|
|
|
- :on-exceed="outLimit"
|
|
|
- :on-preview="filePreview"
|
|
|
- :on-success="onSuccess"
|
|
|
- :before-remove="onRemove">
|
|
|
+ <el-upload v-if="url" ref="upload" :action="url" :limit="limit" :accept="accept" :file-list="list" :list-type="listType" :on-exceed="outLimit" :on-preview="filePreview" :on-success="onSuccess" :before-remove="onRemove">
|
|
|
<el-button type="primary">选择文件</el-button>
|
|
|
<template #tip v-if="tip">
|
|
|
<p style="color: #ff0000">{{ tip }}</p>
|
|
@@ -57,11 +46,11 @@ const emit = defineEmits(['change'])
|
|
|
const filePreview = (file) => {
|
|
|
// this.dialog = { show: true, url: file.url };
|
|
|
window.open(file.url)
|
|
|
-};
|
|
|
+}
|
|
|
// 只允许上传多少个文件
|
|
|
const outLimit = () => {
|
|
|
ElMessage.error(`只允许上传${limit.value}个文件`)
|
|
|
-};
|
|
|
+}
|
|
|
// 上传成功,response:成功信息,file:图片信息,fileList:图片列表
|
|
|
const onSuccess = (response, file) => {
|
|
|
if (response.errcode !== 0) {
|
|
@@ -79,12 +68,11 @@ const onSuccess = (response, file) => {
|
|
|
}
|
|
|
// 删除图片
|
|
|
// file: { id: any; uri: string }, fileList: any
|
|
|
-const onRemove = () => {
|
|
|
- // let arr: Ref<ListItem[]> = _.cloneDeep(list);
|
|
|
- // let info = arr.value.filter((f) => f.id != file.id);
|
|
|
- // emit('change', info);
|
|
|
- return true
|
|
|
-};
|
|
|
+const onRemove = (uploadFile, uploadFiles) => {
|
|
|
+ console.log(uploadFile, uploadFiles)
|
|
|
+ let info = uploadFiles.filter((f) => f.id != uploadFile.id)
|
|
|
+ emit('change', { model: model.value, value: info })
|
|
|
+}
|
|
|
|
|
|
// #endregion
|
|
|
</script>
|