Przeglądaj źródła

添加按钮权限

daxiong.yang 7 lat temu
rodzic
commit
0a0e32a1b2

+ 1 - 1
src/api/modules/menu.js

@ -3,7 +3,7 @@ import requestUrl from '../requestUrl'
3 3
import requestParam from '../requestParam'
4 4
import isInteger from 'lodash/isInteger'
5 5
6
// 获取导航菜单列表
6
// 获取导航菜单列表 / 权限
7 7
export function nav () {
8 8
  return request({
9 9
    url: requestUrl('/sys/menu/nav'),

+ 3 - 0
src/main.js

@ -8,11 +8,14 @@ import VueCookie from 'vue-cookie'  // api: https://github.com/alfhen/vue-cookie
8 8
import '@/element-ui'               // api: https://github.com/ElemeFE/element
9 9
import '@/iconfont'                 // api: http://www.iconfont.cn/
10 10
import '@/assets/scss/index.scss'
11
import { isAuth } from '@/utils'
11 12
12 13
Vue.config.productionTip = false
13 14
14 15
Vue.use(VueCookie)
15 16
17
Vue.prototype.isAuth = isAuth // 挂载权限方法
18
16 19
/* eslint-disable no-new */
17 20
new Vue({
18 21
  el: '#app',

+ 22 - 14
src/utils/index.js

@ -1,23 +1,16 @@
1 1
/**
2
 * 获取字符串字节长度
2
 * 是否有权限
3
 * @param {*} key
3 4
 */
4
export function getStringLength (s) {
5
  return s.replace(/[\u4e00-\u9fa5\uff00-\uffff]/g, '**').length
6
}
7
8
/**
9
 * 获取路由名称, 根据url地址
10
 */
11
export function getRouteNameByUrl (url) {
12
  let val = /.*\/(.*)\.html/.exec(url)
13
  return val && val.length >= 1 ? val[1] : ''
5
export function isAuth (key) {
6
  return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false
14 7
}
15 8
16 9
/**
17 10
 * 树形数据转换
18
 * @param {*} data 数据
19
 * @param {*} id 标记
20
 * @param {*} pid 父级标记
11
 * @param {*} data
12
 * @param {*} id
13
 * @param {*} pid
21 14
 */
22 15
export function treeDataTranslate (data, id, pid) {
23 16
  for (var i = 0; i < data.length; i++) {
@ -33,3 +26,18 @@ export function treeDataTranslate (data, id, pid) {
33 26
  }
34 27
  return data
35 28
}
29
30
/**
31
 * 获取字符串字节长度
32
 */
33
export function getStringLength (s) {
34
  return s.replace(/[\u4e00-\u9fa5\uff00-\uffff]/g, '**').length
35
}
36
37
/**
38
 * 获取路由名称, 根据url地址
39
 */
40
export function getRouteNameByUrl (url) {
41
  let val = /.*\/(.*)\.html/.exec(url)
42
  return val && val.length >= 1 ? val[1] : ''
43
}

+ 8 - 2
src/views/layout/sidebar.vue

@ -82,10 +82,16 @@
82 82
        })
83 83
        this.menuNavActive = menuNav.menuId + ''
84 84
      },
85
      // 获取菜单导航列表
85
      // 获取菜单导航列表 / 权限
86 86
      getMenuNavList () {
87 87
        return API.menu.nav().then(({data}) => {
88
          this.UPDATE_MENU_NAV_LIST(data && data.code === 0 ? data.menuList : [])
88
          if (data && data.code === 0) {
89
            this.UPDATE_MENU_NAV_LIST(data.menuList)
90
            sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]'))
91
          } else {
92
            this.UPDATE_MENU_NAV_LIST([])
93
            sessionStorage.setItem('permissions', '[]')
94
          }
89 95
        })
90 96
      },
91 97
      // 获取菜单导航, 根据路由名称

+ 4 - 4
src/views/role/index.vue

@ -6,8 +6,8 @@
6 6
      </el-form-item>
7 7
      <el-form-item>
8 8
        <el-button @click="getDataList()">查询</el-button>
9
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
10
        <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
9
        <el-button v-if="isAuth('sys:role:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
10
        <el-button v-if="isAuth('sys:role:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
11 11
      </el-form-item>
12 12
    </el-form>
13 13
    <el-table
@ -55,8 +55,8 @@
55 55
        width="200"
56 56
        label="操作">
57 57
        <template slot-scope="scope">
58
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.roleId)">修改</el-button>
59
          <el-button type="text" size="small" @click="deleteHandle(scope.row.roleId)">删除</el-button>
58
          <el-button v-if="isAuth('sys:role:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.roleId)">修改</el-button>
59
          <el-button v-if="isAuth('sys:role:delete')" type="text" size="small" @click="deleteHandle(scope.row.roleId)">删除</el-button>
60 60
        </template>
61 61
      </el-table-column>
62 62
    </el-table>

+ 11 - 11
src/views/schedule/index.vue

@ -6,12 +6,12 @@
6 6
      </el-form-item>
7 7
      <el-form-item>
8 8
        <el-button @click="getDataList()">查询</el-button>
9
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
10
        <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
11
        <el-button type="danger" @click="pauseHandle()" :disabled="dataListSelections.length <= 0">批量暂停</el-button>
12
        <el-button type="danger" @click="resumeHandle()" :disabled="dataListSelections.length <= 0">批量恢复</el-button>
13
        <el-button type="danger" @click="runHandle()" :disabled="dataListSelections.length <= 0">批量立即执行</el-button>
14
        <el-button type="success" @click="logDialogVisible = true">日志列表</el-button>
9
        <el-button v-if="isAuth('sys:schedule:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
10
        <el-button v-if="isAuth('sys:schedule:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
11
        <el-button v-if="isAuth('sys:schedule:pause')" type="danger" @click="pauseHandle()" :disabled="dataListSelections.length <= 0">批量暂停</el-button>
12
        <el-button v-if="isAuth('sys:schedule:resume')" type="danger" @click="resumeHandle()" :disabled="dataListSelections.length <= 0">批量恢复</el-button>
13
        <el-button v-if="isAuth('sys:schedule:run')" type="danger" @click="runHandle()" :disabled="dataListSelections.length <= 0">批量立即执行</el-button>
14
        <el-button v-if="isAuth('sys:schedule:log')" type="success" @click="logDialogVisible = true">日志列表</el-button>
15 15
      </el-form-item>
16 16
    </el-form>
17 17
    <el-table
@ -80,11 +80,11 @@
80 80
        width="200"
81 81
        label="操作">
82 82
        <template slot-scope="scope">
83
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.jobId)">修改</el-button>
84
          <el-button type="text" size="small" @click="deleteHandle(scope.row.jobId)">删除</el-button>
85
          <el-button type="text" size="small" @click="pauseHandle(scope.row.jobId)">暂停</el-button>
86
          <el-button type="text" size="small" @click="resumeHandle(scope.row.jobId)">恢复</el-button>
87
          <el-button type="text" size="small" @click="runHandle(scope.row.jobId)">立即执行</el-button>
83
          <el-button v-if="isAuth('sys:schedule:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.jobId)">修改</el-button>
84
          <el-button v-if="isAuth('sys:schedule:delete')" type="text" size="small" @click="deleteHandle(scope.row.jobId)">删除</el-button>
85
          <el-button v-if="isAuth('sys:schedule:pause')" type="text" size="small" @click="pauseHandle(scope.row.jobId)">暂停</el-button>
86
          <el-button v-if="isAuth('sys:schedule:resume')" type="text" size="small" @click="resumeHandle(scope.row.jobId)">恢复</el-button>
87
          <el-button v-if="isAuth('sys:schedule:run')" type="text" size="small" @click="runHandle(scope.row.jobId)">立即执行</el-button>
88 88
        </template>
89 89
      </el-table-column>
90 90
    </el-table>

+ 4 - 4
src/views/user/index.vue

@ -6,8 +6,8 @@
6 6
      </el-form-item>
7 7
      <el-form-item>
8 8
        <el-button @click="getDataList()">查询</el-button>
9
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
10
        <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
9
        <el-button v-if="isAuth('sys:user:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
10
        <el-button v-if="isAuth('sys:user:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
11 11
      </el-form-item>
12 12
    </el-form>
13 13
    <el-table
@ -71,8 +71,8 @@
71 71
        width="200"
72 72
        label="操作">
73 73
        <template slot-scope="scope">
74
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>
75
          <el-button type="text" size="small" @click="deleteHandle(scope.row.userId)">删除</el-button>
74
          <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>
75
          <el-button v-if="isAuth('sys:user:delete')" type="text" size="small" @click="deleteHandle(scope.row.userId)">删除</el-button>
76 76
        </template>
77 77
      </el-table-column>
78 78
    </el-table>