From 6724e83beb463b7fc059cf0fe6e0cb778ddf808f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=A2=A6?= Date: Tue, 19 May 2026 19:54:48 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A2=98=E7=9B=AE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/paper-question-item/index.vue | 82 ++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/playground/src/components/paper-question-item/index.vue b/playground/src/components/paper-question-item/index.vue index 4092770..7c46912 100644 --- a/playground/src/components/paper-question-item/index.vue +++ b/playground/src/components/paper-question-item/index.vue @@ -123,6 +123,12 @@ const optionsHorizontal = computed(() => { return willSimpleOptionsHorizontal(normalizedOptions.value) }) +// 是否可在编辑弹窗中编辑选项(普通选择题) +const hasEditableOptions = computed(() => { + if (isWanXing.value || isYueDu.value) return false + return !!normalizedOptions.value?.length +}) + // 显示答案那些 const answerVisible = ref(false) const toggleAnswerVisible = () => { @@ -146,9 +152,31 @@ const stemUploading = ref(false) const stemEditorRef = ref() const answerEditorRef = ref() const explanationEditorRef = ref() +const optionEditorRefs = ref([]) +const editOptions = ref<{ label: string; value: string }[]>([]) const stemUploadInputRef = ref() const stemSelectionRange = ref(null) +const setOptionEditorRef = (el: any, idx: number) => { + if (el) optionEditorRefs.value[idx] = el +} + +function getEditableOptionsFromQuestion() { + const opts = normalizedOptions.value + if (!opts?.length || isWanXing.value || isYueDu.value) return [] + return opts.map((o: any) => ({ + label: o.label ?? '', + value: o.value ?? '', + })) +} + +function buildOptionHtmlFromEditors() { + return editOptions.value.map((opt, idx) => ({ + index: opt.label, + html: optionEditorRefs.value[idx]?.innerHTML ?? opt.value ?? '', + })) +} + const saveStemSelection = () => { const selection = window.getSelection() if (!selection || selection.rangeCount === 0) return @@ -234,11 +262,17 @@ const handleEdit = () => { const q = props.question as any editDialogVisible.value = true stemSelectionRange.value = null + editOptions.value = getEditableOptionsFromQuestion() + optionEditorRefs.value = [] nextTick(() => { if (stemEditorRef.value) stemEditorRef.value.innerHTML = q.stem || '' if (answerEditorRef.value) answerEditorRef.value.innerHTML = q.answer || '' if (explanationEditorRef.value) explanationEditorRef.value.innerHTML = q.explanation || '' + editOptions.value.forEach((opt, idx) => { + const el = optionEditorRefs.value[idx] + if (el) el.innerHTML = opt.value || '' + }) }) } @@ -249,17 +283,27 @@ const handleEditSave = async () => { const stem = stemEditorRef.value?.innerHTML || '' const answer = answerEditorRef.value?.innerHTML || '' const explanation = explanationEditorRef.value?.innerHTML || '' - await saveOrUpdateXkwQuestionTitle({ + const payload: Record = { id: q.id, stem, stemHtml: stem, answer, answerHtml: answer, explanation, - }) + } + if (hasEditableOptions.value && editOptions.value.length) { + const optionData = buildOptionHtmlFromEditors() + const optionHtml = JSON.stringify(optionData) + payload.optionHtml = optionHtml + } + await saveOrUpdateXkwQuestionTitle(payload) q.stem = stem q.answer = answer q.explanation = explanation + if (payload.optionHtml) { + q.optionHtml = payload.optionHtml + q.optionList = JSON.parse(payload.optionHtml) + } editDialogVisible.value = false ElMessage.success('保存成功') } finally { @@ -504,6 +548,21 @@ const handleEditSave = async () => { @blur="saveStemSelection" > +
+
选项
+
+ {{ opt.label }}. +
+
+
答案