From b6e5c59a9c40050720998df9e848fd0da35d4741 Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Tue, 14 Feb 2023 10:51:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A2=84=E8=AE=BE=20pinia=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + pnpm-lock.yaml | 36 +++++++++++++++++++++++++++++- src/main.ts | 18 ++++++--------- src/plugins/assets.ts | 14 ++++++++++++ src/plugins/index.ts | 3 +++ src/store/index.ts | 9 ++++++++ src/store/modules/app/index.ts | 19 ++++++++++++++++ src/store/modules/history/index.ts | 12 ++++++++++ src/store/modules/index.ts | 2 ++ 9 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 src/plugins/assets.ts create mode 100644 src/plugins/index.ts create mode 100644 src/store/index.ts create mode 100644 src/store/modules/app/index.ts create mode 100644 src/store/modules/history/index.ts create mode 100644 src/store/modules/index.ts diff --git a/package.json b/package.json index a97f802..6a2dd93 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "naive-ui": "^2.34.3", + "pinia": "^2.0.30", "vue": "^3.2.47", "vue-router": "^4.1.6" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f9fe567..b0b2e76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,7 @@ specifiers: lint-staged: ^13.1.1 naive-ui: ^2.34.3 npm-run-all: ^4.1.5 + pinia: ^2.0.30 postcss: ^8.4.21 rimraf: ^4.1.2 tailwindcss: ^3.2.6 @@ -25,6 +26,7 @@ specifiers: dependencies: naive-ui: 2.34.3_vue@3.2.47 + pinia: 2.0.30_hmuptsblhheur2tugfgucj7gc4 vue: 3.2.47 vue-router: 4.1.6_vue@3.2.47 @@ -3567,6 +3569,24 @@ packages: engines: {node: '>=4'} dev: true + /pinia/2.0.30_hmuptsblhheur2tugfgucj7gc4: + resolution: {integrity: sha512-q6DUmxWwe/mQgg+55QQjykpKC+aGeGdaJV3niminl19V08dE+LRTvSEuqi6/NLSGCKHI49KGL6tMNEOssFiMyA==} + peerDependencies: + '@vue/composition-api': ^1.4.0 + typescript: '>=4.4.4' + vue: ^2.6.14 || ^3.2.0 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + typescript: + optional: true + dependencies: + '@vue/devtools-api': 6.5.0 + typescript: 4.9.5 + vue: 3.2.47 + vue-demi: 0.13.11_vue@3.2.47 + dev: false + /pluralize/8.0.0: resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==} engines: {node: '>=4'} @@ -4284,7 +4304,6 @@ packages: resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} engines: {node: '>=4.2.0'} hasBin: true - dev: true /unbox-primitive/1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} @@ -4390,6 +4409,21 @@ packages: vue: 3.2.47 dev: false + /vue-demi/0.13.11_vue@3.2.47: + resolution: {integrity: sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + peerDependencies: + '@vue/composition-api': ^1.0.0-rc.1 + vue: ^3.0.0-0 || ^2.6.0 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + dependencies: + vue: 3.2.47 + dev: false + /vue-eslint-parser/9.1.0_eslint@8.34.0: resolution: {integrity: sha512-NGn/iQy8/Wb7RrRa4aRkokyCZfOUWk19OP5HP6JEozQFX5AoS/t+Z0ZN7FY4LlmWc4FNI922V7cvX28zctN8dQ==} engines: {node: ^14.17.0 || >=16.0.0} diff --git a/src/main.ts b/src/main.ts index 19f69e9..acbe522 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,21 +1,17 @@ -import './styles/global.css' - import { createApp } from 'vue' import App from './App.vue' +import { setupAssets } from '@/plugins' +import { setupStore } from '@/store' import { setupRouter } from '@/router' -/** Tailwind's Preflight Style Override */ -function naiveStyleOverride() { - const meta = document.createElement('meta') - meta.name = 'naive-ui-style' - document.head.appendChild(meta) -} - -/** Setup */ async function bootstrap() { const app = createApp(App) - naiveStyleOverride() + setupAssets() + + setupStore(app) + await setupRouter(app) + app.mount('#app') } diff --git a/src/plugins/assets.ts b/src/plugins/assets.ts new file mode 100644 index 0000000..b6b4cb0 --- /dev/null +++ b/src/plugins/assets.ts @@ -0,0 +1,14 @@ +import '@/styles/global.css' + +/** Tailwind's Preflight Style Override */ +function naiveStyleOverride() { + const meta = document.createElement('meta') + meta.name = 'naive-ui-style' + document.head.appendChild(meta) +} + +function setupAssets() { + naiveStyleOverride() +} + +export default setupAssets diff --git a/src/plugins/index.ts b/src/plugins/index.ts new file mode 100644 index 0000000..ae1ac22 --- /dev/null +++ b/src/plugins/index.ts @@ -0,0 +1,3 @@ +import setupAssets from './assets' + +export { setupAssets } diff --git a/src/store/index.ts b/src/store/index.ts new file mode 100644 index 0000000..5044bb1 --- /dev/null +++ b/src/store/index.ts @@ -0,0 +1,9 @@ +import type { App } from 'vue' +import { createPinia } from 'pinia' + +export function setupStore(app: App) { + const store = createPinia() + app.use(store) +} + +export * from './modules' diff --git a/src/store/modules/app/index.ts b/src/store/modules/app/index.ts new file mode 100644 index 0000000..ca89ec5 --- /dev/null +++ b/src/store/modules/app/index.ts @@ -0,0 +1,19 @@ +import { defineStore } from 'pinia' + +interface AppState { + siderCollapsed: boolean +} + +export const useAppStore = defineStore('app-store', { + state: (): AppState => ({ + siderCollapsed: false, + }), + actions: { + setSiderCollapsed(collapsed: boolean) { + this.siderCollapsed = collapsed + }, + toggleSiderCollapse() { + this.siderCollapsed = !this.siderCollapsed + }, + }, +}) diff --git a/src/store/modules/history/index.ts b/src/store/modules/history/index.ts new file mode 100644 index 0000000..3f1c2dd --- /dev/null +++ b/src/store/modules/history/index.ts @@ -0,0 +1,12 @@ +import { defineStore } from 'pinia' + +interface HistoryState { + list: any[] +} + +export const useHistoryStore = defineStore('history-store', { + state: (): HistoryState => ({ + list: [], + }), + actions: {}, +}) diff --git a/src/store/modules/index.ts b/src/store/modules/index.ts new file mode 100644 index 0000000..4e0ccdc --- /dev/null +++ b/src/store/modules/index.ts @@ -0,0 +1,2 @@ +export * from './app' +export * from './history'