diff --git a/src/components/SelectTable/index.vue b/src/components/SelectTable/index.vue index c49497d..8053e7d 100644 --- a/src/components/SelectTable/index.vue +++ b/src/components/SelectTable/index.vue @@ -116,7 +116,7 @@ const visibleChange = (val: any) => { currentIndex.value = filterData.value.findIndex(item => item[props.value!] === props.data); if (currentIndex.value >= 0) { tableRef.value.setCurrentRow(filterData.value[currentIndex.value]); - tableRef.value.setScrollTop(currentIndex.value * 30); + tableRef.value.setScrollTop(currentIndex.value); } }, 10); } @@ -238,7 +238,7 @@ const handleKeydown = (e: any) => { tableRef.value.setCurrentRow(filterData.value[currentIndex.value]); // 滚动到当前行 - tableRef.value.setScrollTop(currentIndex.value * 30); + tableRef.value.setScrollTop(currentIndex.value); // 回车确认 if (e.key === "Enter") { diff --git a/src/components/elTable/index.vue b/src/components/elTable/index.vue index 0b9af35..657fa0b 100644 --- a/src/components/elTable/index.vue +++ b/src/components/elTable/index.vue @@ -6,8 +6,9 @@ :highlight-current-row="config.highlightCurrentRow || false" :row-class-name="config.rowClassName" :header-cell-style="config.headerCellStyle" :cell-style="config.cellStyle" :max-height="config.maxHeight" :show-summary="config.summary" :summary-method="getSummaries" :sum-text="config.sumText" :height="config.height" - :size="config.size || 'default'" :empty-text="config.emptyText || '暂无数据'" - @selection-change="handleSelectionChange" @current-change="handleCurrentChange" @row-click="handleRowClick" + :row-key="config.key" :class="{ 'drag-table': enableRowDrag }" :size="config.size || 'default'" + :empty-text="config.emptyText || '暂无数据'" @selection-change="handleSelectionChange" + @current-change="handleCurrentChange" @row-click="handleRowClick" :header-cell-class-name="enableColumnDrag ? 'el-table-header-cell' : ''" @row-dblclick="handleRowDblclick" @sort-change="handleSortChange" v-bind="$attrs"> @@ -137,6 +138,11 @@ const props = defineProps({ enableColumnDrag: { type: Boolean, default: false + }, + // 拖拽行 + enableRowDrag: { + type: Boolean, + default: false } }); @@ -152,6 +158,7 @@ const emit = defineEmits([ "page-change", "size-change", "column-drag-end", + "row-drag-end" ]); // 响应式数据 @@ -247,6 +254,9 @@ onMounted(() => { if (props.enableColumnDrag && tableRef.value) { initColumnDrag(); } + if (props.enableRowDrag && tableRef.value) { + initRowDrag(); + } }); @@ -318,6 +328,37 @@ const initColumnDrag = () => { }; +// 初始化行拖拽 +const initRowDrag = () => { + const tableBody = tableRef.value.$el.querySelector('.el-table__body-wrapper tbody'); + const sortable = new Sortable(tableBody, { + animation: 150, // 拖拽动画时长 + ghostClass: 'sortable-ghost', // 拖拽占位符样式 + chosenClass: 'sortable-chosen', // 选中行样式 + // 拖拽结束回调 + onEnd: (evt: any) => { + const { oldIndex, newIndex } = evt + if (oldIndex === newIndex) return // 未改变位置则不处理 + + // 调整数组顺序 + const moveRow = tableData.value.splice(oldIndex, 1)[0] + tableData.value.splice(newIndex, 0, moveRow) + + // 重新更新排序值 + tableData.value.forEach((item: any, index) => { + item.sort = index + 1 + }) + // console.log("🚀 ~ initRowDrag ~ tableData.value:", tableData.value) + emit('row-drag-end', { + oldIndex, + newIndex, + list: tableData.value + }) + } + }) +}; + + // 暴露方法 const clearSelection = () => { tableRef.value?.clearSelection(); @@ -339,8 +380,8 @@ const setScrollTo = (top: number) => { tableRef.value?.scrollTo(top); }; -const setScrollTop = (height: number) => { - tableRef.value?.setScrollTop(height); +const setScrollTop = (index: number) => { + tableRef.value?.setScrollTop(index * 30); //30px/行 }; const clearSort = () => { diff --git a/src/views/liswork/labItem/tab/parameter.vue b/src/views/liswork/labItem/tab/parameter.vue deleted file mode 100644 index 764e3df..0000000 --- a/src/views/liswork/labItem/tab/parameter.vue +++ /dev/null @@ -1,147 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/views/liswork/work/components/batchCode.vue b/src/views/liswork/work/components/batchCode.vue index d8cf9ad..8a4c525 100644 --- a/src/views/liswork/work/components/batchCode.vue +++ b/src/views/liswork/work/components/batchCode.vue @@ -138,7 +138,7 @@ const handleEnter = () => { prevSpecimen.value = res.data tableData.value.push(res.data) nextTick(() => { - tableRef.value.setScrollTop(tableData.value.length * 30); + tableRef.value.setScrollTop(tableData.value.length); }) currentScanCount.value++; } diff --git a/src/views/liswork/xtwh/comopt/components/sysChannel/index.vue b/src/views/liswork/xtwh/comopt/components/sysChannel/index.vue index 053444c..e8f367c 100644 --- a/src/views/liswork/xtwh/comopt/components/sysChannel/index.vue +++ b/src/views/liswork/xtwh/comopt/components/sysChannel/index.vue @@ -24,6 +24,11 @@ + + + @@ -39,6 +44,8 @@ \ No newline at end of file diff --git a/src/views/liswork/xtwh/comopt/index.vue b/src/views/liswork/xtwh/comopt/index.vue index 599c807..d774bda 100644 --- a/src/views/liswork/xtwh/comopt/index.vue +++ b/src/views/liswork/xtwh/comopt/index.vue @@ -109,10 +109,10 @@ const tabList = [ { key: 'SysInput', label: '界面设定', component: SysInput }, { key: 'SysParameter', label: '参数', component: SysParameter }, { key: 'SysChannel', label: '通道号', component: SysChannel }, - { key: 'SysSort', label: '整体排序', component: SysSort }, + { key: 'SysSort', label: '项目排序', component: SysSort }, { key: 'SysReport', label: '报告单设置', component: SysReport }, ] -const activeName = ref('SysParameter') +const activeName = ref('SysSort') // 计算当前要渲染的组件 const currentComponent = computed(() => {