Browse Source

菜单管理完成

daxiong.yang 7 years ago
parent
commit
3f10755a1a
4 changed files with 55 additions and 28 deletions
  1. 6 3
      src/api/modules/menu.js
  2. 1 1
      src/api/requestParam.js
  3. 43 21
      src/views/menu/add-or-update.vue
  4. 5 3
      src/views/menu/index.vue

+ 6 - 3
src/api/modules/menu.js

@ -31,9 +31,9 @@ export function select () {
31 31
}
32 32
33 33
// 获取菜单信息
34
export function info (menuId) {
34
export function info (id) {
35 35
  return request({
36
    url: requestUrl('/sys/menu/info' + (isInteger(menuId) ? `/${menuId}` : '')),
36
    url: requestUrl('/sys/menu/info' + (isInteger(id) ? `/${id}` : '')),
37 37
    method: 'get',
38 38
    params: requestParam({}, 'get')
39 39
  })
@ -62,6 +62,9 @@ export function del (params) {
62 62
  return request({
63 63
    url: requestUrl('/sys/menu/delete'),
64 64
    method: 'post',
65
    data: requestParam(params)
65
    headers: {
66
      'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
67
    },
68
    data: requestParam(params, 'post', false, 'form')
66 69
  })
67 70
}

+ 1 - 1
src/api/requestParam.js

@ -16,6 +16,6 @@ export default function (params, requestType = 'post', openDefultParams = true,
16 16
    't': new Date().getTime()
17 17
  }
18 18
  params = openDefultParams ? merge(defaults, params) : params
19
  params = requestType === 'post' ? (contentType === 'form' ? qs.stringify(params) : JSON.stringify(params)) : params
19
  params = requestType === 'post' ? (contentType === 'json' ? JSON.stringify(params) : qs.stringify(params)) : params
20 20
  return params
21 21
}

+ 43 - 21
src/views/menu/add-or-update.vue

@ -26,21 +26,22 @@
26 26
            ref="menuListTree"
27 27
            @current-change="menuListTreeCurrentChangeHandle"
28 28
            :default-expand-all="true"
29
            :highlight-current="true"
29 30
            :expand-on-click-node="false">
30 31
          </el-tree>
31 32
        </el-popover>
32 33
        <el-input v-model="dataForm.parentName" v-popover:menuListPopover :readonly="true" placeholder="点击选择上级菜单" class="menu-list__input"></el-input>
33 34
      </el-form-item>
34
      <el-form-item label="菜单URL" prop="url">
35
      <el-form-item v-if="dataForm.type === 1" label="菜单URL" prop="url">
35 36
        <el-input v-model="dataForm.url" placeholder="菜单URL"></el-input>
36 37
      </el-form-item>
37
      <el-form-item label="授权标识" prop="perms">
38
      <el-form-item v-if="dataForm.type !== 0" label="授权标识" prop="perms">
38 39
        <el-input v-model="dataForm.perms" placeholder="多个用逗号分隔, 如: user:list,user:create"></el-input>
39 40
      </el-form-item>
40
      <el-form-item label="排序号" prop="orderNum">
41
        <el-input-number v-model="dataForm.orderNum" :min="1" :max="10" label="排序号"></el-input-number>
41
      <el-form-item v-if="dataForm.type !== 2" label="排序号" prop="orderNum">
42
        <el-input-number v-model="dataForm.orderNum" controls-position="right" :min="0" label="排序号"></el-input-number>
42 43
      </el-form-item>
43
      <el-form-item label="菜单图标" prop="icon">
44
      <el-form-item v-if="dataForm.type !== 2" label="菜单图标" prop="icon">
44 45
        <el-row>
45 46
          <el-col :span="22">
46 47
            <el-input v-model="dataForm.icon" placeholder="菜单图标"></el-input>
@ -68,7 +69,6 @@
68 69
<script>
69 70
  import API from '@/api'
70 71
  import { treeDataTranslate } from '@/utils'
71
  import isFinite from 'lodash/isFinite'
72 72
  export default {
73 73
    data () {
74 74
      var validateUrl = (rule, value, callback) => {
@ -81,14 +81,14 @@
81 81
      return {
82 82
        visible: false,
83 83
        dataForm: {
84
          id: null,
84
          id: 0,
85 85
          type: 1,
86 86
          name: '',
87
          parentId: null,
87
          parentId: 0,
88 88
          parentName: '',
89 89
          url: '',
90 90
          perms: '',
91
          orderNum: '',
91
          orderNum: 0,
92 92
          icon: ''
93 93
        },
94 94
        dataRule: {
@ -111,7 +111,7 @@
111 111
    },
112 112
    methods: {
113 113
      init (id) {
114
        this.dataForm.id = isFinite(id) ? id : null
114
        this.dataForm.id = id || 0
115 115
        API.menu.select().then(({data}) => {
116 116
          this.menuList = treeDataTranslate(data.menuList, 'menuId')
117 117
        }).then(() => {
@ -120,7 +120,22 @@
120 120
            this.$refs['dataForm'].resetFields()
121 121
          })
122 122
        }).then(() => {
123
          if (isFinite(this.dataForm.id)) {
123
          if (!this.dataForm.id) {
124
            // 新增
125
            this.menuListTreeSetCurrentNode()
126
          } else {
127
            // 修改
128
            API.menu.info(this.dataForm.id).then(({data}) => {
129
              this.dataForm.id = data.menu.menuId
130
              this.dataForm.type = data.menu.type
131
              this.dataForm.name = data.menu.name
132
              this.dataForm.parentId = data.menu.parentId
133
              this.dataForm.url = data.menu.url
134
              this.dataForm.perms = data.menu.perms
135
              this.dataForm.orderNum = data.menu.orderNum
136
              this.dataForm.icon = data.menu.icon
137
              this.menuListTreeSetCurrentNode()
138
            })
124 139
          }
125 140
        })
126 141
      },
@ -129,19 +144,26 @@
129 144
        this.dataForm.parentId = data.menuId
130 145
        this.dataForm.parentName = data.name
131 146
      },
147
      // 菜单树设置当前选中节点
148
      menuListTreeSetCurrentNode () {
149
        this.$refs.menuListTree.setCurrentKey(this.dataForm.parentId)
150
        this.dataForm.parentName = (this.$refs.menuListTree.getCurrentNode() || {})['name']
151
      },
152
      // 表单提交
132 153
      dataFormSubmit () {
133 154
        this.$refs['dataForm'].validate((valid) => {
134 155
          if (valid) {
135 156
            var params = {
136
              'userId': this.dataForm.userId || undefined,
137
              'username': this.dataForm.userName,
138
              'password': this.dataForm.password,
139
              'email': this.dataForm.email,
140
              'mobile': this.dataForm.mobile,
141
              'status': this.dataForm.status,
142
              'roleIdList': this.dataForm.roleIdList
157
              'menuId': this.dataForm.id || undefined,
158
              'type': this.dataForm.type,
159
              'name': this.dataForm.name,
160
              'parentId': this.dataForm.parentId,
161
              'url': this.dataForm.url,
162
              'perms': this.dataForm.perms,
163
              'orderNum': this.dataForm.orderNum,
164
              'icon': this.dataForm.icon
143 165
            }
144
            var tick = this.dataForm.userId ? API.user.update(params) : API.user.add(params)
166
            var tick = !this.dataForm.id ? API.menu.add(params) : API.menu.update(params)
145 167
            tick.then(({data}) => {
146 168
              if (data && data.code === 0) {
147 169
                this.$message({
@ -149,8 +171,8 @@
149 171
                  type: 'success',
150 172
                  duration: 1500,
151 173
                  onClose: () => {
152
                    this.addOrUpdateVisible = false
153
                    this.getDataList()
174
                    this.visible = false
175
                    this.$emit('refreshDataList')
154 176
                  }
155 177
                })
156 178
              } else {

+ 5 - 3
src/views/menu/index.vue

@ -65,7 +65,6 @@
65 65
        label="授权标识">
66 66
      </el-table-column>
67 67
      <el-table-column
68
        fixed="right"
69 68
        header-align="center"
70 69
        align="center"
71 70
        width="200"
@ -77,7 +76,7 @@
77 76
      </el-table-column>
78 77
    </tree-table>
79 78
    <!-- 弹窗, 新增 / 修改 -->
80
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate"></add-or-update>
79
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
81 80
  </div>
82 81
</template>
83 82
@ -132,7 +131,10 @@
132 131
          cancelButtonText: '取消',
133 132
          type: 'warning'
134 133
        }).then(() => {
135
          API.menu.del([id]).then(({data}) => {
134
          var params = {
135
            'menuId': id
136
          }
137
          API.menu.del(params).then(({data}) => {
136 138
            if (data && data.code === 0) {
137 139
              this.$message({
138 140
                message: '操作成功',