刘光辉
118 分钟以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { ref, watch } from 'vue';
 
import { useBaseStore } from '#/store';
 
interface BusinessCategory {
  enCode?: string;
  fullName?: string;
  id?: string;
}
 
export function isDmsBusinessCategory(category: string | undefined, options: BusinessCategory[]): boolean {
  if (!category) return false;
  if (category.toUpperCase() === 'DMS') return true;
  const option = options.find((item) => item.id === category);
  return option?.enCode?.toUpperCase() === 'DMS' || option?.fullName?.toUpperCase() === 'DMS';
}
 
export function getSubtableColumnLabel(column: 'action' | 'index', label: string | undefined, isDms: boolean): string {
  const chinese = column === 'index' ? '序号' : '操作';
  if (label && label !== chinese) return label;
  return isDms ? `${chinese}\n${column === 'index' ? 'No.' : 'Action'}` : label || chinese;
}
 
export function useDmsBusinessCategory(getCategory: () => string | undefined) {
  const baseStore = useBaseStore();
  const isDms = ref(false);
  watch(
    getCategory,
    async (category, _previous, onCleanup) => {
      let current = true;
      onCleanup(() => (current = false));
      if (!category) {
        isDms.value = false;
        return;
      }
      const options = (await baseStore.getDictionaryData('businessType')) as BusinessCategory[];
      if (current) isDms.value = isDmsBusinessCategory(category, options);
    },
    { immediate: true },
  );
  return isDms;
}