|
@@ -68,7 +68,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
import { propTypes } from '@/utils/propTypes'
|
|
import { propTypes } from '@/utils/propTypes'
|
|
|
-import type { UploadInstance, UploadProps, UploadRawFile, UploadUserFile } from 'element-plus'
|
|
|
|
|
|
|
+import type { UploadProps, UploadRawFile, UploadUserFile } from 'element-plus'
|
|
|
import { isString } from '@/utils/is'
|
|
import { isString } from '@/utils/is'
|
|
|
import { useUpload } from '@/components/UploadFile/src/useUpload'
|
|
import { useUpload } from '@/components/UploadFile/src/useUpload'
|
|
|
import { UploadFile } from 'element-plus/es/components/upload/src/upload'
|
|
import { UploadFile } from 'element-plus/es/components/upload/src/upload'
|
|
@@ -91,7 +91,6 @@ const props = defineProps({
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// ========== 上传相关 ==========
|
|
// ========== 上传相关 ==========
|
|
|
-const uploadRef = ref<UploadInstance>()
|
|
|
|
|
const uploadList = ref<UploadUserFile[]>([])
|
|
const uploadList = ref<UploadUserFile[]>([])
|
|
|
const fileList = ref<UploadUserFile[]>([])
|
|
const fileList = ref<UploadUserFile[]>([])
|
|
|
const uploadNumber = ref<number>(0)
|
|
const uploadNumber = ref<number>(0)
|
|
@@ -126,6 +125,18 @@ const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => {
|
|
|
uploadNumber.value++
|
|
uploadNumber.value++
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+const getFileUrl = (value: unknown): string => {
|
|
|
|
|
+ if (typeof value === 'string') return value
|
|
|
|
|
+ if (value && typeof value === 'object') {
|
|
|
|
|
+ const file = value as { url?: unknown; path?: unknown; fileUrl?: unknown }
|
|
|
|
|
+ if (typeof file.url === 'string') return file.url
|
|
|
|
|
+ if (typeof file.path === 'string') return file.path
|
|
|
|
|
+ if (typeof file.fileUrl === 'string') return file.fileUrl
|
|
|
|
|
+ }
|
|
|
|
|
+ return ''
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 处理上传的文件发生变化
|
|
// 处理上传的文件发生变化
|
|
|
// const handleFileChange = (uploadFile: UploadFile): void => {
|
|
// const handleFileChange = (uploadFile: UploadFile): void => {
|
|
|
// uploadRef.value.data.path = uploadFile.name
|
|
// uploadRef.value.data.path = uploadFile.name
|
|
@@ -133,10 +144,12 @@ const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => {
|
|
|
// 文件上传成功
|
|
// 文件上传成功
|
|
|
const handleFileSuccess: UploadProps['onSuccess'] = (res: any): void => {
|
|
const handleFileSuccess: UploadProps['onSuccess'] = (res: any): void => {
|
|
|
message.success('上传成功')
|
|
message.success('上传成功')
|
|
|
|
|
+ const url = getFileUrl(res?.data)
|
|
|
|
|
+ if (!url) return
|
|
|
// 删除自身
|
|
// 删除自身
|
|
|
- const index = fileList.value.findIndex((item) => item.response?.data === res.data)
|
|
|
|
|
|
|
+ const index = fileList.value.findIndex((item) => (item.response as any)?.data === res.data)
|
|
|
fileList.value.splice(index, 1)
|
|
fileList.value.splice(index, 1)
|
|
|
- uploadList.value.push({ name: res.data, url: res.data })
|
|
|
|
|
|
|
+ uploadList.value.push({ name: url.substring(url.lastIndexOf('/') + 1), url })
|
|
|
if (uploadList.value.length == uploadNumber.value) {
|
|
if (uploadList.value.length == uploadNumber.value) {
|
|
|
fileList.value.push(...uploadList.value)
|
|
fileList.value.push(...uploadList.value)
|
|
|
uploadList.value = []
|
|
uploadList.value = []
|
|
@@ -185,11 +198,15 @@ watch(
|
|
|
}
|
|
}
|
|
|
// 情况2:数组
|
|
// 情况2:数组
|
|
|
fileList.value.push(
|
|
fileList.value.push(
|
|
|
- ...(val as string[]).map((url) => ({ name: url.substring(url.lastIndexOf('/') + 1), url }))
|
|
|
|
|
|
|
+ ...(val as any[])
|
|
|
|
|
+ .map((item) => getFileUrl(item))
|
|
|
|
|
+ .filter(Boolean)
|
|
|
|
|
+ .map((url) => ({ name: url.substring(url.lastIndexOf('/') + 1), url }))
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
{ immediate: true, deep: true }
|
|
{ immediate: true, deep: true }
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
// 发送文件链接列表更新
|
|
// 发送文件链接列表更新
|
|
|
const emitUpdateModelValue = () => {
|
|
const emitUpdateModelValue = () => {
|
|
|
// 情况1:数组结果
|
|
// 情况1:数组结果
|