dict-utils.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { useUserInfo } from '/@/stores/userInfo';
  2. const stores = useUserInfo();
  3. // 用于在 Table 中把字段的代码转换为名称,示例如下:
  4. /*
  5. import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  6. <el-table-column prop="字段名" label="描述" width="140">
  7. <template #default="scope">
  8. <el-tag :type="di('字典名代码', scope.row.credentialsType)?.tagType"> [{{di("字典名代码", scope.row.credentialsType)?.code}}]{{di("字典名代码", scope.row.credentialsType)?.value}} </el-tag>
  9. </template>
  10. </el-table-column>
  11. */
  12. export function getDictDataItem(dicName: string, dicItemCode: any): any {
  13. return stores.getDictItemByVal(dicName, dicItemCode);
  14. }
  15. export function getDictValByLabel(dicName: string, dicItemCode: any): any {
  16. return stores.getDictValByLabel(dicName, dicItemCode);
  17. }
  18. export function getDictLabelByVal(dicName: string, dicItemCode: any): any {
  19. return stores.getDictLabelByVal(dicName, dicItemCode);
  20. }
  21. // select 控件使用,用于获取字典列表,示例如下:
  22. /*
  23. import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  24. <el-select clearable v-model="ruleForm.字段" placeholder="请选择证件提示">
  25. <el-option v-for="(item,index) in dl('字段名名码')" :key="index" :value="item.code" :label="`[${item.code}] ${item.value}`"></el-option>
  26. </el-select>
  27. */
  28. export function getDictType(dicName: string): any {
  29. return stores.dictList[dicName];
  30. }
  31. export function getDictDataList(dicName: string): any {
  32. return stores.getDictDatasByCode(dicName);
  33. }
  34. // 获取数字类型的
  35. export function getDictDataListInt(dicName: string): any {
  36. return stores.getDictIntDatasByCode(dicName);
  37. }