feat: 新增题目优化 (#443)

This commit is contained in:
Liang-Yaxin 2024-10-31 17:58:38 +08:00 committed by GitHub
parent c93515d2bd
commit f6202d4f91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -11,6 +11,7 @@
:list="item.questionList" :list="item.questionList"
:group="{ name: DND_GROUP, pull: 'clone', put: false }" :group="{ name: DND_GROUP, pull: 'clone', put: false }"
:clone="createNewQuestion" :clone="createNewQuestion"
@end="onDragEnd"
item-key="path" item-key="path"
> >
<template #item="{ element }"> <template #item="{ element }">
@ -53,7 +54,7 @@ import { ref } from 'vue'
const editStore = useEditStore() const editStore = useEditStore()
const { newQuestionIndex } = storeToRefs(editStore) const { newQuestionIndex } = storeToRefs(editStore)
const { addQuestion, setCurrentEditOne, createNewQuestion } = editStore const { addQuestion, hasSetCurrentEditOne, createNewQuestion } = editStore
const activeNames = ref([0, 1]) const activeNames = ref([0, 1])
const previewImg = ref('') const previewImg = ref('')
@ -67,7 +68,11 @@ questionLoader.init({
const onQuestionType = ({ type }) => { const onQuestionType = ({ type }) => {
const newQuestion = createNewQuestion({ type }) const newQuestion = createNewQuestion({ type })
addQuestion({ question: newQuestion, index: newQuestionIndex.value }) addQuestion({ question: newQuestion, index: newQuestionIndex.value })
setCurrentEditOne(newQuestionIndex.value) hasSetCurrentEditOne(newQuestionIndex.value)
}
const onDragEnd = (event) => {
hasSetCurrentEditOne(event.newIndex)
} }
const showPreview = ({ snapshot }, id) => { const showPreview = ({ snapshot }, id) => {

View File

@ -166,10 +166,16 @@ export const useEditStore = defineStore('edit', () => {
if (!questCount) { if (!questCount) {
return startIndex return startIndex
} }
return endIndex return endIndex - 1
} }
}) })
const hasSetCurrentEditOne = (value: number) => {
if(!currentEditOne.value) {
setCurrentEditOne(value)
}
}
// 题目操作:增删改 // 题目操作:增删改
const { copyQuestion, addQuestion, deleteQuestion, moveQuestion } = useQuestionData({ const { copyQuestion, addQuestion, deleteQuestion, moveQuestion } = useQuestionData({
questionDataList, questionDataList,
@ -194,6 +200,7 @@ export const useEditStore = defineStore('edit', () => {
currentEditMeta, currentEditMeta,
newQuestionIndex, newQuestionIndex,
setCurrentEditOne, setCurrentEditOne,
hasSetCurrentEditOne,
changeCurrentEditStatus, changeCurrentEditStatus,
pageEditOne, pageEditOne,