提交 | 用户 | 时间
|
820397
|
1 |
/** |
H |
2 |
* 数据字典工具类 |
|
3 |
*/ |
|
4 |
import { useDictStoreWithOut } from '@/store/modules/dict' |
|
5 |
import { ElementPlusInfoType } from '@/types/elementPlus' |
|
6 |
|
|
7 |
const dictStore = useDictStoreWithOut() |
|
8 |
|
|
9 |
/** |
|
10 |
* 获取 dictType 对应的数据字典数组 |
|
11 |
* |
|
12 |
* @param dictType 数据类型 |
|
13 |
* @returns {*|Array} 数据字典数组 |
|
14 |
*/ |
|
15 |
export interface DictDataType { |
|
16 |
dictType: string |
|
17 |
label: string |
|
18 |
value: string | number | boolean |
|
19 |
colorType: ElementPlusInfoType | '' |
|
20 |
cssClass: string |
|
21 |
} |
|
22 |
|
|
23 |
export interface NumberDictDataType extends DictDataType { |
|
24 |
value: number |
|
25 |
} |
|
26 |
|
|
27 |
export interface StringDictDataType extends DictDataType { |
|
28 |
value: string |
|
29 |
} |
|
30 |
|
|
31 |
export const getDictOptions = (dictType: string) => { |
|
32 |
return dictStore.getDictByType(dictType) || [] |
|
33 |
} |
|
34 |
|
|
35 |
export const getIntDictOptions = (dictType: string): NumberDictDataType[] => { |
|
36 |
// 获得通用的 DictDataType 列表 |
|
37 |
const dictOptions: DictDataType[] = getDictOptions(dictType) |
|
38 |
// 转换成 number 类型的 NumberDictDataType 类型 |
|
39 |
// why 需要特殊转换:避免 IDEA 在 v-for="dict in getIntDictOptions(...)" 时,el-option 的 key 会告警 |
|
40 |
const dictOption: NumberDictDataType[] = [] |
|
41 |
dictOptions.forEach((dict: DictDataType) => { |
|
42 |
dictOption.push({ |
|
43 |
...dict, |
|
44 |
value: parseInt(dict.value + '') |
|
45 |
}) |
|
46 |
}) |
|
47 |
return dictOption |
|
48 |
} |
|
49 |
|
|
50 |
export const getStrDictOptions = (dictType: string) => { |
|
51 |
// 获得通用的 DictDataType 列表 |
|
52 |
const dictOptions: DictDataType[] = getDictOptions(dictType) |
|
53 |
// 转换成 string 类型的 StringDictDataType 类型 |
|
54 |
// why 需要特殊转换:避免 IDEA 在 v-for="dict in getStrDictOptions(...)" 时,el-option 的 key 会告警 |
|
55 |
const dictOption: StringDictDataType[] = [] |
|
56 |
dictOptions.forEach((dict: DictDataType) => { |
|
57 |
dictOption.push({ |
|
58 |
...dict, |
|
59 |
value: dict.value + '' |
|
60 |
}) |
|
61 |
}) |
|
62 |
return dictOption |
|
63 |
} |
|
64 |
|
|
65 |
export const getBoolDictOptions = (dictType: string) => { |
|
66 |
const dictOption: DictDataType[] = [] |
|
67 |
const dictOptions: DictDataType[] = getDictOptions(dictType) |
|
68 |
dictOptions.forEach((dict: DictDataType) => { |
|
69 |
dictOption.push({ |
|
70 |
...dict, |
|
71 |
value: dict.value + '' === 'true' |
|
72 |
}) |
|
73 |
}) |
|
74 |
return dictOption |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* 获取指定字典类型的指定值对应的字典对象 |
|
79 |
* @param dictType 字典类型 |
|
80 |
* @param value 字典值 |
|
81 |
* @return DictDataType 字典对象 |
|
82 |
*/ |
|
83 |
export const getDictObj = (dictType: string, value: any): DictDataType | undefined => { |
|
84 |
const dictOptions: DictDataType[] = getDictOptions(dictType) |
|
85 |
for (const dict of dictOptions) { |
|
86 |
if (dict.value === value + '') { |
|
87 |
return dict |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* 获得字典数据的文本展示 |
|
94 |
* |
|
95 |
* @param dictType 字典类型 |
|
96 |
* @param value 字典数据的值 |
|
97 |
* @return 字典名称 |
|
98 |
*/ |
|
99 |
export const getDictLabel = (dictType: string, value: any): string => { |
|
100 |
const dictOptions: DictDataType[] = getDictOptions(dictType) |
|
101 |
const dictLabel = ref('') |
|
102 |
dictOptions.forEach((dict: DictDataType) => { |
|
103 |
if (dict.value === value + '') { |
|
104 |
dictLabel.value = dict.label |
|
105 |
} |
|
106 |
}) |
|
107 |
return dictLabel.value |
|
108 |
} |
|
109 |
|
|
110 |
export enum DICT_TYPE { |
|
111 |
USER_TYPE = 'user_type', |
|
112 |
COMMON_STATUS = 'common_status', |
|
113 |
TERMINAL = 'terminal', // 终端 |
|
114 |
DATE_INTERVAL = 'date_interval', // 数据间隔 |
|
115 |
|
|
116 |
// ========== SYSTEM 模块 ========== |
|
117 |
SYSTEM_USER_SEX = 'system_user_sex', |
|
118 |
SYSTEM_MENU_TYPE = 'system_menu_type', |
39248b
|
119 |
SYSTEM_APP_MENU_TYPE = 'system_app_menu_type', |
H |
120 |
SYSTEM_APP_TYPE = 'system_app_type', |
820397
|
121 |
SYSTEM_ROLE_TYPE = 'system_role_type', |
H |
122 |
SYSTEM_DATA_SCOPE = 'system_data_scope', |
|
123 |
SYSTEM_NOTICE_TYPE = 'system_notice_type', |
|
124 |
SYSTEM_LOGIN_TYPE = 'system_login_type', |
|
125 |
SYSTEM_LOGIN_RESULT = 'system_login_result', |
|
126 |
SYSTEM_SMS_CHANNEL_CODE = 'system_sms_channel_code', |
|
127 |
SYSTEM_SMS_TEMPLATE_TYPE = 'system_sms_template_type', |
|
128 |
SYSTEM_SMS_SEND_STATUS = 'system_sms_send_status', |
|
129 |
SYSTEM_SMS_RECEIVE_STATUS = 'system_sms_receive_status', |
|
130 |
SYSTEM_OAUTH2_GRANT_TYPE = 'system_oauth2_grant_type', |
|
131 |
SYSTEM_MAIL_SEND_STATUS = 'system_mail_send_status', |
|
132 |
SYSTEM_NOTIFY_TEMPLATE_TYPE = 'system_notify_template_type', |
|
133 |
SYSTEM_SOCIAL_TYPE = 'system_social_type', |
|
134 |
|
|
135 |
// ========== INFRA 模块 ========== |
|
136 |
INFRA_BOOLEAN_STRING = 'infra_boolean_string', |
|
137 |
INFRA_JOB_STATUS = 'infra_job_status', |
|
138 |
INFRA_JOB_LOG_STATUS = 'infra_job_log_status', |
|
139 |
INFRA_API_ERROR_LOG_PROCESS_STATUS = 'infra_api_error_log_process_status', |
|
140 |
INFRA_CONFIG_TYPE = 'infra_config_type', |
|
141 |
INFRA_CODEGEN_TEMPLATE_TYPE = 'infra_codegen_template_type', |
|
142 |
INFRA_CODEGEN_FRONT_TYPE = 'infra_codegen_front_type', |
|
143 |
INFRA_CODEGEN_SCENE = 'infra_codegen_scene', |
|
144 |
INFRA_FILE_STORAGE = 'infra_file_storage', |
|
145 |
INFRA_OPERATE_TYPE = 'infra_operate_type', |
|
146 |
|
|
147 |
// ========== BPM 模块 ========== |
|
148 |
BPM_MODEL_FORM_TYPE = 'bpm_model_form_type', |
|
149 |
BPM_TASK_CANDIDATE_STRATEGY = 'bpm_task_candidate_strategy', |
|
150 |
BPM_PROCESS_INSTANCE_STATUS = 'bpm_process_instance_status', |
|
151 |
BPM_TASK_STATUS = 'bpm_task_status', |
|
152 |
BPM_OA_LEAVE_TYPE = 'bpm_oa_leave_type', |
|
153 |
BPM_PROCESS_LISTENER_TYPE = 'bpm_process_listener_type', |
|
154 |
BPM_PROCESS_LISTENER_VALUE_TYPE = 'bpm_process_listener_value_type', |
|
155 |
|
6badb7
|
156 |
// ========== MODEL - 模型管理模块 ========== |
潘 |
157 |
SCHE_MODEL_TYPE = 'sche_model_type', |
|
158 |
SCHE_MODEL_INVOCATION = 'sche_model_invocation', |
8ea580
|
159 |
SCHE_TRIGGER_METHOD = 'sche_trigger_method', |
9c91ad
|
160 |
MODEL_PARAM_TYPE = 'model_param_type', |
D |
161 |
MODEL_METHOD = 'model_method', |
7767e5
|
162 |
MODEL_TYPE = 'model_type', |
D |
163 |
MODEL_METHOD_SETTING_TYPE = 'model_method_setting_type', |
|
164 |
MODEL_METHOD_SETTING_VALUE_TYPE = 'model_method_setting_value_type', |
4c7918
|
165 |
PRED_GRANULARITY = 'pred_granularity', |
7b1ce6
|
166 |
ITEM_RUN_STATUS = 'item_run_status', |
f87d4e
|
167 |
|
潘 |
168 |
// ========== DATA - 数据平台模块 ========== |
|
169 |
DATA_FIELD_TYPE = 'data_field_type', |
b05c43
|
170 |
TAG_DATA_TYPE = 'tag_data_type', |
e9d8f9
|
171 |
POINT_DATA_TYPE = 'point_data_type', |
dea4e4
|
172 |
IS_ENABLED = 'is_enabled', |
潘 |
173 |
OPCUA_SECURITY_POLICY = 'opcua_security_policy', |
|
174 |
OPCUA_SECURITY_MODE = 'opcua_security_mode', |
|
175 |
OPCUA_CONNECTION_TYPE = 'opcua_connection_type', |
6d9c08
|
176 |
HTTP_METHOD = 'http_method', |
e01139
|
177 |
TIME_GRANULARITY = 'time_granularity', |
d3ee81
|
178 |
DATA_STAT_FUNC = 'data_stat_func', |
潘 |
179 |
IND_TIME_LIMIT = 'ind_time_limit', |
|
180 |
IND_ITEM_TYPE = 'ind_item_type', |
05143c
|
181 |
COM_IS_INT = 'com_is_int', |
e9d8f9
|
182 |
DATA_POINT_TYPE = 'data_point_type', |
660c92
|
183 |
MINFREQID = 'minfreqid', |
c4b4d2
|
184 |
MEASURE_VALUE_TYPE = 'measure_value_type', |
30566d
|
185 |
NVR_ONLINE_STATUS = 'nvr_online_status', |
H |
186 |
CAMERA_BRAND = 'camera_brand', |
c3e84e
|
187 |
CAPTURE_TYPE = 'capture_type', |
820397
|
188 |
} |