UserRoleManager.vue
4.13 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
<template>
<ht-sidebar-dialog
title="分配角色用户"
:visible="dialogVisible"
width="1040px"
:before-close="handleClose"
:close-on-click-modal="false"
append-to-body
>
<ht-table
v-if="dialogVisible"
@load="loadData"
:data="data"
:pageResult="pageResult"
:selection="true"
:show-export="false"
:show-custom-column="false"
:quick-search-props="[
{prop: 'u.fullname_', label: '姓名'},
{prop: 'u.account_', label: '账号'}
]"
ref="userRoleTable"
@selection-change="handleSelectionChange"
>
<template v-slot:toolbar>
<el-button-group>
<el-button
size="small"
type="primary"
@click="showUserDialog()"
icon="el-icon-plus"
>加入用户</el-button
>
<ht-delete-button
:url="roleDeleteUrl"
:htTable="$refs.userRoleTable"
pk="account"
parameter="accounts"
:disabled="isDisabled"
>删除</ht-delete-button
>
</el-button-group>
</template>
<template>
<ht-table-column type="index" width="50" align="center" label="序号" />
<ht-table-column prop="id" label="主键" :sortable="true" hidden />
<ht-table-column
prop="fullname"
label="用户名称"
width="300"
:sortable="true"
:show-overflow-tooltip="true"
/>
<ht-table-column prop="account" label="账号" :sortable="true" />
<ht-table-column prop="email" label="邮箱" />
<ht-table-column prop="mobile" label="手机号码" />
</template>
</ht-table>
<ht-user-dialog
ref="eipUserDialog"
@on-confirm="userDialogOnConfirm"
append-to-body
/>
</ht-sidebar-dialog>
</template>
<script>
import uc from '@/api/uc.js'
import EipUserDialog from '@/components/dialog/EipUserDialog.vue'
export default {
props: {},
components: {
EipUserDialog
},
computed: {
roleDeleteUrl: function() {
return `${window.context.uc}/api/role/v1/roleUser/deleteUserRole?code=${this.roleCode}`
}
},
data() {
return {
dialogVisible: false,
isSubmit: true,
data: [],
pageResult: {
page: 1,
pageSize: 50,
total: 0
},
roleCode: '',
selectedList: [],
isDisabled: true
}
},
watch: {
selectedList: {
handler(val) {
this.isDisabled = val.length < 1 ? true : false
},
deep: true
}
},
created() {},
methods: {
handleClose() {
this.dialogVisible = false
},
showDialog(roleCode) {
this.roleCode = roleCode
this.dialogVisible = true
},
dialogCancle() {
this.dialogVisible = false
},
loadData(param, cb) {
uc.getRoleUsers(this.roleCode, param)
.then(response => {
this.data = response.rows
this.pageResult = {
page: response.page,
pageSize: response.pageSize,
total: response.total
}
})
.finally(() => cb())
},
showUserDialog() {
this.$refs.eipUserDialog.showDialog()
},
userDialogOnConfirm(selection) {
if (!selection || selection.length == 0) {
this.$message.error('请至少选择一个用户')
return
}
let accounts = []
for (let user of selection) {
accounts.push(user.account)
}
let param = {}
param.code = this.roleCode
param.accounts = accounts.join(',')
uc.saveUserRole(param).then(data => {
if (data.state) {
this.$message({
message: data.message,
type: 'success',
showClose: true
})
this.$refs.userRoleTable.load()
return
}
this.$message.error(data.message || '分配用户失败')
})
},
handleSelectionChange(selection) {
this.selectedList = selection
}
}
}
</script>
<style scoped>
div[aria-invalid='true'] >>> .el-input__inner,
div[aria-invalid='true'] >>> .el-input__inner:focus {
border-color: #f56c6c;
}
</style>