constHelper.ts 872 B

1234567891011121314151617181920212223242526272829303132
  1. import type { App } from 'vue';
  2. import { useUserInfo } from '/@/stores/userInfo';
  3. export function setupConstFilter(app: App) {
  4. // 全局过滤器 在vue文件中调用 $filters.codeToName(code,type)
  5. app.config.globalProperties.$filters = {
  6. codeToName(code: any, type: any) {
  7. return codeToName(code, type);
  8. },
  9. };
  10. }
  11. // 常量值转换
  12. export function codeToName(code: any, type: any) {
  13. const userStore = useUserInfo();
  14. try {
  15. const name = userStore.constList
  16. .filter((x: any) => x.code === type)
  17. .map((x: any) => x.data)
  18. .map((x: any) => x.filter((y: any) => y.code === code))
  19. .map((x: any) => x[0].name);
  20. return name[0];
  21. } catch (error) {
  22. return code;
  23. }
  24. }
  25. export function getConstType(type: any) {
  26. const userStore = useUserInfo();
  27. const constType = userStore.constList.filter((x: any) => x.code === type)[0].data;
  28. return constType;
  29. }