-
admin
2024-06-04 a759f5fd41414651325494926583843568bac334
提交 | 用户 | 时间
e57a89 1 <template>
2   <div class="app-container">
3     <h4 class="form-header h4">基本信息</h4>
4     <el-form ref="form" :model="form" label-width="80px">
5       <el-row>
6         <el-col :span="8" :offset="2">
7           <el-form-item label="用户昵称" prop="nickName">
8             <el-input v-model="form.nickName" disabled />
9           </el-form-item>
10         </el-col>
11         <el-col :span="8" :offset="2">
12           <el-form-item label="登录账号" prop="userName">
13             <el-input  v-model="form.userName" disabled />
14           </el-form-item>
15         </el-col>
16       </el-row>
17     </el-form>
18
19     <h4 class="form-header h4">角色信息</h4>
20     <el-table v-loading="loading" :row-key="getRowKey" @row-click="clickRow" ref="table" @selection-change="handleSelectionChange" :data="roles.slice((pageNum-1)*pageSize,pageNum*pageSize)">
21       <el-table-column label="序号" type="index" align="center">
22         <template slot-scope="scope">
23           <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
24         </template>
25       </el-table-column>
26       <el-table-column type="selection" :reserve-selection="true" width="55"></el-table-column>
27       <el-table-column label="角色编号" align="center" prop="roleId" />
28       <el-table-column label="角色名称" align="center" prop="roleName" />
29       <el-table-column label="权限字符" align="center" prop="roleKey" />
30       <el-table-column label="创建时间" align="center" prop="createTime" width="180">
31         <template slot-scope="scope">
32           <span>{{ parseTime(scope.row.createTime) }}</span>
33         </template>
34       </el-table-column>
35     </el-table>
36
37     <pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" />
38
39     <el-form label-width="100px">
40       <el-form-item style="text-align: center;margin-left:-120px;margin-top:30px;">
41         <el-button type="primary" @click="submitForm()">提交</el-button>
42         <el-button @click="close()">返回</el-button>
43       </el-form-item>
44     </el-form>
45   </div>
46 </template>
47
48 <script>
49 import { getAuthRole, updateAuthRole } from "@/api/system/user";
50
51 export default {
52   name: "AuthRole",
53   data() {
54     return {
55        // 遮罩层
56       loading: true,
57       // 分页信息
58       total: 0,
59       pageNum: 1,
60       pageSize: 10,
61       // 选中角色编号
62       roleIds:[],
63       // 角色信息
64       roles: [],
65       // 用户信息
66       form: {}
67     };
68   },
69   created() {
70     const userId = this.$route.params && this.$route.params.userId;
71     if (userId) {
72       this.loading = true;
73       getAuthRole(userId).then((response) => {
74         this.form = response.user;
75         this.roles = response.roles;
76         this.total = this.roles.length;
77         this.$nextTick(() => {
78           this.roles.forEach((row) => {
79             if (row.flag) {
80               this.$refs.table.toggleRowSelection(row);
81             }
82           });
83         });
84         this.loading = false;
85       });
86     }
87   },
88   methods: {
89     /** 单击选中行数据 */
90     clickRow(row) {
91       this.$refs.table.toggleRowSelection(row);
92     },
93     // 多选框选中数据
94     handleSelectionChange(selection) {
95       this.roleIds = selection.map((item) => item.roleId);
96     },
97     // 保存选中的数据编号
98     getRowKey(row) {
99       return row.roleId;
100     },
101     /** 提交按钮 */
102     submitForm() {
103       const userId = this.form.userId;
104       const roleIds = this.roleIds.join(",");
105       updateAuthRole({ userId: userId, roleIds: roleIds }).then((response) => {
106         this.$modal.msgSuccess("授权成功");
107         this.close();
108       });
109     },
110     /** 关闭按钮 */
111     close() {
112       const obj = { path: "/system/user" };
113       this.$tab.closeOpenPage(obj);
114     },
115   },
116 };
117 </script>