feat:我的成绩-增加拖动功能

This commit is contained in:
zhouwentao 2026-01-06 20:42:34 +08:00
parent 431f496b6e
commit 6717ff9bae
3 changed files with 133 additions and 11 deletions

View File

@ -19,6 +19,7 @@
"lodash": "^4.17.21",
"mitt": "^3.0.1",
"sass": "^1.75.0",
"sortablejs": "^1.15.6",
"swiper": "^7.4.1",
"vite-vue": "file:",
"vue": "^3.2.37",

View File

@ -38,6 +38,9 @@ importers:
sass:
specifier: ^1.75.0
version: 1.94.2
sortablejs:
specifier: ^1.15.6
version: 1.15.6
swiper:
specifier: ^7.4.1
version: 7.4.1
@ -1575,6 +1578,9 @@ packages:
resolution: {integrity: sha512-FtyOnWN/wCHTVXOMwvSv26d+ko5vWlIDD6zoUJ7LW8vh+ZBC8QdljveRP+crNrtBwioEUWy/4dMtbBjA4ioNlg==}
engines: {node: '>=0.10.0'}
sortablejs@1.15.6:
resolution: {integrity: sha512-aNfiuwMEpfBM/CN6LY0ibyhxPfPbyFeBTYJKCvzkJ2GkUpazIt3H+QIPAMHwqQ7tMKaHz1Qj+rJJCqljnf4p3A==}
source-map-js@1.2.1:
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'}
@ -3508,6 +3514,8 @@ snapshots:
transitivePeerDependencies:
- supports-color
sortablejs@1.15.6: {}
source-map-js@1.2.1: {}
source-map-resolve@0.5.3:

View File

@ -313,6 +313,18 @@
<div class="flex-item-2 pl-10"><el-button @click="handlerAutoSortVolunteer">智能排序</el-button></div>
</div> -->
</div>
<!-- [修改] 在这里增加保存按钮的显示逻辑 -->
<div class="flex-item-4 pl-20 pr-10" style="line-height: 30px;">
<div class="flexWrap" v-if="state.visible.showOrderSaveBtn">
<div class="flex-item-1" style="color: #f56c6c; font-weight: bold;">提示</div>
<div class="flex-item-4 pl-10">
<span style="font-size: 12px; color: #666; margin-right: 10px;">顺序已变更</span>
<el-button type="primary" size="default" @click="handleSaveVolunteerOrder">保存排序</el-button>
</div>
</div>
</div>
</div>
<div class="flexWrap mt-15">
<div class="flex-item-4 pl-10 pr-10" style="line-height: 30px">
@ -330,7 +342,10 @@
<div class="panetype" v-if="state.scoreInfo.meBatchLevel==0" :class="state.selectForm.batchPaneName==='本科批'?'panetype-active':''" @click="switchBatchPane('本科批')">本科批</div>
<div class="panetype" v-if="state.scoreInfo.meBatchLevel<=3" :class="state.selectForm.batchPaneName==='高职高专'?'panetype-active':''" @click="switchBatchPane('高职高专')">高职高专</div>
</div>
<el-table row-draggable :data="returnVolunteerList()" height="800" style="width: 100%;">
<el-table
ref="volunteerTableRef"
row-key="id"
row-draggable :data="returnVolunteerList()" height="800" style="width: 100%; cursor: move;">
<el-table-column label="招生院校" width="190">
<template #default="scope">
<div class="top-align" v-if="scope.row.schoolName">
@ -704,9 +719,10 @@
</template>
<script setup lang="ts">
document.title = '模拟报志愿|' + import.meta.env.VITE_PROGRAM_TYPE;
import {inject,onMounted,reactive} from 'vue';
import { inject, onMounted, reactive, ref, nextTick, watch } from 'vue'; // ref, nextTick, watch
import Sortable from 'sortablejs'; // [] Sortablejs
import {checkLevel, isNull} from '@/utils/tool';
import {getScore,getRulesEnrollrobabilityMenuList} from '@/axios/api';
import {ScoreInfoEntity} from '@/types/index';
@ -723,6 +739,9 @@ import { useRoute } from 'vue-router';
import VolunteerList from '../volunteer/volunteer-list.vue';
const route = useRoute();
// [] ref DOM
const volunteerTableRef = ref();
//
type myBoolean= boolean | null | undefined;
@ -770,6 +789,7 @@ const state = reactive({
activePage:'zntj',// {label:'',value:'yjtb'},{label:'',value:'wddd'}
pages:[{label:'智能推荐',value:'zntj'},{label:'我的志愿',value:'wdzy'},],//
visible:{
showOrderSaveBtn: false,//
showOtherMajorDialog:false,//
showOtherVolunteerDialog:false,//
switchVolunteerDialog:false,//
@ -1113,9 +1133,7 @@ function getVolunteerDetail(){
let e = null
for(let i=1;i<=64;i++){
e = volunteeZhuanOfIndexsMap.get(i)
if(!e){
volunteerZhuanList.push({indexs:i})
}else{
if(e){
volunteerZhuanList.push(e)
}
}
@ -1125,14 +1143,11 @@ function getVolunteerDetail(){
let volunteerBenList=[] as any
for(let i=1;i<=64;i++){
e = volunteerBenOfIndexsMap.get(i)
if(!e){
volunteerBenList.push({indexs:i})
}else{
if(e){
volunteerBenList.push(e)
}
}
state.volunteerInfo.volunteerBenList = volunteerBenList
}
}).catch((error: any) => {
console.log(error);
@ -1163,7 +1178,6 @@ function returnStorgeVolunteerIndex(majorInfo:any){
//
function selectVolunteer(majorInfo:any){
console.log('aa')
let a = '-'
let key = majorInfo.id
//majorInfo.schoolCode+a+majorInfo.batch+a+majorInfo.majorCode+a+majorInfo.majorName+a+majorInfo.enrollmentCode
let valuesArray = []
@ -1287,6 +1301,7 @@ function cancelSelectVolunteer(majorInfo:any){
let key = majorInfo.id
deleteVolunteerMapByKey(null,key)
}
//
function getRecommendVolunteerList(){
//
@ -1600,6 +1615,92 @@ function returnVolunteerList(){
state.selectForm.batchPaneName==='本科批'?state.volunteerInfo.volunteerBenList:
state.volunteerInfo.volunteerZhuanList;
}
// []
const initSortable = () => {
//
nextTick(() => {
const tableEl = volunteerTableRef.value?.$el;
if (!tableEl) return;
// tbody
const tbody = tableEl.querySelector('.el-table__body-wrapper tbody');
if (tbody) {
Sortable.create(tbody, {
animation: 150, //
handle: '.el-table__row', //
onEnd: ({ newIndex, oldIndex }: any) => {
if (newIndex === oldIndex) return;
// 1.
const currentList = returnVolunteerList();
// 2.
const currRow = currentList.splice(oldIndex, 1)[0];
currentList.splice(newIndex, 0, currRow);
// 3. indexs () UI "1, 2"
currentList.forEach((item: any, index: number) => {
item.indexs = index + 1;
});
// 4.
state.visible.showOrderSaveBtn = true;
//
// ElMessage.info('');
}
});
}
});
};
// [] activePage 'wdzy' ()
watch(() => state.activePage, (newVal) => {
if (newVal === 'wdzy') {
initSortable();
}
});
// [] (DOM)
watch(() => state.selectForm.batchPaneName, () => {
if (state.activePage === 'wdzy') {
initSortable();
}
});
// []
const handleSaveVolunteerOrder = () => {
const currentList = returnVolunteerList();
// id indexs
const sortData = currentList.map((item: any) => ({
id: item.id || item.calculationMajorId, // ID
indexs: item.indexs
})).filter((item: any) => item.id); //
//
//
console.log('提交保存的数据:', sortData);
/*
axiosInstance({
url: ApiConstant.Volunteer.saveOrder, //
method: 'post',
data: sortData
}).then(res => {
if(res.data.success){
ElMessage.success('志愿顺序保存成功');
state.visible.showOrderSaveBtn = false; //
getVolunteerDetail(); //
}
});
*/
//
ElMessage.success('顺序已保存 (演示)');
state.visible.showOrderSaveBtn = false;
};
</script>
<style scoped lang="scss">
@ -1868,4 +1969,16 @@ function returnVolunteerList(){
font-weight: 600;
border-bottom: 1px solid #eeeeee;
}
/* [新增] 拖拽时的样式 */
:deep(.sortable-ghost) {
opacity: 0.8;
background: #ecf5ff !important;
}
:deep(.el-table__row) {
cursor: grab; //
}
:deep(.el-table__row:active) {
cursor: grabbing; //
}
</style>