autoTable.vue
4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!-- 传入接口名称,自动调用接口,并更新表格数据 -->
<template>
<div>
<el-form
:inline="true"
:model="searchForm"
>
<el-form-item label="id:">
<el-input v-model="searchForm.id"></el-input>
</el-form-item>
<el-form-item>
<el-button
size="small"
type="primary"
@click="handleSearch"
>查询</el-button>
<el-button @click="handleCustomCol">定制列</el-button>
<el-button @click="handleOption">
批量操作
</el-button>
</el-form-item>
</el-form>
<glsx-table
ref="tableRef"
:searchForm="searchForm"
:isCustomHead="isCustomHead"
:customHeadShowList="tableHeadShowList"
:tableParams="tableParams"
:getListApi="getListApi"
:pageConf="pageConf"
:beforeSearchFn="beforeSearchFn"
@sortChange="sortChange"
>
<span
slot="showImg"
slot-scope="scope"
>
<img
style="width: 100px; height: 100px;"
:src="scope.scope.coverPicture"
>
</span>
<span
slot="auth-button"
slot-scope="scope"
:data="scope.scope"
>
<el-button
type="text"
@click="handleAdd(scope.scope)"
>新增</el-button>
</span>
</glsx-table>
<glsx-dialog
title="定制列"
:isVisible="isHeadVisible"
@closeDialog="handleHeadClose"
@confirmDialog="handleHeadConfirm"
>
<el-checkbox-group v-model="headShowList">
<el-checkbox
v-for="(item, index) in tableParams.tableColumns"
:key="index"
:label="item.label"
:disabled="!item.hasOwnProperty('isCustomCol')"
></el-checkbox>
</el-checkbox-group>
</glsx-dialog>
</div>
</template>
<script>
import { getListApi } from '../api/test'
// import d2Table from '../components/d2-table'
import glsxDialog from '../components/glsx-dialog'
export default {
data() {
return {
searchForm: {
id: ''
},
// 定制列-弹窗
isHeadVisible: false,
headShowList: [],
// 表格组件
getListApi: getListApi,
isCustomHead: true,
tableHeadShowList: [],
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
// 表格参数
tableParams: {
listName: 'list',
// 行数据的key
mutiSelectUniqueKey: 'id',
// 多选ref的名称
mutiSelectName: 'list',
tableOption: true,
tableColumns: [{
label: 'id',
prop: 'id',
// width: '80px'
}, {
label: '标题',
prop: 'title',
line: 1,
isCustomCol: true,
sortable: true
}, {
label: '状态',
prop: 'status',
formatter: cellValue => {
return {
0: '待审核',
1: '通过',
2: '失败'
}[cellValue.status]
}
}, {
label: '图片',
isCustomCol: true,
prop: 'coverPicture',
addHtml: 'showImg'
}]
}
}
},
components: {
// d2Table,
glsxDialog
},
methods: {
// 刷新表格前的回调函数
beforeSearchFn() {
return new Promise(resolve => {
this.$message('点击查询,可在此格式化搜索项数据')
resolve()
})
},
// 弹窗
handleHeadClose() {
this.headShowList = this.tableHeadShowList
this.isHeadVisible = !this.isHeadVisible
},
handleCustomCol() {
this.handleHeadClose()
},
handleHeadConfirm() {
this.tableHeadShowList = this.headShowList
this.handleHeadClose()
},
// 刷新表格
handleSearch() {
this.$refs.tableRef.refreshTable()
},
sortChange({ column, prop, order }) {
// 添加-排序相关参数
this.searchForm.order = order
this.searchForm.sortAttr = order ? prop : null
this.handleSearch()
},
// 新增
handleAdd(row) {
this.$notify({
title: '提示',
message: '点击了id为' + row.id + '的数据'
})
this.handleSearch()
},
// 获取批量数据
handleOption() {
this.$notify({
title: '提示',
message: '当前选中的数据的id有' + this.$refs.tableRef.mutiSelectArr[this.tableParams.mutiSelectName].map(item => item.id).join(',')
})
}
}
}
</script>
<style scoped>
</style>