dict.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { reactive, ref } from 'vue'
  2. import { getDict } from '@/hooks/web/useDictionaries'
  3. const dictObj = reactive({
  4. payUnit: [], // 薪资单位
  5. scale: [], // 规模
  6. industry: [], // 行业
  7. edu: [], // 学历
  8. exp: [], // 工作经验
  9. area: [], // 地区
  10. jobStatus: [], // 求职状态
  11. marital: [], // 婚姻状态
  12. financing: [] // 融资阶段
  13. })
  14. const dictList = ref([
  15. { type: 'menduner_pay_unit', value: 'payUnit', key: 'payUnit', label: 'payName' },
  16. { type: 'menduner_financing_status', value: 'financing', key: 'financingStatus', label: 'financingName' },
  17. { type: 'menduner_scale', value: 'scale', key: 'scale', label: 'scaleName' },
  18. { type: 'menduner_job_status', value: 'jobStatus', key: 'jobStatus', label: 'jobStatusName' },
  19. { type: 'menduner_marital_status', value: 'marital', key: 'maritalStatus', label: 'maritalStatusName' },
  20. { type: 'menduner_industry_type', value: 'industry', key: 'industryId', label: 'industryName', params: {}, apiType: 'industryList', nameKey: 'nameCn', valueKey: 'id' },
  21. { type: 'menduner_education_type', value: 'edu', key: 'eduType', label: 'eduName' },
  22. { type: 'menduner_exp_type', value: 'exp', key: 'expType', label: 'expName' },
  23. { type: 'menduner_area_type', value: 'area', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaList', nameKey: 'name', valueKey: 'id' },
  24. { type: 'positionData', value: 'position', key: 'positionId', label: 'positionName', params: {}, apiType: 'positionData', nameKey: 'nameCn', valueKey: 'id' }
  25. ])
  26. // 字典
  27. const getDictList = async () => {
  28. dictList.value.forEach(async (val) => {
  29. const { data } = await getDict(val.type, val.params, val.apiType)
  30. dictObj[val.value] = data
  31. })
  32. }
  33. export const getDictListData = async () => {
  34. await getDictList()
  35. }
  36. getDictListData()
  37. export const dealDictArrayData = (res, list) => {
  38. res = list.map(item => {
  39. Object.keys(item).map(e => {
  40. const data = dictList.value.find(k => k.key === e)
  41. if (!data) return
  42. const valueKey = data.nameKey ? data.nameKey : 'label'
  43. const idKey = data.valueKey ? data.valueKey : 'value'
  44. if (!dictObj[data.value] || !Object.keys(dictObj[data.value]).length) return
  45. const result = dictObj[data.value].find(val => val[idKey] === item[e])
  46. if (!result) return
  47. item[data.label] = result[valueKey] || ''
  48. })
  49. return { ...item, active: false, select: false }
  50. })
  51. return res
  52. }
  53. export const dealDictObjData = (res, obj) => {
  54. Object.keys(obj).map(e => {
  55. const data = dictList.value.find(k => k.key === e)
  56. if (!data) return
  57. const valueKey = data.nameKey ? data.nameKey : 'label'
  58. const idKey = data.valueKey ? data.valueKey : 'value'
  59. const result = dictObj[data.value].find(val => val[idKey] === obj[e])
  60. if (!result) return
  61. res[data.label] = result[valueKey]
  62. res = { ...obj, ...res }
  63. })
  64. return res
  65. }