【fix 66426】JTable修复拖拽问题

This commit is contained in:
danshihao
2023-03-21 17:32:18 +08:00
parent e56a81413b
commit 433b1a77b2
3 changed files with 18 additions and 16 deletions
+12 -16
View File
@@ -210,15 +210,18 @@ export default {
// 更新父组件的数据,将排序后的进行渲染 // 更新父组件的数据,将排序后的进行渲染
this.$emit('update:columns', columns) this.$emit('update:columns', columns)
// 按冻结顺序排序 // 按冻结顺序排序
this.resultColumns = [...startArr.sort((a, b) => { this.resultColumns = [
const freezeArr = this.settingColumnsObj.freeze ...startArr.sort((a, b) => {
return freezeArr.indexOf(getKey(a)) - freezeArr.indexOf(getKey(b)) const freezeArr = this.settingColumnsObj.freeze
}), ...midArr, ...endArr] return freezeArr.indexOf(getKey(a)) - freezeArr.indexOf(getKey(b))
}),
...midArr,
...endArr
]
return this.resultColumns return this.resultColumns
}, },
// 初始化表格拖拽 // 初始化表格拖拽
initDrag (columns) { initDrag (columns) {
columns = cloneDeep(columns)
// 没有边框就不能拖拽 // 没有边框就不能拖拽
if (!this.bordered) { if (!this.bordered) {
return return
@@ -230,7 +233,7 @@ export default {
// 第一步:列宽映射 // 第一步:列宽映射
const draggingMap = {} const draggingMap = {}
columns.forEach((col) => { columns.forEach((col) => {
draggingMap[col.dataIndex || col.key] = col.width draggingMap[getKey(col)] = col.width
}) })
const draggingState = Vue.observable(draggingMap) const draggingState = Vue.observable(draggingMap)
// 第二步:表头渲染 // 第二步:表头渲染
@@ -239,15 +242,8 @@ export default {
let thDom = null let thDom = null
// 获取列的key值和特性 // 获取列的key值和特性
const { key, ...restProps } = props const { key, ...restProps } = props
// if (renderField.includes(key)) { // 获取最新列配置
// return const columns = cloneDeep(this.columns)
// }
// renderField.push(key)
// 获取当前列
// const col = tbCols.find((col) => {
// const k = col.dataIndex || col.key
// return k === key
// })
let col let col
if (key === 'selection-column') { if (key === 'selection-column') {
col = {} col = {}
@@ -297,7 +293,7 @@ export default {
> >
{children} {children}
<vue-draggable-resizable <vue-draggable-resizable
key={col.dataIndex || col.key} key={getKey(col)}
class="table-draggable-handle" class="table-draggable-handle"
minw={10} minw={10}
w={10} w={10}
@@ -168,6 +168,7 @@ export default {
resizable: true, resizable: true,
title: 'Date', title: 'Date',
dataIndex: 'date', dataIndex: 'date',
minWidth: 200,
width: 200 width: 200
}, },
{ {
@@ -175,6 +176,7 @@ export default {
columnTitle: 'Name', columnTitle: 'Name',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name',
minWidth: 100,
slots: { title: 'customTitle' }, slots: { title: 'customTitle' },
scopedSlots: { customRender: 'name' } scopedSlots: { customRender: 'name' }
}, },
@@ -182,6 +184,7 @@ export default {
title: 'Tags', title: 'Tags',
key: 'tags', key: 'tags',
dataIndex: 'tags', dataIndex: 'tags',
minWidth: 200,
scopedSlots: { customRender: 'tags' } scopedSlots: { customRender: 'tags' }
}, },
{ {
@@ -75,6 +75,7 @@ export default {
resizable: true, resizable: true,
title: 'Date', title: 'Date',
dataIndex: 'date', dataIndex: 'date',
minWidth: 200,
width: 200 width: 200
}, },
{ {
@@ -82,6 +83,7 @@ export default {
columnTitle: 'Name', columnTitle: 'Name',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name',
minWidth: 100,
slots: { title: 'customTitle' }, slots: { title: 'customTitle' },
scopedSlots: { customRender: 'name' } scopedSlots: { customRender: 'name' }
}, },
@@ -89,6 +91,7 @@ export default {
title: 'Tags', title: 'Tags',
key: 'tags', key: 'tags',
dataIndex: 'tags', dataIndex: 'tags',
minWidth: 200,
scopedSlots: { customRender: 'tags' } scopedSlots: { customRender: 'tags' }
}, },
{ {