From 302c8206fb8804b3e3021c3405494c4cec61f3ea Mon Sep 17 00:00:00 2001 From: zxc <1171051090@qq.com> Date: Mon, 14 Apr 2025 21:21:50 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20update=20dexie=20v4=EF=BC=88#342?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Q&A.md | 2 +- package-lock.json | 17 +++++++---------- package.json | 2 +- src/store/snapshot.ts | 6 +++--- src/utils/database.ts | 28 ++++++++++++---------------- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/doc/Q&A.md b/doc/Q&A.md index a69f8e81..c819514d 100644 --- a/doc/Q&A.md +++ b/doc/Q&A.md @@ -70,7 +70,7 @@ A. 大家都知道,对于一般的插件/库而言,一个封装好的npm包 #### Q. 关于 AI PPT -A. 我不想蹭AI的热度,但无奈太多人将AI看得太重了,于是我做了这个DEMO(它真的没那么复杂),目前此功能仅作参考,内部实现了最基础的AIPPT生成逻辑,即:模板定制 + AI生成数据与模板结合 + 配图替换。为控制成本暂时只能做到这里,但为了达到生产环节的效果,你还需要做更多,例如更多的模板、更细致的AI工作流程。 +A. 首先需要说明,AIPPT不是PPTist的重点,现在或以后都不是,它只是PPTist众多功能中非常小的一部分而已,并且是比较简单一部分,你可以理解为这只是一个跟风的小功能点,我不想蹭AI的热度,但无奈太多人将AI看得太重要太复杂了,于是我做了这个DEMO(它真的没那么复杂),目前此功能仅作参考,内部实现了最基础的AIPPT生成逻辑,即:模板定制 + AI生成数据与模板结合 + 配图替换。为控制成本暂时只能做到这里,但为了达到生产环节的效果,你还需要做更多,例如更多的模板、更细致的AI工作流程。 注:配图替换仅提供方法,不提供实际演示功能,你需要自己提供图片源接入(如AI文生图、图库搜索匹配等方法) diff --git a/package-lock.json b/package-lock.json index 7f99a4eb..604e7368 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "axios": "^1.7.9", "clipboard": "^2.0.11", "crypto-js": "^4.2.0", - "dexie": "3.0.3", + "dexie": "^4.0.11", "echarts": "^5.5.1", "file-saver": "^2.0.5", "hfmath": "^0.0.2", @@ -2301,12 +2301,9 @@ "integrity": "sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==" }, "node_modules/dexie": { - "version": "3.0.3", - "resolved": "https://registry.npmmirror.com/dexie/-/dexie-3.0.3.tgz", - "integrity": "sha512-BSFhGpngnCl1DOr+8YNwBDobRMH0ziJs2vts69VilwetHYOtEDcLqo7d/XiIphM0tJZ2rPPyAGd31lgH2Ln3nw==", - "engines": { - "node": ">=6.0" - } + "version": "4.0.11", + "resolved": "https://registry.npmmirror.com/dexie/-/dexie-4.0.11.tgz", + "integrity": "sha512-SOKO002EqlvBYYKQSew3iymBoN2EQ4BDw/3yprjh7kAfFzjBYkaMNa/pZvcA7HSWlcKSQb9XhPe3wKyQ0x4A8A==" }, "node_modules/dir-glob": { "version": "3.0.1", @@ -6947,9 +6944,9 @@ "integrity": "sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==" }, "dexie": { - "version": "3.0.3", - "resolved": "https://registry.npmmirror.com/dexie/-/dexie-3.0.3.tgz", - "integrity": "sha512-BSFhGpngnCl1DOr+8YNwBDobRMH0ziJs2vts69VilwetHYOtEDcLqo7d/XiIphM0tJZ2rPPyAGd31lgH2Ln3nw==" + "version": "4.0.11", + "resolved": "https://registry.npmmirror.com/dexie/-/dexie-4.0.11.tgz", + "integrity": "sha512-SOKO002EqlvBYYKQSew3iymBoN2EQ4BDw/3yprjh7kAfFzjBYkaMNa/pZvcA7HSWlcKSQb9XhPe3wKyQ0x4A8A==" }, "dir-glob": { "version": "3.0.1", diff --git a/package.json b/package.json index d40b9f51..2d25674c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "axios": "^1.7.9", "clipboard": "^2.0.11", "crypto-js": "^4.2.0", - "dexie": "3.0.3", + "dexie": "^4.0.11", "echarts": "^5.5.1", "file-saver": "^2.0.5", "hfmath": "^0.0.2", diff --git a/src/store/snapshot.ts b/src/store/snapshot.ts index 0bf4fbdc..76f8ca17 100644 --- a/src/store/snapshot.ts +++ b/src/store/snapshot.ts @@ -38,7 +38,7 @@ export const useSnapshotStore = defineStore('snapshot', { const newFirstSnapshot = { index: slidesStore.slideIndex, - slides: slidesStore.slides, + slides: JSON.parse(JSON.stringify(slidesStore.slides)), } await db.snapshots.add(newFirstSnapshot) this.setSnapshotCursor(0) @@ -63,7 +63,7 @@ export const useSnapshotStore = defineStore('snapshot', { // 添加新快照 const snapshot = { index: slidesStore.slideIndex, - slides: slidesStore.slides, + slides: JSON.parse(JSON.stringify(slidesStore.slides)), } await db.snapshots.add(snapshot) @@ -83,7 +83,7 @@ export const useSnapshotStore = defineStore('snapshot', { db.snapshots.update(allKeys[snapshotLength - 2] as number, { index: slidesStore.slideIndex }) } - await db.snapshots.bulkDelete(needDeleteKeys) + await db.snapshots.bulkDelete(needDeleteKeys as number[]) this.setSnapshotCursor(snapshotLength - 1) this.setSnapshotLength(snapshotLength) diff --git a/src/utils/database.ts b/src/utils/database.ts index 18cc925c..6a683c39 100644 --- a/src/utils/database.ts +++ b/src/utils/database.ts @@ -1,14 +1,15 @@ -import Dexie from 'dexie' +import Dexie, { type EntityTable } from 'dexie' import { databaseId } from '@/store/main' import type { Slide } from '@/types/slides' import { LOCALSTORAGE_KEY_DISCARDED_DB } from '@/configs/storage' export interface writingBoardImg { - id: string + id: number dataURL: string } export interface Snapshot { + id: number index: number slides: Slide[] } @@ -41,19 +42,14 @@ export const deleteDiscardedDB = async () => { localStorage.removeItem(LOCALSTORAGE_KEY_DISCARDED_DB) } -class PPTistDB extends Dexie { - public snapshots: Dexie.Table - public writingBoardImgs: Dexie.Table - - public constructor() { - super(`${databaseNamePrefix}_${databaseId}_${new Date().getTime()}`) - this.version(1).stores({ - snapshots: '++id', - writingBoardImgs: '++id', - }) - this.snapshots = this.table('snapshots') - this.writingBoardImgs = this.table('writingBoardImgs') - } +const db = new Dexie(`${databaseNamePrefix}_${databaseId}_${new Date().getTime()}`) as Dexie & { + snapshots: EntityTable, + writingBoardImgs: EntityTable, } -export const db = new PPTistDB() \ No newline at end of file +db.version(1).stores({ + snapshots: '++id', + writingBoardImgs: '++id', +}) + +export { db } \ No newline at end of file