roleDialog.js 2.28 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
var roleDialog = {
  data () {
    return {
      form: {
        id: '',
        name: '',
        remark: '',
        menuIds: []
      },
      props: [
        {
          label: '角色名称',
          prop: 'name',
          inputType: 'input'
        },
        {
          label: '描述',
          prop: 'remark',
          inputType: 'textarea'
        },
        {
          label: '角色授权',
          prop: 'menuIds',
          inputType: 'tree',
          defaultProps: {
            children: 'children',
            label: 'name'
          }
        }
      ],
      rules: {
        name: [
          { required: true, message: '不能为空', trigger: 'change' }
        ],
        prop: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created: function () {
    this.getMenuList()
  },
  methods: {
    getMenuList: function () {
      let self = this
      api({
        url: '/sys/menu/list',
        type: 'get',
        successFuc: function (res) {
          if (res.code === CONFIG.SUCCESS) {
            self.setOptions('menuIds', self.props, res.data)
          }
        }
      })
    },
    // Dialog 打开的回调
    openDialogHandle: function () {
      var self = this
      this.$nextTick(function () {
        if (self.title1 === CONFIG.DETAIL) {
          self.$refs.roleDetail.openInitTree('menuIds')
        } else {
          self.$refs.roleForm.openInitTree('menuIds')
        }
        if (self.title1 === CONFIG.EDIT || self.title1 === CONFIG.ADD) {
          self.clearValidate('roleForm')
        }

        if (self.title1 === CONFIG.EDIT) {
          self.validate('roleForm')
        }
      })
    },
    // Dialog 关闭的回调
    closeDialogHandle: function () {
      if (this.title1 === CONFIG.EDIT || this.title1 === CONFIG.ADD) {
        this.clearForm('roleForm')
        this.$refs.roleForm.clearTree('menuIds')
      }
    },
    // 确定
    confirmHandle: function () {
      this.$refs.roleForm.submitHandle()
      this.close('roleDialog')
    },
    submitHandle: function () {
      this.close('roleDialog')
    },
    // 取消
    cancelHandle: function () {
      this.close('roleDialog')
    }
  }
}