From f1517655b9bb6d8ca22e06f3b91d6060518b2908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=88=BA=E8=9E=88?= Date: Fri, 25 Oct 2024 22:09:11 +0800 Subject: [PATCH] refactor: store --- .github/workflows/deploy.yml | 1 + package.json | 7 +- plugins/unAutoImport.ts | 3 +- pnpm-lock.yaml | 23 +++ src/components/ActionCard.vue | 23 ++- src/components/ErrorDlg.vue | 12 +- src/main.ts | 11 +- src/store.ts | 13 -- src/store/global.ts | 13 ++ src/store/storage.ts | 171 ++++++++++++++++++++++ src/utils/dialog.tsx | 10 +- src/utils/export.ts | 36 +++-- src/utils/fetch.ts | 5 +- src/utils/github.ts | 3 +- src/utils/import.ts | 6 +- src/utils/others.ts | 8 + src/utils/selector.ts | 12 +- src/utils/snapshot.ts | 96 ++++++++++++ src/utils/storage.ts | 217 ---------------------------- src/utils/table.tsx | 8 +- src/utils/url.ts | 43 +++--- src/views/ImportPage.vue | 12 +- src/views/home/HomePage.vue | 22 ++- src/views/snapshot/SearchCard.vue | 28 ++-- src/views/snapshot/SnapshotPage.vue | 22 ++- 25 files changed, 437 insertions(+), 368 deletions(-) delete mode 100644 src/store.ts create mode 100644 src/store/global.ts create mode 100644 src/store/storage.ts create mode 100644 src/utils/snapshot.ts delete mode 100644 src/utils/storage.ts diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6de64e2..65abae2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,7 @@ name: deploy on: + workflow_dispatch: push: branches: ['main'] paths-ignore: diff --git a/package.json b/package.json index 242e323..af697b1 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "naive-ui": "2.40.1", "normalize.css": "8.0.1", "p-limit": "6.1.0", + "pinia": "2.2.4", "prettier": "3.3.3", "qrcode": "1.5.4", "sass": "1.79.4", @@ -74,10 +75,10 @@ "vue-router": "4.4.5" }, "volta": { - "node": "22.7.0", - "pnpm": "9.12.1" + "node": "22.10.0", + "pnpm": "9.12.2" }, - "packageManager": "pnpm@9.12.1", + "packageManager": "pnpm@9.12.2", "simple-git-hooks": { "pre-commit": "pnpm exec lint-staged" }, diff --git a/plugins/unAutoImport.ts b/plugins/unAutoImport.ts index f8e7d74..3e55f6c 100644 --- a/plugins/unAutoImport.ts +++ b/plugins/unAutoImport.ts @@ -3,6 +3,7 @@ import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'; import components from 'unplugin-vue-components/vite'; import type { Plugin } from 'vite'; import naiveComponents from './naive-components.json'; +import process from 'node:process'; export const unAutoImport = (): Plugin[] => { return [ @@ -29,7 +30,7 @@ export const unAutoImport = (): Plugin[] => { globalsPropValue: 'readonly', filepath: '.eslintrc-auto-import.json', }, - dirs: [], + dirs: [process.cwd() + '/src/store'], }), components({ include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0b9f5fc..e8452dd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -113,6 +113,9 @@ importers: p-limit: specifier: 6.1.0 version: 6.1.0 + pinia: + specifier: 2.2.4 + version: 2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)) prettier: specifier: 3.3.3 version: 3.3.3 @@ -2867,6 +2870,18 @@ packages: engines: {node: '>=0.10'} hasBin: true + pinia@2.2.4: + resolution: {integrity: sha512-K7ZhpMY9iJ9ShTC0cR2+PnxdQRuwVIsXDO/WIEV/RnMC/vmSoKDTKW/exNQYPI+4ij10UjXqdNiEHwn47McANQ==} + peerDependencies: + '@vue/composition-api': ^1.4.0 + typescript: '>=4.4.4' + vue: ^2.6.14 || ^3.3.0 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + typescript: + optional: true + pkg-types@1.1.3: resolution: {integrity: sha512-+JrgthZG6m3ckicaOB74TwQ+tBWsFl3qVQg7mN8ulwSOElJ7gBhKzj2VkCPnZ4NlF6kEquYU+RIYNVAvzd54UA==} @@ -6510,6 +6525,14 @@ snapshots: pidtree@0.6.0: {} + pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)): + dependencies: + '@vue/devtools-api': 6.6.4 + vue: 3.5.11(typescript@5.6.3) + vue-demi: 0.14.10(vue@3.5.11(typescript@5.6.3)) + optionalDependencies: + typescript: 5.6.3 + pkg-types@1.1.3: dependencies: confbox: 0.1.7 diff --git a/src/components/ActionCard.vue b/src/components/ActionCard.vue index 37cc0b5..ba22808 100644 --- a/src/components/ActionCard.vue +++ b/src/components/ActionCard.vue @@ -4,18 +4,14 @@ import { message } from '@/utils/discrete'; import { exportSnapshotAsImportId, exportSnapshotAsJpg, - exportSnapshotAsJpgUrl, + exportSnapshotAsImageId, exportSnapshotAsZip, } from '@/utils/export'; import { buildEmptyFn, delay } from '@/utils/others'; -import { - githubJpgStorage, - importStorage, - snapshotStorage, -} from '@/utils/storage'; +import { snapshotStorage } from '@/utils/snapshot'; import { useTask } from '@/utils/task'; import type { Snapshot } from '@/utils/types'; -import { getImportUrl, githubUrlToSelfUrl } from '@/utils/url'; +import { getImportUrl, getImagUrl } from '@/utils/url'; const props = withDefaults( defineProps<{ @@ -36,6 +32,7 @@ const props = withDefaults( ); const router = useRouter(); +const { snapshotImportId, snapshotImageId } = useStorageStore(); const exportJpg = useTask(async () => exportSnapshotAsJpg((await snapshotStorage.getItem(props.snapshot.id))!), @@ -53,12 +50,12 @@ const previewUrl = computed(() => { const exportJpgUrl = useTask(async () => { await waitShareAgree(); - const pngUrl = await exportSnapshotAsJpgUrl( + const imageId = await exportSnapshotAsImageId( (await snapshotStorage.getItem(props.snapshot.id))!, ); showTextDLg({ title: `分享链接`, - content: githubUrlToSelfUrl(pngUrl), + content: getImagUrl(imageId), }); }); @@ -163,8 +160,8 @@ const copy = async (content: string) => { 复制链接-快照 @@ -176,8 +173,8 @@ const copy = async (content: string) => { 生成链接-快照 复制链接-图片 diff --git a/src/components/ErrorDlg.vue b/src/components/ErrorDlg.vue index ae47214..300fd4f 100644 --- a/src/components/ErrorDlg.vue +++ b/src/components/ErrorDlg.vue @@ -1,10 +1,10 @@