From a7334b7749578ea8cf1a99a077641fd9055d6352 Mon Sep 17 00:00:00 2001 From: IchliebedichZhu <54796446@qq.com> Date: Mon, 18 Mar 2024 23:19:29 +0000 Subject: [PATCH] feat: move pinia to new folder --- src/pinia/base/index.ts | 50 +++++++++++++++++++++++ src/{store/modules => pinia}/base/user.ts | 3 +- src/pinia/index.ts | 15 +++++++ src/store/modules/base/index.ts | 41 ------------------- src/utils/axios.ts | 3 +- src/views/components/HeaderOptions.vue | 2 +- 6 files changed, 69 insertions(+), 45 deletions(-) create mode 100644 src/pinia/base/index.ts rename src/{store/modules => pinia}/base/user.ts (95%) create mode 100644 src/pinia/index.ts diff --git a/src/pinia/base/index.ts b/src/pinia/base/index.ts new file mode 100644 index 0000000..e883bef --- /dev/null +++ b/src/pinia/base/index.ts @@ -0,0 +1,50 @@ +/* + * @Author: Jeremy Yu + * @Date: 2024-03-17 15:00:00 + * @Description: Base全局状态管理 + * @LastEditors: Jeremy Yu + * @LastEditTime: 2024-03-18 21:00:00 + */ + +import { defineStore } from 'pinia' + +// import actions from './actions' +// import _config from '@/config' + +type TStoreBaseState = { + loading: boolean | null + scroll: boolean + /** fonts */ + fonts: string[] + /** 抠图服务 */ + app: string | null +} + +type TUserAction = { + hideLoading: () => void + setFonts: (list: string[]) => void +} + +/** Base全局状态管理 */ +const useBaseStore = defineStore<'base', TStoreBaseState, {}, TUserAction>('base', { + state: () => ({ + loading: null, + scroll: true, + fonts: [], // 缓存字体列表 + app: null, // 抠图服务 + }), + actions: { + /** 隐藏loading */ + hideLoading() { + setTimeout(() => { + this.loading = false + }, 600) + }, + setFonts(list: string[]) { + this.fonts = list + }, + } +}) + +export default useBaseStore + diff --git a/src/store/modules/base/user.ts b/src/pinia/base/user.ts similarity index 95% rename from src/store/modules/base/user.ts rename to src/pinia/base/user.ts index 3544ff2..23b9d07 100644 --- a/src/store/modules/base/user.ts +++ b/src/pinia/base/user.ts @@ -3,7 +3,7 @@ * @Date: 2024-03-17 15:00:00 * @Description: User全局状态管理 * @LastEditors: Jeremy Yu - * @LastEditTime: 2024-03-17 15:00:00 + * @LastEditTime: 2024-03-18 21:00:00 */ import { defineStore } from "pinia" @@ -29,6 +29,7 @@ type TUserAction = { managerEdit: (status: boolean) => void } +/** User全局状态管理 */ const useUserStore = defineStore<'userStore', TUserStoreState, {}, TUserAction>('userStore', { state: () => ({ online: true, // 登录状态, diff --git a/src/pinia/index.ts b/src/pinia/index.ts new file mode 100644 index 0000000..6caeb15 --- /dev/null +++ b/src/pinia/index.ts @@ -0,0 +1,15 @@ +/* + * @Author: Jeremy Yu + * @Date: 2024-03-18 21:00:00 + * @Description: 方法暴露 + * @LastEditors: Jeremy Yu + * @LastEditTime: 2024-03-18 21:00:00 + */ + +import useBaseStore from "./base"; +import useUserStore from "./base/user"; + +export { + useBaseStore, + useUserStore, +} diff --git a/src/store/modules/base/index.ts b/src/store/modules/base/index.ts index f8e8e95..6d03977 100644 --- a/src/store/modules/base/index.ts +++ b/src/store/modules/base/index.ts @@ -6,47 +6,6 @@ * @LastEditTime: 2024-03-17 15:00:00 */ -import { defineStore } from 'pinia' - -// import actions from './actions' -// import _config from '@/config' - -type TStoreBaseState = { - loading: boolean | null - scroll: boolean - /** fonts */ - fonts: string[] - /** 抠图服务 */ - app: string | null -} - -type TUserAction = { - hideLoading: () => void - setFonts: (list: string[]) => void -} - -const useBaseStore = defineStore<'base', TStoreBaseState, {}, TUserAction>('base', { - state: () => ({ - loading: null, - scroll: true, - fonts: [], // 缓存字体列表 - app: null, // 抠图服务 - }), - actions: { - /** 隐藏loading */ - hideLoading() { - setTimeout(() => { - this.loading = false - }, 600) - }, - setFonts(list: string[]) { - this.fonts = list - }, - } -}) - -export default useBaseStore - // const all = { // state: { // loading: null, diff --git a/src/utils/axios.ts b/src/utils/axios.ts index 4df4d8b..8f05b41 100644 --- a/src/utils/axios.ts +++ b/src/utils/axios.ts @@ -8,8 +8,7 @@ import axios, { AxiosRequestConfig, AxiosResponse, AxiosStatic } from 'axios' // import store from '@/store' import app_config, { LocalStorageKey } from '@/config' -import useUserStore from '@/store/modules/base/user'; -import useBaseStore from '@/store/modules/base'; +import { useBaseStore, useUserStore } from '@/pinia/index'; axios.defaults.timeout = 30000 axios.defaults.headers.authorization = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTAwMDEsImV4cCI6MTc4ODU3NDc1MDU4NX0.L_t6DFD48Dm6rUPfgIgOWJkz18En1m_-hhMHcpbxliY'; diff --git a/src/views/components/HeaderOptions.vue b/src/views/components/HeaderOptions.vue index e6f4200..d496a01 100644 --- a/src/views/components/HeaderOptions.vue +++ b/src/views/components/HeaderOptions.vue @@ -40,7 +40,7 @@ import _config from '@/config' import useConfirm from '@/common/methods/confirm' // import wGroup from '@/components/modules/widgets/wGroup/wGroup.vue' import { useSetupMapGetters } from '@/common/hooks/mapGetters' -import useUserStore from '@/store/modules/base/user' +import { useUserStore } from '@/pinia/index' type TProps = { modelValue?: boolean