fix: 删除分页判断是否存在题目的逻辑关联 (#402)

This commit is contained in:
dayou 2024-08-14 21:30:16 +08:00 committed by GitHub
parent 3cb843e493
commit 6775a9df5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 7 deletions

View File

@ -2,11 +2,12 @@ import { computed, unref } from 'vue'
import { useQuestionInfo } from './useQuestionInfo' import { useQuestionInfo } from './useQuestionInfo'
import { useEditStore } from '../stores/edit' import { useEditStore } from '../stores/edit'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
const editStore = useEditStore()
const { jumpLogicEngine } = storeToRefs(editStore)
// 目标题的显示逻辑提示文案 // 目标题的显示逻辑提示文案
export const useJumpLogicInfo = (field) => { export const useJumpLogicInfo = (field) => {
const editStore = useEditStore()
const { jumpLogicEngine } = storeToRefs(editStore)
const hasJumpLogic = computed(() => { const hasJumpLogic = computed(() => {
const logicEngine = jumpLogicEngine.value const logicEngine = jumpLogicEngine.value
// 判断该题是否作为了跳转逻辑条件 // 判断该题是否作为了跳转逻辑条件

View File

@ -4,11 +4,12 @@ import { flatten } from 'lodash-es'
import { cleanRichText } from '@/common/xss' import { cleanRichText } from '@/common/xss'
import { useEditStore } from '../stores/edit' import { useEditStore } from '../stores/edit'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
const editStore = useEditStore()
const { showLogicEngine } = storeToRefs(editStore)
// 目标题的显示逻辑提示文案 // 目标题的显示逻辑提示文案
export const useShowLogicInfo = (field) => { export const useShowLogicInfo = (field) => {
const editStore = useEditStore()
const { showLogicEngine } = storeToRefs(editStore)
const hasShowLogic = computed(() => { const hasShowLogic = computed(() => {
const logicEngine = showLogicEngine.value const logicEngine = showLogicEngine.value
// 判断该题是否作为了显示逻辑前置题 // 判断该题是否作为了显示逻辑前置题

View File

@ -22,6 +22,9 @@ import { getCollaboratorPermissions } from '@/management/api/space'
import useEditGlobalBaseConf, { type TypeMethod } from './composables/useEditGlobalBaseConf' import useEditGlobalBaseConf, { type TypeMethod } from './composables/useEditGlobalBaseConf'
import { CODE_MAP } from '../api/base' import { CODE_MAP } from '../api/base'
import { RuleBuild } from '@/common/logicEngine/RuleBuild' 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 = { const innerMetaConfig = {
submit: { submit: {
@ -363,11 +366,26 @@ function usePageEdit(
const deletePage = (index: number) => { const deletePage = (index: number) => {
if (pageConf.value.length <= 1) return if (pageConf.value.length <= 1) return
const { startIndex, endIndex } = getSorter(index) const { startIndex, endIndex } = getSorter(index)
const newQuestion = _cloneDeep(questionDataList.value) const newQuestionList = _cloneDeep(questionDataList.value)
newQuestion.splice(startIndex, endIndex - startIndex) 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) updatePageEditOne(1)
newQuestionList.splice(startIndex, endIndex - startIndex)
schema.pageConf.splice(index - 1, 1) schema.pageConf.splice(index - 1, 1)
questionDataList.value = newQuestion questionDataList.value = newQuestionList
updateTime() updateTime()
} }