feat: 分类顺序校验
This commit is contained in:
@@ -39,16 +39,18 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, nextTick, watch } from 'vue';
|
||||
import { ref, computed, nextTick, watch, onMounted } from 'vue';
|
||||
import Dialog from '@/components/common/dialog/index.vue';
|
||||
import TableForm from '@/components/common/table/tableForm.vue';
|
||||
import { getTagKeyMap, NODE_TYPE } from '@/utils/enum/node';
|
||||
import { getMemberListIds } from '@/utils/task';
|
||||
import { disposeTagKey } from '@/views/task/projectDetail/components/project';
|
||||
import { isCategoryType, isCategoryNodeType } from '@/utils/node';
|
||||
import { isCategoryType, isCategoryNodeType, validateCategoryLevel } from '@/utils/node';
|
||||
import flowTemplateSelect from './flowTemplateSelect.vue';
|
||||
import knowledgeSelect from './knowledgeSelect.vue';
|
||||
import { TABLE_NAME } from '@/utils/enum/tableName';
|
||||
import { useDict } from '@/utils/useDict';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
enum OPERATION_TYPE {
|
||||
ADD = 'add',
|
||||
@@ -62,6 +64,7 @@ interface Props {
|
||||
nodeType?: string;
|
||||
modalTableNameList?: string[];
|
||||
belongProject?: boolean;
|
||||
parentCategoryPath?: string[];
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -72,6 +75,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
modalTableNameList: () => ([TABLE_NAME.TASK_POOL_CATEGORY, TABLE_NAME.TASK_POOL_TASK, TABLE_NAME.TASK_POOL_PERFORMANCE]),
|
||||
detail: null,
|
||||
belongProject: false,
|
||||
parentCategoryPath: () => [],
|
||||
});
|
||||
|
||||
const emits = defineEmits(['update:modelValue', 'confirm']);
|
||||
@@ -80,6 +84,7 @@ const visible = computed({
|
||||
set: (val) => emits('update:modelValue', val),
|
||||
});
|
||||
const tableFormRef = ref<any>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const localDiaTitle = ref('');
|
||||
const localDetail = ref<any>(null);
|
||||
@@ -88,6 +93,8 @@ const localTableName = ref(props.tableName || '');
|
||||
// 流程模板相关
|
||||
const selectedFlowTemplate = ref<any>(null);
|
||||
const standard = ref();
|
||||
const tagSortOrderList = ref<string[]>([]);
|
||||
const tagNameMap = ref<Map<string, string>>(new Map());
|
||||
const onShowFun = () => {
|
||||
resetFun();
|
||||
nextTick(() => {
|
||||
@@ -154,28 +161,28 @@ const prepareFromProps = () => {
|
||||
const operation = props.operationType;
|
||||
const detail = props.detail;
|
||||
|
||||
let text = operation === OPERATION_TYPE.ADD ? '新增' : '编辑';
|
||||
let text = operation === OPERATION_TYPE.ADD ? t('通用.新增') : t('通用.编辑');
|
||||
let targetTableName = props.modalTableNameList?.[1] || '';
|
||||
switch (nodeType) {
|
||||
case NODE_TYPE.CATEGORY:
|
||||
text += '分类';
|
||||
text += t('工况库.分类');
|
||||
targetTableName = props.modalTableNameList?.[0] || targetTableName;
|
||||
break;
|
||||
case NODE_TYPE.TASK:
|
||||
if (props.belongProject) {
|
||||
text += '任务';
|
||||
text += t('通用.任务');
|
||||
} else {
|
||||
text += '工况';
|
||||
text += t('工况库.工况');
|
||||
}
|
||||
targetTableName = props.modalTableNameList?.[1] || targetTableName;
|
||||
break;
|
||||
case NODE_TYPE.PERFORMANCE:
|
||||
text += '指标';
|
||||
text += t('工况库.指标');
|
||||
targetTableName = props.modalTableNameList?.[2] || targetTableName;
|
||||
break;
|
||||
}
|
||||
if (isCategoryNodeType(nodeType)) {
|
||||
text += '分类';
|
||||
text += t('工况库.分类');
|
||||
targetTableName = props.modalTableNameList?.[0] || targetTableName;
|
||||
}
|
||||
|
||||
@@ -202,10 +209,48 @@ watch(() => props.modelValue, (val) => {
|
||||
}
|
||||
});
|
||||
|
||||
const ruleData = ref<any>({
|
||||
const ruleData = computed(() => ({
|
||||
nodeType: [
|
||||
{
|
||||
message: computed(() => {
|
||||
if (tagSortOrderList.value.length === 0) {
|
||||
return t('工况库.需按照配置顺序逐层添加');
|
||||
}
|
||||
const orderNames = tagSortOrderList.value
|
||||
.filter(type => isCategoryNodeType(type))
|
||||
.map(type => tagNameMap.value.get(type) || type)
|
||||
.join(' → ');
|
||||
return t('工况库.请按照顺序添加', { order: orderNames });
|
||||
}),
|
||||
trigger: 'change',
|
||||
validator: (val: unknown) => {
|
||||
if (localOperationType.value === OPERATION_TYPE.EDIT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isCategoryNodeType(val as string)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!props.parentCategoryPath || props.parentCategoryPath.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tagSortOrderList.value.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validateCategoryLevel(
|
||||
val as string,
|
||||
props.parentCategoryPath,
|
||||
tagSortOrderList.value
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
highValue: [
|
||||
{
|
||||
message: '指标类型为数值时,目标值应为数字',
|
||||
message: t('工况库.指标类型为数值时目标值应为数字'),
|
||||
trigger: 'change',
|
||||
validator: (val: unknown) => {
|
||||
if (val === null || val === undefined || val === '') {
|
||||
@@ -227,6 +272,22 @@ const ruleData = ref<any>({
|
||||
},
|
||||
|
||||
],
|
||||
}));
|
||||
|
||||
const initDictData = () => {
|
||||
const { TAG_TYPE_MAP_LIST, POOL_CATEGORY_TYPE } = useDict('TAG_TYPE_MAP_LIST', 'POOL_CATEGORY_TYPE');
|
||||
tagSortOrderList.value = TAG_TYPE_MAP_LIST?.value?.A?.reduce((acc: string[], curr: { value: string; }) => {
|
||||
acc.push(curr.value);
|
||||
return acc;
|
||||
}, []) || [];
|
||||
const categoryTypeList = POOL_CATEGORY_TYPE?.value.A || [];
|
||||
categoryTypeList.forEach((item: { value: string; label: string; }) => {
|
||||
tagNameMap.value.set(item.value, item.label);
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
initDictData();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user