Skip to content

Commit 158af41

Browse files
committed
fix(control): 获取用户角色
1 parent c4398d5 commit 158af41

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

admin/src/views/user/index.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,25 @@
1717
{{ scope.row.id }}
1818
</template>
1919
</el-table-column>
20-
<el-table-column label="用户名称">
20+
21+
<el-table-column label="用户昵称">
2122
<template slot-scope="scope">
2223
{{ scope.row.name }}
2324
</template>
2425
</el-table-column>
2526

27+
<el-table-column label="邮箱">
28+
<template slot-scope="scope">
29+
{{ scope.row.email }}
30+
</template>
31+
</el-table-column>
32+
33+
<el-table-column label="分配的角色">
34+
<template slot-scope="scope">
35+
<el-tag v-for="role in scope.row.roles" :key="role.id">{{ role.name }}</el-tag>
36+
</template>
37+
</el-table-column>
38+
2639
<el-table-column align="center" prop="created_at" label="创建时间" width="">
2740
<template slot-scope="scope">
2841
<i class="el-icon-time"/>
@@ -178,4 +191,7 @@ export default {
178191
.pagination {
179192
margin: 20px auto;
180193
}
194+
.el-tag {
195+
margin: 0 5px;
196+
}
181197
</style>

laravel/app/Http/Controllers/Api/UserController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function __construct()
3737
public function index()
3838
{
3939
$list = User::paginate(11);
40+
foreach ($list as $key => $item) {
41+
$list[$key]['roles'] = $item->roles;
42+
}
4043
return $this->out(200, $list);
4144
}
4245

0 commit comments

Comments
 (0)