【新增】j-table
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
<template>
|
||||
<div>
|
||||
<a-table :columns="aColumns" :dataSource="dataSource" :pagination="ispagination" :rowSelection="rowSelect" bordered
|
||||
:scroll="{ x: 1920 }">
|
||||
<!-- <a slot="name" slot-scope="text,scope">{{ scope.age }}</a> -->
|
||||
<span :slot="a.slots.title" v-for="a in aColumns" :key='a.dataIndex'>{{a.slots.title}}
|
||||
<a-dropdown :trigger="['click']">
|
||||
<a class="ant-dropdown-link" @click="e => e.preventDefault()">
|
||||
<!-- 操作 -->
|
||||
<a-icon type="down" />
|
||||
</a>
|
||||
<a-menu slot="overlay">
|
||||
<a-sub-menu key="dj" title="冻结列头">
|
||||
<a-menu-item>
|
||||
<a-radio-group v-model="value" @change="((e)=>{fixedC(e,a.dataIndex)})">
|
||||
<a-radio :style="radioStyle" :value="1">
|
||||
左侧冻结
|
||||
</a-radio>
|
||||
<a-radio :style="radioStyle" :value="2">
|
||||
右侧冻结
|
||||
</a-radio>
|
||||
<a-radio :style="radioStyle" :value="3">
|
||||
解冻
|
||||
</a-radio>
|
||||
</a-radio-group>
|
||||
</a-menu-item>
|
||||
</a-sub-menu>
|
||||
<a-sub-menu key="sx" title="筛选列头">
|
||||
<a-menu-item>
|
||||
<a-checkbox-group v-model="checkedList" :options="plainOptions" @change="onChange" />
|
||||
</a-menu-item>
|
||||
</a-sub-menu>
|
||||
</a-menu>
|
||||
</a-dropdown>
|
||||
</span>
|
||||
</a-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
Table
|
||||
} from 'ant-design-vue'
|
||||
|
||||
export default {
|
||||
name: 'Jtable',
|
||||
props: Object.assign({
|
||||
isShowPage: {
|
||||
type: Boolean,
|
||||
default () {
|
||||
return true
|
||||
}
|
||||
},
|
||||
isCheck: {
|
||||
type: Boolean,
|
||||
default () {
|
||||
return true
|
||||
}
|
||||
},
|
||||
}, Table.props, {
|
||||
rowSelection: {
|
||||
type: Object,
|
||||
default () {
|
||||
return {
|
||||
type: 'checkbox'
|
||||
}
|
||||
}
|
||||
},
|
||||
pagination: {
|
||||
type: Object,
|
||||
default () {
|
||||
return {
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
pageSizeOptions: ['10', '20', '30'],
|
||||
showTotal: (total, range) => {
|
||||
return range[0] + "-" + range[1] + " 共" + total + "条"
|
||||
},
|
||||
showQuickJumper: true,
|
||||
showSizeChanger: true,
|
||||
total: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
}),
|
||||
data() {
|
||||
return {
|
||||
aColumns: this.columns,
|
||||
midColumns: this.columns,
|
||||
checkedList: [],
|
||||
plainOptions: [],
|
||||
|
||||
fixedList: [],
|
||||
fixedOptions: [],
|
||||
value: 3,
|
||||
radioStyle: {
|
||||
display: 'block',
|
||||
height: '30px',
|
||||
lineHeight: '30px',
|
||||
},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
rowSelect() {
|
||||
if (this.isCheck) {
|
||||
return this.rowSelection
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
},
|
||||
ispagination() {
|
||||
if (this.isShowPage) {
|
||||
return this.pagination
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
console.log(this.aColumns)
|
||||
let pList = []
|
||||
this.columns.forEach((item) => {
|
||||
pList.push(item.dataIndex)
|
||||
})
|
||||
this.plainOptions = pList
|
||||
this.checkedList = pList
|
||||
|
||||
this.fixedOptions = pList
|
||||
},
|
||||
methods: {
|
||||
// 用户可自行筛选列头显示的字段
|
||||
onChange(e) {
|
||||
let newList = [] //最初始list
|
||||
let resList = [] //两个数组不同
|
||||
this.columns.forEach((item) => {
|
||||
newList.push(item.dataIndex)
|
||||
})
|
||||
|
||||
function getArrDifference(arr1, arr2) {
|
||||
return arr1.concat(arr2).filter(function(v, i, arr) {
|
||||
return arr.indexOf(v) === arr.lastIndexOf(v);
|
||||
});
|
||||
}
|
||||
resList = getArrDifference(e, newList)
|
||||
if (resList.length === 0) {
|
||||
// 如果数组为空,则把父组件传过来的表头赋值给
|
||||
this.aColumns = this.columns
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < resList.length; i++) {
|
||||
this.midColumns = this.midColumns.filter(item =>
|
||||
item.dataIndex !== resList[i]
|
||||
)
|
||||
}
|
||||
this.aColumns = this.midColumns
|
||||
//重置
|
||||
this.midColumns = this.columns
|
||||
},
|
||||
// 用户可自行冻结列头
|
||||
// fixedChange(e) {
|
||||
// //先判断有没有修改,
|
||||
// if (e.length === 0) {
|
||||
// this.aColumns.forEach((item) => {
|
||||
// if (item.fixed) {
|
||||
// item.fixed = false
|
||||
// }
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// //清空所有fixed属性
|
||||
// for (let i = 0; i < e.length; i++) {
|
||||
// this.aColumns.forEach((item) => {
|
||||
// if (item.fixed) {
|
||||
// item.fixed = false
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// //把对应点击的fixed属性变为true
|
||||
// for (let i = 0; i < e.length; i++) {
|
||||
// this.aColumns.find(item => {
|
||||
// if (item.dataIndex === e[i]) {
|
||||
// item.fixed = true
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// },
|
||||
fixedC(e, dataIndex) {
|
||||
// console.log(e.target.value, dataIndex)
|
||||
if (e.target.value === 1) { //左侧冻结
|
||||
this.aColumns.find(item => {
|
||||
if (item.dataIndex === dataIndex) {
|
||||
item.fixed = 'left'
|
||||
}
|
||||
})
|
||||
} else if (e.target.value === 2) { //右侧冻结
|
||||
this.aColumns.find(item => {
|
||||
if (item.dataIndex === dataIndex) {
|
||||
item.fixed = 'right'
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.aColumns.find(item => { //解冻
|
||||
if (item.dataIndex === dataIndex) {
|
||||
item.fixed = false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.ant-checkbox-group-item {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user