【修改】JTable规范代码

This commit is contained in:
dusicong
2021-03-22 10:57:25 +08:00
parent 49bda883e8
commit 262ddc937c
+62 -52
View File
@@ -1,28 +1,35 @@
<template> <template>
<div> <div>
<!-- TODO 使用标签 应每个参数一行保持整体写法统一和美观度--> <!-- TODO 使用标签 应每个参数一行保持整体写法统一和美观度-->
<a-table :columns="aColumns" :dataSource="dataSource" :pagination="ispagination" :rowSelection="rowSelect" bordered <a-table
:scroll="{ x: 1920 }"> :columns="aColumns"
<!-- <a slot="name" slot-scope="text,scope">{{ scope.age }}</a> --> :dataSource="dataSource"
<span :slot="a.slots.title" v-for="a in aColumns" :key='a.dataIndex'>{{a.slots.title}} :pagination="ispagination"
:rowSelection="rowSelect"
bordered
:scroll="{ x: 1920 }"
>
<span :slot="a.slots.title" v-for="a in aColumns" :key="a.dataIndex">
{{ a.slots.title }}
<a-dropdown :trigger="['click']"> <a-dropdown :trigger="['click']">
<a class="ant-dropdown-link" @click="e => e.preventDefault()"> <a class="ant-dropdown-link" @click="(e) => e.preventDefault()">
<!-- 操作 --> <!-- 操作 -->
<a-icon type="down" /> <a-icon type="down" />
</a> </a>
<a-menu slot="overlay"> <a-menu slot="overlay">
<a-sub-menu key="dj" title="冻结列头"> <a-sub-menu key="dj" title="冻结列头">
<a-menu-item> <a-menu-item>
<a-radio-group v-model="a.slots.fixedValue" @change="((e)=>{fixedChange(e,a.dataIndex)})"> <a-radio-group
<a-radio :style="radioStyle" :value="1"> v-model="a.slots.fixedValue"
左侧冻结 @change="
</a-radio> (e) => {
<a-radio :style="radioStyle" :value="2"> fixedChange(e, a.dataIndex)
右侧冻结 }
</a-radio> "
<a-radio :style="radioStyle" :value="3"> >
解冻 <a-radio :style="radioStyle" :value="1"> 左侧冻结 </a-radio>
</a-radio> <a-radio :style="radioStyle" :value="2"> 右侧冻结 </a-radio>
<a-radio :style="radioStyle" :value="3"> 解冻 </a-radio>
</a-radio-group> </a-radio-group>
</a-menu-item> </a-menu-item>
</a-sub-menu> </a-sub-menu>
@@ -39,52 +46,54 @@
</template> </template>
<script> <script>
import { import { Table } from 'ant-design-vue'
Table
} from 'ant-design-vue'
export default { export default {
// TODO 命名和全局保持统一,应为JTable // TODO 命名和全局保持统一,应为JTable
name: 'JTable', name: 'JTable',
props: Object.assign({ props: Object.assign(
{
isShowPage: { isShowPage: {
type: Boolean, type: Boolean,
default () { default() {
return true return true
} },
}, },
isCheck: { isCheck: {
type: Boolean, type: Boolean,
default () { default() {
return true return true
}
}, },
}, Table.props, { },
},
Table.props,
{
rowSelection: { rowSelection: {
type: Object, type: Object,
default () { default() {
return { return {
type: 'checkbox' type: 'checkbox',
}
} }
}, },
},
pagination: { pagination: {
type: Object, type: Object,
default () { default() {
return { return {
current: 1, current: 1,
pageSize: 10, pageSize: 10,
pageSizeOptions: ['10', '20', '30'], pageSizeOptions: ['10', '20', '30'],
showTotal: (total, range) => { showTotal: (total, range) => {
return range[0] + "-" + range[1] + " " + total + "" return range[0] + '-' + range[1] + ' 共' + total + '条'
}, },
showQuickJumper: true, showQuickJumper: true,
showSizeChanger: true, showSizeChanger: true,
total: 0 total: 0,
}
} }
}, },
}), },
}
),
data() { data() {
return { return {
aColumns: this.columns, aColumns: this.columns,
@@ -121,7 +130,7 @@
}) })
// 读取localStorage中的数据 // 读取localStorage中的数据
var storageCloumns = JSON.parse(localStorage.getItem("pro__Cloumns")) var storageCloumns = JSON.parse(localStorage.getItem('pro__Cloumns'))
// console.log(storageCloumns) // console.log(storageCloumns)
if (storageCloumns) { if (storageCloumns) {
this.aColumns = storageCloumns this.aColumns = storageCloumns
@@ -146,55 +155,56 @@
if (diffList.length === 0) { if (diffList.length === 0) {
// 如果数组为空,则把父组件传过来的表头赋值给 // 如果数组为空,则把父组件传过来的表头赋值给
this.aColumns = this.columns this.aColumns = this.columns
localStorage.setItem("pro__Cloumns", JSON.stringify(this.aColumns)) localStorage.setItem('pro__Cloumns', JSON.stringify(this.aColumns))
return return
} }
// TODO midColumns这个变量应该声明为局部变量,作为全局变量但没有全局使用是不合理的 // TODO midColumns这个变量应该声明为局部变量,作为全局变量但没有全局使用是不合理的
let midColumns = this.columns let midColumns = this.columns
for (let i = 0; i < diffList.length; i++) { for (let i = 0; i < diffList.length; i++) {
midColumns = midColumns.filter(item => midColumns = midColumns.filter((item) => item.dataIndex !== diffList[i])
item.dataIndex !== diffList[i]
)
} }
this.aColumns = midColumns this.aColumns = midColumns
localStorage.setItem("pro__Cloumns", JSON.stringify(this.aColumns)) localStorage.setItem('pro__Cloumns', JSON.stringify(this.aColumns))
// console.log(JSON.parse(localStorage.getItem("pro__Cloumns"))) // console.log(JSON.parse(localStorage.getItem("pro__Cloumns")))
}, },
getArrDifference(arr1, arr2) { getArrDifference(arr1, arr2) {
return arr1.concat(arr2).filter(function(v, i, arr) { return arr1.concat(arr2).filter(function (v, i, arr) {
return arr.indexOf(v) === arr.lastIndexOf(v); return arr.indexOf(v) === arr.lastIndexOf(v)
}); })
}, },
fixedChange(e, dataIndex) { fixedChange(e, dataIndex) {
// console.log(e.target.value, dataIndex) // console.log(e.target.value, dataIndex)
if (e.target.value === 1) { //左侧冻结 if (e.target.value === 1) {
this.aColumns.find(item => { //左侧冻结
this.aColumns.find((item) => {
if (item.dataIndex === dataIndex) { if (item.dataIndex === dataIndex) {
item.fixed = 'left' item.fixed = 'left'
} }
}) })
} else if (e.target.value === 2) { //右侧冻结 } else if (e.target.value === 2) {
this.aColumns.find(item => { //右侧冻结
this.aColumns.find((item) => {
if (item.dataIndex === dataIndex) { if (item.dataIndex === dataIndex) {
item.fixed = 'right' item.fixed = 'right'
} }
}) })
} else { } else {
this.aColumns.find(item => { //解冻 this.aColumns.find((item) => {
//解冻
if (item.dataIndex === dataIndex) { if (item.dataIndex === dataIndex) {
item.fixed = false item.fixed = false
} }
}) })
} }
} },
} },
} }
</script> </script>
<style> <style>
.ant-checkbox-group-item { .ant-checkbox-group-item {
display: block; display: block;
margin-bottom: 8px; margin-bottom: 8px;
} }
</style> </style>