diff --git a/packages/vue3-util/CHANGELOG.md b/packages/vue3-util/CHANGELOG.md index cb7da7fdf3167c73f4000f187cfa8f6b09577940..152be23ba43a20d81864e272493b5450f4f0f478 100644 --- a/packages/vue3-util/CHANGELOG.md +++ b/packages/vue3-util/CHANGELOG.md @@ -9,6 +9,7 @@ ### Changed +- 新增支持微服务组件数据存储useMicroCompStore - 路由上菜单项标识持久化 ### Fixed diff --git a/packages/vue3-util/src/util/store/index.ts b/packages/vue3-util/src/util/store/index.ts index ead684cb5b831527c09b29aef7ea9b219aefe28b..66d91e9818659e001a67c2b5c7c093b2d4539873 100644 --- a/packages/vue3-util/src/util/store/index.ts +++ b/packages/vue3-util/src/util/store/index.ts @@ -2,5 +2,6 @@ import { createPinia } from 'pinia'; export * from './app-store/app-store'; export * from './ui-store/ui-store'; +export * from './micro-component-store/micro-component-store'; export const piniaInstance = createPinia(); diff --git a/packages/vue3-util/src/util/store/micro-component-store/micro-component-data.ts b/packages/vue3-util/src/util/store/micro-component-store/micro-component-data.ts new file mode 100644 index 0000000000000000000000000000000000000000..90df2aaf8c45faf7d486bb05116e20230fdce139 --- /dev/null +++ b/packages/vue3-util/src/util/store/micro-component-store/micro-component-data.ts @@ -0,0 +1,129 @@ +export interface IOrgDataStore { + /** + * @description 获取单位数据 + * @memberof IOrgDataStore + */ + getOrgData: (key: string) => IData | null; + + /** + * @description 更新单位数据 + * @memberof IOrgDataStore + */ + updateOrgData: (key: string, data: IData) => void; + + /** + * @description 获取部门数据 + * @memberof IOrgDataStore + */ + getDeptData: (key: string) => IData | null; + + /** + * @description 更新部门数据 + * @memberof IOrgDataStore + */ + updateDeptData: (key: string, data: IData) => void; + + /** + * @description 获取人员数据 + * @memberof IOrgDataStore + */ + getPersonData: (key: string) => IData | null; + + /** + * @description 更新人员数据 + * @memberof IOrgDataStore + */ + updatePersonData: (key: string, data: IData) => void; + + /** + * @description 获取所有存储的数据 + * @memberof IOrgDataStore + */ + getAllData: () => IData; +} + +/** + * @description 微服务组件数据存储 + * @export + * @returns {*} {IOrgDataStore} + */ +export function useMicroCompDataStore(): IOrgDataStore { + // 单位数据 + const orgData = new Map(); + // 部门数据 + const deptData = new Map(); + // 人员数据 + const personData = new Map(); + + /** + * @description 获取单位数据 + * @param {string} key + * @returns {*} {IData} + */ + function getOrgData(key: string): IData { + return orgData.get(key); + } + + /** 更新单位数据 + * @description + * @param {string} key + * @param {IData} data + */ + function updateOrgData(key: string, data: IData) { + orgData.set(key, data); + } + + /** + * @description 获取部门数据 + * @param {string} key + * @returns {*} {IData} + */ + function getDeptData(key: string): IData { + return deptData.get(key); + } + + /** + * @description 更新部门数据 + * @param {string} key + * @param {IData} data + */ + function updateDeptData(key: string, data: IData) { + deptData.set(key, data); + } + + /** + * @description 获取人员数据 + * @param {string} key + * @returns {*} {IData} + */ + function getPersonData(key: string): IData { + return personData.get(key); + } + + /** + * @description 更新人员数据 + * @param {string} key + * @param {IData} data + */ + function updatePersonData(key: string, data: IData) { + personData.set(key, data); + } + + function getAllData() { + return { + orgData, + deptData, + personData, + }; + } + + return { + getOrgData, + updateOrgData, + getDeptData, + updateDeptData, + getPersonData, + updatePersonData, + getAllData, + }; +} diff --git a/packages/vue3-util/src/util/store/micro-component-store/micro-component-store.ts b/packages/vue3-util/src/util/store/micro-component-store/micro-component-store.ts new file mode 100644 index 0000000000000000000000000000000000000000..ab7519f1eba2fe69000896300eef5682c7351349 --- /dev/null +++ b/packages/vue3-util/src/util/store/micro-component-store/micro-component-store.ts @@ -0,0 +1,22 @@ +import { defineStore } from 'pinia'; +import { reactive } from 'vue'; +import { useMicroCompDataStore } from './micro-component-data'; + +export interface IMicroCompStore { + // 微服务组件数据 + microCompData: IData; +} + +export const useMicroCompStore = defineStore('microCompStore', () => { + // 微服务组件数据 + const microCompData = useMicroCompDataStore(); + const getMicroCompData = () => { + return microCompData.getAllData(); + }; + + const microCompStore = reactive({ + microCompData: getMicroCompData(), + }); + + return { microCompStore, microCompData }; +});