123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- /**
- * 数据字典工具类
- */
- import request from "@/utils/request";
- import { getStoreObject, setStoreObject } from './common'
- const DICT_NAME = '_dict';
- export const useDictStoreWithOut = () => {
- const listSimpleDictData = async () => {
- const result = await request.get('/admin-api/system/dict-data/list-all-simple')
- return result.data;
- }
- const dictObj = getStoreObject(DICT_NAME);
- if (!dictObj) {
- listSimpleDictData().then((resultData) => {
- if (resultData && resultData?.length > 0) {
- setStoreObject(DICT_NAME, resultData);
- }
- });
- }
- }
- /**
- * 获取 dictType 对应的数据字典数组
- *
- * @param dictType 数据类型
- * @returns {*|Array} 数据字典数组
- */
- export interface DictDataType {
- dictType: string
- label: string
- value: string | number | boolean
- cssClass: string
- }
- export const getDictOptions = (dictType: string, option?: {
- dictType?: string
- label?: string
- value?: string
- cssClass?: string
- }) => {
- const dictStore = getStoreObject(DICT_NAME);
- const nDicts: any[] = []
- dictStore.forEach((dict: DictDataType) => {
- if (dict.dictType === dictType) {
- nDicts.push({
- [option?.dictType ?? 'dictType']: dict.dictType,
- [option?.label ?? 'label']: dict.label,
- [option?.value ?? 'value']: dict.value,
- [option?.cssClass ?? 'cssClass']: dict.cssClass,
- })
- }
- })
- return nDicts;
- }
- export const getIntDictOptions = (dictType: string) => {
- const dictOption: DictDataType[] = []
- const dictOptions: DictDataType[] = getDictOptions(dictType)
- dictOptions.forEach((dict: DictDataType) => {
- dictOption.push({
- ...dict,
- value: parseInt(dict.value + '')
- })
- })
- return dictOption
- }
- export const getStrDictOptions = (dictType: string) => {
- const dictOption: DictDataType[] = []
- const dictOptions: DictDataType[] = getDictOptions(dictType)
- dictOptions.forEach((dict: DictDataType) => {
- dictOption.push({
- ...dict,
- value: dict.value + ''
- })
- })
- return dictOption
- }
- export const getBoolDictOptions = (dictType: string) => {
- const dictOption: DictDataType[] = []
- const dictOptions: DictDataType[] = getDictOptions(dictType)
- dictOptions.forEach((dict: DictDataType) => {
- dictOption.push({
- ...dict,
- value: dict.value + '' === 'true'
- })
- })
- return dictOption
- }
- /**
- * 获取指定字典类型的指定值对应的字典对象
- * @param dictType 字典类型
- * @param value 字典值
- * @return DictDataType 字典对象
- */
- export const getDictObj = (dictType: string, value: any): DictDataType | undefined => {
- const dictOptions: DictDataType[] = getDictOptions(dictType)
- for (const dict of dictOptions) {
- if (dict.value === value + '') {
- return dict
- }
- }
- }
- /**
- * 获得字典数据的文本展示
- *
- * @param dictType 字典类型
- * @param value 字典数据的值
- * @return 字典名称
- */
- export const getDictLabel = (dictType: string, value: any): string => {
- const dictOptions: DictDataType[] = getDictOptions(dictType)
- const dictLabel = ref('')
- dictOptions.forEach((dict: DictDataType) => {
- if (dict.value === value + '') {
- dictLabel.value = dict.label
- }
- })
- return dictLabel.value
- }
- export enum DICT_TYPE {
- USER_TYPE = 'user_type',
- COMMON_STATUS = 'common_status',
- COMMON_STATE = 'common_state',
- SYSTEM_TENANT_PACKAGE_ID = 'system_tenant_package_id',
- TERMINAL = 'terminal', // 终端
- // ========== SYSTEM 模块 ==========
- SYSTEM_USER_SEX = 'system_user_sex',
- SYSTEM_MENU_TYPE = 'system_menu_type',
- SYSTEM_ROLE_TYPE = 'system_role_type',
- SYSTEM_DATA_SCOPE = 'system_data_scope',
- SYSTEM_NOTICE_TYPE = 'system_notice_type',
- SYSTEM_OPERATE_TYPE = 'system_operate_type',
- SYSTEM_LOGIN_TYPE = 'system_login_type',
- SYSTEM_LOGIN_RESULT = 'system_login_result',
- SYSTEM_SMS_CHANNEL_CODE = 'system_sms_channel_code',
- SYSTEM_SMS_TEMPLATE_TYPE = 'system_sms_template_type',
- SYSTEM_SMS_SEND_STATUS = 'system_sms_send_status',
- SYSTEM_SMS_RECEIVE_STATUS = 'system_sms_receive_status',
- SYSTEM_ERROR_CODE_TYPE = 'system_error_code_type',
- SYSTEM_OAUTH2_GRANT_TYPE = 'system_oauth2_grant_type',
- SYSTEM_MAIL_SEND_STATUS = 'system_mail_send_status',
- SYSTEM_NOTIFY_TEMPLATE_TYPE = 'system_notify_template_type',
- // ========== INFRA 模块 ==========
- INFRA_BOOLEAN_STRING = 'infra_boolean_string',
- INFRA_JOB_STATUS = 'infra_job_status',
- INFRA_JOB_LOG_STATUS = 'infra_job_log_status',
- INFRA_API_ERROR_LOG_PROCESS_STATUS = 'infra_api_error_log_process_status',
- INFRA_CONFIG_TYPE = 'infra_config_type',
- INFRA_CODEGEN_TEMPLATE_TYPE = 'infra_codegen_template_type',
- INFRA_CODEGEN_FRONT_TYPE = 'infra_codegen_front_type',
- INFRA_CODEGEN_SCENE = 'infra_codegen_scene',
- INFRA_FILE_STORAGE = 'infra_file_storage',
- // ========== ADM 模块 ==========
- ADM_ATTENDANCE_STATUS = 'adm_attendance_status',
- // ========== BUSINESS 模块 ==========
- WF_COMMON_COST_TYPE = 'WF_COMMON_COST_TYPE',
- WF_SEAL_TYPE = 'WF_SEAL_TYPE',
- WF_SEAL_NAME = 'WF_SEAL_NAME',
- WF_TRAVEL_COST_OTHER_TYPE = 'WF_TRAVEL_COST_OTHER_TYPE',
- WF_TRAVEL_COST_VEHICLE_TYPE = 'WF_TRAVEL_COST_VEHICLE_TYPE',
- FINANCE_STATUS = 'finance_status',
- PROJECT_STATUS = 'project_status',
- CONTRACT_COST_STATUS = 'CONTRACT_COST_STATUS',
- CONTRACT_SIGN_STATUS = 'contract_is_sign',
- CONTRACT_SIGN_WAY = 'contract_sign_way',
- CONTRACT_MAIN_TYPE = 'contract_main_type',
- CONTRACT_SECOND_TYPE = 'contract_second_type',
- SUBCONTRACT_SHARE_WAY='subcontract_share_way',
- PROJECT_HY = 'project_hy',
- POST_TYPE = 'post_type',
- ABILITY_LEVEL = 'ABILITY_LEVEL',
- INVOICE_OUT_STATUS = 'INVOICE_OUT_STATUS',
- INVOICE_TYPE = 'invoice_type',
- WF_LEAVE_TYPE = 'WF_LEAVE_TYPE',
- RECRUIT_TYPE = 'RECRUIT_TYPE',
- SEX_TYPE = 'sex_type',
- NATION_TYPE = 'nation_type',
- HY_TYPE = 'hy_type',
- HK_TYPE = 'hk_type',
- POLITY_TYPE = 'polity_type',
- XL_TYPE = 'xl_type',
- }
|