25
25
<!-- usernameHeader -->
26
26
<template #usernameHeader =" scope " >
27
27
<el-button type =" primary" @click =" ElMessage.success('我是通过作用域插槽渲染的表头')" >
28
- {{ scope.row .label }}
28
+ {{ scope.column .label }}
29
29
</el-button >
30
30
</template >
31
31
<!-- createTime -->
51
51
import { ref , reactive } from " vue" ;
52
52
import { useRouter } from " vue-router" ;
53
53
import { User } from " @/api/interface" ;
54
- import { ColumnProps } from " @/components/ProTable/interface" ;
55
54
import { useHandleData } from " @/hooks/useHandleData" ;
56
55
import { useDownload } from " @/hooks/useDownload" ;
57
56
import { useAuthButtons } from " @/hooks/useAuthButtons" ;
58
57
import { ElMessage , ElMessageBox } from " element-plus" ;
59
58
import ProTable from " @/components/ProTable/index.vue" ;
60
59
import ImportExcel from " @/components/ImportExcel/index.vue" ;
61
60
import UserDrawer from " @/views/proTable/components/UserDrawer.vue" ;
61
+ import { ProTableInstance , ColumnProps , HeaderRenderScope } from " @/components/ProTable/interface" ;
62
62
import { CirclePlus , Delete , EditPen , Download , Upload , View , Refresh } from " @element-plus/icons-vue" ;
63
63
import {
64
64
getUserList ,
@@ -81,7 +81,7 @@ const toDetail = () => {
81
81
};
82
82
83
83
// 获取 ProTable 元素,调用其获取刷新数据方法(还能获取到当前查询参数,方便导出携带参数)
84
- const proTable = ref ();
84
+ const proTable = ref < ProTableInstance > ();
85
85
86
86
// 如果表格需要初始化请求参数,直接定义传给 ProTable(之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
87
87
const initParam = reactive ({ type: 1 });
@@ -111,10 +111,10 @@ const getTableList = (params: any) => {
111
111
const { BUTTONS } = useAuthButtons ();
112
112
113
113
// 自定义渲染表头(使用tsx语法)
114
- const headerRender = (row : ColumnProps ) => {
114
+ const headerRender = (scope : HeaderRenderScope < User . ResUserList > ) => {
115
115
return (
116
116
<el-button type = " primary" onClick = { () => ElMessage .success (" 我是通过 tsx 语法渲染的表头" )} >
117
- { row .label }
117
+ { scope . column .label }
118
118
</el-button >
119
119
);
120
120
};
@@ -210,32 +210,32 @@ const columns: ColumnProps<User.ResUserList>[] = [
210
210
// 删除用户信息
211
211
const deleteAccount = async (params : User .ResUserList ) => {
212
212
await useHandleData (deleteUser , { id: [params .id ] }, ` 删除【${params .username }】用户 ` );
213
- proTable .value .getTableList ();
213
+ proTable .value ? .getTableList ();
214
214
};
215
215
216
216
// 批量删除用户信息
217
217
const batchDelete = async (id : string []) => {
218
218
await useHandleData (deleteUser , { id }, " 删除所选用户信息" );
219
- proTable .value .clearSelection ();
220
- proTable .value .getTableList ();
219
+ proTable .value ? .clearSelection ();
220
+ proTable .value ? .getTableList ();
221
221
};
222
222
223
223
// 重置用户密码
224
224
const resetPass = async (params : User .ResUserList ) => {
225
225
await useHandleData (resetUserPassWord , { id: params .id }, ` 重置【${params .username }】用户密码 ` );
226
- proTable .value .getTableList ();
226
+ proTable .value ? .getTableList ();
227
227
};
228
228
229
229
// 切换用户状态
230
230
const changeStatus = async (row : User .ResUserList ) => {
231
231
await useHandleData (changeUserStatus , { id: row .id , status: row .status == 1 ? 0 : 1 }, ` 切换【${row .username }】用户状态 ` );
232
- proTable .value .getTableList ();
232
+ proTable .value ? .getTableList ();
233
233
};
234
234
235
235
// 导出用户列表
236
236
const downloadFile = async () => {
237
237
ElMessageBox .confirm (" 确认导出用户数据?" , " 温馨提示" , { type: " warning" }).then (() =>
238
- useDownload (exportUserInfo , " 用户列表" , proTable .value .searchParam )
238
+ useDownload (exportUserInfo , " 用户列表" , proTable .value ? .searchParam )
239
239
);
240
240
};
241
241
@@ -246,7 +246,7 @@ const batchAdd = () => {
246
246
title: " 用户" ,
247
247
tempApi: exportUserInfo ,
248
248
importApi: BatchAddUser ,
249
- getTableList: proTable .value .getTableList
249
+ getTableList: proTable .value ? .getTableList
250
250
};
251
251
dialogRef .value ?.acceptParams (params );
252
252
};
@@ -259,7 +259,7 @@ const openDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
259
259
isView: title === " 查看" ,
260
260
row: { ... row },
261
261
api: title === " 新增" ? addUser : title === " 编辑" ? editUser : undefined ,
262
- getTableList: proTable .value .getTableList
262
+ getTableList: proTable .value ? .getTableList
263
263
};
264
264
drawerRef .value ?.acceptParams (params );
265
265
};
0 commit comments