mirror of
https://gitee.com/nicefold/seewis-soybean-plus.git
synced 2026-10-14 03:52:28 +08:00
fix(components): 修复字典组件多语言切换无法实时更新问题
This commit is contained in:
@@ -31,7 +31,8 @@ const dictTagData = computed<Api.System.DictData[]>(() => {
|
||||
if (props.dictData) {
|
||||
const dictData = jsonClone(props.dictData);
|
||||
if (dictData.dictLabel?.startsWith(`dict.${dictData.dictType}.`)) {
|
||||
dictData.dictLabel = $t(dictData.dictLabel as App.I18n.I18nKey);
|
||||
dictData.isI18n = true;
|
||||
dictData.i18nKey = dictData.dictLabel as App.I18n.I18nKey;
|
||||
}
|
||||
return [dictData];
|
||||
}
|
||||
@@ -54,7 +55,7 @@ const dictTagData = computed<Api.System.DictData[]>(() => {
|
||||
v-bind="$attrs"
|
||||
:type="item.listClass || 'default'"
|
||||
>
|
||||
{{ item.dictLabel }}
|
||||
{{ item.isI18n ? $t(item.i18nKey) : item.dictLabel }}
|
||||
</NTag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -3,7 +3,6 @@ import { storeToRefs } from 'pinia';
|
||||
import { fetchGetDictDataByType } from '@/service/api/system';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { isNull } from '@/utils/common';
|
||||
import { $t } from '@/locales';
|
||||
|
||||
export function useDict(dictType: string, immediate: boolean = true) {
|
||||
const dictStore = useDictStore();
|
||||
@@ -21,11 +20,6 @@ export function useDict(dictType: string, immediate: boolean = true) {
|
||||
}
|
||||
const { data: dictData, error } = await fetchGetDictDataByType(dictType);
|
||||
if (error) return;
|
||||
dictData.forEach(dict => {
|
||||
if (dict.dictLabel?.startsWith(`dict.${dictType}.`)) {
|
||||
dict.dictLabel = $t(dict.dictLabel as App.I18n.I18nKey);
|
||||
}
|
||||
});
|
||||
dictStore.setDict(dictType, dictData);
|
||||
data.value = dictData;
|
||||
}
|
||||
@@ -44,15 +38,20 @@ export function useDict(dictType: string, immediate: boolean = true) {
|
||||
await getData();
|
||||
}
|
||||
|
||||
options.value = data.value.map(dict => ({ label: dict.dictLabel!, value: dict.dictValue! }));
|
||||
options.value = data.value.map(dict => ({
|
||||
label: dict.dictLabel!,
|
||||
value: dict.dictValue!
|
||||
}));
|
||||
}
|
||||
|
||||
function transformDictData(dictValue: string[] | number[] | string | number) {
|
||||
if (!data.value.length || isNull(dictValue)) return undefined;
|
||||
if (isNull(dictValue)) return undefined;
|
||||
const currentData = dictStore.getDict(dictType) ?? data.value;
|
||||
if (!currentData.length) return undefined;
|
||||
if (Array.isArray(dictValue)) {
|
||||
return data.value.filter(dict => dictValue.some(value => dict.dictValue === value.toString()));
|
||||
return currentData.filter(dict => dictValue.some(value => dict.dictValue === value.toString()));
|
||||
}
|
||||
return data.value.filter(dict => dict.dictValue === dictValue.toString());
|
||||
return currentData.filter(dict => dict.dictValue === dictValue.toString());
|
||||
}
|
||||
|
||||
if (immediate) {
|
||||
|
||||
Vendored
+4
@@ -372,6 +372,10 @@ declare namespace Api {
|
||||
listClass: NaiveUI.ThemeColor;
|
||||
/** 备注 */
|
||||
remark: string;
|
||||
/** 是否多语言 */
|
||||
isI18n?: boolean;
|
||||
/** 多语言标识 */
|
||||
i18nKey: App.I18n.I18nKey;
|
||||
}>;
|
||||
|
||||
/** dict data search params */
|
||||
|
||||
Reference in New Issue
Block a user