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;
|
}
|