<repo_name>ytxfate/authority_manager_front<file_sep>/src/api/authority/user_manager.js
import request from '@/utils/request'

export function getUsersInfo(params, data) {
  return request({
    url: '/authority/get_users_info',
    method: 'post',
    params,
    data
  })
}

export function deleteUser(params) {
  return request({
    url: '/authority/delete_user',
    method: 'get',
    params
  })
}

export function getAllRoles() {
  return request({
    url: '/authority/get_all_roles',
    method: 'get'
  })
}

export function getUserRoles(params) {
  return request({
    url: '/authority/get_user_roles',
    method: 'get',
    params
  })
}

export function userRelateRoles(data) {
  return request({
    url: '/authority/user_relate_roles',
    method: 'post',
    data
  })
}
<file_sep>/src/utils/request.js
import axios from 'axios'
import { Message } from 'element-ui'
import store from '@/store'

// create an axios instance
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// request interceptor
service.interceptors.request.use(
  config => {
    // do something before request is sent

    if (store.getters.token) {
      config.headers['Authorization'] = store.getters.token
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
let isRefreshing = false
let requests = []

// response interceptor
service.interceptors.response.use(
  response => {
    const res = response.data
    if (res.code === 200) {
      return res
    } else if (res.code === 1200) {
      Message({
        message: res.msg || '请登录',
        type: 'warning',
        duration: 2 * 1000
      })
      store.dispatch('user/resetToken').then(() => {
        setTimeout(() => location.reload(), 2000)
      })
    } else if (res.code === 1102) {
      const config = response.config
      if (!isRefreshing) {
        isRefreshing = true
        store.dispatch('user/refreshToken').then(res => {
          config.headers['Authorization'] = res.jwt
          config.baseURL = ''
          requests.forEach(cd => cd(res.jwt))
          requests = []
          service(response.config)
        }).catch(() => {
          Message({
            message: '刷新认证信息失败，请重新登录',
            type: 'warning',
            duration: 2 * 1000
          })
          store.dispatch('user/resetToken').then(() => {
            setTimeout(() => location.reload(), 2000)
          })
        }).finally(() => {
          isRefreshing = false
        })
      } else {
        // 正在刷新token，将返回一个未执行resolve的promise
        return new Promise((resolve) => {
          // 将resolve放进队列，用一个函数形式来保存，等token刷新后直接执行
          requests.push(() => {
            config.baseURL = ''
            config.headers['Authorization'] = store.getters.token
            resolve(service(config))
          })
        })
      }
    } else {
      Message({
        message: res.msg || 'Error',
        type: 'error',
        duration: 5 * 1000
      })
      return Promise.reject(new Error(res.message || 'Error'))
    }
  },
  error => {
    console.log('err' + error) // for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)

export default service
<file_sep>/README.md
# authority_manager_front
权限管理系统简单实现 -- 前端部分（基于 vue-element_admin 开发）<file_sep>/src/api/authority/menu_manager.js
import request from '@/utils/request'

export function getMenus(params, data) {
  return request({
    url: '/authority/get_menus_info',
    method: 'post',
    params,
    data
  })
}

export function addMenu(data) {
  return request({
    url: '/authority/add_menu',
    method: 'post',
    data
  })
}

export function getDepthMenus(params) {
  return request({
    url: '/authority/get_depth_menus',
    method: 'get',
    params
  })
}

export function deleteMenu(params) {
  return request({
    url: '/authority/delete_menu',
    method: 'get',
    params
  })
}

export function editMenu(data) {
  return request({
    url: '/authority/edit_menu',
    method: 'post',
    data
  })
}
<file_sep>/src/api/authority/role_manager.js
import request from '@/utils/request'

export function getRoles(params, data) {
  return request({
    url: '/authority/get_roles_info',
    method: 'post',
    params,
    data
  })
}

export function addRole(data) {
  return request({
    url: '/authority/add_role',
    method: 'post',
    data
  })
}

export function deleteRole(params) {
  return request({
    url: '/authority/delete_role',
    method: 'get',
    params
  })
}

export function editRole(data) {
  return request({
    url: '/authority/edit_role',
    method: 'post',
    data
  })
}

export function getMenuListTree() {
  return request({
    url: '/authority/get_menu_list_tree',
    method: 'get'
  })
}

export function roleRelateMenus(data) {
  return request({
    url: '/authority/role_relate_menus',
    method: 'post',
    data
  })
}

export function getRelatedMenuIds(params) {
  return request({
    url: '/authority/get_related_menu_ids',
    method: 'get',
    params
  })
}
