123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- <template>
- <div class="main-contain">
- <div class="position">
- <bread-crumb :crumbs="crumbs"></bread-crumb>
- <el-button
- type="primary"
- size="small"
- icon="el-icon-circle-plus"
- style="float:right;"
- @click="addRoleAction"
- >新增</el-button
- >
- </div>
- <div class="app-container" v-loading="loading_roles">
- <!-- <el-table
- :data="roles"
- v-loading="loading_roles"
- border
- :row-style="{ color: '#303133' }"
- :header-cell-style="{
- backgroundColor: 'rgb(245, 247, 250)',
- color: '#606266'
- }"
- >
- <el-table-column label="角色名称" prop="name" min-width="20%" align="center"></el-table-column>
- <el-table-column label="角色描述" prop="intro" min-width="25%" align="center"></el-table-column>
- <el-table-column label="状态" min-width="15%" align="center">
- <template slot-scope="scope">
- <div v-if="scope.row.status == 1" style="color: #67C23A; font-size:20px;">
- <li class="el-icon-success"></li>
- </div>
- <div v-else style="color: #F56C6C; font-size:20px;">
- <li class="el-icon-error"></li>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="180" align="center">
- <template slot-scope="scope">
- <router-link :to="{ path: '/role/perview', query: { id: scope.row.id } }">
- <el-tooltip class="item" effect="dark" content="权限设置" placement="top">
- <el-button type="warning" icon="el-icon-setting" size="small"></el-button>
- </el-tooltip>
- </router-link>
- <el-tooltip class="item" effect="dark" content="编辑" placement="top">
- <el-button
- type="primary"
- size="small"
- icon="el-icon-edit-outline"
- @click="modifyRoleAction(scope.row)"
- ></el-button>
- </el-tooltip>
-
- <el-tooltip class="item" effect="dark" content="移除" placement="top">
- <el-button
- type="danger"
- size="small"
- icon="el-icon-delete"
- v-if="scope.row.status === 1"
- @click="disableRoleAction(scope.row)"
- ></el-button>
- </el-tooltip>
-
- <el-tooltip class="item" effect="dark" content="恢复" placement="top">
- <el-button
- type="info"
- size="small"
- icon="el-icon-refresh"
- v-if="scope.row.status !== 1"
- @click="recoverRoleAction(scope.row)"
- ></el-button>
- </el-tooltip>
- </template>
- </el-table-column>
- </el-table>
-
- <el-row style="margin-top: 15px;" v-if="role_total_count > 10">
- <el-col :span="24">
- <el-pagination
- :total="role_total_count"
- :current-page.sync="current_page"
- @current-change="pageChange"
- :page-size="10"
- layout="total, prev, pager, next, jumper"
- ></el-pagination>
- </el-col>
- </el-row>-->
-
- <edit-role
- ref="edit_role"
- @did-edit-role="didModifyRole"
- ></edit-role>
-
- <add-role
- ref="add_role"
- @did-add-role="didAddRole"
- ></add-role>
-
- <permission-settings ref="permission_settings" @delete="deleteRole()"></permission-settings>
- <user-management ref="user_management"></user-management>
-
- <div class="roleTitle">
- <i class="el-icon-warning warn"></i>
- <p>
- 根据员工的职能选择角色,然后新增账号,可以自定义角色,进行权限配置
- </p>
- </div>
- <div class="roleBox">
- <div class="roleOne" v-for="item in this.roles">
- <div class="setting">
- <i class="el-icon-setting"></i>
- <span style="margin-right:20px" @click="onClick(item.id)">权限配置</span>
- </div>
- <div class="avatar">
- <img v-if="item.name == '子管理员'" src="../../assets/img/pc1.png" alt=""/>
- <img v-else-if="item.name == '医生'" src="../../assets/img/pc2.png" alt=""/>
- <img v-else-if="item.name == '护士'" src="../../assets/img/pc3.png" alt=""/>
- <img v-else-if="item.name == '库存'" src="../../assets/img/pc4.png" alt=""/>
- <img v-else-if="item.name == '院长'" src="../../assets/img/pc5.png" alt=""/>
- <img v-else-if="item.name == '运营'" src="../../assets/img/pc6.png" alt=""/>
- <img v-else-if="item.name == '技师'" src="../../assets/img/pc7.png" alt=""/>
- <img v-else src="../../assets/img/pc1.png" alt=""/>
-
-
-
- <p class="avatarname">{{item.name}}</p>
- </div>
- <div class="roleTip">
- {{item.intro}}
- </div>
- <div class="roleTxt">
- 该角色目前已配置
- <span style="color:#4A8AF3">{{item.staff_number}}</span> 个员工
- </div>
- <div class="btnBox">
- <el-button @click="addStaff(item.id)">新增用户</el-button>
- <el-button @click="onClickManagement(item.id)">用户管理</el-button>
- </div>
- </div>
-
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import EditRole from "./components/EditRole.vue";
- import PermissionSettings from "./components/PermissionSettings.vue";
- import { getRoles, setRoleStatus,getRolesList } from "@/api/role/role";
- import UserManagement from "./components/UserManagement.vue";
- import BreadCrumb from "@/xt_pages/components/bread-crumb";
- import AddRole from './components/AddRole'
-
- export default {
- components: {
- AddRole,
- EditRole,
- BreadCrumb,
- PermissionSettings,
- UserManagement
- },
- data: function() {
- return {
- crumbs: [
- { path: false, name: "权限管理" },
- { path: false, name: "角色管理" }
- ],
- loading_roles: true,
- roles: [],
- role_total_count: 0,
- current_page: 1
- };
- },
- created: function() {
- this.requestRoleWithPage(1);
- },
- methods: {
- addStaff(role_id){
- this.$refs.edit_role.show(role_id);
-
- },
- requestRoleWithPage: function(page) {
- this.roles.splice(0, this.roles.length);
- this.loading_roles = true;
- getRolesList(page)
- .then(rs => {
- this.loading_roles = false;
- const resp = rs.data;
- if (resp.state === 1) {
-
- for (let i = 0; i < resp.data.roles.length; i++) {
- if (!resp.data.roles[i].is_super_admin) {
- this.roles.push(resp.data.roles[i])
- }
- }
- // this.roles.push(...resp.data.roles);
- } else {
- this.$message.error(resp.msg);
- }
- })
- .catch(err => {
- this.loading_roles = false;
- this.$message.error(err);
- });
- },
- addRoleAction: function() {
- // 父组件调用子组件方法 https://segmentfault.com/a/1190000009525355
- this.$refs.add_role.show();
- },
- modifyRoleAction: function(row) {
- this.$refs.edit_role.modify(row.id, row.name, row.intro);
- },
- disableRoleAction: function(row) {
- this.$msgbox({
- title: "提示",
- message: "是否确定要移除该角色",
- showCancelButton: true,
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- beforeClose: (action, instance, done) => {
- if (action === "confirm") {
- instance.confirmButtonLoading = true;
- instance.confirmButtonText = "移除中...";
-
- setRoleStatus(row.id, false)
- .then(rs => {
- done();
- instance.confirmButtonLoading = false;
-
- const resp = rs.data;
- if (resp.state === 1) {
- row.status = 0;
- } else {
- this.$message.error(resp.msg);
- }
- })
- .catch(err => {
- done();
- this.$message.error(err);
- instance.confirmButtonLoading = false;
- });
- } else {
- done();
- }
- }
- });
- },
- recoverRoleAction: function(row) {
- const loading = this.$loading({
- lock: true,
- text: "正在恢复角色...",
- spinner: "el-icon-loading",
- background: "rgba(0, 0, 0, 0.7)"
- });
-
- setRoleStatus(row.id, true)
- .then(rs => {
- loading.close();
-
- const resp = rs.data;
- if (resp.state === 1) {
- row.status = 1;
- } else {
- this.$message.error(resp.msg);
- }
- })
- .catch(err => {
- loading.close();
- this.$message.error(err);
- });
- },
- didAddRole: function(id, name, intro, status,staff_number) {
- this.roles.push({ id: id, name: name, intro: intro, status: status ,staff_number: staff_number});
- },
- didModifyRole: function() {
- this.requestRoleWithPage(1);
-
- },
- pageChange: function(nextPage) {
- this.requestRoleWithPage(nextPage);
- },
- ///
-
- onClick(role_id) {
- this.$refs.permission_settings.show(role_id);
- },
- onClickManagement(role_id) {
- this.$refs.user_management.show(role_id);
- },deleteRole(){
- this.$refs.permission_settings.hide();
- this.requestRoleWithPage(1);
- }
- }
- };
- </script>
- <style rel="stylesheet/scss" lang="scss" scoped>
- .el-button + .el-button {
- margin-left: 0 !important;
- }
- .roleTitle {
- display: flex;
- align-items: center;
- font-size: 14px;
- margin-bottom: 24px;
- .warn {
- font-size: 18px;
- color: #409eff;
- margin-right: 5px;
- }
- }
- .roleBox {
- display: flex;
- flex-wrap: wrap;
- .roleOne {
- width: 280px;
- height: 350px;
- margin: 0 15px 20px;
- border: 1px solid rgba(235, 238, 240, 1);
- border-radius: 4px;
- overflow: hidden;
- }
- .setting {
- // float: right;
- text-align: right;
- margin-right: 20px;
- margin-top: 20px;
- width: 100%;
- color: #313234;
- }
- .avatar {
- width: 100%;
- display: flex;
- justify-content: space-around;
- flex-direction: column;
- align-items: center;
- img {
- width: 60px;
- height: 60px;
- margin: 10px 0;
- }
- .avatarname {
- font-size: 18px;
- }
- }
- .roleTip {
- width: 82%;
- margin: 20px auto 10px;
- font-size: 14px;
- color: #989898;
- }
- .roleTxt {
- width: 82%;
- margin: 0 auto;
- font-size: 14px;
- color: #666666;
- }
- .btnBox {
- width: 82%;
- margin: 0 auto;
- display: flex;
- justify-content: space-between;
- margin-top: 50px;
- }
- }
- </style>
- <style>
- .el-table td,
- .el-table th.is-leaf,
- .el-table--border,
- .el-table--group {
- border-color: #d0d3da;
- }
- .el-table--border::after,
- .el-table--group::after,
- .el-table::before {
- background-color: #d0d3da;
- }
- </style>
|