|
@@ -1,6 +1,14 @@
|
|
<template>
|
|
<template>
|
|
<a-list :grid="{ gutter: 20, column: 3 }" :data-source="current">
|
|
<a-list :grid="{ gutter: 20, column: 3 }" :data-source="current">
|
|
- <template #renderItem="{ item }: { item: FileItem | typeof addMarked }">
|
|
|
|
|
|
+ <template
|
|
|
|
+ #renderItem="{
|
|
|
|
+ item,
|
|
|
|
+ index
|
|
|
|
+ }: {
|
|
|
|
+ item: string | typeof addMarked,
|
|
|
|
+ index: number
|
|
|
|
+ }"
|
|
|
|
+ >
|
|
<a-list-item class="scene-item">
|
|
<a-list-item class="scene-item">
|
|
<div v-if="item === addMarked" class="add-album">
|
|
<div v-if="item === addMarked" class="add-album">
|
|
<a-upload
|
|
<a-upload
|
|
@@ -21,9 +29,9 @@
|
|
</a-upload>
|
|
</a-upload>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
- <div v-else class="scene-sign" v-if="item.status === 'done'">
|
|
|
|
- <img v-if="item.response" :src="item.response?.data" />
|
|
|
|
- <span class="delete-scene" @click="deleteAblum(item)">
|
|
|
|
|
|
+ <div v-else class="scene-sign">
|
|
|
|
+ <a-image v-if="item" :src="item" />
|
|
|
|
+ <span class="delete-scene" @click="deleteAblum(index)">
|
|
<close-outlined class="delete-scene-icon" />
|
|
<close-outlined class="delete-scene-icon" />
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
@@ -38,7 +46,6 @@ import { Modal, message } from 'ant-design-vue'
|
|
import type { UploadChangeParam } from 'ant-design-vue'
|
|
import type { UploadChangeParam } from 'ant-design-vue'
|
|
import { useI18n } from '@/hook/useI18n'
|
|
import { useI18n } from '@/hook/useI18n'
|
|
import { watchEffect } from 'vue'
|
|
import { watchEffect } from 'vue'
|
|
-import { uniqBy } from 'lodash-es'
|
|
|
|
|
|
|
|
export interface FileItem {
|
|
export interface FileItem {
|
|
uid: string
|
|
uid: string
|
|
@@ -64,64 +71,37 @@ const props = defineProps<{ data: string[] }>()
|
|
const addMarked = Symbol('add-album')
|
|
const addMarked = Symbol('add-album')
|
|
const albumFile = ref<any[]>([])
|
|
const albumFile = ref<any[]>([])
|
|
const albumFileExist = ref<any[]>([])
|
|
const albumFileExist = ref<any[]>([])
|
|
-const totalist = computed(() =>
|
|
|
|
- uniqBy([albumFile.value, albumFileExist.value], 'response.data')
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-const current = computed(() => [
|
|
|
|
- addMarked,
|
|
|
|
- // ...totalist.value
|
|
|
|
- // ...albumFileExist.value,
|
|
|
|
- ...albumFile.value
|
|
|
|
-])
|
|
|
|
-const albumList = computed(() =>
|
|
|
|
- Array.from(albumFile.value).reduce((prev, cur) => {
|
|
|
|
- if (prev && cur.response?.data) {
|
|
|
|
- return prev.concat(cur.response.data)
|
|
|
|
- }
|
|
|
|
- }, [])
|
|
|
|
-)
|
|
|
|
|
|
|
|
-const deleteAblum = (item: FileItem) => {
|
|
|
|
- const index = albumFile.value.findIndex(i => i.uid === item.uid)
|
|
|
|
|
|
+const current = computed(() => [addMarked, ...albumFileExist.value])
|
|
|
|
|
|
- if (index > -1) {
|
|
|
|
- albumFile.value.splice(index, 1)
|
|
|
|
|
|
+const deleteAblum = (index: number) => {
|
|
|
|
+ console.log('index', index)
|
|
|
|
+ if (index - 1 > -1) {
|
|
|
|
+ albumFileExist.value.splice(index - 1, 1)
|
|
}
|
|
}
|
|
- const syncData = albumList.value ? albumList.value : []
|
|
|
|
- console.log('sync', syncData)
|
|
|
|
|
|
+ const syncData = albumFileExist.value.length ? albumFileExist.value : []
|
|
emit('syncList', syncData)
|
|
emit('syncList', syncData)
|
|
}
|
|
}
|
|
const emit = defineEmits(['syncList'])
|
|
const emit = defineEmits(['syncList'])
|
|
|
|
+
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
- console.log('totalist', totalist)
|
|
|
|
if (props.data?.length) {
|
|
if (props.data?.length) {
|
|
- const mapper = Array.from(props.data).map((i, index) => {
|
|
|
|
- const tempData = {} as FileItem
|
|
|
|
- tempData.uid = `data-${index}`
|
|
|
|
- tempData.response = {
|
|
|
|
- data: i,
|
|
|
|
- ok: 0
|
|
|
|
- }
|
|
|
|
- tempData.status = 'done'
|
|
|
|
- return tempData
|
|
|
|
- })
|
|
|
|
- albumFile.value = uniqBy(
|
|
|
|
- albumFile.value.concat(mapper),
|
|
|
|
- 'response.data'
|
|
|
|
- )
|
|
|
|
|
|
+ albumFileExist.value = props.data
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
const handleABlumChange = (info: UploadChangeParam) => {
|
|
const handleABlumChange = (info: UploadChangeParam) => {
|
|
if (info.file.status === 'done') {
|
|
if (info.file.status === 'done') {
|
|
- const syncData = albumList.value ? albumList.value : []
|
|
|
|
- console.log('sync', syncData)
|
|
|
|
|
|
+ const { code, data } = info.file.response
|
|
|
|
+ if (code === 0) {
|
|
|
|
+ albumFileExist.value.push(data)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const syncData = albumFileExist.value.length ? albumFileExist.value : []
|
|
emit('syncList', syncData)
|
|
emit('syncList', syncData)
|
|
} else if (info.file.status === 'error') {
|
|
} else if (info.file.status === 'error') {
|
|
message.error(`${info.file.name} file upload failed.`)
|
|
message.error(`${info.file.name} file upload failed.`)
|
|
}
|
|
}
|
|
- console.log('check', albumFile)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
const handleBeforeUpload = (file: any) => {
|
|
const handleBeforeUpload = (file: any) => {
|