roleManagePage.vue 29.6 KB
Newer Older
qzhxx's avatar
qzhxx 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
<template>
  <div class="roleManagePage H100">
    <div class="head_box">
      <h6>系统管理&nbsp;/&nbsp;角色管理</h6>
      <h4>角色管理</h4>
    </div>
    <div class="content_box">
      <div class="form_box h778px" >
        <el-form :inline="true" :model="form" class="search-form" onsubmit="return false;">
          <el-form-item label="">
            <el-input  size="mini" placeholder="请输入角色名称"  v-model="form.name" @keyup.enter.native="Search" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="mini"  type="primary" class="btn_form_search" @click="Search">查询</el-button>
          </el-form-item>
          <el-form-item class="r-float">
            <el-button size="mini" type="primary" class="btn_form_add" icon="el-icon-plus" @click="addRole()">&nbsp;&nbsp;&nbsp;</el-button>
            <el-dropdown>
              <el-button style="margin-left: 10px;" size="mini" class="btn_form_add">批量操作</el-button>
              <el-dropdown-menu slot="dropdown" >
                <el-dropdown-item @click.native="multipleDelete">批量删除</el-dropdown-item>
                <el-dropdown-item  @click.native="multipleDisable">批量禁用</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
        </el-form>
        <div class="scrool">
          <el-table style="width:100%;" ref="multipleTable"  :data="tableData" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column label="角色名称" prop="name" ></el-table-column>
          <el-table-column label="角色说明" show-overflow-tooltip prop="instruction"></el-table-column>
          <el-table-column label="状态" prop="status" >
            <template slot-scope="scope">
              <div class="statusBox">
                <span class="active" :style="{'backgroundColor':(scope.row.status ? 'rgba(82,196,26,1)' :'rgba(0,0,0,0.25)')}"></span>
                <span class="openKey">{{scope.row.status ? '启用':'禁用'}}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="登录权限" prop="allowLogin" >
            <template slot-scope="scope">
              <div class="statusBox">
                <span class="active" :style="{'backgroundColor':(scope.row.allowLogin ? 'rgba(82,196,26,1)' :'rgba(0,0,0,0.25)')}"></span>
                <span class="openKey">{{scope.row.allowLogin ? '允许':'禁止'}}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作"  header-align="center" align="center" width="230">
            <template slot-scope="scope">
              <el-button-group >
liqin's avatar
liqin committed
51 52 53 54
                <el-button title="编辑" size="mini" type="text" @click="openEdit(scope.row)">编辑&nbsp;|&nbsp;</el-button>
                <el-button title="权限分配" size="mini" type="text" @click="allocate(scope.row)">权限分配&nbsp;|&nbsp;</el-button>
                <el-button title="菜单分配" type="text" size="mini" @click="munuAllocate(scope.row)">菜单分配&nbsp;|&nbsp;</el-button>
                <el-button title="删除" type="text" size="mini" @click="handleDelete(scope.row)">删除</el-button>
qzhxx's avatar
qzhxx committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68
              </el-button-group>
            </template>
          </el-table-column>
        </el-table>
        </div>
        <el-pagination small background
           @current-change="handleCurrentChange"
           :current-page="page.currentPage"
           :page-size="page.pageSize"
           layout="prev, pager, next"
           :total="page.total">
        </el-pagination>
      </div>
      <!--新建弹框-->
liqin's avatar
liqin committed
69
      <el-dialog title="新建" :visible.sync="FormVisible2" :before-close="close2">
qzhxx's avatar
qzhxx committed
70
        <div class="form_box">
liqin's avatar
liqin committed
71
          <el-form :model="roleform" ref="roleform" :rules="rules2"  >
qzhxx's avatar
qzhxx committed
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
            <el-form-item label="角色名称:" prop="name" :label-width="formLabelWidth">
              <el-input v-model="roleform.name" size="small" clearable auto-complete="off" placeholder="请输入您的角色名称"
                        onkeyup="this.value=this.value.replace(/^ +| +$/g,'')"></el-input>
            </el-form-item>
            <el-form-item label="角色说明:" prop="instruction" :label-width="formLabelWidth">
              <el-input v-model="roleform.instruction"  size="small" clearable auto-complete="off" placeholder="输入角色说明"
                        onkeyup="this.value=this.value.replace(/^ +| +$/g,'')"></el-input>
            </el-form-item>
            <el-form-item label="角色状态:" prop="status" :label-width="formLabelWidth">
              <el-radio v-model="roleform.status" label="1">启用</el-radio>
              <el-radio v-model="roleform.status" label="0">禁用</el-radio>
            </el-form-item>
            <el-form-item label="登录权限:" prop="status" :label-width="formLabelWidth">
              <el-radio v-model="roleform.allowLogin" label="1">允许</el-radio>
              <el-radio v-model="roleform.allowLogin" label="0">禁止</el-radio>
            </el-form-item>
            <el-form-item label="权限选择:" prop="permissionIds" :label-width="formLabelWidth" style="height: 275px;">
              <template slot-scope="scope">
                <el-tree
                  :data="treeData"
                  show-checkbox
                  default-expand-all
                  node-key="id"
                  ref="tree1"
                  highlight-current
                  v-model="roleform.permissionIds"
                  @check = 'haha'
                  style="height: 280px;overflow:auto;"
                >
                </el-tree>
              </template>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button class="r-float" size="mini" type="primary" @click="roleSave">确定</el-button>
            <el-button class="r-float" size="mini" @click="close2">取消</el-button>
          </div>
        </div>
      </el-dialog>
      <!--编辑弹框-->
      <el-dialog title="编辑" :visible.sync="FormVisible1"  :before-close="close1">
        <div class="form_box">
          <el-form :model="editform"  ref="editform"  :rules="rules" >
            <el-form-item label="角色名称:" prop="name" :label-width="formLabelWidth" >
              <el-input v-model="editform.name" size="small" clearable auto-complete="off"  onkeyup="this.value=this.value.replace(/^ +| +$/g,'')"></el-input>
            </el-form-item>
            <el-form-item label="角色说明:" prop="instruction" :label-width="formLabelWidth">
              <el-input v-model="editform.instruction" size="small" clearable auto-complete="off"  onkeyup="this.value=this.value.replace(/^ +| +$/g,'')"></el-input>
            </el-form-item>
            <el-form-item label="状  态:" prop="status" :label-width="formLabelWidth">
              <el-radio v-model="editform.status"  label="1">启用</el-radio>
              <el-radio v-model="editform.status"  label="0">禁用</el-radio>
            </el-form-item>
            <el-form-item label="登录权限:" prop="is_allow_login" :label-width="formLabelWidth">
              <el-radio v-model="editform.allowLogin"  label="1">允许</el-radio>
              <el-radio v-model="editform.allowLogin"  label="0">禁止</el-radio>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button class="r-float" size="mini" type="primary" @click="saveEdit('form')">确定</el-button>
            <el-button class="r-float" size="mini" @click="close1">取 消</el-button>
          </div>
        </div>
      </el-dialog>
      <!--权限分配弹框-->
      <el-dialog class="allocate" title=" " :visible.sync="FormVisible"  :before-close="close">
        <div class="form_box allocate">
          <el-form :model="form1"  ref="form1"  :rules="rules"  >
            <el-form-item label="权限选择:" prop="permissionIds" :label-width="formLabelWidth" style="height: 480px;overflow:auto;">
              <template slot-scope="scope">
                <el-tree :data="treeData" show-checkbox node-key="id"
                         default-expand-all ref="tree" highlight-current v-model="form1.permissionIds" @check = 'haha'>
                </el-tree>
              </template>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button class="r-float" size="mini" type="primary" @click="submitForm('form1')">确定</el-button>
            <el-button class="r-float" size="mini" @click="close">取 消</el-button>
          </div>
        </div>
      </el-dialog>
      <!--菜单分配弹框-->
      <el-dialog title="菜单分配" :visible.sync="menuFormVisible">
        <div class="form_box allocate">
          <el-form :model="formMenu"  ref="formMenu">
            <el-form-item label="菜单选择:" prop="permissionIds" :label-width="formLabelWidth" style="height: 480px;overflow:auto;">
              <template slot-scope="scope">
                <el-tree :data="menuTreeData"
                         check-strictly="true"
                         show-checkbox node-key="id"
                         default-expand-all
                         ref="menuTree"
                         highlight-current
                         v-model="formMenu.menuIds" @check ='menuCheck'>
                </el-tree>
              </template>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button class="r-float" size="mini" type="primary" @click="menusubmitForm('formMenu')">确定</el-button>
            <el-button class="r-float" size="mini" @click="memuclose">取 消</el-button>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
  let thisRoleId = '';
  export default {
    data() {
      return {
        page: {
          currentPage: 1, //当前页
          pageSize: null, //每页条数
          total: null, //总条数
        },
        tableData: [],
        treeData: [],
        menuTreeData:[],
        menuTreeIds:[],
        FormVisible: false,
        FormVisible1: false,
        FormVisible2: false,
        menuFormVisible:false,
        formLabelWidth: "100px",
        status: '1',
        allowLogin: '1',
        form:{
          name:''
        },
        roleform: {
          name: '',
          instruction: '',
          status: '1',
          allowLogin: '1',
          permissionIds: '',
        },
        editform: {
          name: '',
          instruction: '',
          status: true,
          allowLogin: true,
        },
        form1: {
          permissionIds: '',
        },
        formMenu:{
          menuIds:''
        },
        typeList: [],
        rules2: {
          name: [
            {required: true, message: '请输入角色名'},
            {max: 20, message: '不能超过20个字符'},
            {pattern: /^([\u4e00-\u9fa5]{1,20}|[a-zA-Z\.\s]{1,20})$/, message: '请输入正确的角色名'}
          ],
          instruction: [
            {required: true, message: '请输入角色说明'},
            {max: 50, message: '不能超过50个字符'},
          ],
          permissionIds: [
            // {required: true, message: '请输入角色说明'},
          ]
        },
        rules: {
          name: [
            {required: true, message: '请输入角色名'},
            {max: 20, message: '不能超过20个字符'}
          ],
          instruction: [
            {required: true, message: '请输入角色说明'},
            {max: 50, message: '不能超过50个字符'},
          ],
        },
        value: '',
        roleId:'',
      }
    },
    computed: {
    },
    mounted() {
      this.onSearch();

    },
    components: {},
    methods: {
      addRole() {
        this.FormVisible2 = true;
        $('.el-dialog__title').html('新建');
        this.getProTree();
      },
      //获得数据接口
      getTableData(param) {
        let vm = this;
        vm.$https({
          url : "role/getRoleList",
          method: 'get',
          authType: this.backToken
        },param).then((res)=>{
          let data = res.data;
          vm.page.pageSize = data.size;
          vm.page.total = data.total;
          vm.tableData = data.records;
        }).catch(function(err){
          console.log(err);
        })
      },
      // 分页
      handleCurrentChange(val) {
        let _this = this;
        _this.page.currentPage = val;
        _this.onSearch();
      },
      onSearch() {
        let _this = this;
        let param = _this.getSearchQuery();
        _this.getTableData(param)
      },
      Search(){
        let _this = this;
        _this.page.currentPage = 1;
        let param = {
liqin's avatar
liqin committed
296
          "_index":  _this.page.currentPage,
qzhxx's avatar
qzhxx committed
297 298 299 300 301 302 303 304 305
          "_size": _this.page.pageSize,
          "name": _this.form.name,
        };
        this.getTableData(param);
      },
      // // 获取当前查询参数
      getSearchQuery() {
        let _this = this;
        let searchObj = {
liqin's avatar
liqin committed
306
          "_index":  _this.page.currentPage,
qzhxx's avatar
qzhxx committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
          "_size": _this.page.pageSize
        };
        for (let key in _this.form) {
          if (_this.form[key]) {
            searchObj[key] = _this.form[key];
          }
        }
        return searchObj;
      },
      // 删除
      handleDelete(row) {
        let _this = this;
        this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          _this.$https({
            method: 'delete',
            url: 'role/delete?roleId='+ row.id,
            authType: this.backToken
          }).then((res) => {
            if(res.data.status == 201 || res.data.status == 200){
              this.$message({type: 'success', message: res.data.message});
            }else{
              this.$message({type: 'error', message: res.data.message});
            }
            _this.Search();
          }, (error) => {
            this.$message({type: 'fail', message: "删除失败!" + error.response.data});
          })
        })
      },
      // 批量操作
      handleSelectionChange(selection){
        let _this = this;
        _this.selection = selection;
      },
      getMultipleSelect () {
        let _this = this;
        let arr = [];
        let str = '';
        if (_this.selection){
          _this.selection.forEach(function (e) {
            arr.push(e.id);
          })
          str = arr.join(',');
        }else{
          str = '';
        }
        return str;
      },
      // 批量禁用
      multipleDisable () {
        let _this = this;
        let str = _this.getMultipleSelect();
        if (str) {
          this.$confirm('此操作将禁用角色权限, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }).then(() => {
            _this.$https({
              url:'role/batchDis?roleIds='+str,
              method:'put',
              authType: this.backToken
            }).then((res) => {
              if(res.data.status == 201 || res.data.status == 200){
                this.$message({type: 'success', message: res.data.message});
              }else{
                this.$message({type: 'error', message: res.data.message});
              }
              //重新查询数据
              _this.onSearch();
            }, (error) => {})
          })
        } else {
          this.$message({
            type: 'info',
            message: '请至少选择一个选项'
          });
        }
      },
      // 批量删除
      multipleDelete () {
        let _this = this;
        let str = _this.getMultipleSelect();
        if (str) {
          this.$confirm('此操作将删除选中角色, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }).then(() => {
            _this.$https({
              url:'role/batchDel?roleIds='+str,
              method:'DELETE',
              authType: this.backToken
            })
              .then((res) => {
                  if(res.data.status == 201 || res.data.status == 200){
                    this.$message({
                      type: 'success',
                      message: res.data.message
                    });
                  }else{
                    this.$message({
                      type: 'error',
                      message: res.data.message
                    });
                  }
                  //重新查询数据
                  _this.onSearch();

                }, (error) => {
                }
              )
          })
        } else {
          this.$message({
            type: 'info',
            message: '请至少选择一个选项!'
          });
        }
      },
      // 新增角色
      roleSave() {
        let _this = this;
        _this.$refs.roleform.validate((valid) => {
          if (valid) {
            let keysId = _this.$refs.tree1.getCheckedKeys();
            let searchObj = {}
            for (let key in _this.roleform) {
              if (_this.roleform[key]) {
                searchObj[key] = _this.roleform[key];
              }
            }
            searchObj.status =_this.roleform.status == '1'? 'true':'false';
            searchObj.allowLogin =_this.roleform.allowLogin == '1'? 'true':'false';
            console.log(keysId);
            let arr = [];
            let str = '';
            keysId.forEach(function (e){
              arr.push(e);
            });
            str =arr.join(',');
            searchObj.permissionIds = str;
            _this.$https({
              url: 'role/add',
              method: 'post',
              authType: this.backToken
            }, _this.$qs.stringify(searchObj)).then((res) => {
                  if (res.data.status == 200 || res.data.status == 201) {
                    _this.$message({
                      type: 'success',
                      message: res.data.message
                    });
                    _this.Search();
                    _this.FormVisible2 = false;
                    for (let key in _this.roleform) {
                      _this.roleform[key]=null;
                    }
                    _this.roleform.status = '1';
                    _this.roleform.allowLogin = '1';
                    _this.$refs['roleform'].resetFields();
                  } else {
                    _this.$message({
                      type: 'error',
                      message: res.data.message
                    });
                  }
                }, (error) => {
                  _this.$message({
                    type: 'error',
                    message: error
                  });
                }
              )
        }
        });
      },
      close1() {
        this.FormVisible1=false;
        this.$refs['editform'].resetFields();
      },
      close2() {
        this.FormVisible2 = false;
        for (let key in this.roleform) {
          this.roleform[key]=null;
        }
        this.roleform.status = '1';
        this.roleform.allowLogin = '1';
        this.$refs['roleform'].resetFields();
      },
      // 编辑弹框
      openEdit(row){
        $('.el-dialog__title').html('编辑');
        let  _this=this;
        _this.$https({
          url : "role/getById?Id="+row.id,
          method: 'get',
          authType: this.backToken
        }).then((res)=>{
          let data = res.data;
          _this.editform = data;
          let status = data.status == true? '1':'0';
          let allowLogin = data.allowLogin == true? '1':'0';
          _this.editform.status= status;
          _this.editform.allowLogin= allowLogin;
        }).catch(function(err){
          console.log(err);
        })
        _this.FormVisible1 = true;
      },
      // 编辑后提交
      saveEdit() {
        let _this = this;
        _this.$refs.editform.validate((valid) => {
          if (valid) {
            let searchObj = {}
            searchObj.id = _this.editform.id;
            searchObj.name = _this.editform.name;
            searchObj.instruction = _this.editform.instruction;
            searchObj.status = _this.editform.status == '1'? true:false;
            searchObj.allowLogin = _this.editform.allowLogin == '1'? true:false;
            if (searchObj.id && searchObj.id != "") {
              _this.$https({
                url: 'role/edit',
                method: 'put',
                authType: this.backToken
              }, _this.$qs.stringify(searchObj))
                .then((res) => {
                    if (res.status == 200) {
                      _this.$message({
                        type: 'success',
                        message: '修改成功!'
                      });
                      //重新查询数据
                      _this.onSearch();
                      // //关闭窗口
                      _this.FormVisible1=false;
                      _this.$refs['editform'].resetFields();

                    } else {
                      _this.$message({
                        type: 'error',
                        message: res.data.message
                      });
                    }
                  }, (error) => {
                  }
                )
            }
          }
        });
      },
      // 权限分配
      allocate(row) {
        this.getProTree();
        $('.el-dialog__title').html('权限分配');
        let  _this=this;
        thisRoleId = row.id;
        _this.$https({
          url : "role/rights?roleId="+row.id,
          method: 'get',
          authType: this.backToken
        }).then((res)=>{
          let data = res.data;
          let arr = [];
          for (let item of data) {
            if(item.checked == 'true'){
              arr.push(item.id);
            }
          }
          _this.$refs.tree.setCheckedKeys(arr);
        }).catch(function(err){
          console.log(err);
        });
        _this.FormVisible = true;
      },
      //菜单分配
      munuAllocate(row){
        $('.el-dialog__title').html('菜单分配');
        let vm=this;
        vm.menuTreeIds=[];
        vm.roleId=row.id
        vm.getMenuTree(row.id)
      },
      haha (data) {
        let _this = this;
        _this.form1.permissionIds = data;
      },
      menuCheck(data){
        this.formMenu.menuIds=data;
      },
      // 渲染权限选择的数据
      getProTree() {
        let _this = this;
        _this.$https({
          method: 'get',
          url: 'role/rights',
          authType: this.backToken
        }).then((res) => {
            let data = res.data;
            let A = [];
            data.map((e, i) => {
              if(e.pId == 0){
                let obj = {
                  id: e.id,
                  label: e.name,
                  children: []
                };
                A.push(obj);
              }
            });
            for (let j in A) {
              for (let i in data) {
                if(data[i].pId == A[j].id) {
                  let obj = {
                    id: data[i].id,
                    label: data[i].name,
                  };
                  A[j].children.push(obj);
                }
              }
            }
            if (_this.treeData == null) {
              _this.treeData = A;
            } else {
              _this.treeData = [];
              _this.treeData = A;
            }
          }, (error) => {
            console.log(error)
          }
        )

      },
      //获取菜单接口
      getMenuTree(roleId){
        let vm = this;
        vm.$https({
          method: 'get',
          url: 'menu/getRoleMenu?roleId='+roleId,
          authType: vm.backToken
        }).then((res) => {
          let treeData=res.data;
          let tempArr=[];
          let tempIds=[];
          for(let i=0,len=treeData.length;i<len;i++){
            let treeObj=treeData[i];
            let obj={};
            if(treeObj.parentId=='0'){ //根节点
              obj.label=treeObj.menuName;
              obj.id=treeObj.id;
              obj.sort=treeObj.sort
              if(treeObj.checked=='true'){
                tempIds.push(treeObj.id)
              }
              obj.children=[];
              for(let k=0,klen=treeData.length;k<klen;k++){
                let ktreeObj=treeData[k];
                let kobj={};
                if(ktreeObj.parentId==treeObj.id){
                  kobj.label=ktreeObj.menuName.split('-')[1];
                  kobj.id=ktreeObj.id;
                  kobj.sort=ktreeObj.sort;
                  if(ktreeObj.checked=='true'){
                    tempIds.push(ktreeObj.id)
                  }
                  obj.children.push(kobj)
                }
              }
            }
            if(JSON.stringify(obj) != "{}"){
              tempArr.push(obj)
            }
          }
          let lastTreeData=tempArr.sort(function (a,b) {
            if(a.children.length!=0){
              a.children.sort(function (c,d) {
                return c.sort-d.sort
              })
            }
            return a.sort-b.sort
          })
          vm.menuTreeIds=tempIds;
          vm.menuTreeData=lastTreeData
          vm.menuFormVisible=true;
          setTimeout(function () {
            vm.$refs['menuTree'].setCheckedKeys(vm.menuTreeIds);
          },100)
          }, (error) => {
            console.log(error)
          }
        )
      },
      // 分配权限
      submitForm() {
        let roleId = thisRoleId;
        let _this = this;
        let keysId = _this.$refs.tree.getCheckedKeys();
        _this.$https({
            url: 'role/updateRoleRights?roleId='+roleId+'&permissionIds='+keysId,
            method: 'post',
            authType: this.backToken
          }).then((res) => {
            if (res.data.status == 200 || res.data.status == 201) {
              _this.$message({
                type: 'success',
                message: res.data.message
              });
              _this.close();
              _this.onSearch();
            } else {
              _this.$message({
                type: 'error',
                message: res.data.message
              });
            }
          }, (error) => {
            _this.$message({
              type: 'error',
              message: error
            });
          })
      },

      menusubmitForm(){
        let _this=this;
        let keysId = _this.$refs['menuTree'].getCheckedKeys();
        let arr = [];
        arr = keysId.map(function (id) {
          return id;
        });
        // console.log(arr);
        _this.$https({
          url: 'role/updateRoleMenu?roleId='+_this.roleId+'&menuIds='+arr,
          method: 'post',
          authType: this.backToken
        }).then((res) => {
          if (res.data.status == 200 || res.data.status == 201) {
            _this.$message({
              type: 'success',
              message: res.data.message
            });
            _this.memuclose();
            _this.onSearch();
          } else {
            _this.$message({
              type: 'error',
              message: res.data.message
            });
          }
        }, (error) => {
          _this.$message({
            type: 'error',
            message: error
          });
        })
      },
      close() {
        this.FormVisible=false;
      },
      memuclose(){
        this.menuFormVisible=false
      }
    }
  }
</script>

<style lang="less">
  @import '../../style/common';
  .roleManagePage{
    .content_box{
      .input_box{
        width: 100%;
        min-width: 815px;
        margin-bottom: 30px;
        .el-input, .el-select{
          max-width:272px;
          height:32px;
          background:rgba(255,255,255,1);
          border-radius:4px;
          .el-input__inner{
            height:32px;
          }
        }
        .btn_form_search,.btn_form_add{
          height: 32px;
          text-align: center;
          padding: 0 15px;
        }
      }
      .scrool {
        width: 100%;
        height: calc(100% - 100px);
        overflow-x: hidden;
        overflow-y: scroll;
        .el-table {
          .el-table__header-wrapper {
            .el-table__header {
              .has-gutter tr th {
                background: rgba(250, 250, 250, 1);
              }

            }
          }
          .el-table__body-wrapper {
            width: 100%;
            table tbody tr td {
              padding: 6px 0px;
            }
          }
        }
      }

      /*提示弹框*/
      .el-message-box__wrapper{
        .el-message-box{
          width:433px !important;
          height: 180px !important;
        }
      }


      /*!*编辑弹框*!*/
      .el-dialog{
        width: 600px;
        margin-top: 12vh!important;
        background:rgba(255,255,255,1);
        box-shadow:0px 4px 12px 0px rgba(0,0,0,0.2);
        border-radius:4px;
        .el-dialog__header{
          padding: 15px;
          border-bottom: 1px solid rgba(0,0,0,0.09);
        }
        .el-dialog__body{
          padding: 0px!important;
          border: 1px solid transparent;
          .form_box{
            padding-bottom: 40px;
            .el-form {
              margin-bottom: 20px;
              .el-form-item{
                margin: 10px  50px 20px;
                .el-form-item__content{
                  width: 360px;
                }
              }
              .el-input{
                width: 100%;
              }
            }
            .dialog-footer{
              border-top: 1px solid rgba(0,0,0,0.09);
              padding-top: 8px;
              .el-button{
                margin-right: 10px;
                padding: 8px 16px;
              }
            }
          }
        }
      }
    }
  }



</style>