feat(imgConfig): 优化图片存储结构

新增uuid依赖用于生成唯一ID,改进图片上传功能中的本地存储结构,
使用uuid替代时间戳作为键名以避免冲突,并调整从indexedDB读取数据的方式。
This commit is contained in:
log1997
2025-12-04 13:47:28 +08:00
parent f062f7c9e6
commit cdd4972870
7 changed files with 309 additions and 284 deletions

View File

@@ -1,4 +1,5 @@
<script setup lang='ts'>
import localforage from 'localforage'
import { storeToRefs } from 'pinia'
import { onMounted, ref, watch } from 'vue'
import { ColorPicker } from 'vue3-colorpicker'
@@ -8,6 +9,7 @@ import { daisyuiThemes } from '@/constant/theme'
import i18n, { languageList } from '@/locales/i18n'
import useStore from '@/store'
import { themeChange } from '@/utils'
import { clearAllDbStore } from '@/utils/localforage'
import PatternSetting from './components/PatternSetting.vue'
import 'vue3-colorpicker/style.css'
@@ -94,18 +96,12 @@ function resetData() {
globalConfig.reset()
personConfig.reset()
prizeConfig.resetDefault()
// 删除所有indexDb
clearAllDbStore()
// 刷新页面
window.location.reload()
}
// const handleChangeShowFields = (fieldItem: any) => {
// formData.value.showField.map((item) => {
// if (item.label === fieldItem.label) {
// item.value = !item.value
// }
// })
// }
watch(() => formData.value.rowCount, () => {
payload.rowCount = formData.value.rowCount
parseSchema(payload).then((res) => {

View File

@@ -1,6 +1,7 @@
<script setup lang='ts'>
import type { IFileData } from '@/components/ImageUpload/type'
import localforage from 'localforage'
import { v4 as uuidv4 } from 'uuid'
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import CustomDialog from '@/components/Dialog/index.vue'
@@ -47,10 +48,11 @@ async function uploadFile(fileData: IFileData | null) {
async function getImageDbStore() {
const keys = await imageDbStore.keys()
if (keys.length > 0) {
imageDbStore.iterate((value, key) => {
imageDbStore.iterate((value: { fileName: string, dataUrl: string }, key: string) => {
console.log(value, key)
globalConfig.addImage({
id: key,
name: key,
name: value.fileName,
url: 'Storage',
})
})
@@ -59,8 +61,11 @@ async function getImageDbStore() {
function submitUpload() {
if (imageData.value) {
const { dataUrl, fileName } = imageData.value
console.log(dataUrl, fileName)
imageDbStore.setItem(`${new Date().getTime().toString()}+${fileName}`, dataUrl)
const uniqueId = uuidv4()
imageDbStore.setItem(uniqueId, {
dataUrl,
fileName,
})
.then(() => {
imgUploadToast.value = 1
getImageDbStore()