<template>
  <div>
    <table class='table table-striped'>
      <thead>
        <tr>
          <th scope='col'>状态</th>
          <th scope='col'>员工姓名</th>
          <th scope='col'>角色名称</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for='item in list' :key='item.eid'>
          <th scope='row'>{{item.status === 1 ? '正常' : '未入职'}}</th>
          <td>{{item.ename}}</td>
          <td>{{item.rname}}</td>
          <td>
            <div class='btn-group btn-group-sm' role='group' aria-label='Basic example'>
              <button type='button' class='btn btn-secondary' data-toggle='modal' data-target='#exampleModal'
                data-whatever='@mdo' @click='findAllRole(item)'>配置角色</button>
            </div>
          </td>
        </tr>
      </tbody>
    </table>
    <div class='modal fade' id='exampleModal' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel'
      aria-hidden='true'>
      <div class='modal-dialog' role='document'>
        <div class='modal-content'>
          <div class='modal-header'>
            <h5 class='modal-title' id='exampleModalLabel'>配置角色</h5>
            <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
              <span aria-hidden='true'>&times;</span>
            </button>
          </div>
          <div class='modal-body'>
            <div class='col-md-12'>
              <div class='form-group'>
                <label for='recipient-name' class='col-form-label'>员工姓名:</label>
                <input v-model='formData.ename' class='form-control form-control-lg' type='text'>
                <label for='recipient-name' class='col-form-label'>角色名称:</label>
                <select v-model='formData.rid' class='custom-select custom-select-lg mb-3'>
                  <option :value='items.rid' v-for='items in roleList' :key='items.rid'>{{items.rname}}</option>
                </select>
              </div>
            </div>
          </div>
          <div class='modal-footer'>
            <button type='button' class='btn btn-secondary' id='cancel' data-dismiss='modal'>取消</button>
            <button type='button' class='btn btn-primary' @click='modifyRoleByEid'>提交</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios';

export default {
  data() {
    return {
      list: [],
      roleList: [],
      formData: {
        ename: '',
        rid: ''
      }
    };
  },
  mounted() {
    this.findAllEmp();
  },
  methods: {
    modifyRoleByEid() {
      axios.post('/emp/saveRoleAndEmp', this.formData).then((resp) => {
        $('#cancel').click();
        this.findAllEmp();
      });
    },
    findAllRole(item) {
      this.formData = item;
      axios.get('/role/findAllRole').then((resp) => {
        this.roleList = resp.data;
      });
    },
    findAllEmp() {
      axios.get('/emp/findAllEmp').then((resp) => {
        this.list = resp.data;
      });
    }
  }
};
</script>
Vue 权限配置:基于后端数据实现员工角色管理

原文地址: https://www.cveoy.top/t/topic/oNsk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录