ow
This commit is contained in:
1 parent
d2c2b3cf59
commit
4359903d9c
33 files changed
+2708
-246
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { computed } from "vue";
|
||||
import type { ComputedRef } from "vue";
|
||||
import i18n from "@/locales";
|
||||
import { SelectOption } from "@/data/auto/selectOption";
|
||||
|
||||
/**
|
||||
* 基于应用启动时已合并到 i18n 的 locale 数据(main.ts -> mergeDbLocaleMessages),
|
||||
* 提供策略组下拉选项,避免再次调用服务器。
|
||||
* 映射规则与后端 LocaleService.FindSelectOption 保持一致:
|
||||
* BindValue = Name, DisplayName = Value
|
||||
* 顺序为 i18n 中 locale 表的合并顺序(对应 locale 表 order_by 的插入顺序)。
|
||||
*/
|
||||
export const useLocalePolicy = () => {
|
||||
const getPolicyOptions = (groupName: string, blank = true): SelectOption[] => {
|
||||
const locale = ((i18n.global.locale as any)?.value ?? "zh-cn") as string;
|
||||
const messages = (i18n.global.messages as any)?.value ?? {};
|
||||
const group: Record<string, unknown> = messages[locale]?.[groupName] ?? {};
|
||||
|
||||
const options: SelectOption[] = [];
|
||||
if (blank) options.push(new SelectOption());
|
||||
|
||||
Object.entries(group).forEach(([key, value]) => {
|
||||
const option = new SelectOption();
|
||||
option.BindValue = key;
|
||||
option.DisplayName = String(value);
|
||||
options.push(option);
|
||||
});
|
||||
return options;
|
||||
};
|
||||
|
||||
const getPolicyOptionsComputed = (
|
||||
groupName: string,
|
||||
blank = true
|
||||
): ComputedRef<SelectOption[]> => computed(() => getPolicyOptions(groupName, blank));
|
||||
|
||||
/**
|
||||
* 可直接绑定 <a-select :options> 的选项结构(label/value)
|
||||
*/
|
||||
const getPolicySelectOptions = (groupName: string, blank = true): { label: string; value: string }[] => {
|
||||
return getPolicyOptions(groupName, blank).map((o) => ({
|
||||
label: o.DisplayName,
|
||||
value: o.BindValue,
|
||||
}));
|
||||
};
|
||||
|
||||
const getPolicySelectOptionsComputed = (
|
||||
groupName: string,
|
||||
blank = true
|
||||
): ComputedRef<{ label: string; value: string }[]> =>
|
||||
computed(() => getPolicySelectOptions(groupName, blank));
|
||||
|
||||
return {
|
||||
getPolicyOptions,
|
||||
getPolicyOptionsComputed,
|
||||
getPolicySelectOptions,
|
||||
getPolicySelectOptionsComputed,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user