From 908655680e4d630471a4fd4f20164252e6c4eef6 Mon Sep 17 00:00:00 2001 From: pdsuwwz Date: Thu, 29 Jun 2023 18:33:12 +0800 Subject: [PATCH 1/2] feat: update home mock pinia --- .eslintrc-auto-import.json | 18 +++++++- auto-imports.d.ts | 48 ++++++++++++++++++++ src/modules/HomeFront/data/index.ts | 15 +++++++ src/modules/HomeFront/pages/index.vue | 63 +++++---------------------- src/modules/HomeFront/store/index.ts | 29 +++++++++++- src/modules/HomeFront/types/index.ts | 8 ++++ src/store/plugins/debounce.ts | 15 +++++++ src/types/index.d.ts | 4 ++ vite.config.ts | 3 +- 9 files changed, 149 insertions(+), 54 deletions(-) create mode 100644 src/modules/HomeFront/types/index.ts create mode 100644 src/store/plugins/debounce.ts diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index 112c462..718f772 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -316,6 +316,22 @@ "DropdownOption": true, "ConfigProviderProps": true, "MenuOption": true, - "DataTableRowKey": true + "DataTableRowKey": true, + "useCostAnalysisStore": true, + "useCostBudgetStore": true, + "useCostCollectionStore": true, + "useCostDistributeStore": true, + "useExampleComponentStore": true, + "useHomeFrontStore": true, + "useMaterialBackupStore": true, + "useMaterialPrepareStore": true, + "useMaterialReviewStore": true, + "useMemberAccessStore": true, + "useMemberTeamStore": true, + "useNestedLevelStore": true, + "useProjectStore": true, + "useResultStore": true, + "useUserAccountStore": true, + "useUserAccountStoreWithOut": true } } diff --git a/auto-imports.d.ts b/auto-imports.d.ts index d1cac9d..7c9e871 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -139,6 +139,10 @@ declare global { const useCloned: typeof import('@vueuse/core')['useCloned'] const useColorMode: typeof import('@vueuse/core')['useColorMode'] const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog'] + const useCostAnalysisStore: typeof import('./src/modules/CostAnalysis/store/index')['useCostAnalysisStore'] + const useCostBudgetStore: typeof import('./src/modules/CostBudget/store/index')['useCostBudgetStore'] + const useCostCollectionStore: typeof import('./src/modules/CostCollection/store/index')['useCostCollectionStore'] + const useCostDistributeStore: typeof import('./src/modules/CostDistribute/store/index')['useCostDistributeStore'] const useCounter: typeof import('@vueuse/core')['useCounter'] const useCssModule: typeof import('vue')['useCssModule'] const useCssVar: typeof import('@vueuse/core')['useCssVar'] @@ -168,6 +172,7 @@ declare global { const useEventBus: typeof import('@vueuse/core')['useEventBus'] const useEventListener: typeof import('@vueuse/core')['useEventListener'] const useEventSource: typeof import('@vueuse/core')['useEventSource'] + const useExampleComponentStore: typeof import('./src/modules/ExampleComponent/store/index')['useExampleComponentStore'] const useEyeDropper: typeof import('@vueuse/core')['useEyeDropper'] const useFavicon: typeof import('@vueuse/core')['useFavicon'] const useFetch: typeof import('@vueuse/core')['useFetch'] @@ -179,6 +184,7 @@ declare global { const useFullscreen: typeof import('@vueuse/core')['useFullscreen'] const useGamepad: typeof import('@vueuse/core')['useGamepad'] const useGeolocation: typeof import('@vueuse/core')['useGeolocation'] + const useHomeFrontStore: typeof import('./src/modules/HomeFront/store/index')['useHomeFrontStore'] const useIdle: typeof import('@vueuse/core')['useIdle'] const useImage: typeof import('@vueuse/core')['useImage'] const useInfiniteScroll: typeof import('@vueuse/core')['useInfiniteScroll'] @@ -192,8 +198,13 @@ declare global { const useLocalStorage: typeof import('@vueuse/core')['useLocalStorage'] const useMagicKeys: typeof import('@vueuse/core')['useMagicKeys'] const useManualRefHistory: typeof import('@vueuse/core')['useManualRefHistory'] + const useMaterialBackupStore: typeof import('./src/modules/MaterialBackup/store/index')['useMaterialBackupStore'] + const useMaterialPrepareStore: typeof import('./src/modules/MaterialPrepare/store/index')['useMaterialPrepareStore'] + const useMaterialReviewStore: typeof import('./src/modules/MaterialReview/store/index')['useMaterialReviewStore'] const useMediaControls: typeof import('@vueuse/core')['useMediaControls'] const useMediaQuery: typeof import('@vueuse/core')['useMediaQuery'] + const useMemberAccessStore: typeof import('./src/modules/MemberAccess/store/index')['useMemberAccessStore'] + const useMemberTeamStore: typeof import('./src/modules/MemberTeam/store/index')['useMemberTeamStore'] const useMemoize: typeof import('@vueuse/core')['useMemoize'] const useMemory: typeof import('@vueuse/core')['useMemory'] const useMessage: typeof import('naive-ui')['useMessage'] @@ -203,6 +214,7 @@ declare global { const useMousePressed: typeof import('@vueuse/core')['useMousePressed'] const useMutationObserver: typeof import('@vueuse/core')['useMutationObserver'] const useNavigatorLanguage: typeof import('@vueuse/core')['useNavigatorLanguage'] + const useNestedLevelStore: typeof import('./src/modules/NestedLevel/store/index')['useNestedLevelStore'] const useNetwork: typeof import('@vueuse/core')['useNetwork'] const useNotification: typeof import('naive-ui')['useNotification'] const useNow: typeof import('@vueuse/core')['useNow'] @@ -223,9 +235,11 @@ declare global { const usePreferredLanguages: typeof import('@vueuse/core')['usePreferredLanguages'] const usePreferredReducedMotion: typeof import('@vueuse/core')['usePreferredReducedMotion'] const usePrevious: typeof import('@vueuse/core')['usePrevious'] + const useProjectStore: typeof import('./src/modules/Project/store/index')['useProjectStore'] const useRafFn: typeof import('@vueuse/core')['useRafFn'] const useRefHistory: typeof import('@vueuse/core')['useRefHistory'] const useResizeObserver: typeof import('@vueuse/core')['useResizeObserver'] + const useResultStore: typeof import('./src/modules/Result/store/index')['useResultStore'] const useRoute: typeof import('vue-router')['useRoute'] const useRouter: typeof import('vue-router')['useRouter'] const useScreenOrientation: typeof import('@vueuse/core')['useScreenOrientation'] @@ -265,6 +279,8 @@ declare global { const useToggle: typeof import('@vueuse/core')['useToggle'] const useTransition: typeof import('@vueuse/core')['useTransition'] const useUrlSearchParams: typeof import('@vueuse/core')['useUrlSearchParams'] + const useUserAccountStore: typeof import('./src/modules/UserAccount/store/index')['useUserAccountStore'] + const useUserAccountStoreWithOut: typeof import('./src/modules/UserAccount/store/index')['useUserAccountStoreWithOut'] const useUserMedia: typeof import('@vueuse/core')['useUserMedia'] const useVModel: typeof import('@vueuse/core')['useVModel'] const useVModels: typeof import('@vueuse/core')['useVModels'] @@ -445,6 +461,10 @@ declare module 'vue' { readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef readonly useConfirmDialog: UnwrapRef + readonly useCostAnalysisStore: UnwrapRef + readonly useCostBudgetStore: UnwrapRef + readonly useCostCollectionStore: UnwrapRef + readonly useCostDistributeStore: UnwrapRef readonly useCounter: UnwrapRef readonly useCssModule: UnwrapRef readonly useCssVar: UnwrapRef @@ -474,6 +494,7 @@ declare module 'vue' { readonly useEventBus: UnwrapRef readonly useEventListener: UnwrapRef readonly useEventSource: UnwrapRef + readonly useExampleComponentStore: UnwrapRef readonly useEyeDropper: UnwrapRef readonly useFavicon: UnwrapRef readonly useFetch: UnwrapRef @@ -485,6 +506,7 @@ declare module 'vue' { readonly useFullscreen: UnwrapRef readonly useGamepad: UnwrapRef readonly useGeolocation: UnwrapRef + readonly useHomeFrontStore: UnwrapRef readonly useIdle: UnwrapRef readonly useImage: UnwrapRef readonly useInfiniteScroll: UnwrapRef @@ -498,8 +520,13 @@ declare module 'vue' { readonly useLocalStorage: UnwrapRef readonly useMagicKeys: UnwrapRef readonly useManualRefHistory: UnwrapRef + readonly useMaterialBackupStore: UnwrapRef + readonly useMaterialPrepareStore: UnwrapRef + readonly useMaterialReviewStore: UnwrapRef readonly useMediaControls: UnwrapRef readonly useMediaQuery: UnwrapRef + readonly useMemberAccessStore: UnwrapRef + readonly useMemberTeamStore: UnwrapRef readonly useMemoize: UnwrapRef readonly useMemory: UnwrapRef readonly useMessage: UnwrapRef @@ -509,6 +536,7 @@ declare module 'vue' { readonly useMousePressed: UnwrapRef readonly useMutationObserver: UnwrapRef readonly useNavigatorLanguage: UnwrapRef + readonly useNestedLevelStore: UnwrapRef readonly useNetwork: UnwrapRef readonly useNotification: UnwrapRef readonly useNow: UnwrapRef @@ -529,9 +557,11 @@ declare module 'vue' { readonly usePreferredLanguages: UnwrapRef readonly usePreferredReducedMotion: UnwrapRef readonly usePrevious: UnwrapRef + readonly useProjectStore: UnwrapRef readonly useRafFn: UnwrapRef readonly useRefHistory: UnwrapRef readonly useResizeObserver: UnwrapRef + readonly useResultStore: UnwrapRef readonly useRoute: UnwrapRef readonly useRouter: UnwrapRef readonly useScreenOrientation: UnwrapRef @@ -571,6 +601,8 @@ declare module 'vue' { readonly useToggle: UnwrapRef readonly useTransition: UnwrapRef readonly useUrlSearchParams: UnwrapRef + readonly useUserAccountStore: UnwrapRef + readonly useUserAccountStoreWithOut: UnwrapRef readonly useUserMedia: UnwrapRef readonly useVModel: UnwrapRef readonly useVModels: UnwrapRef @@ -741,6 +773,10 @@ declare module '@vue/runtime-core' { readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef readonly useConfirmDialog: UnwrapRef + readonly useCostAnalysisStore: UnwrapRef + readonly useCostBudgetStore: UnwrapRef + readonly useCostCollectionStore: UnwrapRef + readonly useCostDistributeStore: UnwrapRef readonly useCounter: UnwrapRef readonly useCssModule: UnwrapRef readonly useCssVar: UnwrapRef @@ -770,6 +806,7 @@ declare module '@vue/runtime-core' { readonly useEventBus: UnwrapRef readonly useEventListener: UnwrapRef readonly useEventSource: UnwrapRef + readonly useExampleComponentStore: UnwrapRef readonly useEyeDropper: UnwrapRef readonly useFavicon: UnwrapRef readonly useFetch: UnwrapRef @@ -781,6 +818,7 @@ declare module '@vue/runtime-core' { readonly useFullscreen: UnwrapRef readonly useGamepad: UnwrapRef readonly useGeolocation: UnwrapRef + readonly useHomeFrontStore: UnwrapRef readonly useIdle: UnwrapRef readonly useImage: UnwrapRef readonly useInfiniteScroll: UnwrapRef @@ -794,8 +832,13 @@ declare module '@vue/runtime-core' { readonly useLocalStorage: UnwrapRef readonly useMagicKeys: UnwrapRef readonly useManualRefHistory: UnwrapRef + readonly useMaterialBackupStore: UnwrapRef + readonly useMaterialPrepareStore: UnwrapRef + readonly useMaterialReviewStore: UnwrapRef readonly useMediaControls: UnwrapRef readonly useMediaQuery: UnwrapRef + readonly useMemberAccessStore: UnwrapRef + readonly useMemberTeamStore: UnwrapRef readonly useMemoize: UnwrapRef readonly useMemory: UnwrapRef readonly useMessage: UnwrapRef @@ -805,6 +848,7 @@ declare module '@vue/runtime-core' { readonly useMousePressed: UnwrapRef readonly useMutationObserver: UnwrapRef readonly useNavigatorLanguage: UnwrapRef + readonly useNestedLevelStore: UnwrapRef readonly useNetwork: UnwrapRef readonly useNotification: UnwrapRef readonly useNow: UnwrapRef @@ -825,9 +869,11 @@ declare module '@vue/runtime-core' { readonly usePreferredLanguages: UnwrapRef readonly usePreferredReducedMotion: UnwrapRef readonly usePrevious: UnwrapRef + readonly useProjectStore: UnwrapRef readonly useRafFn: UnwrapRef readonly useRefHistory: UnwrapRef readonly useResizeObserver: UnwrapRef + readonly useResultStore: UnwrapRef readonly useRoute: UnwrapRef readonly useRouter: UnwrapRef readonly useScreenOrientation: UnwrapRef @@ -867,6 +913,8 @@ declare module '@vue/runtime-core' { readonly useToggle: UnwrapRef readonly useTransition: UnwrapRef readonly useUrlSearchParams: UnwrapRef + readonly useUserAccountStore: UnwrapRef + readonly useUserAccountStoreWithOut: UnwrapRef readonly useUserMedia: UnwrapRef readonly useVModel: UnwrapRef readonly useVModels: UnwrapRef diff --git a/src/modules/HomeFront/data/index.ts b/src/modules/HomeFront/data/index.ts index 9e85e87..d5b9bc0 100644 --- a/src/modules/HomeFront/data/index.ts +++ b/src/modules/HomeFront/data/index.ts @@ -6,3 +6,18 @@ export const testData = { isPublished: false, createTime: '2021.01.29' } + +/** + * 首页项目列表 模拟数据 + */ +export const mockHomeProjectList = Array.from({ length: 50 }).map((item, index) => { + const id = index + 1 + return { + id: '' + id, + project_code: 'ACBD' + id, + project_name: '项目' + id, + status: '进行中', + create_time: '2023-06-14 12:00', + create_by: '李华' + } +}) diff --git a/src/modules/HomeFront/pages/index.vue b/src/modules/HomeFront/pages/index.vue index 014bd6f..1d5b542 100755 --- a/src/modules/HomeFront/pages/index.vue +++ b/src/modules/HomeFront/pages/index.vue @@ -58,6 +58,10 @@ import { Search as IconSearch, Add as IconAdd } from '@vicons/carbon' import { PaperPlaneRegular as IconPaperPlaneRegular } from '@vicons/fa' import { NButton } from 'naive-ui' +import type { ProjectItem } from '@/modules/HomeFront/types' + + +const homeFrontStore = useHomeFrontStore() /** * 首页项目列表 @@ -68,14 +72,6 @@ defineOptions({ const router = useRouter() -type ProjectItem = { - id: string - project_code: string - project_name: string - status: string - create_time: string - create_by: string -} const tableData = ref>([]) @@ -152,54 +148,19 @@ const handlerPreviewDetail = (row: ProjectItem) => { const tableLoading = ref(true) -setTimeout(() => { - // tableData.value = [ - // { - // id: '1111', - // project_code: 'ACBD', - // project_name: '项目一', - // status: '进行中', - // create_time: '2023-06-14 12:00', - // create_by: '李华' - // }, - // { - // id: '222', - // project_code: 'EFGH', - // project_name: '项目二', - // status: '已完成', - // create_time: '2023-06-14 12:00', - // create_by: '李雷' - // } - // ] - - tableData.value = Array.from({ length: 50 }).map((item, index) => { - - const id = index + 1 - - return { - id: '' + id, - project_code: 'ACBD' + id, - project_name: '项目' + id, - status: '进行中', - create_time: '2023-06-14 12:00', - create_by: '李华' - } - }) + +const initHomeProjectList = async () => { + tableLoading.value = true + homeFrontStore.fetchHomeProjectList() tableLoading.value = false -}, 300) +} +initHomeProjectList() + const searchValue = ref('') const filterTableData = ref>([]) -const handleChangeTableData = _.debounce( - () => { - filterTableData.value = tableData.value.filter(({ project_name }) => { - return searchValue.value.includes(project_name) || - project_name.includes(searchValue.value) - }) - }, - 400 -) +const handleChangeTableData = homeFrontStore.fetchSearchHomeProjectList handleChangeTableData() diff --git a/src/modules/HomeFront/store/index.ts b/src/modules/HomeFront/store/index.ts index b40bafc..6d61cd6 100755 --- a/src/modules/HomeFront/store/index.ts +++ b/src/modules/HomeFront/store/index.ts @@ -2,11 +2,15 @@ import { defineStore } from 'pinia' import { sleep } from '@/utils/request' import * as HomeFrontAPI from '../api' +import * as HomeFrontData from '../data' + +import type { ProjectItem } from '@/modules/HomeFront/types' + export const useHomeFrontStore = defineStore('HomeFront', { state: () => { return { - demoList: {} + homeProjectList: [] } }, getters: { @@ -16,6 +20,29 @@ export const useHomeFrontStore = defineStore('HomeFront', { await sleep(200) const res = await HomeFrontAPI.createProject(query) return this.filterResponse(res) + }, + async fetchHomeProjectList() { + await sleep(320) + + const res = { + msg: 'ok', + error: 0, + data: HomeFrontData.mockHomeProjectList + } + + return this.filterResponse(res, ({ data }) => { + this.homeProjectList = data + }) + }, + fetchSearchHomeProjectList(searchValue = '') { + return this.homeProjectList.filter(projectItem => { + const { project_name } = projectItem as ProjectItem + return searchValue.includes(project_name) || + project_name.includes(searchValue) + }) } + }, + debounce: { + fetchSearchHomeProjectList: 400 } }) diff --git a/src/modules/HomeFront/types/index.ts b/src/modules/HomeFront/types/index.ts new file mode 100644 index 0000000..d66d553 --- /dev/null +++ b/src/modules/HomeFront/types/index.ts @@ -0,0 +1,8 @@ +export type ProjectItem = { + id: string + project_code: string + project_name: string + status: string + create_time: string + create_by: string +} diff --git a/src/store/plugins/debounce.ts b/src/store/plugins/debounce.ts new file mode 100644 index 0000000..b55530a --- /dev/null +++ b/src/store/plugins/debounce.ts @@ -0,0 +1,15 @@ +import { store } from '..' +// 使用任意防抖库 + +store.use(({ options, store }) => { + if (options.debounce) { + // 我们正在用新的 action 来覆盖这些 action + return Object.keys(options.debounce).reduce((debouncedActions, action) => { + debouncedActions[action] = _.debounce( + store[action], + options.debounce![action] + ) + return debouncedActions + }, {}) + } +}) diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 476f40e..52caa8a 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -51,6 +51,10 @@ declare module 'pinia' { filterResponse: typeof getFilterResponse router: typeof router } + export interface DefineStoreOptionsBase { + // 任意 action 都允许定义一个防抖的毫秒数 + debounce?: Partial, number>> + } } declare module 'vue-router' { diff --git a/vite.config.ts b/vite.config.ts index e143dd5..b4d0c1c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -115,7 +115,8 @@ export default defineConfig(({ mode }) => { ? [] : [NaiveUiResolver()], dirs: [ - './src/hooks' + './src/hooks', + './src/modules/**/store' ], dts: './auto-imports.d.ts', eslintrc: { From 593bd18616a2d5e1df2d75756117960671e42aaf Mon Sep 17 00:00:00 2001 From: pdsuwwz Date: Fri, 30 Jun 2023 10:25:45 +0800 Subject: [PATCH 2/2] feat: add debounce plugin for pinia --- .eslintrc-auto-import.json | 3 ++- auto-imports.d.ts | 2 ++ src/modules/HomeFront/pages/index.vue | 5 ++--- src/modules/HomeFront/store/index.ts | 16 ++++++++++++---- src/store/index.ts | 9 +++++++-- src/store/plugins/debounce.ts | 10 ++++------ src/store/plugins/externalProperties.ts | 7 +++++++ src/store/plugins/index.ts | 9 ++------- src/store/utils/mixin.ts | 2 +- vite.config.ts | 7 +++++++ 10 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 src/store/plugins/externalProperties.ts diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index 718f772..c544f15 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -332,6 +332,7 @@ "useProjectStore": true, "useResultStore": true, "useUserAccountStore": true, - "useUserAccountStoreWithOut": true + "useUserAccountStoreWithOut": true, + "StoreActions": true } } diff --git a/auto-imports.d.ts b/auto-imports.d.ts index 7c9e871..0bbed8c 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -321,6 +321,8 @@ declare global { export type { RouteRecordRaw, RouteLocationRaw, LocationQuery, NavigationFailure, RouteParams, RouteLocationNormalizedLoaded, RouteRecordName, NavigationGuard } from 'vue-router' // @ts-ignore export type { GlobalThemeOverrides, ConfigProviderProps, DataTableColumns, DataTableRowKey, DropdownOption, MenuOption, FormInst } from 'naive-ui' + // @ts-ignore + export type { StoreActions } from 'pinia' } // for vue template auto import import { UnwrapRef } from 'vue' diff --git a/src/modules/HomeFront/pages/index.vue b/src/modules/HomeFront/pages/index.vue index 1d5b542..4e0c98d 100755 --- a/src/modules/HomeFront/pages/index.vue +++ b/src/modules/HomeFront/pages/index.vue @@ -151,7 +151,7 @@ const tableLoading = ref(true) const initHomeProjectList = async () => { tableLoading.value = true - homeFrontStore.fetchHomeProjectList() + await homeFrontStore.fetchHomeProjectList() tableLoading.value = false } initHomeProjectList() @@ -159,9 +159,8 @@ initHomeProjectList() const searchValue = ref('') -const filterTableData = ref>([]) +const filterTableData = computed(() => homeFrontStore.homeProjectList) const handleChangeTableData = homeFrontStore.fetchSearchHomeProjectList -handleChangeTableData() diff --git a/src/modules/HomeFront/store/index.ts b/src/modules/HomeFront/store/index.ts index 6d61cd6..3dc6e75 100755 --- a/src/modules/HomeFront/store/index.ts +++ b/src/modules/HomeFront/store/index.ts @@ -35,10 +35,18 @@ export const useHomeFrontStore = defineStore('HomeFront', { }) }, fetchSearchHomeProjectList(searchValue = '') { - return this.homeProjectList.filter(projectItem => { - const { project_name } = projectItem as ProjectItem - return searchValue.includes(project_name) || - project_name.includes(searchValue) + const res = { + msg: 'ok', + error: 0, + data: HomeFrontData.mockHomeProjectList + } + + return this.filterResponse(res, ({ data }) => { + this.homeProjectList = data.filter(projectItem => { + const { project_name } = projectItem as ProjectItem + return searchValue.includes(project_name) || + project_name.includes(searchValue) + }) }) } }, diff --git a/src/store/index.ts b/src/store/index.ts index df9fdee..ee96851 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,5 +1,8 @@ import { createPinia } from 'pinia' -import { pluginPinia } from '@/store/plugins' +import { + pluginExternalProperties, + pluginDebounceAction +} from '@/store/plugins' const store = createPinia() @@ -7,5 +10,7 @@ export function setupStore(app: App) { app.use(store) } -store.use(pluginPinia) +store.use(pluginExternalProperties) +store.use(pluginDebounceAction) + export { store } diff --git a/src/store/plugins/debounce.ts b/src/store/plugins/debounce.ts index b55530a..e6670e2 100644 --- a/src/store/plugins/debounce.ts +++ b/src/store/plugins/debounce.ts @@ -1,9 +1,7 @@ -import { store } from '..' -// 使用任意防抖库 - -store.use(({ options, store }) => { +// 支持使用任意防抖库 +export const pluginDebounceAction = ({ options, store }) => { if (options.debounce) { - // 我们正在用新的 action 来覆盖这些 action + // 使用新的 action 来覆盖这些 action return Object.keys(options.debounce).reduce((debouncedActions, action) => { debouncedActions[action] = _.debounce( store[action], @@ -12,4 +10,4 @@ store.use(({ options, store }) => { return debouncedActions }, {}) } -}) +} diff --git a/src/store/plugins/externalProperties.ts b/src/store/plugins/externalProperties.ts new file mode 100644 index 0000000..1a96c80 --- /dev/null +++ b/src/store/plugins/externalProperties.ts @@ -0,0 +1,7 @@ +import { getFilterResponse } from '@/store/utils/mixin' +import router from '@/router' + +export const pluginExternalProperties = ({ store }) => { + store.filterResponse = getFilterResponse + store.router = router +} diff --git a/src/store/plugins/index.ts b/src/store/plugins/index.ts index 8d70f50..80ba336 100644 --- a/src/store/plugins/index.ts +++ b/src/store/plugins/index.ts @@ -2,10 +2,5 @@ * Plugins for Pinia */ -import { getFilterResponse } from '@/store/utils/mixin' -import router from '@/router' - -export const pluginPinia = ({ store }) => { - store.filterResponse = getFilterResponse - store.router = router -} +export { pluginExternalProperties } from '@/store/plugins/externalProperties' +export { pluginDebounceAction } from '@/store/plugins/debounce' diff --git a/src/store/utils/mixin.ts b/src/store/utils/mixin.ts index 2ae718f..aca1ea1 100644 --- a/src/store/utils/mixin.ts +++ b/src/store/utils/mixin.ts @@ -13,7 +13,7 @@ export function getFilterResponse( } else { errorCallback ? errorCallback(res) - : window.$message.error(res.msg!, { + : window.$ModalMessage.error(res.msg!, { closable: true }) } diff --git a/vite.config.ts b/vite.config.ts index b4d0c1c..5f9555e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -108,6 +108,13 @@ export default defineConfig(({ mode }) => { 'FormInst' ], type: true + }, + { + from: 'pinia', + imports: [ + 'StoreActions' + ], + type: true } ], resolvers: