autoTable.vue
3.2 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
<!-- 传入接口名称,自动调用接口,并更新表格数据 -->
<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="handleOption">
批量操作
</el-button>
</el-form-item>
</el-form>
<glsx-table
ref="tableRef"
:searchForm="searchForm"
: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>
</div>
</template>
<script>
import { getListApi } from '../api/test'
export default {
data() {
return {
searchForm: {
id: ''
},
getListApi: getListApi,
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,
sortable: true
}, {
label: '状态',
prop: 'status',
formatter: cellValue => {
return {
0: '待审核',
1: '通过',
2: '失败'
}[cellValue.status]
}
}, {
label: '图片',
prop: 'coverPicture',
addHtml: 'showImg'
}]
}
}
},
methods: {
// 刷新表格前的回调函数
beforeSearchFn() {
return new Promise(resolve => {
this.$message('点击查询,可在此格式化搜索项数据')
resolve()
})
},
// 刷新表格
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>