Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyuchuixue committed Mar 2, 2025
2 parents 80ed137 + da2e8da commit 3e56d35
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
## 在线体验

- 官网地址:https://szadmin.cn
- 文档地址:https://szadmin.cn/md/Help/doc/start.html
- 文档地址:https://szadmin.cn/md/Help/doc/info/start.html
- 预览地址:https://preview.szadmin.cn
- 代码仓库:
- 前端:
Expand Down
2 changes: 1 addition & 1 deletion src/api/interface/system/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export namespace IDict {
export interface DictCustom {
callbackShowStyle: string;
codeName: string;
id: number;
id: string;
isLock: string;
isShow: string;
sort: number;
Expand Down
13 changes: 12 additions & 1 deletion src/api/modules/system/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const editDictData = (params: IDict.Dict) => {
};

/**
* 删除字d典
* 删除字典
* @param params
* @returns {*}
*/
Expand All @@ -94,3 +94,14 @@ export const getDictTypeOptions = () => {
export const exportDictSql = (params: { ids: number[] }) => {
return http.post<string>(ADMIN_MODULE + `/sys-dict/sql/export`, params);
};

/**
* 获取指定字典
* @param params
* @returns {*}
*/
export const getDictByCode = (params: { typeCode: string[] }) => {
const searchParams = new URLSearchParams();
params.typeCode.forEach(code => searchParams.append('typeCode', code));
return http.get<Record<string, IDict.DictCustom[]>>(ADMIN_MODULE + `/sys-dict/code?${searchParams.toString()}`);
};
13 changes: 13 additions & 0 deletions src/hooks/useDict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { onMounted } from 'vue';
import { useOptionsStore } from '@/stores/modules/options';

/**
* 自定义 Hook,用于批量刷新字典数据
* @param typeCode 字典类型数组
*/
export function useDict(typeCode: string[]) {
const optionsStore = useOptionsStore();
onMounted(async () => {
await optionsStore.getDictByCodes(typeCode);
});
}
12 changes: 10 additions & 2 deletions src/stores/modules/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia';
import { getAllDict } from '@/api/modules/system/dict';
import { getAllDict, getDictByCode } from '@/api/modules/system/dict';
import piniaPersistConfig from '@/stores/helper/persist';
import type { IDict } from '@/api/interface/system/dict';
import { ref } from 'vue';
Expand All @@ -25,12 +25,20 @@ export const useOptionsStore = defineStore(
isLoaded.value = false;
}

async function getDictByCodes(typeCodes: string[]) {
const { data } = await getDictByCode({ typeCode: typeCodes });
typeCodes.forEach(code => {
dictOptions.value[code] = data[code];
});
}

return {
isLoaded,
dictOptions,
getAllDictList,
getDictOptions,
setReloadOptions
setReloadOptions,
getDictByCodes
};
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/views/teacher/teacherStatistics/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ import { downloadTemplate } from '@/api/modules/system/common';
import { ElMessageBox } from 'element-plus';
import { useDownload } from '@/hooks/useDownload';
import RemoteSearchSelect from '@/components/RemoteSearchSelect/index.vue';
import { useDict } from '@/hooks/useDict';
defineOptions({
name: 'TeacherStatisticsView'
});
useDict(['account_status', 'dynamic_user_options']); // 使用useDict Hook 主动加载字典 【演示案例】
const optionsStore = useOptionsStore();
const proTableRef = ref<ProTableInstance>();
// 表格配置项
Expand Down

0 comments on commit 3e56d35

Please sign in to comment.