|
1
|
<template>
|
|
2
|
<a-drawer
|
|
3
|
:title="title"
|
|
4
5
|
:width="drawerWidth"
@close="handleCancel"
|
|
6
|
:visible="visible"
|
|
7
8
|
:confirmLoading="confirmLoading">
|
|
9
|
<div :style="{width: '100%',border: '1px solid #e9e9e9',padding: '10px 16px',background: '#fff',}">
|
|
10
11
12
13
|
<a-spin :spinning="confirmLoading">
<a-form :form="form">
<a-form-item label="菜单类型" :labelCol="labelCol" :wrapperCol="wrapperCol" >
|
|
14
|
<a-radio-group @change="onChangeMenuType" v-decorator="['menuType',{'initialValue':localMenuType}]">
|
|
15
16
|
<a-radio :value="0">一级菜单</a-radio>
<a-radio :value="1">子菜单</a-radio>
|
|
17
|
<a-radio :value="2">按钮/权限</a-radio>
|
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
</a-radio-group>
</a-form-item>
<a-form-item
:labelCol="labelCol"
:wrapperCol="wrapperCol"
:label="menuLabel"
hasFeedback >
<a-input placeholder="请输入菜单名称" v-decorator="[ 'name', validatorRules.name]" :readOnly="disableSubmit"/>
</a-form-item>
<a-form-item
v-show="localMenuType!=0"
label="上级菜单"
:labelCol="labelCol"
|
|
34
35
36
37
38
|
:wrapperCol="wrapperCol"
:validate-status="validateStatus"
:hasFeedback="true"
:required="true">
<span slot="help">{{ validateStatus=='error'?'请选择上级菜单':' ' }}</span>
|
|
39
40
41
42
43
44
|
<a-tree-select
style="width:100%"
:dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
:treeData="treeData"
v-model="model.parentId"
placeholder="请选择父级菜单"
|
|
45
46
|
:disabled="disableSubmit"
@change="handleParentIdChange">
|
|
47
48
49
50
51
52
53
|
</a-tree-select>
</a-form-item>
<a-form-item
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="菜单路径">
|
|
54
|
<a-input placeholder="请输入菜单路径" v-decorator="[ 'url',validatorRules.url]" :readOnly="disableSubmit"/>
|
|
55
56
57
58
59
60
61
|
</a-form-item>
<a-form-item
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="前端组件">
|
|
62
|
<a-input placeholder="请输入前端组件" v-decorator="[ 'component',validatorRules.component]" :readOnly="disableSubmit"/>
|
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
</a-form-item>
<a-form-item
v-show="localMenuType==0"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="默认跳转地址">
<a-input placeholder="请输入路由参数 redirect" v-decorator="[ 'redirect',{}]" :readOnly="disableSubmit"/>
</a-form-item>
<a-form-item
v-show="!show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="授权标识">
|
|
78
|
<a-input placeholder="多个用逗号分隔, 如: user:list,user:create" v-decorator="[ 'perms', {rules:[{ required: false, message: '请输入授权标识!' },{validator: this.validatePerms }]}]" :readOnly="disableSubmit"/>
|
|
79
80
81
|
</a-form-item>
<a-form-item
|
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
v-show="!show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="授权策略">
<j-dict-select-tag v-decorator="['permsType', {}]" placeholder="请选择授权策略" :type="'radio'" :triggerChange="true" dictCode="global_perms_type"/>
</a-form-item>
<a-form-item
v-show="!show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="状态">
<j-dict-select-tag v-decorator="['status', {}]" placeholder="请选择状态" :type="'radio'" :triggerChange="true" dictCode="valid_status"/>
</a-form-item>
<a-form-item
|
|
100
101
102
103
|
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="菜单图标">
|
|
104
|
<a-input placeholder="点击选择图标" v-model="model.icon" :readOnly="disableSubmit">
|
|
105
106
107
108
109
110
111
112
113
|
<a-icon slot="addonAfter" type="setting" @click="selectIcons" />
</a-input>
</a-form-item>
<a-form-item
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="排序">
|
|
114
|
<a-input-number placeholder="请输入菜单排序" style="width: 200px" v-decorator="[ 'sortNo',validatorRules.sortNo]" :readOnly="disableSubmit"/>
|
|
115
116
117
118
119
120
|
</a-form-item>
<a-form-item
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
|
|
121
122
123
124
125
126
127
128
|
label="是否路由菜单">
<a-switch checkedChildren="是" unCheckedChildren="否" v-model="routeSwitch"/>
</a-form-item>
<a-form-item
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
|
|
129
130
131
132
133
134
135
136
|
label="隐藏路由">
<a-switch checkedChildren="是" unCheckedChildren="否" v-model="menuHidden"/>
</a-form-item>
<a-form-item
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
|
|
137
138
139
140
141
142
143
144
145
|
label="是否缓存路由">
<a-switch checkedChildren="是" unCheckedChildren="否" v-model="isKeepalive"/>
</a-form-item>
<a-form-item
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
|
|
146
147
148
149
|
label="聚合路由">
<a-switch checkedChildren="是" unCheckedChildren="否" v-model="alwaysShow"/>
</a-form-item>
|
|
150
151
152
153
154
155
156
157
158
159
|
<!--update_begin author:wuxianquan date:20190908 for:增加组件,外链打开方式可选 -->
<a-form-item
v-show="show"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="打开方式">
<a-switch checkedChildren="外部" unCheckedChildren="内部" v-model="internalOrExternal"/>
</a-form-item>
<!--update_end author:wuxianquan date:20190908 for:增加组件,外链打开方式可选 -->
|
|
160
161
162
163
164
165
|
</a-form>
<!-- 选择图标 -->
<icons @choose="handleIconChoose" @close="handleIconCancel" :iconChooseVisible="iconChooseVisible"></icons>
</a-spin>
|
|
166
167
168
169
170
171
172
173
|
<a-row :style="{textAlign:'right'}">
<a-button :style="{marginRight: '8px'}" @click="handleCancel">
关闭
</a-button>
<a-button :disabled="disableSubmit" @click="handleOk" type="primary">确定</a-button>
</a-row>
</div>
</a-drawer>
|
|
174
175
176
|
</template>
<script>
|
|
177
|
import {addPermission,editPermission,queryTreeList, duplicateCheck} from '@/api/api'
|
|
178
179
|
import Icons from './icon/Icons'
import pick from 'lodash.pick'
|
|
180
|
|
|
181
182
183
184
185
|
export default {
name: "PermissionModal",
components: {Icons},
data () {
return {
|
|
186
|
drawerWidth:700,
|
|
187
188
189
190
191
192
|
treeData:[],
treeValue: '0-0-4',
title:"操作",
visible: false,
disableSubmit:false,
model: {},
|
|
193
|
localMenuType:0,
|
|
194
195
|
alwaysShow:false,//表单元素-聚合路由
menuHidden:false,//表单元素-隐藏路由
|
|
196
|
routeSwitch:true, //是否路由菜单
|
|
197
198
199
|
/*update_begin author:wuxianquan date:20190908 for:定义变量,初始值代表内部打开*/
internalOrExternal:false,//菜单打开方式
/*update_end author:wuxianquan date:20190908 for:定义变量,初始值代表内部打开*/
|
|
200
|
isKeepalive:true, //是否缓存路由
|
|
201
202
|
show:true,//根据菜单类型,动态显示隐藏表单元素
menuLabel:'菜单名称',
|
|
203
|
isRequrie:true, // 是否需要验证
|
|
204
205
206
207
208
209
210
211
212
213
214
|
labelCol: {
xs: { span: 24 },
sm: { span: 5 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 },
},
confirmLoading: false,
form: this.$form.createForm(this),
|
|
215
216
217
218
219
220
221
222
|
iconChooseVisible: false,
validateStatus:""
}
},
computed:{
validatorRules:function() {
return {
|
|
223
|
name:{rules: [{ required: true, message: '请输入菜单标题!' }]},
|
|
224
225
|
component:{rules: [{ required: this.show, message: '请输入前端组件!' }]},
url:{rules: [{ required: this.show, message: '请输入菜单路径!' }]},
|
|
226
|
permsType:{rules: [{ required: true, message: '请输入授权策略!' }]},
|
|
227
|
sortNo:{initialValue:1.0},
|
|
228
|
}
|
|
229
230
231
|
}
},
created () {
|
|
232
|
this.initDictConfig();
|
|
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
},
methods: {
loadTree(){
var that = this;
queryTreeList().then((res)=>{
if(res.success){
console.log('----queryTreeList---')
console.log(res)
that.treeData = [];
let treeList = res.result.treeList
for(let a=0;a<treeList.length;a++){
let temp = treeList[a];
temp.isLeaf = temp.leaf;
that.treeData.push(temp);
}
}
});
},
add () {
|
|
252
253
|
// 默认值
this.edit({status:'1',permsType:'1',route:true});
|
|
254
255
|
},
edit (record) {
|
|
256
|
this.resetScreenSize(); // 调用此方法,根据屏幕宽度自适应调整抽屉的宽度
|
|
257
258
|
this.form.resetFields();
this.model = Object.assign({}, record);
|
|
259
260
|
//--------------------------------------------------------------------------------------------------
//根据菜单类型,动态展示页面字段
|
|
261
262
263
|
console.log(record)
this.alwaysShow = !record.alwaysShow?false:true;
this.menuHidden = !record.hidden?false:true;
|
|
264
|
|
|
265
266
267
|
if(record.route!=null){
this.routeSwitch = record.route?true:false;
}
|
|
268
|
|
|
269
270
271
272
273
274
|
if(record.keepAlive!=null){
this.isKeepalive = record.keepAlive?true:false;
}else{
this.isKeepalive = false; // 升级兼容 如果没有(后台没有传过来、或者是新建)默认为false
}
|
|
275
276
277
278
279
280
281
|
/*update_begin author:wuxianquan date:20190908 for:编辑初始化数据*/
if(record.internalOrExternal!=null){
this.internalOrExternal = record.internalOrExternal?true:false;
}else{
this.internalOrExternal = false;
}
/*update_end author:wuxianquan date:20190908 for:编辑初始化数据*/
|
|
282
|
|
|
283
|
|
|
284
285
286
|
//console.log('record.menuType', record.menuType);
this.show = record.menuType==2?false:true;
this.menuLabel = record.menuType==2?'按钮/权限':'菜单名称';
|
|
287
|
|
|
288
289
|
if(this.model.parentId){
this.localMenuType = 1;
|
|
290
|
}else{
|
|
291
|
this.localMenuType = 0;
|
|
292
|
}
|
|
293
|
//----------------------------------------------------------------------------------------------
|
|
294
295
296
|
this.visible = true;
this.loadTree();
|
|
297
|
let fieldsVal = pick(this.model,'name','perms','permsType','component','redirect','url','sortNo','menuType','status');
|
|
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
this.$nextTick(() => {
this.form.setFieldsValue(fieldsVal)
});
},
close () {
this.$emit('close');
this.disableSubmit = false;
this.visible = false;
},
handleOk () {
const that = this;
// 触发表单验证
this.form.validateFields((err, values) => {
if (!err) {
this.model.alwaysShow = this.alwaysShow;
this.model.hidden = this.menuHidden;
|
|
314
|
this.model.route = this.routeSwitch;
|
|
315
|
this.model.keepAlive = this.isKeepalive;
|
|
316
317
318
319
|
/*update_begin author:wuxianquan date:20190908 for:获取值*/
this.model.internalOrExternal = this.internalOrExternal;
/*update_end author:wuxianquan date:20190908 for:获取值*/
|
|
320
|
let formData = Object.assign(this.model, values);
|
|
321
322
323
324
325
326
327
328
|
if ((formData.menuType == 1 || formData.menuType == 2) && !formData.parentId) {
that.validateStatus = 'error';
that.$message.error("请检查你填的类型以及信息是否正确!");
return;
} else {
that.validateStatus = 'success';
}
that.confirmLoading = true;
|
|
329
330
|
console.log(formData);
let obj;
|
|
331
332
333
334
|
if (!this.model.id) {
obj = addPermission(formData);
} else {
obj = editPermission(formData);
|
|
335
|
}
|
|
336
337
|
obj.then((res) => {
if (res.success) {
|
|
338
339
|
that.$message.success(res.message);
that.$emit('ok');
|
|
340
|
} else {
|
|
341
342
343
344
345
|
that.$message.warning(res.message);
}
}).finally(() => {
that.confirmLoading = false;
that.close();
|
|
346
|
});
|
|
347
348
349
350
351
352
353
354
355
356
357
358
359
|
}
})
},
handleCancel () {
this.close()
},
validateNumber(rule, value, callback){
if(!value || new RegExp(/^[0-9]*[1-9][0-9]*$/).test(value)){
callback();
}else{
callback("请输入正整数!");
}
},
|
|
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
validatePerms(rule, value, callback){
if(value && value.length>0){
//校验授权标识是否存在
var params = {
tableName: 'sys_permission',
fieldName: 'perms',
fieldVal: value,
dataId: this.model.id
};
duplicateCheck(params).then((res) => {
if (res.success) {
callback()
} else {
callback("授权标识已存在!")
}
})
}else{
callback()
}
},
|
|
380
|
onChangeMenuType(e) {
|
|
381
|
//console.log('localMenuType checked', e.target.value)
|
|
382
383
384
|
this.localMenuType=e.target.value
if(e.target.value == 2){
this.show = false;
|
|
385
|
this.menuLabel = '按钮/权限';
|
|
386
387
388
389
|
}else{
this.show = true;
this.menuLabel = '菜单名称';
}
|
|
390
391
392
|
this.$nextTick(() => {
this.form.validateFields(['url','component'], { force: true });
});
|
|
393
394
395
396
397
398
399
400
401
402
403
404
405
|
},
selectIcons(){
this.iconChooseVisible = true
},
handleIconCancel () {
this.iconChooseVisible = false
},
handleIconChoose (value) {
console.log(value)
this.model.icon = value
this.form.icon = value
this.iconChooseVisible = false
},
|
|
406
407
408
409
410
411
412
413
414
|
// 根据屏幕变化,设置抽屉尺寸
resetScreenSize(){
let screenWidth = document.body.clientWidth;
if(screenWidth < 500){
this.drawerWidth = screenWidth;
}else{
this.drawerWidth = 700;
}
},
|
|
415
416
|
initDictConfig() {
},
|
|
417
418
419
420
421
422
423
|
handleParentIdChange(value){
if(!value){
this.validateStatus="error"
}else{
this.validateStatus="success"
}
}
|
|
424
425
426
427
428
429
|
}
}
</script>
<style scoped>
|
|
430
|
</style>
|