新增pinia持久化插件

This commit is contained in:
刘引
2025-12-26 11:11:18 +08:00
parent aff235bbf4
commit 99e1c9b445
10 changed files with 3534 additions and 17 deletions

View File

@@ -1 +1 @@
# Vue 3 + Typescript + Vite + TDesignNext + DayJs + Pinia
# Vue 3 + Typescript + Vite + ElementUI-Plus + DayJs + Pinia

1
dev-dist/registerSW.js Normal file
View File

@@ -0,0 +1 @@
if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'classic' })

92
dev-dist/sw.js Normal file
View File

@@ -0,0 +1,92 @@
/**
* Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// If the loader is already loaded, just stop.
if (!self.define) {
let registry = {};
// Used for `eval` and `importScripts` where we can't get script URL by other means.
// In both cases, it's safe to use a global var because those functions are synchronous.
let nextDefineUri;
const singleRequire = (uri, parentUri) => {
uri = new URL(uri + ".js", parentUri).href;
return registry[uri] || (
new Promise(resolve => {
if ("document" in self) {
const script = document.createElement("script");
script.src = uri;
script.onload = resolve;
document.head.appendChild(script);
} else {
nextDefineUri = uri;
importScripts(uri);
resolve();
}
})
.then(() => {
let promise = registry[uri];
if (!promise) {
throw new Error(`Module ${uri} didnt register its module`);
}
return promise;
})
);
};
self.define = (depsNames, factory) => {
const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
if (registry[uri]) {
// Module is already loading or loaded.
return;
}
let exports = {};
const require = depUri => singleRequire(depUri, uri);
const specialDeps = {
module: { uri },
exports,
require
};
registry[uri] = Promise.all(depsNames.map(
depName => specialDeps[depName] || require(depName)
)).then(deps => {
factory(...deps);
return exports;
});
};
}
define(['./workbox-86c9b217'], (function (workbox) { 'use strict';
self.skipWaiting();
workbox.clientsClaim();
/**
* The precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
workbox.precacheAndRoute([{
"url": "registerSW.js",
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.t9v2fs5c6io"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
allowlist: [/^\/$/]
}));
}));

3391
dev-dist/workbox-86c9b217.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -12,6 +12,7 @@
"dayjs": "^1.11.18",
"normalize.css": "^8.0.1",
"pinia": "^3.0.3",
"pinia-plugin-persistedstate": "^4.7.1",
"qs": "^6.14.0",
"tdesign-vue-next": "^1.17.1",
"vite-plugin-pwa": "^1.1.0",

32
pnpm-lock.yaml generated
View File

@@ -20,6 +20,9 @@ importers:
pinia:
specifier: ^3.0.3
version: 3.0.3(typescript@5.1.6)(vue@3.5.22(typescript@5.1.6))
pinia-plugin-persistedstate:
specifier: ^4.7.1
version: 4.7.1(pinia@3.0.3(typescript@5.1.6)(vue@3.5.22(typescript@5.1.6)))
qs:
specifier: ^6.14.0
version: 6.14.0
@@ -1304,6 +1307,9 @@ packages:
resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==}
engines: {node: '>= 0.4'}
defu@6.1.4:
resolution: {integrity: sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg==}
delayed-stream@1.0.0:
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
engines: {node: '>=0.4.0'}
@@ -1895,6 +1901,20 @@ packages:
resolution: {integrity: sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==}
engines: {node: '>=12'}
pinia-plugin-persistedstate@4.7.1:
resolution: {integrity: sha512-WHOqh2esDlR3eAaknPbqXrkkj0D24h8shrDPqysgCFR6ghqP/fpFfJmMPJp0gETHsvrh9YNNg6dQfo2OEtDnIQ==}
peerDependencies:
'@nuxt/kit': '>=3.0.0'
'@pinia/nuxt': '>=0.10.0'
pinia: '>=3.0.0'
peerDependenciesMeta:
'@nuxt/kit':
optional: true
'@pinia/nuxt':
optional: true
pinia:
optional: true
pinia@3.0.3:
resolution: {integrity: sha512-ttXO/InUULUXkMHpTdp9Fj4hLpD/2AoJdmAbAeW2yu1iy1k+pkFekQXw5VpC0/5p51IOR/jDaDRfRWRnMMsGOA==}
peerDependencies:
@@ -3348,8 +3368,8 @@ snapshots:
'@jridgewell/source-map@0.3.6':
dependencies:
'@jridgewell/gen-mapping': 0.3.8
'@jridgewell/trace-mapping': 0.3.25
'@jridgewell/gen-mapping': 0.3.13
'@jridgewell/trace-mapping': 0.3.31
'@jridgewell/sourcemap-codec@1.5.5': {}
@@ -3909,6 +3929,8 @@ snapshots:
has-property-descriptors: 1.0.2
object-keys: 1.1.1
defu@6.1.4: {}
delayed-stream@1.0.0: {}
detect-libc@1.0.3:
@@ -4513,6 +4535,12 @@ snapshots:
picomatch@4.0.3: {}
pinia-plugin-persistedstate@4.7.1(pinia@3.0.3(typescript@5.1.6)(vue@3.5.22(typescript@5.1.6))):
dependencies:
defu: 6.1.4
optionalDependencies:
pinia: 3.0.3(typescript@5.1.6)(vue@3.5.22(typescript@5.1.6))
pinia@3.0.3(typescript@5.1.6)(vue@3.5.22(typescript@5.1.6)):
dependencies:
'@vue/devtools-api': 7.7.7

BIN
src/excelHandle.lnk Normal file

Binary file not shown.

View File

@@ -14,12 +14,10 @@ import { startVersionCheck } from './utils/versionCheck'
import TDesign from 'tdesign-vue-next'
import 'tdesign-vue-next/es/style/index.css'
import 'normalize.css/normalize.css'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
// 启动版本检测服务 (20秒检查一次)
startVersionCheck(1000 * 20)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate) // 注入插件
// 挂载到app上
createApp(App)
.use(router)
.use(createPinia())
.use(TDesign)
.mount('#app')
createApp(App).use(router).use(pinia).use(TDesign).mount('#app')

View File

@@ -1,10 +1,16 @@
import { defineStore } from 'pinia'
import { reactive } from 'vue'
export const useUserStore = defineStore('useUserStore', () => {
export const useUserStore = defineStore(
'useUserStore',
() => {
const userInfo = reactive({
name: 'yin.liu',
age: 18
})
return { userInfo }
})
},
{
persist: true
}
)

View File

@@ -63,7 +63,7 @@ export default defineConfig({
},
server: {
host: '0.0.0.0',
port: 5173,
port: 6677,
open: true,
proxy: {
'/api': {