优化表格数据

This commit is contained in:
qq787203167
2022-01-21 17:12:00 +08:00
parent 17b6b5b2fb
commit eacb07650c
2 changed files with 67 additions and 40 deletions
+36 -38
View File
@@ -4,11 +4,9 @@
<table class="box-table" cellpadding="0" cellspacing="0"> <table class="box-table" cellpadding="0" cellspacing="0">
<thead> <thead>
<tr id="table_thead_tr"> <tr id="table_thead_tr">
<a-checkbox-group @change="checkboxAll($event)"> <th class="checkbox" style="margin-top: 24px;display: inline-block">
<th class="checkbox" style="margin-top: 24px;display: inline-block"> <a-checkbox :checked="tableAll" :indeterminate="indeterminate" @change="checkboxAll($event)"></a-checkbox>
<a-checkbox></a-checkbox> </th>
</th>
</a-checkbox-group>
</tr> </tr>
</thead> </thead>
<tbody id="table_tbody_tr"> <tbody id="table_tbody_tr">
@@ -20,11 +18,8 @@
<td v-for="val in Object.keys(item)" v-if="val != 'id'" class="box-td" :title="item[val]"> <td v-for="val in Object.keys(item)" v-if="val != 'id'" class="box-td" :title="item[val]">
{{item[val]}} {{item[val]}}
</td> </td>
<td class="box-td box-th-po"> <td class="box-td box-th-po" v-if="isOperation">
<a class="text" v-if="Collection">收藏</a> <a class="text" v-for="(ol,index) in OperationList" @click="OperationClick(ol,item)">{{ol.text}}</a>
<a class="text" v-if="subscribe">订阅</a>
<a class="text" v-if="edit">编辑</a>
<a class="text" v-if="del">删除</a>
</td> </td>
</tr> </tr>
</a-checkbox-group> </a-checkbox-group>
@@ -50,26 +45,21 @@
export default { export default {
name: 'index', name: 'index',
props: { props: {
edit: { //接口
type: Boolean,
default: false
},
del: {
type: Boolean,
default: false
},
Collection: {
type: Boolean,
default: false
},
subscribe: {
type: Boolean,
default: false
},
url: { url: {
type: Object, type: Object,
default: {} default: {}
} },
// 操作按钮
OperationList: {
type: Array,
default: []
},
//是否显示操作;默认显示
isOperation:{
type: Boolean,
default:true,
},
}, },
data() { data() {
return { return {
@@ -122,34 +112,39 @@
'col7': 0.6 'col7': 0.6
} }
], ],
checkboxList: [] checkboxList: [],
tableAll: false,
indeterminate: false
} }
}, },
mounted() { mounted() {
eventBUs.$on('searchQuery', target => { eventBUs.$on('searchQuery', target => {
console.log(target); console.log(target)
}); })
eventBUs.$on('searchReset', target => { eventBUs.$on('searchReset', target => {
console.log(target); console.log(target)
}); })
this.getData() this.getData()
}, },
methods: { methods: {
getData() { getData() {
var jsonHead = this.jsonHead var jsonHead = this.jsonHead
for (var i = 0; i < jsonHead.length; i++) { for (var i = 0; i < jsonHead.length; i++) {
$('#table_thead_tr').append('<th class="box-th">' + jsonHead[i].enName + '</br>' + jsonHead[i].name + '</th>') $('#table_thead_tr').append('<th class="box-th">' + jsonHead[i].enName + '</br>' + jsonHead[i].name + '</th>')
} }
let th = '<th class="box-th box-th-po">' + 'Operation ' + '</br>' + '操作' + '</th>' if (this.isOperation){
$('#table_thead_tr').append(th) let th = '<th class="box-th box-th-po">' + 'Operation ' + '</br>' + '操作' + '</th>'
$('#table_thead_tr').append(th)
}
}, },
checkboxChange(value) { checkboxChange(checkedList) {
console.log(value) this.indeterminate = !!checkedList.length && checkedList.length < this.jsonBody.length
this.tableAll = checkedList.length === this.jsonBody.length
}, },
checkboxAll(event) { checkboxAll(event) {
this.tableAll = event.target.checked
this.checkboxList = [] this.checkboxList = []
if (event.length > 0) { if (this.tableAll) {
this.jsonBody.forEach(res => { this.jsonBody.forEach(res => {
this.checkboxList.push(res.id) this.checkboxList.push(res.id)
}) })
@@ -157,6 +152,9 @@
}, },
onChange() { onChange() {
},
OperationClick(ol, item) {
this.$emit(ol.ClickEvent, item)
} }
} }
} }
+31 -2
View File
@@ -7,7 +7,12 @@
<a-button @click="handleCompare()" type="primary" icon="plus">{{$t('DataComparison')}}</a-button> <a-button @click="handleCompare()" type="primary" icon="plus">{{$t('DataComparison')}}</a-button>
</div> </div>
<div> <div>
<tableData edit del :url="{}"/> <tableData
:OperationList="OperationList"
@editTable="editTable"
@deleteTable="deleteTable"
:url="{}"
/>
</div> </div>
<addForm ref="addFormClick"/> <addForm ref="addFormClick"/>
</a-card> </a-card>
@@ -33,6 +38,24 @@
{ name: '名称', placeholder: '请输入姓名', attrModel: 'name', enName: 'title' }, { name: '名称', placeholder: '请输入姓名', attrModel: 'name', enName: 'title' },
{ name: '标题', placeholder: '请输入标题', attrModel: 'title', enName: 'title' } { name: '标题', placeholder: '请输入标题', attrModel: 'title', enName: 'title' }
], ],
OperationList: [
{
text: '编辑',
ClickEvent: 'editTable'
},
{
text: '删除',
ClickEvent: 'deleteTable'
},
{
text: '收藏',
ClickEvent: 'Collection'
},
{
text: '订阅',
ClickEvent: 'subscribe'
}
],
selectedRowKeys: [], selectedRowKeys: [],
dataSource: [], dataSource: [],
loading: false, loading: false,
@@ -73,7 +96,13 @@
}, },
handleCompare() { handleCompare() {
this.$refs.addFormClick.add() this.$refs.addFormClick.add()
} },
editTable(item) {
console.log(item)
},
deleteTable(){
console.log(3)
},
} }
} }
</script> </script>