inleft
2022-03-01 88f419df77ade235ea5e5e24be204842a24b7b33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
<template>
 
  <a-modal
    title="编辑菜单"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    :destroyOnClose="true"
  >
    <a-spin :spinning="formLoading">
      <a-form :form="form" >
 
        <a-form-item v-show="false" >
          <a-input v-decorator="['id']" />
        </a-form-item>
 
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="菜单名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              hasFeedback
            >
              <a-input placeholder="请输入菜单名称" v-decorator="['name',{rules: [{required: true, min: 1, message: '请输入菜单名称!'}]}]" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              style="width: 100%"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="菜单编号"
              hasFeedback
            >
              <a-input placeholder="请输入菜单编号" v-decorator="['code', {rules: [{required: true, min: 1, message: '请输入菜单编号!'}]}]" />
            </a-form-item>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="所属应用"
              has-feedback
            >
              <a-select style="width: 100%" :disabled="appDisabled" placeholder="请选择应用分类" v-decorator="['application', {rules: [{ required: true, message: '请选择应用分类!' }]}]" >
                <a-select-option v-for="(item,index) in appData" :key="index" :value="item.code" @click="changeApplication(item.code)">{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="菜单层级"
            >
              <a-radio-group v-decorator="['type',{rules: [{ required: true, message: '请选择菜单层级!' }]}]" >
                <a-radio v-for="(item,index) in typeData" :key="index" :value="item.code" @click="meneTypeFunc(item.code)">{{ item.value }}</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <div v-show="pidShow">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="父级菜单"
                has-feedback
              >
                <a-tree-select
                  v-decorator="['pid', {rules: [{ required: true, message: '请选择父级菜单!' }]}]"
                  style="width: 100%"
                  :dropdownStyle="{ maxHeight: '300px', overflow: 'auto' }"
                  :treeData="menuTreeData"
                  placeholder="请选择父级菜单"
                  treeDefaultExpandAll
                  @change="setPid"
                >
                  <span slot="title" slot-scope="{ id }">{{ id }}
                  </span>
                </a-tree-select>
              </a-form-item>
            </div>
            <div v-show="redirectShow">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
              >
                <span slot="label">
                  <a-tooltip title="如需打开首页加载此目录下菜单,请填写加载菜单路由,设为首页后其他设置的主页将被替代">
                    <a-icon type="question-circle-o" />
                  </a-tooltip>&nbsp;
                  重定向
                </span>
                <a-input prop="redirect" placeholder="请输入重定向地址" v-decorator="['redirect']" />
              </a-form-item>
            </div>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <span slot="label">
                <a-tooltip title="按钮:无,菜单:内链、外链、组件">
                  <a-icon type="question-circle-o" />
                </a-tooltip>&nbsp;
                打开方式
              </span>
              <a-radio-group :disabled="openTypeDisabled" v-decorator="['openType',{rules: [{ required: true, message: '请选择打开方式!' }]}]">
                <a-radio v-for="(item,index) in openTypeData" :key="index" :value="item.code" @click="meneOpenTypeFunc(item.code)">{{ item.value }}</a-radio>
              </a-radio-group>
            </a-form-item>
 
          </a-col>
        </a-row>
 
        <a-divider />
 
        <a-row :gutter="24" >
          <a-col :md="12" :sm="24">
            <div v-show="componentShow">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                hasFeedback
              >
                <span slot="label">
                  <a-tooltip title="前端vue组件 views文件夹下路径,例:system/menu/index。注:目录级填写:RouteView(不带面包屑),PageView(带面包屑),菜单级内链打开http链接填写:Iframe">
                    <a-icon type="question-circle-o" />
                  </a-tooltip>&nbsp;
                  前端组件
                </span>
                <a-input placeholder="请输入前端组件" :disabled="componentDisabled" prop="component" v-decorator="['component',{rules: [{required: componentRequired, message: '请输入前端组件'}]}]"/>
              </a-form-item>
            </div>
          </a-col>
          <a-col :md="12" :sm="24">
            <div v-show="routerShow">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                hasFeedback
              >
                <span slot="label">
                  <a-tooltip title="浏览器显示的URL,例:/menu,对应打开页面为菜单页面">
                    <a-icon type="question-circle-o" />
                  </a-tooltip>&nbsp;
                  路由地址
                </span>
                <a-input placeholder="请输入路由" v-decorator="['router', {rules: [{required: routerRequired, message: '请输入路由!'}]}]" />
              </a-form-item>
            </div>
            <div v-show="permissionShow">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="权限标识"
                hasFeedback
              >
                <a-input placeholder="请输入权限标识" v-decorator="['permission', {rules: [{required: permissionRequired, message: '请输入权限标识!'}]}]" />
              </a-form-item>
            </div>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <div v-show="linkShow" >
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                hasFeedback
              >
                <span slot="label">
                  <a-tooltip title="当选择了需要内链或外链打开的选项,此处输入要打开的链接地址,例:https://www.xiaonuo.vip">
                    <a-icon type="question-circle-o" />
                  </a-tooltip>&nbsp;
                  内外链地址
                </span>
                <a-input placeholder="请输入内链打开地址" :disabled="linkDisabled" v-decorator="['link', {rules: [{required: linkRequired, message: '请输入权限标识!'}]}]" />
              </a-form-item>
            </div>
          </a-col>
          <a-col :md="12" :sm="24">
            <div v-show="iconShow" >
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="图标"
              >
                <a-input placeholder="请选择图标" disabled="disabled" v-decorator="['icon']" >
                  <a-icon slot="addonAfter" @click="openIconSele()" type="setting" />
                </a-input>
              </a-form-item>
            </div>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <span slot="label">
                <a-tooltip title="系统权重:菜单可分配给任何角色,业务权重:菜单对超级管理员不可见">
                  <a-icon type="question-circle-o" />
                </a-tooltip>&nbsp;
                权重
              </span>
              <a-radio-group v-decorator="['weight']">
                <a-radio v-for="(item,index) in weightData" :key="index" :value="item.code" >{{ item.value }}</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="是否可见"
            >
              <a-switch id="visible" checkedChildren="是" unCheckedChildren="否" v-decorator="['visible', { valuePropName: 'checked' }]"/>
            </a-form-item>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="排序"
            >
              <a-input-number style="width: 100%" v-decorator="['sort', { initialValue: 100 }]" :min="1" :max="1000" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="备注"
              hasFeedback
            >
              <a-input placeholder="请输入备注" v-decorator="['remark']"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
 
      </a-form>
    </a-spin>
    <a-modal
      :width="850"
      :visible="visibleIcon"
      @cancel="handleCancelIcon"
      footer=""
      :mask="false"
      :closable="false"
      :destroyOnClose="true"
    >
      <icon-selector v-model="currentSelectedIcon" @change="handleIconChange"/>
    </a-modal>
  </a-modal>
</template>
 
<script>
  import { getAppList } from '@/api/modular/system/appManage'
  import { getMenuTree, sysMenuEdit } from '@/api/modular/system/menuManage'
  import IconSelector from '@/components/IconSelector'
  import { sysDictTypeDropDown } from '@/api/modular/system/dictManage'
  export default {
    name: 'MenuEdit',
    components: { IconSelector },
 
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        visibleIcon: false,
        visible: false,
        confirmLoading: false,
        appData: [],
        menuTreeData: [],
        redirectShow: true,
        componentShow: true,
        componentDisabled: false,
        componentRequired: true,
        routerRequired: true,
        routerShow: true,
        iconShow: true,
        openTypeShow: true,
        pidShow: true,
        permissionShow: true,
        permissionRequired: true,
        // 图标组件
        currentSelectedIcon: 'pause-circle',
        typeData: [],
        openTypeData: [],
        weightData: [],
        formLoading: true,
        linkShow: true,
        openTypeDisabled: false,
        openTypeDefault: [],
        openType: '',
        linkRequired: true,
        linkDisabled: false,
        type: '',
        pid: '',
        appDisabled: false,
        form: this.$form.createForm(this)
      }
    },
 
    watch: {
      pid (val) {
        if (val === '0') {
           // 再不能切换应用
          this.appDisabled = false
        } else {
          this.appDisabled = true
        }
      }
    },
 
    methods: {
      // 打开页面初始化
      edit (record) {
        this.visible = true
        // 获取系统应用列表
        this.getSysApplist()
        this.sysDictTypeDropDown()
 
        // 图标
        this.currentSelectedIcon = record.icon
        // 默认选中菜单项,并初始化
        this.form.getFieldDecorator('type', { valuePropName: 'checked', initialValue: record.type.toString() })
        this.meneTypeFunc(record.type.toString(), record.openType.toString())
 
        // 默认选中的单选框
        // eslint-disable-next-line no-unused-vars
        const visibleDef = false
        // eslint-disable-next-line eqeqeq
        if (record.visible == 'Y') {
          this.visibleDef = true
        }
        this.form.getFieldDecorator('weight', { valuePropName: 'checked', initialValue: record.weight.toString() })
        this.form.getFieldDecorator('visible', { valuePropName: 'checked', initialValue: this.visibleDef })
        this.form.getFieldDecorator('icon', { initialValue: record.icon })
        setTimeout(() => {
           this.setMenuItem(record)
          this.changeApplication(record.application)
        }, 100)
      },
 
      setMenuItem (record) {
        this.form.setFieldsValue(
          {
            id: record.id,
            name: record.name,
            code: record.code,
            application: record.application,
            redirect: record.redirect,
            component: record.component,
            permission: record.permission,
            link: record.link,
            router: record.router,
            sort: record.sort,
            remark: record.remark
          }
        )
        this.form.getFieldDecorator('pid', { initialValue: record.pid })
        this.pid = record.pid
      },
 
      /**
       * 获取字典数据
       */
      sysDictTypeDropDown () {
        this.formLoading = true
        // 菜单类型
        sysDictTypeDropDown({ code: 'menu_type' }).then((res) => {
          this.typeData = res.data
        })
        // 权重
        sysDictTypeDropDown({ code: 'menu_weight' }).then((res) => {
          this.weightData = res.data
        })
        // 内外链
        sysDictTypeDropDown({ code: 'open_type' }).then((res) => {
          this.openTypeData = res.data
          this.formLoading = false
        })
      },
 
      /**
       * 选择父级
       */
      setPid (value) {
        this.pid = value
      },
 
      getSysApplist () {
        return getAppList().then((res) => {
          if (res.success) {
            this.appData = res.data
          } else {
            this.$message.warning(res.message)
          }
        })
      },
      changeApplication (value) {
        getMenuTree({ 'application': value }).then((res) => {
          if (res.success) {
            this.form.resetFields(`pid`, [])
            this.menuTreeData = [{
              'id': '-1',
              'parentId': '0',
              'title': '顶级',
              'value': '0',
              'pid': '0',
              'children': res.data
            }]
          } else {
            this.$message.warning(res.message)
          }
        })
      },
 
      /**
       * 选择菜单类型执行初始化表单变量
       */
      meneTypeFunc (type, openType) {
        this.type = type
        // eslint-disable-next-line eqeqeq
        if (type == '0' || type == '1') {
          // 内外链地址显示,给空值
          this.linkShow = true
          this.form.resetFields(`link`, [])
          // 图标选择显示
          this.iconShow = true
          // 路由必填,设置空值,并显示
          this.routerRequired = true
          this.form.getFieldDecorator('router', { initialValue: '' })
          this.routerShow = true
          // 权限标识框隐藏,选填,给空值
          this.permissionShow = false
          this.permissionRequired = false
          this.form.getFieldDecorator('permission', { initialValue: '' })
          // 打开方式设置为组件 ,禁用选择方式
          this.openType = openType
          this.form.getFieldDecorator('openType', { initialValue: this.openType })
          this.openTypeDisabled = false
        }
        // eslint-disable-next-line eqeqeq
        if (type == '0') {
          // 重定向展示,并给空
          this.redirectShow = true
          this.form.resetFields(`redirect`, [])
          // 组件默认为显示,设置可输入,给默认组件 PageView,验证必填
          this.componentShow = true
          this.componentDisabled = false
          this.form.getFieldDecorator('component', { initialValue: 'PageView' })
          this.componentRequired = true
          // 父级初始化顶级,并将其隐藏
          this.form.getFieldDecorator('pid', { initialValue: '0' })
          this.pid = '0'
          this.pidShow = false
        } else {
          // eslint-disable-next-line eqeqeq
          if (type == '1') {
            // 组件可以手输,取消值
            this.componentDisabled = false
            this.form.getFieldDecorator('component', { initialValue: '' })
          }
          // 重定向输入隐藏,并给空值
          this.redirectShow = false
          this.form.getFieldDecorator('redirect', { initialValue: '' })
          // 父级选择放开
          this.pidShow = true
        }
        // eslint-disable-next-line eqeqeq
        if (type == '2') {
          // 组件设置不填,不可输入,并给空(手输的跟设置的)
          this.componentRequired = false
          this.componentDisabled = true
          this.form.resetFields(`component`, [])
          this.form.getFieldDecorator('component', { initialValue: '' })
          // 路由选填,设置空值,并隐藏
          this.routerRequired = true
          this.form.getFieldDecorator('router', { initialValue: '' })
          this.routerShow = false
          // 内外链地址隐藏,给空值
          this.linkShow = false
          this.form.getFieldDecorator('link', { initialValue: '' })
          // 权限标识框显示,必填,给空值
          this.permissionShow = true
          this.permissionRequired = true
          this.form.getFieldDecorator('permission', { initialValue: '' })
          // 图标选择隐藏,并给空
          this.iconShow = false
          this.form.getFieldDecorator('icon', { initialValue: '' })
          // 打开方式设置为无 ,禁用选择方式
          this.openType = '0'
          this.form.getFieldDecorator('openType', { initialValue: this.openType })
          this.openTypeDisabled = true
          // 取消icon
          this.form.getFieldDecorator('icon', { initialValue: '' })
        }
        this.meneOpenTypeFunc(this.openType)
      },
 
      /**
       * 选择打开方式执行方法
       */
      meneOpenTypeFunc (openType) {
        this.form.resetFields(`openType`, openType)
        // eslint-disable-next-line eqeqeq
        if (openType == '2' || openType == '3') {
          // 点击内外链的时候保留原值,其他清空
          if (this.linkDisabled === false) {
            this.form.resetFields(`link`, [])
          }
          // 设置内外链可手输,加验证
          this.linkDisabled = false
          this.linkRequired = true
        } else {
          // 设置内外链不可手输,取消值,取消验证
          this.linkDisabled = true
          this.form.resetFields(`link`, [])
          this.linkRequired = false
        }
        // 另起一个分支
        // eslint-disable-next-line eqeqeq
        if (openType == '3') {
          this.componentRequired = false
          this.componentDisabled = true
          this.form.resetFields(`component`, [])
          this.form.getFieldDecorator('component', { initialValue: '' })
        } else {
          this.componentRequired = true
          // eslint-disable-next-line eqeqeq
          if (this.type == '1' || this.type == '2') {
            this.form.getFieldDecorator('component', { initialValue: '' })
          } else {
            this.form.resetFields(`component`, [])
            this.form.getFieldDecorator('component', { initialValue: 'PageView' })
          }
          // eslint-disable-next-line eqeqeq
          if (openType == '2') {
            // 组件设置为 iframe
            this.form.resetFields(`component`, [])
            this.form.getFieldDecorator('component', { initialValue: 'Iframe' })
          }
        }
        // eslint-disable-next-line eqeqeq
        if (this.type == '2') {
          // eslint-disable-next-line eqeqeq
          if (openType == '0') {
            this.componentRequired = false
            this.routerRequired = false
          }
        }
      },
 
      openIconSele () {
        this.visibleIcon = true
      },
      handleIconChange (icon) {
        // console.log('新图标:'+icon)
        this.form.getFieldDecorator('icon', { initialValue: icon })
        // this.form.resetFields(`icon`,icon);
 
        this.visibleIcon = false
      },
      handleCancelIcon () {
        this.visibleIcon = false
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            if (values.visible) {
              values.visible = 'Y'
            } else {
              values.visible = 'N'
            }
            sysMenuEdit(values).then((res) => {
              this.confirmLoading = false
              if (res.success) {
                this.$message.success('编辑成功')
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败:' + res.message)
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.confirmLoading = false
        this.visible = false
      }
    }
 
  }
</script>