Skip to content

Commit

Permalink
fix: 新增题目优化 (#463)
Browse files Browse the repository at this point in the history
* feat: 新增题目优化

* feat: 新增题目优化

* feat: 新增题目优化

* feat: 新增题目优化

* fix: 修改新增题目优化验收问题

* fix: 修复插入题目序号问题以及删除未使用代码

* fix:  删除未使用代码

* fix: onDragEnd

* fix: 修复添加分页的题目序号问题

---------

Co-authored-by: 梁亚鑫 <[email protected]>
Co-authored-by: Liang-Yaxin <[email protected]>
  • Loading branch information
3 people authored Dec 31, 2024
1 parent 2aefaff commit 89544e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
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

0 comments on commit 89544e2

Please sign in to comment.