-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(projects): Using data dictionary rendering.
- Loading branch information
1 parent
b6f597d
commit b1e228e
Showing
35 changed files
with
302 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +0,0 @@ | ||
import { transformRecordToOption } from '@/utils/common'; | ||
|
||
export const enableStatusRecord: Record<Api.Common.EnableStatus, App.I18n.I18nKey> = { | ||
'1': 'page.manage.common.status.enable', | ||
'0': 'page.manage.common.status.disable' | ||
}; | ||
|
||
export const enableStatusTag: Record<Api.Common.EnableStatus, NaiveUI.ThemeColor> = { | ||
0: 'error', | ||
1: 'success' | ||
}; | ||
|
||
export const enableStatusOptions = transformRecordToOption(enableStatusRecord); | ||
|
||
/** user gender */ | ||
export const userGenderRecord: Record<Api.SystemManage.UserGender, App.I18n.I18nKey> = { | ||
'0': 'page.manage.user.userGender.confidential', | ||
'1': 'page.manage.user.userGender.male', | ||
'2': 'page.manage.user.userGender.female' | ||
}; | ||
|
||
export const userGenderTag: Record<Api.SystemManage.UserGender, NaiveUI.ThemeColor> = { | ||
0: 'warning', | ||
1: 'primary', | ||
2: 'error' | ||
}; | ||
|
||
export const userGenderOptions = transformRecordToOption(userGenderRecord); | ||
|
||
/** menu type */ | ||
export const menuTypeRecord: Record<Api.SystemManage.MenuType, App.I18n.I18nKey> = { | ||
'1': 'page.manage.menu.menuType.directory', | ||
'2': 'page.manage.menu.menuType.menu' | ||
}; | ||
|
||
export const menuTypeTag: Record<Api.SystemManage.MenuType, NaiveUI.ThemeColor> = { | ||
1: 'default', | ||
2: 'primary' | ||
}; | ||
|
||
export const menuTypeOptions = transformRecordToOption(menuTypeRecord); | ||
|
||
/** menu icon type */ | ||
export const menuIconTypeRecord: Record<Api.SystemManage.IconType, App.I18n.I18nKey> = { | ||
'1': 'page.manage.menu.iconType.iconify', | ||
'2': 'page.manage.menu.iconType.local' | ||
}; | ||
|
||
export const menuIconTypeOptions = transformRecordToOption(menuIconTypeRecord); | ||
|
||
/** monitor logs login status */ | ||
export const logsLoginStatusRecord: Record<Api.Monitor.LogsLoginStatus, App.I18n.I18nKey> = { | ||
'0': 'page.monitor.logs.login.loginStatus.fail', | ||
'1': 'page.monitor.logs.login.loginStatus.success' | ||
}; | ||
|
||
export const logsLoginStatusTag: Record<Api.Monitor.LogsLoginStatus, NaiveUI.ThemeColor> = { | ||
0: 'error', | ||
1: 'success' | ||
}; | ||
|
||
export const logsLoginStatusOptions = transformRecordToOption(logsLoginStatusRecord); | ||
|
||
/** monitor logs scheduler status */ | ||
export const logsSchedulerStatusRecord: Record<Api.Monitor.SchedulerExecuteStatus, App.I18n.I18nKey> = { | ||
FAIL: 'page.monitor.logs.scheduler.executeStatus.fail', | ||
SUCCESS: 'page.monitor.logs.scheduler.executeStatus.success' | ||
}; | ||
|
||
export const logsSchedulerStatusTag: Record<Api.Monitor.SchedulerExecuteStatus, NaiveUI.ThemeColor> = { | ||
FAIL: 'error', | ||
SUCCESS: 'success' | ||
}; | ||
|
||
export const logsSchedulerStatusOptions = transformRecordToOption(logsSchedulerStatusRecord); | ||
|
||
/** monitor scheduler trigger state */ | ||
export const schedulerTriggerStateRecord: Record<Api.Monitor.SchedulerTriggerState, App.I18n.I18nKey> = { | ||
WAITING: 'page.monitor.scheduler.triggerStates.waiting', | ||
ACQUIRED: 'page.monitor.scheduler.triggerStates.acquired', | ||
EXECUTING: 'page.monitor.scheduler.triggerStates.executing', | ||
PAUSED: 'page.monitor.scheduler.triggerStates.paused', | ||
BLOCKED: 'page.monitor.scheduler.triggerStates.blocked', | ||
ERROR: 'page.monitor.scheduler.triggerStates.error' | ||
}; | ||
|
||
export const schedulerTriggerStateTag: Record<Api.Monitor.SchedulerTriggerState, NaiveUI.ThemeColor> = { | ||
WAITING: 'success', | ||
ACQUIRED: 'success', | ||
EXECUTING: 'success', | ||
PAUSED: 'error', | ||
BLOCKED: 'error', | ||
ERROR: 'error' | ||
}; | ||
|
||
export const schedulerTriggerStateOptions = transformRecordToOption(schedulerTriggerStateRecord); | ||
|
||
/** dict type */ | ||
export const dictTypeRecord: Record<Api.SystemManage.DictType, App.I18n.I18nKey> = { | ||
'1': 'page.manage.dict.dictType.system', | ||
'2': 'page.manage.dict.dictType.business' | ||
}; | ||
|
||
export const dictTypeOptions = transformRecordToOption(dictTypeRecord); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { transformRecordToOption } from '@/utils/common'; | ||
|
||
export const yesOrNoRecord: Record<CommonType.YesOrNo, App.I18n.I18nKey> = { | ||
Y: 'common.yesOrNo.yes', | ||
N: 'common.yesOrNo.no' | ||
const themeColorRecord: Record<NaiveUI.ThemeColor, string> = { | ||
default: 'Default', | ||
error: 'Error', | ||
primary: 'Primary', | ||
info: 'Info', | ||
success: 'Success', | ||
warning: 'Warning' | ||
}; | ||
|
||
export const yesOrNoTag: Record<CommonType.YesOrNo, NaiveUI.ThemeColor> = { | ||
Y: 'success', | ||
N: 'error' | ||
}; | ||
|
||
export const yesOrNoOptions = transformRecordToOption(yesOrNoRecord); | ||
export const themeColorOptions = transformRecordToOption(themeColorRecord); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { NTag, NText } from 'naive-ui'; | ||
import type { VNode } from 'vue'; | ||
import { h } from 'vue'; | ||
import { useDictStore } from '@/store/modules/dict'; | ||
|
||
export function useDict() { | ||
const dictStore = useDictStore(); | ||
|
||
/** | ||
* Get dictionary options by dictionary code | ||
* | ||
* @param code Dictionary code | ||
* @returns Dictionary options array | ||
*/ | ||
function dictOptions(code: string): Api.SystemManage.DictOptions[] | [] { | ||
return dictStore.options(code); | ||
} | ||
|
||
/** | ||
* Get the dictionary item type by dictionary code and value | ||
* | ||
* @param code Dictionary code | ||
* @param value Dictionary item value | ||
* @returns The theme color associated with the dictionary item type | ||
*/ | ||
function dcitType(code: string, value: string): NaiveUI.ThemeColor { | ||
return dictStore.type(code).get(value) || 'default'; | ||
} | ||
|
||
/** | ||
* Get dictionary label by dictionary code and value | ||
* | ||
* @param code Dictionary code | ||
* @param value Dictionary item value | ||
* @returns Dictionary item label | ||
*/ | ||
function dictLabel(code: string, value: string): string { | ||
return dictStore.map(code).get(value) || ''; | ||
} | ||
|
||
/** | ||
* Get dictionary text node by dictionary code and value | ||
* | ||
* @param code Dictionary code | ||
* @param value Dictionary item value | ||
* @returns VNode representing the dictionary text | ||
*/ | ||
function dictText(code: string, value: string | null): VNode | null { | ||
if (value === null) return null; | ||
const type = dcitType(code, value); | ||
return h(NText, { type }, () => dictLabel(code, value)); | ||
} | ||
|
||
/** | ||
* Get dictionary tag node by dictionary code and value | ||
* | ||
* @param code Dictionary code | ||
* @param value Dictionary item value | ||
* @returns VNode representing the dictionary tag | ||
*/ | ||
function dictTag(code: string, value: string | null): VNode | null { | ||
if (value === null) return null; | ||
const type = dcitType(code, value); | ||
return h(NTag, { type, bordered: false }, () => dictLabel(code, value)); | ||
} | ||
|
||
return { | ||
dictLabel, | ||
dcitType, | ||
dictText, | ||
dictTag, | ||
dictOptions | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { defineStore } from 'pinia'; | ||
import { ref } from 'vue'; | ||
import { SetupStoreId } from '@/enum'; | ||
import { fetchGetAllDictItemMap } from '@/service/api'; | ||
|
||
export const useDictStore = defineStore(SetupStoreId.Dict, () => { | ||
const dictItemMap = ref<Map<String, Api.SystemManage.DictOptions[]>>(); | ||
|
||
/** Initialize dictionary data */ | ||
async function init() { | ||
// Fetch data from API | ||
const { error, data } = await fetchGetAllDictItemMap(); | ||
if (!error) { | ||
// Convert the fetched data to a Map and assign it to dictItemMap | ||
dictItemMap.value = new Map(Object.entries(data)); | ||
} | ||
} | ||
|
||
/** | ||
* Get dictionary item type map by dictionary code | ||
* | ||
* @param code Dictionary code | ||
* @returns Dictionary item type map | ||
*/ | ||
function type(code: string): Map<string, NaiveUI.ThemeColor> { | ||
return options(code).reduce((acc, item) => acc.set(item.value, item.type), new Map<string, NaiveUI.ThemeColor>()); | ||
} | ||
|
||
/** | ||
* Get dictionary item label map by dictionary code | ||
* | ||
* @param code Dictionary code | ||
* @returns Dictionary item label map | ||
*/ | ||
function map(code: string): Map<string, string> { | ||
return options(code).reduce((acc, item) => acc.set(item.value, item.label), new Map<string, string>()); | ||
} | ||
|
||
/** | ||
* Get dictionary item array by dictionary code | ||
* | ||
* @param code Dictionary code | ||
* @returns Dictionary item array | ||
*/ | ||
function options(code: string): Api.SystemManage.DictOptions[] | [] { | ||
return dictItemMap.value?.get(code) || []; | ||
} | ||
|
||
return { | ||
init, | ||
type, | ||
map, | ||
options | ||
}; | ||
}); |
Oops, something went wrong.