refactor: dictOptions代码重构

master
dap 6 months ago
parent 8c2718a49e
commit 7535bd6096

@ -4,6 +4,10 @@
- Modal/Drawer中使用VxeTable tooltip需要设置更高的z-index 防止被遮挡
**OTHERS**
- 移除`getDict`方法
# 1.4.1
**FEATURES**

@ -3,20 +3,17 @@ import { dictDataInfo } from '#/api/system/dict/dict-data';
import { useDictStore } from '#/store/dict';
/**
*
* Select, Radio, Checkbox使
* @warning `getDictOptions()[0]`
* @warning `formatNumber` Astring Bnumber
*
* @param dictName
* @param dataGetter
* @param formatNumber valuenumber
* @returns
* @returns Options
*/
function fetchAndCacheDictData<T>(
dictName: string,
dataGetter: () => T[],
formatNumber = false,
): T[] {
const { dictRequestCache, setDictInfo } = useDictStore();
// 有调用方决定如何获取数据
const dataList = dataGetter();
export function getDictOptions(dictName: string, formatNumber = false) {
const { dictRequestCache, setDictInfo, getDictOptions } = useDictStore();
const dataList = getDictOptions(dictName);
// 检查请求状态缓存
if (dataList.length === 0 && !dictRequestCache.has(dictName)) {
@ -54,29 +51,3 @@ function fetchAndCacheDictData<T>(
}
return dataList;
}
/**
* 使
* @deprecated 使getDictOptions
* @param dictName
* @returns
*/
export function getDict(dictName: string) {
const { getDictOptions } = useDictStore();
return fetchAndCacheDictData(dictName, () => getDictOptions(dictName));
}
/**
* Select, Radio, Checkbox使
* @param dictName
* @param formatNumber valuenumber
* @returns Options
*/
export function getDictOptions(dictName: string, formatNumber = false) {
const { getDictOptions } = useDictStore();
return fetchAndCacheDictData(
dictName,
() => getDictOptions(dictName),
formatNumber,
);
}

Loading…
Cancel
Save