拖拽-可设置最小宽度

This commit is contained in:
zyn
2023-02-07 13:39:30 +08:00
parent f9d4148fc9
commit d1590420cb
3 changed files with 155 additions and 78 deletions
@@ -0,0 +1,39 @@
<template>
<a-table
:components="drag(columnshistory,'columns')"
class="table"
:columns="columnshistory"
:pagination="false"
:scroll="{y: 400}"
:data-source="dataSourcehistory"
:loading="loading"
>
<span slot="content" slot-scope="text,record">
<a-tooltip placement="topLeft">
<template slot="title">
<span v-html="text"></span>
</template>
<span v-html="text"></span>
</a-tooltip>
</span>
<span slot="detailText" slot-scope="text,record">
<span class="text" :title="text">
{{text && text.length > 10?text.slice(0,9)+'...':text}}
</span>
</span>
</a-table>
</template>
<script>
import { ResizeHeader, ResizeColumnProvide } from '@/mixins/header'
export default {
name: 'historyTable.vue',
props:['columnshistory','dataSourcehistory'],
mixins:[ResizeHeader, ResizeColumnProvide],
}
</script>
<style scoped>
</style>
@@ -3,6 +3,7 @@
<div class="box"> <div class="box">
<!-- --> <!-- -->
<a-table <a-table
:components="drag(columns,'columns',JSON.parse(JSON.stringify([[columns[3],500]])))"
class="table" class="table"
rowKey="id" rowKey="id"
:row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
@@ -179,28 +180,29 @@
@ok="handleOk" @ok="handleOk"
@cancel="handleCancel" @cancel="handleCancel"
> >
<a-table <historyTable :columnshistory='columnshistory' :dataSourcehistory='dataSourcehistory'></historyTable>
class="table" <!-- <a-table-->
:columns="columnshistory" <!-- class="table"-->
:pagination="false" <!-- :columns="columnshistory"-->
:scroll="{y: 400}" <!-- :pagination="false"-->
:data-source="dataSourcehistory" <!-- :scroll="{y: 400}"-->
:loading="loading" <!-- :data-source="dataSourcehistory"-->
> <!-- :loading="loading"-->
<span slot="content" slot-scope="text,record"> <!-- >-->
<a-tooltip placement="topLeft"> <!-- <span slot="content" slot-scope="text,record">-->
<template slot="title"> <!-- <a-tooltip placement="topLeft">-->
<span v-html="text"></span> <!-- <template slot="title">-->
</template> <!-- <span v-html="text"></span>-->
<span v-html="text"></span> <!-- </template>-->
</a-tooltip> <!-- <span v-html="text"></span>-->
</span> <!-- </a-tooltip>-->
<span slot="detailText" slot-scope="text,record"> <!-- </span>-->
<span class="text" :title="text"> <!-- <span slot="detailText" slot-scope="text,record">-->
{{text && text.length > 10?text.slice(0,9)+'...':text}} <!-- <span class="text" :title="text">-->
</span> <!-- {{text && text.length > 10?text.slice(0,9)+'...':text}}-->
</span> <!-- </span>-->
</a-table> <!-- </span>-->
<!-- </a-table>-->
<div class="page" v-if="dataSourcehistory.length > 0"> <div class="page" v-if="dataSourcehistory.length > 0">
<a-pagination <a-pagination
:show-total="total => $t('total')+` ${total} `+$t('strip')" :show-total="total => $t('total')+` ${total} `+$t('strip')"
@@ -271,11 +273,14 @@
import { ACCESS_TOKEN } from '@/store/mutation-types' import { ACCESS_TOKEN } from '@/store/mutation-types'
import axios from 'axios' import axios from 'axios'
import Vue from 'vue' import Vue from 'vue'
import VueDraggableResizable from 'vue-draggable-resizable' // import VueDraggableResizable from 'vue-draggable-resizable'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { ResizeHeader, ResizeColumnProvide } from '@/mixins/header'
import historyTable from './historyTable.vue'
export default { export default {
name: 'index', name: 'index',
mixins:[ResizeHeader, ResizeColumnProvide],
props: { props: {
//接口 //接口
url: { url: {
@@ -304,47 +309,48 @@
}, },
components: { components: {
CollectionType, CollectionType,
VueDraggableResizable // VueDraggableResizable
historyTable
}, },
data() { data() {
this.components = { // this.components = {
header: { // header: {
cell: (h, props, children) => { // cell: (h, props, children) => {
const { key, ...restProps } = props // const { key, ...restProps } = props
//
// 此处的this.columns 是定义的table的表头属性变量 // // 此处的this.columns 是定义的table的表头属性变量
//
const col = this.columns.find((col) => { // const col = this.columns.find((col) => {
const k = col.dataIndex || col.key // const k = col.dataIndex || col.key
return k === key // return k === key
}) // })
//
if (!col || !col.width) { // if (!col || !col.width) {
return h('th', { ...restProps }, [...children]) // return h('th', { ...restProps }, [...children])
} // }
//
const dragProps = { // const dragProps = {
key: col.dataIndex || col.key, // key: col.dataIndex || col.key,
class: 'table-draggable-handle', // class: 'table-draggable-handle',
attrs: { // attrs: {
w: 10, // w: 10,
x: col.width, // x: col.width,
z: 1, // z: 1,
axis: 'x', // axis: 'x',
draggable: false, // draggable: false,
resizable: false // resizable: false
}, // },
on: { // on: {
dragging: (x, y) => { // dragging: (x, y) => {
col.width = Math.max(x, 1) // col.width = Math.max(x, 1)
} // }
} // }
} // }
const drag = h('vue-draggable-resizable', { ...dragProps }) // const drag = h('vue-draggable-resizable', { ...dragProps })
return h('th', { ...restProps, class: 'resize-table-th' }, [...children, drag]) // return h('th', { ...restProps, class: 'resize-table-th' }, [...children, drag])
} // }
} // }
} // }
return { return {
token: Vue.ls.get(ACCESS_TOKEN), token: Vue.ls.get(ACCESS_TOKEN),
jsonBody: [], jsonBody: [],
@@ -411,14 +417,15 @@
{ {
title: this.$t('OperationDetails'), title: this.$t('OperationDetails'),
dataIndex: 'logContent', dataIndex: 'logContent',
align: 'center', align: 'left',
width: 320,
ellipsis: true, ellipsis: true,
scopedSlots: { customRender: 'content' } scopedSlots: { customRender: 'content' }
}, },
{ {
title: this.$t('OperationTime'), title: this.$t('OperationTime'),
dataIndex: 'createTime', dataIndex: 'createTime',
align: 'center', align: 'left',
ellipsis: true, ellipsis: true,
width: 180 width: 180
} }
@@ -767,10 +774,10 @@
let num = 0 let num = 0
this.content = [] this.content = []
jsonHead.forEach((res, index) => { jsonHead.forEach((res, index) => {
console.log(res) // console.log(res)
// 配置列 // 配置列
if (res.type) { if (res.type) {
console.log('配置') // console.log('配置')
this.columns.push({ this.columns.push({
dataIndex: res.db_field_name, dataIndex: res.db_field_name,
align: 'left', align: 'left',
@@ -965,7 +972,7 @@
Object.keys(Obj).forEach((item) => { Object.keys(Obj).forEach((item) => {
if (Obj[item] instanceof Object && Obj[item].controlType !== undefined) { if (Obj[item] instanceof Object && Obj[item].controlType !== undefined) {
Obj[item].list.forEach((itemLi) => { Obj[item].list.forEach((itemLi) => {
console.log(item) // console.log(item)
if((this.currentPersonRole == 'homo' || this.currentPersonRole == 'admin') && item == 'referencesCol'){ if((this.currentPersonRole == 'homo' || this.currentPersonRole == 'admin') && item == 'referencesCol'){
itemLi.isLock = 0 itemLi.isLock = 0
}else{ }else{
+42 -11
View File
@@ -5,9 +5,10 @@ const events = {
move: 'mousemove', move: 'mousemove',
stop: 'mouseup' stop: 'mouseup'
} }
let tableAll = [] let tableAll = [] // 单个页面存放多个表格的columns
var columnsAll = [] var columnsAll = []
var columnsKey = '' var columnsKey = ''
let minColumn = [] // 存放设置最小宽的列及宽度
const DragHandler = { const DragHandler = {
name: 'nio-drag-handler', name: 'nio-drag-handler',
//获取混入的方法(重新设置表头宽度) //获取混入的方法(重新设置表头宽度)
@@ -86,9 +87,10 @@ const DragHandler = {
return h('div', { class: 'nio-drag-handler', on: { mousedown: this.handleMouseDown } }, [line]) return h('div', { class: 'nio-drag-handler', on: { mousedown: this.handleMouseDown } }, [line])
} }
} }
const ResizeHeaderOne = function(val, name) { const ResizeHeaderOne = function(val, name ,minWidths) {
columnsAll = val columnsAll = val
columnsKey = name columnsKey = name
minColumn = minWidths
if(tableAll.indexOf(val) === -1){ if(tableAll.indexOf(val) === -1){
tableAll.push(val) tableAll.push(val)
} }
@@ -96,16 +98,44 @@ const ResizeHeaderOne = function(val, name) {
const { key, column, ...restProps } = props const { key, column, ...restProps } = props
let col = {} let col = {}
// 处理多级表头 // 处理多级表头
col = getRenderCoL(key, val) // col = getRenderCoL(key, val)
col = getRenderCoL(key, columnsAll)
let content = [].concat(children) let content = [].concat(children)
console.log(col)
if (col) { if (col) {
const handlerVNode = h(DragHandler, { let handlerVNode;
props: { if(minColumn && minColumn.length>0){
width: col.width, // 存放所有需要手动设置最小宽度的列的dataIndex
minWidth: Math.min(col.width, 100), let colsdataIndex = []
column: col minColumn.forEach((item)=>{
colsdataIndex.push(item[0].dataIndex)
handlerVNode = h(DragHandler, {
props: {
width: col.width,
minWidth: Math.min(item[1]),
column: JSON.parse(JSON.stringify(item[0]))
}
}, [])
})
// 不需要手动设置最小宽度的列
if(colsdataIndex.indexOf(col.dataIndex) === -1){
handlerVNode = h(DragHandler, {
props: {
width: col.width,
minWidth: Math.min(col.width, 100),
column: col
}
}, [])
} }
}, []) }else{
handlerVNode = h(DragHandler, {
props: {
width: col.width,
minWidth: Math.min(col.width, 100),
column: col
}
}, [])
}
content = content.concat( content = content.concat(
handlerVNode handlerVNode
) )
@@ -119,10 +149,11 @@ const ResizeHeaderOne = function(val, name) {
} }
export const ResizeHeader = { export const ResizeHeader = {
methods: { methods: {
drag(columns, name) { drag(columns, name ,minWidths) {
return { return {
header: { header: {
cell: ResizeHeaderOne(columns, name) // minWidths : 最小宽度 => [[需要设置的列,最小宽],[需要设置的列,最小宽],...]
cell: ResizeHeaderOne(columns, name,minWidths)
} }
} }
} }