2024-05-23 13:52:57 +00:00
|
|
|
import { computed, unref } from 'vue'
|
2024-05-21 13:31:55 +00:00
|
|
|
import { useQuestionInfo } from './useQuestionInfo'
|
|
|
|
import { flatten } from 'lodash-es'
|
|
|
|
import { cleanRichText } from '@/common/xss'
|
|
|
|
import { showLogicEngine } from '@/management/hooks/useShowLogicEngine'
|
|
|
|
|
|
|
|
// 目标题的显示逻辑提示文案
|
|
|
|
export const useShowLogicInfo = (field) => {
|
|
|
|
const hasShowLogic = computed(() => {
|
|
|
|
const logicEngine = showLogicEngine.value
|
|
|
|
// 判断该题是否作为了显示逻辑前置题
|
|
|
|
const isField = logicEngine?.findTargetsByFields(field)?.length > 0
|
|
|
|
// 判断该题是否作为了显示逻辑目标题
|
|
|
|
const isTarget = logicEngine?.findTargetsByScope(field)?.length > 0
|
|
|
|
return isField || isTarget
|
|
|
|
})
|
|
|
|
const getShowLogicText = computed(() => {
|
|
|
|
const logicEngine = showLogicEngine.value
|
2024-05-23 13:52:57 +00:00
|
|
|
// 获取目标题的规则
|
|
|
|
const rules = logicEngine?.findConditionByTarget(field) || []
|
|
|
|
|
|
|
|
const conditions = flatten(rules).map((item) => {
|
|
|
|
const { getQuestionTitle, getOptionTitle } = useQuestionInfo(item.field)
|
2024-05-21 13:31:55 +00:00
|
|
|
return `<span>【 ${cleanRichText(getQuestionTitle.value())}】 选择了 【${getOptionTitle.value(unref(item.value)).join('、')}】</span> <br/>`
|
|
|
|
})
|
2024-05-23 13:52:57 +00:00
|
|
|
return conditions.length
|
|
|
|
? conditions.join('') + '<span> 满足以上全部,则显示本题</span>'
|
|
|
|
: ''
|
2024-05-21 13:31:55 +00:00
|
|
|
})
|
|
|
|
return { hasShowLogic, getShowLogicText }
|
2024-05-23 13:52:57 +00:00
|
|
|
}
|