role.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb :crumbs="crumbs"></bread-crumb>
  5. <el-button
  6. type="primary"
  7. size="small"
  8. icon="el-icon-circle-plus"
  9. style="float:right;"
  10. @click="addRoleAction"
  11. >新增</el-button
  12. >
  13. </div>
  14. <div class="app-container" v-loading="loading_roles">
  15. <!-- <el-table
  16. :data="roles"
  17. v-loading="loading_roles"
  18. border
  19. :row-style="{ color: '#303133' }"
  20. :header-cell-style="{
  21. backgroundColor: 'rgb(245, 247, 250)',
  22. color: '#606266'
  23. }"
  24. >
  25. <el-table-column label="角色名称" prop="name" min-width="20%" align="center"></el-table-column>
  26. <el-table-column label="角色描述" prop="intro" min-width="25%" align="center"></el-table-column>
  27. <el-table-column label="状态" min-width="15%" align="center">
  28. <template slot-scope="scope">
  29. <div v-if="scope.row.status == 1" style="color: #67C23A; font-size:20px;">
  30. <li class="el-icon-success"></li>
  31. </div>
  32. <div v-else style="color: #F56C6C; font-size:20px;">
  33. <li class="el-icon-error"></li>
  34. </div>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="操作" width="180" align="center">
  38. <template slot-scope="scope">
  39. <router-link :to="{ path: '/role/perview', query: { id: scope.row.id } }">
  40. <el-tooltip class="item" effect="dark" content="权限设置" placement="top">
  41. <el-button type="warning" icon="el-icon-setting" size="small"></el-button>
  42. </el-tooltip>
  43. </router-link>
  44. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  45. <el-button
  46. type="primary"
  47. size="small"
  48. icon="el-icon-edit-outline"
  49. @click="modifyRoleAction(scope.row)"
  50. ></el-button>
  51. </el-tooltip>
  52. <el-tooltip class="item" effect="dark" content="移除" placement="top">
  53. <el-button
  54. type="danger"
  55. size="small"
  56. icon="el-icon-delete"
  57. v-if="scope.row.status === 1"
  58. @click="disableRoleAction(scope.row)"
  59. ></el-button>
  60. </el-tooltip>
  61. <el-tooltip class="item" effect="dark" content="恢复" placement="top">
  62. <el-button
  63. type="info"
  64. size="small"
  65. icon="el-icon-refresh"
  66. v-if="scope.row.status !== 1"
  67. @click="recoverRoleAction(scope.row)"
  68. ></el-button>
  69. </el-tooltip>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <el-row style="margin-top: 15px;" v-if="role_total_count > 10">
  74. <el-col :span="24">
  75. <el-pagination
  76. :total="role_total_count"
  77. :current-page.sync="current_page"
  78. @current-change="pageChange"
  79. :page-size="10"
  80. layout="total, prev, pager, next, jumper"
  81. ></el-pagination>
  82. </el-col>
  83. </el-row>-->
  84. <edit-role
  85. ref="edit_role"
  86. @did-edit-role="didModifyRole"
  87. ></edit-role>
  88. <add-role
  89. ref="add_role"
  90. @did-add-role="didAddRole"
  91. ></add-role>
  92. <permission-settings ref="permission_settings" @delete="deleteRole()"></permission-settings>
  93. <user-management ref="user_management"></user-management>
  94. <div class="roleTitle">
  95. <i class="el-icon-warning warn"></i>
  96. <p>
  97. 根据员工的职能选择角色,然后新增账号,可以自定义角色,进行权限配置
  98. </p>
  99. </div>
  100. <div class="roleBox">
  101. <div class="roleOne" v-for="item in this.roles">
  102. <div class="setting">
  103. <i class="el-icon-setting"></i>
  104. <span style="margin-right:20px" @click="onClick(item.id)">权限配置</span>
  105. </div>
  106. <div class="avatar">
  107. <img v-if="item.name == '子管理员'" src="../../assets/img/pc1.png" alt=""/>
  108. <img v-else-if="item.name == '医生'" src="../../assets/img/pc2.png" alt=""/>
  109. <img v-else-if="item.name == '护士'" src="../../assets/img/pc3.png" alt=""/>
  110. <img v-else-if="item.name == '库存'" src="../../assets/img/pc4.png" alt=""/>
  111. <img v-else-if="item.name == '院长'" src="../../assets/img/pc5.png" alt=""/>
  112. <img v-else-if="item.name == '运营'" src="../../assets/img/pc6.png" alt=""/>
  113. <img v-else-if="item.name == '技师'" src="../../assets/img/pc7.png" alt=""/>
  114. <img v-else src="../../assets/img/pc1.png" alt=""/>
  115. <p class="avatarname">{{item.name}}</p>
  116. </div>
  117. <div class="roleTip">
  118. {{item.intro}}
  119. </div>
  120. <div class="roleTxt">
  121. 该角色目前已配置
  122. <span style="color:#4A8AF3">{{item.staff_number}}</span> 个员工
  123. </div>
  124. <div class="btnBox">
  125. <el-button @click="addStaff(item.id)">新增用户</el-button>
  126. <el-button @click="onClickManagement(item.id)">用户管理</el-button>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </template>
  133. <script>
  134. import EditRole from "./components/EditRole.vue";
  135. import PermissionSettings from "./components/PermissionSettings.vue";
  136. import { getRoles, setRoleStatus,getRolesList } from "@/api/role/role";
  137. import UserManagement from "./components/UserManagement.vue";
  138. import BreadCrumb from "@/xt_pages/components/bread-crumb";
  139. import AddRole from './components/AddRole'
  140. export default {
  141. components: {
  142. AddRole,
  143. EditRole,
  144. BreadCrumb,
  145. PermissionSettings,
  146. UserManagement
  147. },
  148. data: function() {
  149. return {
  150. crumbs: [
  151. { path: false, name: "权限管理" },
  152. { path: false, name: "角色管理" }
  153. ],
  154. loading_roles: true,
  155. roles: [],
  156. role_total_count: 0,
  157. current_page: 1
  158. };
  159. },
  160. created: function() {
  161. this.requestRoleWithPage(1);
  162. },
  163. methods: {
  164. addStaff(role_id){
  165. this.$refs.edit_role.show(role_id);
  166. },
  167. requestRoleWithPage: function(page) {
  168. this.roles.splice(0, this.roles.length);
  169. this.loading_roles = true;
  170. getRolesList(page)
  171. .then(rs => {
  172. this.loading_roles = false;
  173. const resp = rs.data;
  174. if (resp.state === 1) {
  175. for (let i = 0; i < resp.data.roles.length; i++) {
  176. if (!resp.data.roles[i].is_super_admin) {
  177. this.roles.push(resp.data.roles[i])
  178. }
  179. }
  180. // this.roles.push(...resp.data.roles);
  181. } else {
  182. this.$message.error(resp.msg);
  183. }
  184. })
  185. .catch(err => {
  186. this.loading_roles = false;
  187. this.$message.error(err);
  188. });
  189. },
  190. addRoleAction: function() {
  191. // 父组件调用子组件方法 https://segmentfault.com/a/1190000009525355
  192. this.$refs.add_role.show();
  193. },
  194. modifyRoleAction: function(row) {
  195. this.$refs.edit_role.modify(row.id, row.name, row.intro);
  196. },
  197. disableRoleAction: function(row) {
  198. this.$msgbox({
  199. title: "提示",
  200. message: "是否确定要移除该角色",
  201. showCancelButton: true,
  202. confirmButtonText: "确定",
  203. cancelButtonText: "取消",
  204. type: "warning",
  205. beforeClose: (action, instance, done) => {
  206. if (action === "confirm") {
  207. instance.confirmButtonLoading = true;
  208. instance.confirmButtonText = "移除中...";
  209. setRoleStatus(row.id, false)
  210. .then(rs => {
  211. done();
  212. instance.confirmButtonLoading = false;
  213. const resp = rs.data;
  214. if (resp.state === 1) {
  215. row.status = 0;
  216. } else {
  217. this.$message.error(resp.msg);
  218. }
  219. })
  220. .catch(err => {
  221. done();
  222. this.$message.error(err);
  223. instance.confirmButtonLoading = false;
  224. });
  225. } else {
  226. done();
  227. }
  228. }
  229. });
  230. },
  231. recoverRoleAction: function(row) {
  232. const loading = this.$loading({
  233. lock: true,
  234. text: "正在恢复角色...",
  235. spinner: "el-icon-loading",
  236. background: "rgba(0, 0, 0, 0.7)"
  237. });
  238. setRoleStatus(row.id, true)
  239. .then(rs => {
  240. loading.close();
  241. const resp = rs.data;
  242. if (resp.state === 1) {
  243. row.status = 1;
  244. } else {
  245. this.$message.error(resp.msg);
  246. }
  247. })
  248. .catch(err => {
  249. loading.close();
  250. this.$message.error(err);
  251. });
  252. },
  253. didAddRole: function(id, name, intro, status,staff_number) {
  254. this.roles.push({ id: id, name: name, intro: intro, status: status ,staff_number: staff_number});
  255. },
  256. didModifyRole: function() {
  257. this.requestRoleWithPage(1);
  258. },
  259. pageChange: function(nextPage) {
  260. this.requestRoleWithPage(nextPage);
  261. },
  262. ///
  263. onClick(role_id) {
  264. this.$refs.permission_settings.show(role_id);
  265. },
  266. onClickManagement(role_id) {
  267. this.$refs.user_management.show(role_id);
  268. },deleteRole(){
  269. this.$refs.permission_settings.hide();
  270. this.requestRoleWithPage(1);
  271. }
  272. }
  273. };
  274. </script>
  275. <style rel="stylesheet/scss" lang="scss" scoped>
  276. .el-button + .el-button {
  277. margin-left: 0 !important;
  278. }
  279. .roleTitle {
  280. display: flex;
  281. align-items: center;
  282. font-size: 14px;
  283. margin-bottom: 24px;
  284. .warn {
  285. font-size: 18px;
  286. color: #409eff;
  287. margin-right: 5px;
  288. }
  289. }
  290. .roleBox {
  291. display: flex;
  292. flex-wrap: wrap;
  293. .roleOne {
  294. width: 280px;
  295. height: 350px;
  296. margin: 0 15px 20px;
  297. border: 1px solid rgba(235, 238, 240, 1);
  298. border-radius: 4px;
  299. overflow: hidden;
  300. }
  301. .setting {
  302. // float: right;
  303. text-align: right;
  304. margin-right: 20px;
  305. margin-top: 20px;
  306. width: 100%;
  307. color: #313234;
  308. }
  309. .avatar {
  310. width: 100%;
  311. display: flex;
  312. justify-content: space-around;
  313. flex-direction: column;
  314. align-items: center;
  315. img {
  316. width: 60px;
  317. height: 60px;
  318. margin: 10px 0;
  319. }
  320. .avatarname {
  321. font-size: 18px;
  322. }
  323. }
  324. .roleTip {
  325. width: 82%;
  326. margin: 20px auto 10px;
  327. font-size: 14px;
  328. color: #989898;
  329. }
  330. .roleTxt {
  331. width: 82%;
  332. margin: 0 auto;
  333. font-size: 14px;
  334. color: #666666;
  335. }
  336. .btnBox {
  337. width: 82%;
  338. margin: 0 auto;
  339. display: flex;
  340. justify-content: space-between;
  341. margin-top: 50px;
  342. }
  343. }
  344. </style>
  345. <style>
  346. .el-table td,
  347. .el-table th.is-leaf,
  348. .el-table--border,
  349. .el-table--group {
  350. border-color: #d0d3da;
  351. }
  352. .el-table--border::after,
  353. .el-table--group::after,
  354. .el-table::before {
  355. background-color: #d0d3da;
  356. }
  357. </style>