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 1/9] =?UTF-8?q?feat:=20=E9=A2=84=E8=AE=BE=20pinia=20?= =?UTF-8?q?=E7=9B=B8=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' From b03f804e35adb490aa5862419f984fe19f6e91e0 Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Tue, 14 Feb 2023 11:34:46 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=E4=BE=A7=E8=BE=B9=E6=A0=8F?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 + pnpm-lock.yaml | 12 ++++ .../business/Chat/layout/sider/Footer.vue | 5 +- .../business/Chat/layout/sider/index.vue | 30 ++-------- src/store/modules/app/helper.ts | 18 ++++++ src/store/modules/app/index.ts | 13 ++-- src/utils/crypto/index.ts | 18 ++++++ src/utils/is/index.ts | 55 +++++++++++++++++ src/utils/storage/index.ts | 1 + src/utils/storage/local.ts | 59 +++++++++++++++++++ 10 files changed, 177 insertions(+), 36 deletions(-) create mode 100644 src/store/modules/app/helper.ts create mode 100644 src/utils/crypto/index.ts create mode 100644 src/utils/is/index.ts create mode 100644 src/utils/storage/index.ts create mode 100644 src/utils/storage/local.ts diff --git a/package.json b/package.json index 6a2dd93..3fd7979 100644 --- a/package.json +++ b/package.json @@ -32,10 +32,12 @@ "@commitlint/cli": "^17.4.3", "@commitlint/config-conventional": "^17.4.3", "@iconify/vue": "^4.1.0", + "@types/crypto-js": "^4.1.1", "@types/node": "^18.13.0", "@vitejs/plugin-vue": "^4.0.0", "autoprefixer": "^10.4.13", "axios": "^1.3.2", + "crypto-js": "^4.1.1", "eslint": "^8.34.0", "husky": "^8.0.3", "lint-staged": "^13.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b0b2e76..5bd96a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,10 +5,12 @@ specifiers: '@commitlint/cli': ^17.4.3 '@commitlint/config-conventional': ^17.4.3 '@iconify/vue': ^4.1.0 + '@types/crypto-js': ^4.1.1 '@types/node': ^18.13.0 '@vitejs/plugin-vue': ^4.0.0 autoprefixer: ^10.4.13 axios: ^1.3.2 + crypto-js: ^4.1.1 eslint: ^8.34.0 husky: ^8.0.3 lint-staged: ^13.1.1 @@ -35,10 +37,12 @@ devDependencies: '@commitlint/cli': 17.4.3 '@commitlint/config-conventional': 17.4.3 '@iconify/vue': 4.1.0_vue@3.2.47 + '@types/crypto-js': 4.1.1 '@types/node': 18.13.0 '@vitejs/plugin-vue': 4.0.0_vite@4.1.1+vue@3.2.47 autoprefixer: 10.4.13_postcss@8.4.21 axios: 1.3.2 + crypto-js: 4.1.1 eslint: 8.34.0 husky: 8.0.3 lint-staged: 13.1.1 @@ -697,6 +701,10 @@ packages: resolution: {integrity: sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==} dev: true + /@types/crypto-js/4.1.1: + resolution: {integrity: sha512-BG7fQKZ689HIoc5h+6D2Dgq1fABRa0RbBWKBd9SP/MVRVXROflpm5fhwyATX5duFmbStzyzyycPB8qUYKDH3NA==} + dev: true + /@types/json-schema/7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true @@ -1529,6 +1537,10 @@ packages: which: 2.0.2 dev: true + /crypto-js/4.1.1: + resolution: {integrity: sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==} + dev: true + /css-render/0.15.12: resolution: {integrity: sha512-eWzS66patiGkTTik+ipO9qNGZ+uNuGyTmnz6/+EJIiFg8+3yZRpnMwgFo8YdXhQRsiePzehnusrxVvugNjXzbw==} dependencies: diff --git a/src/components/business/Chat/layout/sider/Footer.vue b/src/components/business/Chat/layout/sider/Footer.vue index a485c3a..cc72d0d 100644 --- a/src/components/business/Chat/layout/sider/Footer.vue +++ b/src/components/business/Chat/layout/sider/Footer.vue @@ -3,9 +3,8 @@ import { HoverButton, SvgIcon, UserAvatar } from '@/components/common'