TenantAdminDrawer.vue
6.22 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<template>
<BasicDrawer
v-bind="$attrs"
@register="tenantAdminDrawer"
showFooter
title="租户管理员"
width="60%"
@ok="handleSubmit"
>
<BasicTable @register="tenantAdminTable">
<template #toolbar>
<a-button type="primary" @click="handleCreateTenantAdmin">新增租户管理员</a-button>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '短信激活',
icon: 'ant-design:send-outlined',
tooltip: '发送激活短信',
ifShow: record.phoneNumber != null && !record.hasPassword,
onClick: handleSendMsg.bind(null, record),
},
{
label: '清除密码',
icon: 'ant-design:clear-outlined',
tooltip: '清除密码',
ifShow: record.hasPassword,
onClick: handleResetPassword.bind(null, record),
},
{
label: '编辑',
icon: 'clarity:note-edit-line',
tooltip: '编辑',
onClick: handleEdit.bind(null, record),
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
tooltip: '删除',
color: 'error',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
},
},
]"
/>
</template>
<template #status="{ record }">
<Tag
:color="
record.userStatusEnum === 'NORMAL'
? 'green'
: record.userStatusEnum === 'DISABLED'
? 'red'
: 'orange'
"
>
{{
record.userStatusEnum === 'NORMAL'
? '正常'
: record.userStatusEnum === 'DISABLED'
? '已禁用'
: '已过期'
}}
</Tag>
</template>
</BasicTable>
<TenantAdminFormDrawer @register="tenantAdminFormDrawer" @success="handleSuccess" />
</BasicDrawer>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { BasicDrawer, useDrawer, useDrawerInner } from '/@/components/Drawer';
import { BasicColumn, BasicTable, TableAction, useTable } from '/@/components/Table';
import {
deleteTenantAdmin,
getTenantAdminPage,
resetPassword,
sendMessageOrEmail,
} from '/@/api/tenant/tenantApi';
import { Tag } from 'ant-design-vue';
import TenantAdminFormDrawer from './TenantAdminFormDrawer.vue';
import { MessageTypeEnum, SendResetPasswordEmailMsg } from '/@/api/tenant/tenantInfo';
import { useMessage } from '/@/hooks/web/useMessage';
import { RoleEnum } from '/@/enums/roleEnum';
export default defineComponent({
name: 'TenantAdminDrawer',
components: {
BasicDrawer,
BasicTable,
TenantAdminFormDrawer,
Tag,
TableAction,
},
emits: ['register'],
setup() {
const { createMessage } = useMessage();
const [tenantAdminFormDrawer, { openDrawer: openTenantAdminFormDrawer }] = useDrawer();
const tenantId = ref('');
async function handleCreateTenantAdmin() {
const { items: getPageData } = await getTenantAdminPage({
page: 1,
pageSize: 1000,
tenantId: tenantId.value,
roleType: RoleEnum.TENANT_ADMIN,
tenantCode: '',
});
openTenantAdminFormDrawer(true, {
isUpdate: false,
tenantId: tenantId.value,
judgeExistUserName: getPageData,
});
}
function handleEdit(record: Recordable) {
openTenantAdminFormDrawer(true, {
isUpdate: true,
record,
tenantId: tenantId.value,
});
}
function handleDelete(record: Recordable) {
deleteTenantAdmin([record.id]).then(() => {
createMessage.success('删除成功');
handleSuccess();
});
}
function handleResetPassword(record: Recordable) {
resetPassword(record.id);
createMessage.success('清空密码成功');
handleSuccess();
}
function handleSendMsg(record: Recordable) {
const req = new SendResetPasswordEmailMsg(record.id, MessageTypeEnum.PHONE_MESSAGE);
sendMessageOrEmail(req).then(() => {
createMessage.success('短信发送成功');
handleSuccess();
});
}
const tenantAdminColumns = [
{
title: '用户名',
dataIndex: 'username',
width: 50,
},
{
title: '真实名字',
dataIndex: 'realName',
width: 50,
},
{
title: '电话号码',
dataIndex: 'phoneNumber',
width: 50,
},
{
title: '邮箱',
dataIndex: 'email',
width: 70,
},
{
title: '状态',
dataIndex: 'userStatus',
width: 30,
slots: { customRender: 'status' },
},
];
const [tenantAdminTable, { reload }] = useTable({
api: getTenantAdminPage,
columns: tenantAdminColumns as BasicColumn[],
showTableSetting: true,
bordered: true,
showIndexColumn: false,
searchInfo: {
tenantId,
roleType: RoleEnum.TENANT_ADMIN,
},
actionColumn: {
width: 100,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: 'right',
},
});
//默认传递页面数据
const [tenantAdminDrawer, { closeDrawer }] = useDrawerInner(async (data) => {
tenantId.value = data.record.tenantId;
reload();
});
//提交按钮
async function handleSubmit() {
closeDrawer(); //关闭侧框
}
function handleSuccess() {
reload();
}
return {
tenantAdminDrawer,
handleCreateTenantAdmin,
handleSubmit,
tenantAdminTable,
tenantId,
tenantAdminFormDrawer,
handleSuccess,
handleEdit,
handleDelete,
handleResetPassword,
handleSendMsg,
};
},
});
</script>