Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 新增题目优化 #463

Merged
merged 13 commits into from
Dec 31, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const props = defineProps({

const editStore = useEditStore()
const { pageCount, schema, newQuestionIndex } = storeToRefs(editStore)
const { getSorter } = editStore

const {
updatePageEditOne,
Expand Down Expand Up @@ -82,7 +83,10 @@ const addPageControls = () => {
updatePageEditOne(pageCount.value + 1)
setCurrentEditOne(null)
addQuestion({ question: newQuestion, index: newQuestionIndex.value })
setCurrentEditOne(newQuestionIndex.value)
setTimeout(() => {
const { endIndex } = getSorter();
setCurrentEditOne(endIndex - 1);
});
addPage()
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:list="item.questionList"
:group="{ name: DND_GROUP, pull: 'clone', put: false }"
:clone="createNewQuestion"
@end="onDragEnd"
item-key="path"
>
<template #item="{ element }">
Expand Down Expand Up @@ -52,8 +53,9 @@ import { useEditStore } from '@/management/stores/edit'
import { ref } from 'vue'

const editStore = useEditStore()
const { newQuestionIndex } = storeToRefs(editStore)
const { addQuestion, setCurrentEditOne, createNewQuestion } = editStore
const { newQuestionIndex, schema } = storeToRefs(editStore)
const { addQuestion, setCurrentEditOne, getSorter, createNewQuestion } = editStore


const activeNames = ref([0, 1, 2])
const previewImg = ref('')
Expand All @@ -65,10 +67,19 @@ questionLoader.init({
})

const onQuestionType = ({ type }) => {
const newQuestion = createNewQuestion({ type })
addQuestion({ question: newQuestion, index: newQuestionIndex.value })
setCurrentEditOne(newQuestionIndex.value)
}
const newQuestion = createNewQuestion({ type });
addQuestion({ question: newQuestion, index: newQuestionIndex.value });
setTimeout(() => {
const { endIndex } = getSorter();
setCurrentEditOne(endIndex - 1);
});
};

const onDragEnd = (event) => {
const { startIndex } = getSorter();
setCurrentEditOne(schema.pageEditOne === 1 ? event.newIndex : startIndex + event.newIndex);
};


const showPreview = ({ snapshot }, id) => {
previewImg.value = snapshot
Expand Down
2 changes: 1 addition & 1 deletion web/src/management/stores/composables/usePageEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function usePageEdit(
const getSorter = (index?: number) => {
let startIndex = 0
const newPageEditOne = index || pageEditOne.value
const endIndex = pageConf.value[newPageEditOne - 1]
const endIndex = newPageEditOne > pageConf.value.length ? 0 : pageConf.value[newPageEditOne - 1]

for (let index = 0; index < pageConf.value.length; index++) {
const item = pageConf.value[index]
Expand Down
Loading