RoleEdit.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.curObj && this.curObj.id ? '编辑角色' : '添加角色'"
  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="80px">
  13. <div slot="otherItem" class="scoped-tree">
  14. <!-- check-strictly -->
  15. <el-tree
  16. :data="curData"
  17. show-checkbox
  18. node-key="id"
  19. :default-expanded-keys="checkedIds"
  20. :default-checked-keys="checkedIds"
  21. ref="menuTree"
  22. :props="defaultProps">
  23. </el-tree>
  24. </div>
  25. <div slot="footer">
  26. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  27. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  28. </div>
  29. </base-form>
  30. </el-dialog>
  31. </template>
  32. <script>
  33. export default {
  34. props: {
  35. isShow: Boolean,
  36. curObj: Object
  37. },
  38. mixins,
  39. data() {
  40. return {
  41. formData: [],
  42. curData: [],
  43. checkedIds: [],
  44. defaultProps: {
  45. children: 'children',
  46. label: 'name'
  47. },
  48. loading: true,
  49. }
  50. },
  51. watch: {
  52. isShow: function(val) {
  53. if (val) {
  54. let params = {...this.curObj}
  55. this.checkedIds = params.permissions_ids || []
  56. this.formData = [
  57. {label: '角色名称', key: 'name', rules: 1},
  58. {label: '角色描述', key: 'description', rules: 1},
  59. ]
  60. this.setDefaultValue(params)
  61. }
  62. }
  63. },
  64. created () {
  65. this.getMenu()
  66. },
  67. methods: {
  68. getMenu () {
  69. this.$api.base.admpermissionslist().then(res => {
  70. this.curData = [...res]
  71. })
  72. },
  73. systemChange (val) {
  74. // console.log(val)
  75. },
  76. close (str) {
  77. if (str === 'confirm') {
  78. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  79. if (valid) {
  80. const oldform = this.$refs.ruleForm.baseForm
  81. let params = {...oldform}
  82. let str = 'admrolesadd'
  83. if(this.curObj && this.curObj.id) {
  84. params.id = this.curObj.id
  85. str = 'admrolesedit'
  86. }
  87. const resIds = this.$refs.menuTree.getCheckedNodes(false, false).map(item=> {
  88. return item.id
  89. })
  90. params.node = resIds.join(',')
  91. this.$api.base[str](params).then(data => {
  92. this.$msgs('保存成功!')
  93. this.$emit('close', params)
  94. // this.setDefaultValue()
  95. })
  96. }
  97. })
  98. } else {
  99. this.$emit('close')
  100. this.setDefaultValue()
  101. }
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. ::v-deep .scoped-tree {
  108. height: 300px;
  109. overflow-y: auto;
  110. .el-tree {
  111. background: #f7f7f7;
  112. }
  113. }
  114. </style>