|
@@ -282,15 +282,16 @@ export default defineComponent({
|
|
|
|
|
|
const initOptions = () => {
|
|
const initOptions = () => {
|
|
const answers = props.data.answers || []
|
|
const answers = props.data.answers || []
|
|
|
|
+ const userAnswer = props.data.userAnswer || [] // 用户填写的答案
|
|
answers.forEach((answer: any) => {
|
|
answers.forEach((answer: any) => {
|
|
const tmp = {
|
|
const tmp = {
|
|
- index: answer.examinationQuestionAnswerId,
|
|
|
|
- leftValue: answer.questionAnswer,
|
|
|
|
- rightValue: answer.questionExtra,
|
|
|
|
- leftType: answer.questionAnswerTypeCode || 'TXT',
|
|
|
|
- rightType: answer.questionExtraTypeCode || 'TXT',
|
|
|
|
- left: false,
|
|
|
|
- right: false,
|
|
|
|
|
|
+ index: answer.examinationQuestionAnswerId, // 左边的值
|
|
|
|
+ leftValue: answer.questionAnswer, // 左边的值
|
|
|
|
+ rightValue: answer.questionExtra, // 右边的值
|
|
|
|
+ leftType: answer.questionAnswerTypeCode || 'TXT', // 左边类型
|
|
|
|
+ rightType: answer.questionExtraTypeCode || 'TXT', // 右边类型
|
|
|
|
+ left: false, // 左边是否选中
|
|
|
|
+ right: false, // 右边是否选中
|
|
leftLocked: false, // 是否已经连线
|
|
leftLocked: false, // 是否已经连线
|
|
rightLocked: false // 是否已经连线
|
|
rightLocked: false // 是否已经连线
|
|
}
|
|
}
|
|
@@ -298,7 +299,53 @@ export default defineComponent({
|
|
state.options.push(tmp)
|
|
state.options.push(tmp)
|
|
})
|
|
})
|
|
|
|
|
|
- console.log(state.options)
|
|
|
|
|
|
+ // 反显答案-初始化数据
|
|
|
|
+ userAnswer.forEach((user: any) => {
|
|
|
|
+ console.log(user)
|
|
|
|
+ const temps: any = {
|
|
|
|
+ startPoint: { x: 0, y: 0 },
|
|
|
|
+ endPoint: { x: 0, y: 0 },
|
|
|
|
+ leftIndex: 0,
|
|
|
|
+ rightIndex: 0
|
|
|
|
+ }
|
|
|
|
+ state.options.forEach((option: any) => {
|
|
|
|
+ // 左边状态
|
|
|
|
+ if (option.index === user.answerId) {
|
|
|
|
+ option.left = true
|
|
|
|
+ option.leftLocked = true
|
|
|
|
+ temps.leftIndex = option.index
|
|
|
|
+ }
|
|
|
|
+ // 右边状态
|
|
|
|
+ if (option.rightValue === user.extra) {
|
|
|
|
+ option.right = true
|
|
|
|
+ option.leftLocked = true
|
|
|
|
+ temps.rightIndex = option.index
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ state.drawLineList.push(temps)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ console.log(state.drawLineList, state.options)
|
|
|
|
+ // 反显答案-连线
|
|
|
|
+ nextTick(() => {
|
|
|
|
+ state.drawLineList.forEach((draw: any) => {
|
|
|
|
+ state.selectItem = []
|
|
|
|
+ const leftObj: any = useRect(document.getElementById(draw.leftIndex + '-left') as any)
|
|
|
|
+ leftObj.index = draw.leftIndex
|
|
|
|
+ state.selectItem[0] = leftObj
|
|
|
|
+ const rightObj: any = useRect(document.getElementById(draw.leftIndex + '-right') as any)
|
|
|
|
+ rightObj.index = draw.rightIndex
|
|
|
|
+ state.selectItem[1] = rightObj
|
|
|
|
+
|
|
|
|
+ const postion = calcPoint()
|
|
|
|
+ draw.endPoint = postion.endPoint
|
|
|
|
+ draw.startPoint = postion.startPoint
|
|
|
|
+ state.selectItem = []
|
|
|
|
+ })
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ renderDrawLine(canvasRef.value)
|
|
|
|
+ }, 60)
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
@@ -335,6 +382,7 @@ export default defineComponent({
|
|
<div class={styles.answerItem}>
|
|
<div class={styles.answerItem}>
|
|
<div
|
|
<div
|
|
class={[styles.unitItem, item.left && styles.active]}
|
|
class={[styles.unitItem, item.left && styles.active]}
|
|
|
|
+ id={item.index + '-left'}
|
|
onClick={(e: any) => onLeftClick(e, item)}
|
|
onClick={(e: any) => onLeftClick(e, item)}
|
|
>
|
|
>
|
|
{item.leftType === 'TXT' && item.leftValue}
|
|
{item.leftType === 'TXT' && item.leftValue}
|
|
@@ -342,6 +390,7 @@ export default defineComponent({
|
|
</div>
|
|
</div>
|
|
<div
|
|
<div
|
|
class={[styles.unitItem, item.right && styles.active]}
|
|
class={[styles.unitItem, item.right && styles.active]}
|
|
|
|
+ id={item.index + '-right'}
|
|
onClick={(e: any) => onRightClick(e, item)}
|
|
onClick={(e: any) => onRightClick(e, item)}
|
|
>
|
|
>
|
|
{item.rightType === 'TXT' && item.rightValue}
|
|
{item.rightType === 'TXT' && item.rightValue}
|