addOrRights.vue 8.25 KB
Newer Older
fengzhaoyu committed
1 2 3
<template>
  <div class="addOrRights">
    <a-button type="primary" @click="back()"><img style="margin-top:-4px;margin-right: 6px;width: 14px" src="../../../assets/back.png"/>返回</a-button>
fengzhaoyu committed
4
    <div class="title">添加角色</div>
fengzhaoyu committed
5 6 7 8
    <a-form :form="form">
      <a-form-item label="角色名称" v-bind="formItemLayout" >
        <a-input
          placeholder="请填写角色名称"
liang ce committed
9
          v-decorator="['roleName',{
fengzhaoyu committed
10
            rules: [{required: true, message: '角色名称不能为空'}, {max: 10, message: '角色名称不能超过10个字符'}],
liang ce committed
11 12
            initialValue: roleName,
          }]"
fengzhaoyu committed
13 14 15 16
        />
      </a-form-item>
      <a-form-item label="角色描述" v-bind="formItemLayout" >
        <a-input
liang ce committed
17
          placeholder="请填写角色的描述"
liang ce committed
18
          v-decorator="['roleDesc',{
fengzhaoyu committed
19
            rules: [{required: false,  message: '角色描述不能为空'}, {max: 50, message: '角色描述不能超过50个字符'}],
liang ce committed
20 21
            initialValue: roleDesc,
          }]"
fengzhaoyu committed
22 23 24
        />
      </a-form-item>
      <a-form-item label="选择成员" v-bind="formItemLayout" >
fengzhaoyu committed
25 26
        <div class="selectPeople" @click="selectPeople">
          <span  v-show="!members.length">选择成员</span>
liang ce committed
27
          <span v-show="members.length" v-for='(item, index) in members' :key="index" :style="{'margin-left': '3px',color:'rgba(0,0,0,0.85)',width:'20%',overflow:'hidden'}">{{item}}</span>
fengzhaoyu committed
28
        </div>
fengzhaoyu committed
29 30
      </a-form-item>
    </a-form>
liang ce committed
31 32 33 34 35 36 37
    <div class="permisson">
      <div class="permissonLeft">分配权限:</div>
      <div class="permissonRight">
        <tree v-model="selectList" :trees="treesdata" v-on:closeParent="close" :classId="classList" :idx="0"></tree>
        <a-button @click="confirm" style="margin-top: 40px" type="primary">保存</a-button>
      </div>
    </div>
fengzhaoyu committed
38 39 40 41 42
  </div>
</template>
<script>
import { $http } from '../../../api/axios'
import { config } from '../../../api/config'
liang ce committed
43
import tree from './tree.vue'
fengzhaoyu committed
44
export default {
liang ce committed
45 46 47
  components: {
    tree
  },
fengzhaoyu committed
48 49 50
  name: 'addOrRights',
  data () {
    return {
liang ce committed
51
      type: 0,
fengzhaoyu committed
52 53 54 55 56 57 58 59 60 61
      form: this.$form.createForm(this),
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 3 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 8 }
        }
fengzhaoyu committed
62
      },
liang ce committed
63
      roleId: '',
fengzhaoyu committed
64 65
      trees: [],
      roleName: '', // 角色名称
liang ce committed
66
      roleDesc: '', // 角色描述
fengzhaoyu committed
67 68
      members: [], // 选择成员
      ddUserIds: [],
liang ce committed
69 70 71
      treesdata: [],
      classList: [['box1', 'permissonTitle'], ['box2', 'box2-2'], ['box3', 'box3-3']],
      selectList: []
fengzhaoyu committed
72 73 74 75
    }
  },
  created () {
    if (JSON.stringify(this.$route.params) === '{}') {
liang ce committed
76 77
      this.type = 0
      this.getTree()
fengzhaoyu committed
78
    } else {
liang ce committed
79
      this.type = 1
fengzhaoyu committed
80
      this.roleName = this.$route.params.record.roleName
liang ce committed
81 82 83 84
      this.roleDesc = this.$route.params.record.roleDesc
      this.roleId = this.$route.params.roleId
      this.members = this.$route.params.record.action.name
      this.ddUserIds = this.$route.params.record.action.ddUserId
fengzhaoyu committed
85 86
      let data = {
        roleId: this.$route.params.roleId
fengzhaoyu committed
87
      }
liang ce committed
88
      $http.post('/admin/menu/tree/roleById', data).then(res => {
liang ce committed
89 90 91
        this.selectList = res.data.data
      }).then(() => {
        this.getTree()
fengzhaoyu committed
92
      })
fengzhaoyu committed
93 94
    }
  },
liang ce committed
95 96
  mounted () {
  },
fengzhaoyu committed
97
  methods: {
liang ce committed
98 99 100
    close (data) {
      console.log(data)
    },
fengzhaoyu committed
101
    back () {
fengzhaoyu committed
102
      this.$router.push({ name: 'rightsManagement' })
fengzhaoyu committed
103 104 105
    },
    // 选人
    selectPeople () {
fengzhaoyu committed
106
      config.ddready('ddchooseTen', this.ddUserIds).then((res) => {
liang ce committed
107
        this.members = []
fengzhaoyu committed
108 109
        this.ddUserIds = []
        // this.members = this.duplicateRemoval(this.members)
liang ce committed
110
        res.users.forEach((item, index) => {
fengzhaoyu committed
111
          this.ddUserIds.push(item.emplId)
liang ce committed
112
          this.members.push(item.name)
fengzhaoyu committed
113
        })
fengzhaoyu committed
114 115 116 117
      })
    },
    // 确定 提交表单
    confirm () {
fengzhaoyu committed
118 119 120 121 122 123 124 125
      if (this.ddUserIds.length === 0) {
        this.$confirm({
          content: '请先选择成员',
          onOk () {
            // that.changeData(record, index)
          },
          onCancel () {}
        })
liang ce committed
126 127 128 129 130 131 132 133
      } else if (!this.form.getFieldValue('roleName')) {
        this.$confirm({
          content: '请先填写角色名称',
          onOk () {
            // that.changeData(record, index)
          },
          onCancel () {}
        })
fengzhaoyu committed
134
      } else {
liang ce committed
135 136 137 138 139 140 141 142 143
        if (this.type === 0) {
          let data = {
            roleName: this.form.getFieldValue('roleName'),
            roleCode: this.form.getFieldValue('roleName'),
            roleDesc: this.form.getFieldValue('roleDesc'),
            ddUserIds: this.ddUserIds,
            menuIds: this.selectList,
            item: 'e-card'
          }
liang ce committed
144
          $http.post(`/admin/manager/addFullRole`, data).then(res => {
liang ce committed
145 146
            if (res.data.code === 0) {
              this.$message.success('保存成功')
liang ce committed
147
              this.$router.push({ name: 'rightsManagement' })
liang ce committed
148 149 150 151 152 153 154 155 156 157 158 159 160
            } else {
              this.$message.error(res.data.msg)
            }
          })
        } else {
          let data = {
            roleId: this.roleId,
            roleName: this.form.getFieldValue('roleName'),
            roleDesc: this.form.getFieldValue('roleDesc'),
            ddUserIds: this.ddUserIds,
            item: 'e-card',
            menuIds: this.selectList
          }
liang ce committed
161
          $http.post(`/admin/manager/modifyFullRole`, data).then(res => {
liang ce committed
162 163 164 165 166 167
            if (res.data.code === 0) {
              this.$message.success('保存成功')
            } else {
              this.$message.error(res.data.msg)
            }
          })
fengzhaoyu committed
168 169 170 171
        }
      }
    },
    getTree () {
liang ce committed
172
      let that = this
fengzhaoyu committed
173 174 175 176
      let data = {
        item: 'e-card'
      }
      $http.post(`/admin/menu/tree`, data).then(success => {
liang ce committed
177 178 179 180 181
        let souceIndex
        let data = success.data.data
        data.map((item, index) => {
          if (item.code === 'sys_super_admin') {
            souceIndex = index
fengzhaoyu committed
182 183
          }
        })
liang ce committed
184 185
        data.splice(souceIndex, 1)
        that.treesdata = that.treeAddAttribute(data)
fengzhaoyu committed
186 187
      })
    },
liang ce committed
188 189 190 191 192
    treeAddAttribute (data) {
      const addKey = data => data.map(item => {
        let plainOptions = []
        item.children.map(item2 => {
          plainOptions.push(item2.id)
fengzhaoyu committed
193
        })
liang ce committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
        var checkedList = [...this.selectList.filter(function (v) {
          return plainOptions.indexOf(v) !== -1 // 利用filter方法来遍历是否有相同的元素
        })]
        var indeterminate = (checkedList !== '' && checkedList.length > 0 && checkedList.length !== plainOptions.length)
        let checkAll = false
        return {
          ...item,
          indeterminate,
          checkedList,
          plainOptions,
          checkAll,
          children: addKey(item.children)
        }
      })
      const result = addKey(data)
      return result
fengzhaoyu committed
210 211 212 213 214
    }
  }
}
</script>

liang ce committed
215
<style lang="less">
fengzhaoyu committed
216 217 218 219 220
  .title{
    font-weight: bolder;
    line-height: 22px;
    margin:27px 0 18px 0;
  }
fengzhaoyu committed
221
  .ant-form-item /deep/ .ant-input {
fengzhaoyu committed
222
    height: 40px;
fengzhaoyu committed
223
    margin-left: 5px;
fengzhaoyu committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
  }
  .addOrRights /deep/ .ant-form-item-label {
    width: 9.5% !important;
  }
  .permisson {
    display: flex;
    height: 500px;
  }
  .permissonLeft {
    height: 65px;
    line-height: 65px;
    font-weight: 400;
    width: 9.5%;
    text-align: right;
    font-size: 14px;
    color: rgba(0,0,0,0.85);
  }
  .permissonRight {
    font-family: 'PingFangSC-Medium;';
    height: 500px;
    width: 100%;
    font-size: 14px;
    color: rgba(0,0,0,0.85);
  }
  .permissonTitle {
    padding: 22px 20px;
    background: #FAFAFA;
    border: 1px solid #F8F8F8;
    border-radius: 4px 4px 0px 0px;
  }
  .confirm {
    margin-top: 40px;
  }
fengzhaoyu committed
257 258 259 260 261 262 263 264 265 266 267
  .addOrRights /deep/ .ant-checkbox-group {
    width: 100% !important;
    color: rgba(0,0,0,0.85);
  }
  .addOrRights /deep/.ant-row {
    width: 100% !important;
  }
  .selectPeople {
    width: 100%;
    font-size: 14px;
    color: #cccccc;
fengzhaoyu committed
268
    min-height: 39px;
fengzhaoyu committed
269 270 271 272 273 274
    line-height: 40px;
    margin-left: 5px;
    text-indent: 10px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 5px;
  }
liang ce committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
  .box2>div{
    display: flex;
    border: 1px solid #f8f8f8;
  }
  .box2-2{
    flex: 4;
    border-right: 1px solid #f8f8f8;
    display: flex;
    align-items: center;
    padding-left: 20px;
  }
  .box3{
    flex: 20;
    padding-top: 22px;
  }
  .box3>div{
    width: 25%;
    float: left;
  }
  .box3-3{
    padding-bottom: 22px;
    padding-left: 22px;
  }
fengzhaoyu committed
298
</style>