|
@@ -1,4 +1,4 @@
|
|
|
-
|
|
|
+import { getDictionariesDetails } from '@/api/system'
|
|
|
// 菜单类型字典
|
|
|
export const MENU_TYPE = {
|
|
|
DIRECTORY: 0,
|
|
@@ -23,14 +23,14 @@ export const APPROVAL_STATUS = [
|
|
|
]
|
|
|
|
|
|
// 员工状态
|
|
|
-export const EMPLOYEE_STATUS = [
|
|
|
- { text: '在职', color: 'primary', value: 0 },
|
|
|
- { text: '退休', color: 'info', value: 1 },
|
|
|
- { text: '离职', color: 'danger', value: 2 },
|
|
|
- { text: '借调', color: 'warning', value: 3 },
|
|
|
- { text: '病休', color: 'info', value: 4 },
|
|
|
- { text: '产假', color: 'info', value: 5 }
|
|
|
-]
|
|
|
+// export const EMPLOYEE_STATUS = [
|
|
|
+// { text: '在职', color: 'primary', value: 0 },
|
|
|
+// { text: '退休', color: 'info', value: 1 },
|
|
|
+// { text: '离职', color: 'danger', value: 2 },
|
|
|
+// { text: '借调', color: 'warning', value: 3 },
|
|
|
+// { text: '病休', color: 'info', value: 4 },
|
|
|
+// { text: '产假', color: 'info', value: 5 }
|
|
|
+// ]
|
|
|
|
|
|
export const BONUS_ALLOCATION_STATUS = {
|
|
|
0: {
|
|
@@ -46,3 +46,87 @@ export const BONUS_ALLOCATION_STATUS = {
|
|
|
color: 'info'
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// const EMPLOYEE_STATUS = {}
|
|
|
+
|
|
|
+// 字典缓存对象
|
|
|
+const dictCache = {}
|
|
|
+
|
|
|
+// 字典配置
|
|
|
+const DICT_CONFIG = {
|
|
|
+ EMPLOYEE_STATUS: {
|
|
|
+ code: 'employeeStatus',
|
|
|
+ data: null
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取字典数据
|
|
|
+ * @param {string} dictKey 字典键名
|
|
|
+ * @returns {Promise} 返回字典数据
|
|
|
+ */
|
|
|
+async function getDict (dictKey) {
|
|
|
+ // 如果缓存中有数据,直接返回
|
|
|
+ if (dictCache[dictKey]) {
|
|
|
+ return dictCache[dictKey]
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有配置,抛出错误
|
|
|
+ if (!DICT_CONFIG[dictKey]) {
|
|
|
+ throw new Error(`字典 ${dictKey} 未配置`)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果已有数据但未缓存,先缓存
|
|
|
+ if (DICT_CONFIG[dictKey].data) {
|
|
|
+ dictCache[dictKey] = DICT_CONFIG[dictKey].data
|
|
|
+ return dictCache[dictKey]
|
|
|
+ }
|
|
|
+ // 从API获取数据
|
|
|
+ try {
|
|
|
+ const { data } = await getDictionariesDetails({ dictCode: DICT_CONFIG[dictKey].code })
|
|
|
+ const _data = data.map(item => {
|
|
|
+ return {
|
|
|
+ label: item.dictTitle,
|
|
|
+ value: item.dictValue,
|
|
|
+ color: item.webContent?.dictColor
|
|
|
+ }
|
|
|
+ })
|
|
|
+ DICT_CONFIG[dictKey].data = _data
|
|
|
+ dictCache[dictKey] = _data
|
|
|
+ return _data
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`获取字典 ${dictKey} 失败:`, error)
|
|
|
+ throw error
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 默认导出字典获取方法
|
|
|
+export default {
|
|
|
+ /**
|
|
|
+ * 获取单个字典
|
|
|
+ * @param {string} dictKey 字典键名
|
|
|
+ * @returns {Promise} 返回字典数据
|
|
|
+ */
|
|
|
+ get: getDict,
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取多个字典
|
|
|
+ * @param {Array} dictKeys 字典键名数组
|
|
|
+ * @returns {Promise} 返回字典对象 {dictKey1: data, dictKey2: data}
|
|
|
+ */
|
|
|
+ async getMultiple (dictKeys) {
|
|
|
+ const result = {}
|
|
|
+ await Promise.all(dictKeys.map(async key => {
|
|
|
+ result[key] = await getDict(key)
|
|
|
+ }))
|
|
|
+ return result
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预加载字典
|
|
|
+ * @param {Array} dictKeys 需要预加载的字典键名数组
|
|
|
+ */
|
|
|
+ preload (dictKeys) {
|
|
|
+ return this.getMultiple(dictKeys)
|
|
|
+ }
|
|
|
+}
|