perf(projects): use transformObjectToOption to generate option of object labels
This commit is contained in:
parent
eb8e49e23c
commit
da611fb10b
6
src/constants/_shared.ts
Normal file
6
src/constants/_shared.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export function transformObjectToOption<T extends object>(obj: T) {
|
||||||
|
return Object.entries(obj).map(([value, label]) => ({
|
||||||
|
value,
|
||||||
|
label
|
||||||
|
})) as Common.OptionWithKey<keyof T>[];
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
import { transformObjectToOption } from './_shared';
|
||||||
|
|
||||||
export const loginModuleLabels: Record<UnionKey.LoginModule, string> = {
|
export const loginModuleLabels: Record<UnionKey.LoginModule, string> = {
|
||||||
'pwd-login': '账密登录',
|
'pwd-login': '账密登录',
|
||||||
'code-login': '手机验证码登录',
|
'code-login': '手机验证码登录',
|
||||||
@ -11,23 +13,14 @@ export const userRoleLabels: Record<Auth.RoleType, string> = {
|
|||||||
admin: '管理员',
|
admin: '管理员',
|
||||||
user: '普通用户'
|
user: '普通用户'
|
||||||
};
|
};
|
||||||
|
export const userRoleOptions = transformObjectToOption(loginModuleLabels);
|
||||||
export const userRoleOptions: Common.OptionWithKey<Auth.RoleType>[] = [
|
|
||||||
{ value: 'super', label: userRoleLabels.super },
|
|
||||||
{ value: 'admin', label: userRoleLabels.admin },
|
|
||||||
{ value: 'user', label: userRoleLabels.user }
|
|
||||||
];
|
|
||||||
|
|
||||||
/** 用户性别 */
|
/** 用户性别 */
|
||||||
export const genderLabels: Record<UserManagement.GenderKey, string> = {
|
export const genderLabels: Record<UserManagement.GenderKey, string> = {
|
||||||
0: '女',
|
0: '女',
|
||||||
1: '男'
|
1: '男'
|
||||||
};
|
};
|
||||||
|
export const genderOptions = transformObjectToOption(genderLabels);
|
||||||
export const genderOptions: Common.OptionWithKey<UserManagement.GenderKey>[] = [
|
|
||||||
{ value: '0', label: genderLabels['0'] },
|
|
||||||
{ value: '1', label: genderLabels['1'] }
|
|
||||||
];
|
|
||||||
|
|
||||||
/** 用户状态 */
|
/** 用户状态 */
|
||||||
export const userStatusLabels: Record<UserManagement.UserStatusKey, string> = {
|
export const userStatusLabels: Record<UserManagement.UserStatusKey, string> = {
|
||||||
@ -36,10 +29,4 @@ export const userStatusLabels: Record<UserManagement.UserStatusKey, string> = {
|
|||||||
3: '冻结',
|
3: '冻结',
|
||||||
4: '软删除'
|
4: '软删除'
|
||||||
};
|
};
|
||||||
|
export const userStatusOptions = transformObjectToOption(userStatusLabels);
|
||||||
export const userStatusOptions: Common.OptionWithKey<UserManagement.UserStatusKey>[] = [
|
|
||||||
{ value: '1', label: userStatusLabels['1'] },
|
|
||||||
{ value: '2', label: userStatusLabels['2'] },
|
|
||||||
{ value: '3', label: userStatusLabels['3'] },
|
|
||||||
{ value: '4', label: userStatusLabels['4'] }
|
|
||||||
];
|
|
||||||
|
@ -1,81 +1,31 @@
|
|||||||
|
import { transformObjectToOption } from './_shared';
|
||||||
|
|
||||||
export const themeLayoutModeLabels: Record<UnionKey.ThemeLayoutMode, string> = {
|
export const themeLayoutModeLabels: Record<UnionKey.ThemeLayoutMode, string> = {
|
||||||
vertical: '左侧菜单模式',
|
vertical: '左侧菜单模式',
|
||||||
horizontal: '顶部菜单模式',
|
horizontal: '顶部菜单模式',
|
||||||
'vertical-mix': '左侧菜单混合模式',
|
'vertical-mix': '左侧菜单混合模式',
|
||||||
'horizontal-mix': '顶部菜单混合模式'
|
'horizontal-mix': '顶部菜单混合模式'
|
||||||
};
|
};
|
||||||
|
export const themeLayoutModeOptions = transformObjectToOption(themeLayoutModeLabels);
|
||||||
export const themeLayoutModeOptions: Common.OptionWithKey<UnionKey.ThemeLayoutMode>[] = [
|
|
||||||
{
|
|
||||||
value: 'vertical',
|
|
||||||
label: themeLayoutModeLabels.vertical
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'horizontal',
|
|
||||||
label: themeLayoutModeLabels.horizontal
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'vertical-mix',
|
|
||||||
label: themeLayoutModeLabels['vertical-mix']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'horizontal-mix',
|
|
||||||
label: themeLayoutModeLabels['horizontal-mix']
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export const themeScrollModeLabels: Record<UnionKey.ThemeScrollMode, string> = {
|
export const themeScrollModeLabels: Record<UnionKey.ThemeScrollMode, string> = {
|
||||||
wrapper: '外层滚动',
|
wrapper: '外层滚动',
|
||||||
content: '主体滚动'
|
content: '主体滚动'
|
||||||
};
|
};
|
||||||
|
export const themeScrollModeOptions = transformObjectToOption(themeScrollModeLabels);
|
||||||
export const themeScrollModeOptions: Common.OptionWithKey<UnionKey.ThemeScrollMode>[] = [
|
|
||||||
{
|
|
||||||
value: 'wrapper',
|
|
||||||
label: themeScrollModeLabels.wrapper
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'content',
|
|
||||||
label: themeScrollModeLabels.content
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export const themeTabModeLabels: Record<UnionKey.ThemeTabMode, string> = {
|
export const themeTabModeLabels: Record<UnionKey.ThemeTabMode, string> = {
|
||||||
chrome: '谷歌风格',
|
chrome: '谷歌风格',
|
||||||
button: '按钮风格'
|
button: '按钮风格'
|
||||||
};
|
};
|
||||||
|
export const themeTabModeOptions = transformObjectToOption(themeTabModeLabels);
|
||||||
export const themeTabModeOptions: Common.OptionWithKey<UnionKey.ThemeTabMode>[] = [
|
|
||||||
{
|
|
||||||
value: 'chrome',
|
|
||||||
label: themeTabModeLabels.chrome
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'button',
|
|
||||||
label: themeTabModeLabels.button
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export const themeHorizontalMenuPositionLabels: Record<UnionKey.ThemeHorizontalMenuPosition, string> = {
|
export const themeHorizontalMenuPositionLabels: Record<UnionKey.ThemeHorizontalMenuPosition, string> = {
|
||||||
'flex-start': '居左',
|
'flex-start': '居左',
|
||||||
center: '居中',
|
center: '居中',
|
||||||
'flex-end': '居右'
|
'flex-end': '居右'
|
||||||
};
|
};
|
||||||
|
export const themeHorizontalMenuPositionOptions = transformObjectToOption(themeHorizontalMenuPositionLabels);
|
||||||
export const themeHorizontalMenuPositionOptions: Common.OptionWithKey<UnionKey.ThemeHorizontalMenuPosition>[] = [
|
|
||||||
{
|
|
||||||
value: 'flex-start',
|
|
||||||
label: themeHorizontalMenuPositionLabels['flex-start']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'center',
|
|
||||||
label: themeHorizontalMenuPositionLabels.center
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'flex-end',
|
|
||||||
label: themeHorizontalMenuPositionLabels['flex-end']
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export const themeAnimateModeLabels: Record<UnionKey.ThemeAnimateMode, string> = {
|
export const themeAnimateModeLabels: Record<UnionKey.ThemeAnimateMode, string> = {
|
||||||
'zoom-fade': '渐变',
|
'zoom-fade': '渐变',
|
||||||
@ -85,30 +35,4 @@ export const themeAnimateModeLabels: Record<UnionKey.ThemeAnimateMode, string> =
|
|||||||
'fade-bottom': '底部消退',
|
'fade-bottom': '底部消退',
|
||||||
'fade-scale': '缩放消退'
|
'fade-scale': '缩放消退'
|
||||||
};
|
};
|
||||||
|
export const themeAnimateModeOptions = transformObjectToOption(themeAnimateModeLabels);
|
||||||
export const themeAnimateModeOptions: Common.OptionWithKey<UnionKey.ThemeAnimateMode>[] = [
|
|
||||||
{
|
|
||||||
value: 'zoom-fade',
|
|
||||||
label: themeAnimateModeLabels['zoom-fade']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'zoom-out',
|
|
||||||
label: themeAnimateModeLabels['zoom-out']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'fade-slide',
|
|
||||||
label: themeAnimateModeLabels['fade-slide']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'fade',
|
|
||||||
label: themeAnimateModeLabels.fade
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'fade-bottom',
|
|
||||||
label: themeAnimateModeLabels['fade-bottom']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'fade-scale',
|
|
||||||
label: themeAnimateModeLabels['fade-scale']
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
Loading…
Reference in New Issue
Block a user