menuDialog.js 4.58 KB
Newer Older
刘弈臻's avatar
刘弈臻 committed
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
const ADDCHILD = '添加子级菜单'
var menuDialog = {
  data: function () {
    return {
      iconVisible: false,
      otherData: {
        icon: ''
      },
      form: {
        id: '',
        parentName: '',
        parentId: '',
        name: '',
        icon: '',
        url: '',
        type: '',
        moduleType: '',
        permission: '',
        sort: ''
      },
      props: [
        {
          label: '上级菜单',
          prop: 'parentName',
          defaultProp: 'parentId',
          inputType: 'inputTree',
          visible: false
        },
        {
          label: '名称',
          prop: 'name',
          inputType: 'input'
        },
        {
          label: '图标',
          prop: 'icon',
          inputType: 'other'
        },
        {
          label: '链接',
          prop: 'url',
          inputType: 'input'
        },
        {
          label: '类型',
          prop: 'type',
          inputType: 'select'
        },
        {
          label: '所属模块',
          prop: 'moduleType',
          inputType: 'select'
        },
        {
          label: '权限规则',
          prop: 'permission',
          inputType: 'input'
        },
        {
          label: '排序',
          prop: 'sort',
          inputType: 'input'
        }
      ],
      rules: {
        parentName: [
          { required: true, message: '不能为空', trigger: 'change' }
        ],
        name: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        icon: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '不能为空', trigger: 'change' }
        ],
        moduleType: [
          { required: true, message: '不能为空', trigger: 'change' }
        ],
        permission: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        sort: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    icons: function () {
      return icons
    }
  },
  created: function () {
    this.getModuleType()
    this.getParentId()
    this.getType()
  },
  methods: {
    // 类型
    getType: function () {
      var self = this
      api({
        url: '/sys/menu/type',
        type: 'get',
        successFuc: function (res) {
          self.setOptions('type', self.props, res.data)
        }
      })
    },
    // 所属模块
    getModuleType: function () {
      var self = this
      api({
        url: '/sys/menu/moduleType',
        type: 'get',
        successFuc: function (res) {
          console.log('moduleType', res)
          self.setOptions('moduleType', self.props, res.data)
        }
      })
    },
    // 上级菜单
    getParentId: function () {
      var self = this
      api({
        url: '/sys/menu/parentId',
        type: 'get',
        successFuc: function (res) {
          self.setOptions('parentName', self.props, res.data)
        }
      })
    },
    // Dialog 打开的回调
    openDialogHandle: function () {
      var self = this
      this.$nextTick(function () {
        if (self.title1 === CONFIG.ADDCHILD) {
          self.$set(self.otherData, 'icon', '')
          self.$set(self.props[0], 'reference', false)
        } else {
          if (self.title1 === CONFIG.EDIT) {
            self.$set(self.otherData, 'icon', self.formData.icon)
          } else if (self.title1 === CONFIG.ADD) {
            self.$set(self.otherData, 'icon', '')
          }
        }
        if (self.title1 === CONFIG.ADD || self.title1 === ADDCHILD) {
          self.clearValidate('menuForm')
        }
        if (self.title1 === CONFIG.EDIT) {
          self.validate('menuForm')
        }
      })
    },
    // Dialog 关闭的回调
    closeDialogHandle: function () {
      if (this.title1 === CONFIG.EDIT || this.title1 === CONFIG.ADD || this.title1 === ADDCHILD) {
        this.clearForm('menuForm')
      }
      if (this.title1 === ADDCHILD) {
        this.$set(this.props[0], 'reference', true)
      }
    },
    // 确定
    confirmHandle: function () {
      this.$refs.menuForm.submitHandle()
    },
    submitHandle: function (data) {
      this.close('menuDialog')
    },
    iconChangeHandle: function (icon) {
      this.$set(this.otherData, 'icon', icon)
      this.iconVisible = false
    },
    // 取消
    cancelHandle: function () {
      this.close('menuDialog')
    }
  }
}