dict.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { reactive } 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. financing: [] // 融资阶段
  11. })
  12. const dictList = [
  13. { type: 'menduner_pay_unit', value: 'payUnit', key: 'payUnit', label: 'payName' },
  14. { type: 'menduner_financing_status', value: 'financing', key: 'financingStatus', label: 'financingName' },
  15. { type: 'menduner_scale', value: 'scale', key: 'scale', label: 'scaleName' },
  16. { type: 'menduner_industry_type', value: 'industry', key: 'industryId', label: 'industryName', params: {}, apiType: 'industryList', nameKey: 'nameCn', valueKey: 'id' },
  17. { type: 'menduner_education_type', value: 'edu', key: 'eduType', label: 'eduName' },
  18. { type: 'menduner_exp_type', value: 'exp', key: 'expType', label: 'expName' },
  19. { type: 'menduner_area_type', value: 'area', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaList', nameKey: 'name', valueKey: 'id' }
  20. ]
  21. // 字典
  22. const getDictList = async () => {
  23. dictList.forEach(async (val) => {
  24. const { data } = await getDict(val.type, val.params, val.apiType)
  25. dictObj[val.value] = data
  26. })
  27. }
  28. getDictList()
  29. export const dealDictData = (res, list) => {
  30. dictList.forEach(item => {
  31. const valueKey = item.nameKey ? item.nameKey : 'label'
  32. const idKey = item.valueKey ? item.valueKey : 'value'
  33. if (Array.isArray(list)) {
  34. res = list.map(e => {
  35. const obj = dictObj[item.value].find(k => Number(k[idKey]) === Number(e[item.key]))
  36. if (!obj) return
  37. e[item.label] = obj[valueKey] || ''
  38. e.active = false
  39. return e
  40. })
  41. return
  42. }
  43. for(let i in list) {
  44. if (i === item.key) {
  45. const obj = dictObj[item.value].find(k => Number(k[idKey]) === Number(list[i]))
  46. if (!obj) return
  47. res[item.label] = obj[valueKey]
  48. }
  49. }
  50. })
  51. return res
  52. }