GenMenuForm.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="创建菜单"
  5. :close-on-click-modal="false"
  6. v-dialogDrag
  7. :visible.sync="visible">
  8. <el-form size="small" :model="inputForm" ref="inputForm" @keyup.enter.native="doSubmit()"
  9. label-width="120px" @submit.native.prevent>
  10. <el-form-item label="上级菜单" prop="parent.id" :rules="[{required: true, message: '请选择上级菜单', trigger: 'blur'}]">
  11. <SelectTree
  12. ref="menuParentTree"
  13. :props="{
  14. value: 'id', // ID字段名
  15. label: 'name', // 显示名称
  16. children: 'children' // 子级字段名
  17. }"
  18. :data="menuList"
  19. :value="inputForm.parent.id"
  20. :clearable="true"
  21. :accordion="true"
  22. @getValue="(value) => {inputForm.parent.id=value}"/>
  23. </el-form-item>
  24. <el-form-item label="名称" prop="name" :rules="[{required: true, message: '名称不能为空', trigger: 'blur'}]">
  25. <el-input maxlength="200" v-model="inputForm.name"
  26. placeholder="菜单名称"></el-input>
  27. </el-form-item>
  28. <el-form-item v-if="inputForm.type !== '2'" label="菜单图标" prop="icon">
  29. <el-input v-model="inputForm.icon" @focus="selectIcon" clearable :readonly="true" style="width:100%" placeholder="菜单图标名称"></el-input>
  30. </el-form-item>
  31. </el-form>
  32. <span slot="footer" class="dialog-footer">
  33. <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
  34. <el-button size="small" type="primary" icon="el-icon-circle-check" @click="doSubmit()">确定</el-button>
  35. </span>
  36. </el-dialog>
  37. <Icon ref="icon" @getValue="value => inputForm.icon = value"></Icon>
  38. </div>
  39. </template>
  40. <script>
  41. import Icon from './icon'
  42. import SelectTree from '@/components/treeSelect/treeSelect.vue'
  43. import MenuService from '@/api/sys/MenuService'
  44. export default {
  45. data () {
  46. return {
  47. visible: false,
  48. menuList: [],
  49. menuListTreeProps: {
  50. label: 'name',
  51. children: 'children'
  52. },
  53. inputForm: {
  54. parent: {
  55. id: ''
  56. },
  57. name: '',
  58. href: '',
  59. icon: '',
  60. isShow: '1',
  61. affix: '2',
  62. type: '1',
  63. target: ''
  64. }
  65. }
  66. },
  67. components: {
  68. SelectTree,
  69. Icon
  70. },
  71. menuService: null,
  72. created () {
  73. this.menuService = new MenuService()
  74. },
  75. methods: {
  76. init (url, name, target) {
  77. this.inputForm.href = url
  78. this.inputForm.name = name
  79. this.inputForm.target = target
  80. this.menuService.treeData().then(({data}) => {
  81. this.menuList = data
  82. })
  83. this.visible = true
  84. this.$nextTick(() => {
  85. this.$refs['inputForm'].resetFields()
  86. this.$refs.menuParentTree.clearHandle()
  87. })
  88. },
  89. // 图标选中
  90. iconActiveHandle (iconName) {
  91. this.inputForm.icon = iconName
  92. },
  93. selectIcon () {
  94. this.$refs.icon.visible = true
  95. },
  96. // 表单提交
  97. doSubmit () {
  98. this.$refs['inputForm'].validate((valid) => {
  99. if (valid) {
  100. let inputForm = JSON.parse(JSON.stringify(this.inputForm))
  101. inputForm.href = inputForm.href + '&title=' + inputForm.name
  102. this.menuService.save(inputForm).then(({data}) => {
  103. this.$message.success({dangerouslyUseHTMLString: true, message: data})
  104. this.visible = false
  105. })
  106. }
  107. })
  108. }
  109. }
  110. }
  111. </script>