diff --git a/web/src/management/hooks/useJumpLogicInfo.js b/web/src/management/hooks/useJumpLogicInfo.js index 5fc90fb7..2cd906ff 100644 --- a/web/src/management/hooks/useJumpLogicInfo.js +++ b/web/src/management/hooks/useJumpLogicInfo.js @@ -2,11 +2,12 @@ import { computed, unref } from 'vue' import { useQuestionInfo } from './useQuestionInfo' import { useEditStore } from '../stores/edit' import { storeToRefs } from 'pinia' -const editStore = useEditStore() -const { jumpLogicEngine } = storeToRefs(editStore) + // 目标题的显示逻辑提示文案 export const useJumpLogicInfo = (field) => { + const editStore = useEditStore() + const { jumpLogicEngine } = storeToRefs(editStore) const hasJumpLogic = computed(() => { const logicEngine = jumpLogicEngine.value // 判断该题是否作为了跳转逻辑条件 diff --git a/web/src/management/hooks/useShowLogicInfo.js b/web/src/management/hooks/useShowLogicInfo.js index 5f46eb30..c27d844f 100644 --- a/web/src/management/hooks/useShowLogicInfo.js +++ b/web/src/management/hooks/useShowLogicInfo.js @@ -4,11 +4,12 @@ import { flatten } from 'lodash-es' import { cleanRichText } from '@/common/xss' import { useEditStore } from '../stores/edit' import { storeToRefs } from 'pinia' -const editStore = useEditStore() -const { showLogicEngine } = storeToRefs(editStore) // 目标题的显示逻辑提示文案 export const useShowLogicInfo = (field) => { + const editStore = useEditStore() + const { showLogicEngine } = storeToRefs(editStore) + const hasShowLogic = computed(() => { const logicEngine = showLogicEngine.value // 判断该题是否作为了显示逻辑前置题 diff --git a/web/src/management/stores/edit.ts b/web/src/management/stores/edit.ts index 1def51af..2568f523 100644 --- a/web/src/management/stores/edit.ts +++ b/web/src/management/stores/edit.ts @@ -22,6 +22,9 @@ import { getCollaboratorPermissions } from '@/management/api/space' import useEditGlobalBaseConf, { type TypeMethod } from './composables/useEditGlobalBaseConf' import { CODE_MAP } from '../api/base' import { RuleBuild } from '@/common/logicEngine/RuleBuild' +import { useShowLogicInfo } from '@/management/hooks/useShowLogicInfo' +import { useJumpLogicInfo } from '@/management/hooks/useJumpLogicInfo' +import { ElMessageBox } from 'element-plus' const innerMetaConfig = { submit: { @@ -363,11 +366,26 @@ function usePageEdit( const deletePage = (index: number) => { if (pageConf.value.length <= 1) return const { startIndex, endIndex } = getSorter(index) - const newQuestion = _cloneDeep(questionDataList.value) - newQuestion.splice(startIndex, endIndex - startIndex) + const newQuestionList = _cloneDeep(questionDataList.value) + const deleteFields = newQuestionList.slice(startIndex, endIndex - startIndex).map(i => i.field) + + // 删除分页判断题目是否存在逻辑关联 + const hasLogic = deleteFields.filter((field) => { + const { hasShowLogic } = useShowLogicInfo(field) + const { hasJumpLogic } = useJumpLogicInfo(field) + return hasShowLogic || hasJumpLogic + }) + if(hasLogic.length) { + ElMessageBox.alert('该分页下有题目被显示或跳转逻辑关联,请先清除逻辑依赖', '提示', { + confirmButtonText: '确定', + type: 'warning' + }) + return + } updatePageEditOne(1) + newQuestionList.splice(startIndex, endIndex - startIndex) schema.pageConf.splice(index - 1, 1) - questionDataList.value = newQuestion + questionDataList.value = newQuestionList updateTime() }