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

feat: 新增编辑问卷界面拖动操作 #104

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"unplugin-auto-import": "^0.18.3",
"unplugin-vue-components": "^0.27.4",
"vue": "^3.4.26",
"vue-draggable-next": "^2.2.1",
"vue-hooks-plus": "^2.2.1",
"vue-router": "^4.3.2"
},
Expand Down
36 changes: 31 additions & 5 deletions src/pages/DetailInfo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
group="people"
@update="onUpdate"
>-->
<VueDraggableNext
v-model="question"
:animation="300"
ghost-class="ghost"
@end="updateQuestionSerialNumbers"
>

<div v-for="q in question" :key="q.serial_num" >
<!-- 根据问题类型渲染组件 -->
<div v-if="q.question_type === 1">
Expand Down Expand Up @@ -148,7 +155,7 @@
</el-skeleton>
</div>
</div>
<!--</VueDraggable>-->
</VueDraggableNext>
</div>
<div class="flex justify-center items-center gap-160 mt-20">
<button class="btn btn-success dark:opacity-75 dark:text-white"
Expand Down Expand Up @@ -216,6 +223,7 @@
import SkeletonCard from "@/pages/DetailInfo/skeletonCard.vue";
import router from "@/router";
import {closeLoading, startLoading} from "@/utilities";
import {VueDraggableNext} from "vue-draggable-next"

const selectedOption = ref(1);
const selectedNumber = ref(1);
Expand Down Expand Up @@ -336,6 +344,12 @@
unique: setting.isUnique,
});

question.value.forEach((q, index) => {
q.serial_num = index + 1;
});

console.log(question.value)

// 等待 DOM 更新完成后再执行滚动
nextTick(() => {
if (questionnaireContainer.value) {
Expand All @@ -350,7 +364,7 @@
watch(selectedOption, cleanReg);

const deleteQuestion = (serial_num: number) => {
console.log(serial_num);
// console.log(serial_num);
question.value = question.value.filter((item) => item.serial_num !== serial_num);
question.value.forEach((item) => {
if (item.serial_num > serial_num) {
Expand All @@ -363,7 +377,7 @@
submitData.value = deepCopy(formData.value);
question.value = deepCopy(formData.value.questions);
time.value = submitData.value.time
console.log(question.value);
// console.log(question.value);
ElNotification.success('成功放弃修改');
showModal('reverseQuestionnaireSubmit',true)
router.push('/admin')
Expand All @@ -372,7 +386,7 @@
const submit = (state:number) => {
submitData.value.time = time.value
submitData.value.questions = question.value;
console.log(question.value);
// console.log(question.value);
if(isNew === 'false') {
useRequest(() => setQuestionnaireDetailAPI(submitData.value), {
onBefore: () => startLoading(),
Expand Down Expand Up @@ -425,8 +439,20 @@
});
};**/

//导入可拖动组件
import {VueDraggable} from 'vue-draggable-plus';

Check warning on line 443 in src/pages/DetailInfo/index.vue

View workflow job for this annotation

GitHub Actions / CI

'VueDraggable' is defined but never used
//修改serial_num
const updateQuestionSerialNumbers = () => {
question.value.forEach((q, index) => {
q.serial_num = index + 1;
});
console.log(question.value)
}

</script>

<style scoped>

.ghost {
opacity: 0.4;
}
</style>
Loading