MenuEdit.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :show-close="false"
  5. :close-on-click-modal="false"
  6. :visible.sync="isShow"
  7. :title="this.curType === 'edit' ? '编辑节点' : '添加节点'"
  8. :fullscreen="false"
  9. width="470px"
  10. custom-class="xl-dialog"
  11. center>
  12. <base-form style="width:400px" :data="formData" ref="ruleForm" :isInline="false" labelWidth="120px">
  13. <div slot="footer">
  14. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  15. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  16. </div>
  17. </base-form>
  18. </el-dialog>
  19. </template>
  20. <script>
  21. export default {
  22. props: {
  23. isShow: Boolean,
  24. curObj: Object,
  25. curType: String,
  26. },
  27. inject: ['parentData'],
  28. mixins,
  29. data() {
  30. return {
  31. formData: [],
  32. loading: true
  33. }
  34. },
  35. watch: {
  36. isShow: function(val) {
  37. if (val) {
  38. let params = {}
  39. if (this.curType === 'edit') {
  40. params = {...this.curObj}
  41. let parentIdArr = JSON.parse(JSON.stringify(params.ids))
  42. if (params.ids && params.ids.length > 1) {
  43. parentIdArr.pop()
  44. params.parentIdArr = parentIdArr
  45. }
  46. }
  47. if (this.curType === 'add') {
  48. params = {
  49. parentName: this.curObj.name,
  50. perm_status: '1',
  51. perm_type: '2',
  52. menu_hidden: '1',
  53. parentIdArr: this.curObj.ids
  54. }
  55. }
  56. this.getDef(params)
  57. }
  58. }
  59. },
  60. methods: {
  61. typeChange () {
  62. let params = {...this.$refs.ruleForm.baseForm}
  63. this.getDef(params)
  64. },
  65. getDef (params) {
  66. let newParams = {...params}
  67. if (!newParams.method) newParams.method = 'POST'
  68. if (params.perm_type && params.perm_type === '1') {
  69. this.formData = [
  70. {label: '上级节点', key: 'parentIdArr', type: 'cascader', options: this.parentData.curData, props: { checkStrictly: true }},
  71. {label: '节点类型', key: 'perm_type', type: 'select', options: this.$dictData.perm_type, rules: 1, changeHandle: this.typeChange},
  72. {label: '目录名称', key: 'name', rules: 1},
  73. {label: '目录路径', key: 'path', rules: 1},
  74. {label: '目录排序', key: 'sort'},
  75. {label: '状态', key: 'perm_status', type: 'select', clearable: false, options: this.$dictData.perm_status},
  76. ]
  77. } else if (params.perm_type && params.perm_type === '2') {
  78. this.formData = [
  79. {label: '上级节点', key: 'parentIdArr', type: 'cascader', options: this.parentData.curData, props: { checkStrictly: true }},
  80. {label: '节点类型', key: 'perm_type', type: 'select', options: this.$dictData.perm_type, rules: 1, changeHandle: this.typeChange},
  81. {label: '菜单名称', key: 'name', rules: 1},
  82. {label: '菜单路径', key: 'path', rules: 1},
  83. {label: '菜单排序', key: 'sort'},
  84. {label: '菜单栏', key: 'menu_hidden', type: 'select', clearable: false, options: this.$dictData.show_hidden},
  85. {label: '状态', key: 'perm_status', type: 'select', clearable: false, options: this.$dictData.perm_status},
  86. ]
  87. } else {
  88. this.formData = [
  89. {label: '上级节点', key: 'parentIdArr', type: 'cascader', options: this.parentData.curData, props: { checkStrictly: true }},
  90. {label: '节点类型', key: 'perm_type', type: 'select', options: this.$dictData.perm_type, rules: 1, changeHandle: this.typeChange},
  91. {label: '接口名称', key: 'name', rules: 1},
  92. {label: '接口路径', key: 'route', rules: 1},
  93. {label: '提交方式', key: 'method', rules: 1},
  94. {label: '状态', key: 'perm_status', type: 'select', clearable: false, options: this.$dictData.perm_status},
  95. ]
  96. }
  97. this.setDefaultValue(newParams)
  98. },
  99. close (str) {
  100. if (str === 'confirm') {
  101. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  102. if (valid) {
  103. const oldform = this.$refs.ruleForm.baseForm
  104. let params = {...oldform}
  105. let str = 'admpermissionsadd'
  106. params.p_id = params.parentIdArr[params.parentIdArr.length - 1]
  107. delete params.parentIdArr
  108. if (!params.sort) delete params.sort
  109. if(this.curType === 'edit') {
  110. // params.p_id = this.curObj.p_id
  111. params.id = this.curObj.id
  112. str = 'admpermissionsedit'
  113. }
  114. this.$api.base[str](params).then(data => {
  115. this.$msgs('保存成功!')
  116. this.$emit('close', params)
  117. // this.setDefaultValue()
  118. })
  119. }
  120. })
  121. } else {
  122. this.$emit('close')
  123. this.setDefaultValue()
  124. }
  125. }
  126. }
  127. }
  128. </script>