This commit is contained in:
yaoyanan
2021-03-23 15:40:36 +08:00
85 changed files with 2814 additions and 14597 deletions
+153 -170
View File
@@ -1,28 +1,35 @@
<template>
<div>
<!-- TODO 使用标签 应每个参数一行保持整体写法统一和美观度-->
<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}}
<!-- TODO 使用标签 应每个参数一行保持整体写法统一和美观度-->
<a-table
:columns="aColumns"
:dataSource="dataSource"
: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 class="ant-dropdown-link" @click="e => e.preventDefault()">
<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
v-model="a.slots.fixedValue"
@change="
(e) => {
fixedChange(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>
@@ -39,189 +46,165 @@
</template>
<script>
import {
Table
} from 'ant-design-vue'
import { Table } from 'ant-design-vue'
export default {
// TODO 命名和全局保持统一,应为JTable
name: 'Jtable',
props: Object.assign({
export default {
// TODO 命名和全局保持统一,应为JTable
name: 'JTable',
props: Object.assign(
{
isShowPage: {
type: Boolean,
default () {
default() {
return true
}
},
},
isCheck: {
type: Boolean,
default () {
default() {
return true
}
},
},
}, Table.props, {
},
Table.props,
{
rowSelection: {
type: Object,
default () {
default() {
return {
type: 'checkbox'
type: 'checkbox',
}
}
},
},
pagination: {
type: Object,
default () {
default() {
return {
current: 1,
pageSize: 10,
pageSizeOptions: ['10', '20', '30'],
showTotal: (total, range) => {
return range[0] + "-" + range[1] + " " + total + ""
return range[0] + '-' + range[1] + ' 共' + total + '条'
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
total: 0,
}
}
},
}),
data() {
return {
aColumns: this.columns,
midColumns: this.columns,
checkedList: [],
plainOptions: [],
// TODO 未用到的变量请删掉
fixedList: [],
// TODO 初始化了,但未使用的变量请删掉
fixedOptions: [],
// TODO 代码中不要出现魔数,使用变量标明3的含义。实在无法处理的地方,最起码给个注释
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)
// pList含义不清晰,无法理解
let pList = []
this.columns.forEach((item) => {
pList.push(item.dataIndex)
})
this.plainOptions = pList
this.checkedList = pList
this.fixedOptions = pList
},
methods: {
// 用户可自行筛选列头显示的字段
// TODO 该段代码复杂,建议逻辑复杂的代码,在方法名上注释清楚大致逻辑
onChange(e) {
let newList = [] //最初始list
let resList = [] //两个数组不同
this.columns.forEach((item) => {
newList.push(item.dataIndex)
})
// TODO 不要在method里套function,可以考虑另开一个method函数,再进行调用
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
}
// TODO midColumns这个变量应该声明为局部变量,作为全局变量但没有全局使用是不合理的
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
}
})
}
}
}
}
),
data() {
return {
aColumns: this.columns,
checkedList: [],
plainOptions: [],
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)
// 遍历出筛选列头的所有选项
this.columns.forEach((item) => {
this.plainOptions.push(item.dataIndex)
})
// 读取localStorage中的数据
var storageCloumns = JSON.parse(localStorage.getItem('pro__Cloumns'))
// console.log(storageCloumns)
if (storageCloumns) {
this.aColumns = storageCloumns
}
// 遍历出筛选列头中的已选项
this.aColumns.forEach((item) => {
this.checkedList.push(item.dataIndex)
})
},
methods: {
// 用户可自行筛选列头显示的字段
// TODO 该段代码复杂,建议逻辑复杂的代码,在方法名上注释清楚大致逻辑
onChange(e) {
let initList = [] //最初始list
let diffList = [] //两个数组不同
// 首先遍历父组件传来的columns,拿到其中每一项的dataIndex,形成一个最初始的数组
this.columns.forEach((item) => {
initList.push(item.dataIndex)
})
// 拿到两个数组的不同的项
diffList = this.getArrDifference(e, initList)
if (diffList.length === 0) {
// 如果数组为空,则把父组件传过来的表头赋值给
this.aColumns = this.columns
localStorage.setItem('pro__Cloumns', JSON.stringify(this.aColumns))
return
}
// TODO midColumns这个变量应该声明为局部变量,作为全局变量但没有全局使用是不合理的
let midColumns = this.columns
for (let i = 0; i < diffList.length; i++) {
midColumns = midColumns.filter((item) => item.dataIndex !== diffList[i])
}
this.aColumns = midColumns
localStorage.setItem('pro__Cloumns', JSON.stringify(this.aColumns))
// console.log(JSON.parse(localStorage.getItem("pro__Cloumns")))
},
getArrDifference(arr1, arr2) {
return arr1.concat(arr2).filter(function (v, i, arr) {
return arr.indexOf(v) === arr.lastIndexOf(v)
})
},
fixedChange(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;
}
.ant-checkbox-group-item {
display: block;
margin-bottom: 8px;
}
</style>