OrgAuthPage.vue 19.2 KB
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 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 296 297 298 299 300 301 302 303 304 305 306 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
<template>
  <div class="fullheight">
    <ht-table
      @load="loadData"
      :data="data"
      :pageResult="pageResult"
      :selection="true"
      :quick-search-props="[{prop: 'b.FULLNAME_', label: '管理员'}]"
      ref="htTable"
      :show-custom-column="false"
      :show-export="false"
      @row-click="rowClick"
      @selection-change="handleSelectionChange"
    >
      <template v-slot:toolbar>
        <el-button-group>
          <el-button
            size="small"
            @click="showDialog()"
            icon="el-icon-plus"
            type="primary"
            >添加</el-button
          >
          <ht-delete-button
            :url="demDeleteUrl"
            :htTable="$refs.htTable"
            @after-delete="afterDelete"
            parameter="id"
            :disabled="isDisabled"
            >删除</ht-delete-button
          >
        </el-button-group>
      </template>
      <template>
        <ht-table-column type="index" width="58" align="center" label="序号" />
        <ht-table-column
          prop="userName"
          label="管理员"
          width="128"
          :sortable="true"
          :show-overflow-tooltip="true"
        >
          <template v-slot="{row, column, $index}">
            <el-link
              type="primary"
              @click="handleCommand({row: row, command: 'editOrgAuthPage'})"
              title="点击编辑"
              >{{ row.userName }}</el-link
            >
          </template>
        </ht-table-column>

        <ht-table-column prop="orgName" label="管理的组织" width="150" />
        <ht-table-column prop="demName" label="所属维度" width="100" />
        <ht-table-column prop="orgPerms" label="组织权限" width="180">
          <template v-slot="{row}">
            <el-tag
              v-if="row.orgPerms && row.orgPerms.indexOf('add') >= 0"
              type="info"
              >增加</el-tag
            >
            <el-tag
              v-if="row.orgPerms && row.orgPerms.indexOf('delete') >= 0"
              type="info"
              >删除</el-tag
            >
            <el-tag
              v-if="row.orgPerms && row.orgPerms.indexOf('edit') >= 0"
              type="info"
              >修改</el-tag
            >
          </template>
        </ht-table-column>
        <ht-table-column prop="userPerms" label="组织人员权限" width="180">
          <template v-slot="{row}">
            <el-tag
              v-if="row.userPerms && row.userPerms.indexOf('add') >= 0"
              type="info"
              >增加</el-tag
            >
            <el-tag
              v-if="row.userPerms && row.userPerms.indexOf('delete') >= 0"
              type="info"
              >删除</el-tag
            >
            <el-tag
              v-if="row.userPerms && row.userPerms.indexOf('edit') >= 0"
              type="info"
              >修改</el-tag
            >
            <el-tag
              v-if="row.userPerms && row.userPerms.indexOf('setMaster') >= 0"
              type="info"
              >设置主组织</el-tag
            >
            <el-tag
              v-if="row.userPerms && row.userPerms.indexOf('setPos') >= 0"
              type="info"
              >设置岗位</el-tag
            >
          </template>
        </ht-table-column>
        <ht-table-column prop="posPerms" label="组织岗位权限" width="180">
          <template v-slot="{row}">
            <el-tag
              v-if="row.posPerms && row.posPerms.indexOf('add') >= 0"
              type="info"
              >增加</el-tag
            >
            <el-tag
              v-if="row.posPerms && row.posPerms.indexOf('delete') >= 0"
              type="info"
              >删除</el-tag
            >
            <el-tag
              v-if="row.posPerms && row.posPerms.indexOf('edit') >= 0"
              type="info"
              >修改</el-tag
            >
          </template>
        </ht-table-column>
        <ht-table-column prop="orgauthPerms" label="分级权限" width="180">
          <template v-slot="{row}">
            <el-tag
              v-if="row.orgauthPerms && row.orgauthPerms.indexOf('add') >= 0"
              type="info"
              >增加</el-tag
            >
            <el-tag
              v-if="row.orgauthPerms && row.orgauthPerms.indexOf('delete') >= 0"
              type="info"
              >删除</el-tag
            >
            <el-tag
              v-if="row.orgauthPerms && row.orgauthPerms.indexOf('edit') >= 0"
              type="info"
              >修改</el-tag
            >
          </template>
        </ht-table-column>
        <ht-table-column prop="rolePerms" label="组织角色权限" width="180">
          <template v-slot="{row}">
            <el-tag
              v-if="row.rolePerms && row.rolePerms.indexOf('add') >= 0"
              type="info"
            >
              增加
            </el-tag>
            <el-tag
              v-if="row.rolePerms && row.rolePerms.indexOf('delete') >= 0"
              type="info"
            >
              删除
            </el-tag>
          </template>
        </ht-table-column>
        <!-- <ht-table-column prop="layoutPerms" label="布局权限" width="100">
          <template v-slot="{ row }">
            <el-tag
              v-if="row.layoutPerms && row.layoutPerms.indexOf('add') >= 0"
              type="info">增加</el-tag
            >
            <el-tag
              v-if="row.layoutPerms && row.layoutPerms.indexOf('delete') >= 0"
              type="info">删除</el-tag
            >
            <el-tag
              v-if="row.layoutPerms && row.layoutPerms.indexOf('edit') >= 0"
              type="info">修改</el-tag
            >
          </template>
        </ht-table-column> -->
      </template>
    </ht-table>

    <el-dialog
      width="50%"
      :title="dialogTitle"
      :visible="dialogVisible"
      :before-close="handleClose"
      :destroy-on-close="true"
      :append-to-body="true"
    >
      <el-form v-model="orgAuth" v-form id="authForm">
        <ht-form-item
          label="用户账号"
          prop="name"
          label-width="100px"
          v-show="false"
        >
          <ht-input v-model="orgAuth.account" />
        </ht-form-item>
        <ht-form-item label="组织管理员" prop="name" label-width="100px">
          <!--          <ht-input-->
          <!--            v-model="orgAuth.userName"-->
          <!--            autocomplete="off"-->
          <!--            :validate="{ required: true }"-->
          <!--            :disabled="true"-->
          <!--          ></ht-input>-->
          <!--          <el-button type="primary" icon="el-icon-user" @click="selectUser"-->
          <!--            >选择用户</el-button-->
          <!--          >-->
          <ht-user-selector-input
            v-model="orgAuth.userName"
            placeholder="选择用户"
            :append-to-body="true"
            :single="true"
            @input="valueChange"
            :config="{account: 'orgAuth.account'}"
          />
        </ht-form-item>
        <ht-form-item label="是否全选">
          <el-button icon="icon-test" @click="selectAll">{{
            isSelectAll
          }}</el-button>
        </ht-form-item>
        <ht-form-item label="组织权限" prop="code" label-width="100px">
          <ht-checkbox
            v-model="orgAuth.orgPerms"
            :options="checkValue"
            :validate="{required: false}"
            @input="checkClick"
          />
        </ht-form-item>
        <ht-form-item label="组织人员权限" prop="code" label-width="100px">
          <ht-checkbox
            v-model="orgAuth.userPerms"
            :options="userCheckValue"
            :validate="{required: false}"
            @input="checkClick"
          />
        </ht-form-item>
        <ht-form-item label="组织岗位权限" prop="code" label-width="100px">
          <ht-checkbox
            v-model="orgAuth.posPerms"
            :options="checkValue"
            :validate="{required: false}"
            @input="checkClick"
          />
        </ht-form-item>
        <ht-form-item label="分级权限" prop="code" label-width="100px">
          <ht-checkbox
            v-model="orgAuth.orgauthPerms"
            :options="checkValue"
            :validate="{required: false}"
            @input="checkClick"
          />
        </ht-form-item>
        <!-- <ht-form-item label="布局权限" prop="code" label-width="100px">
          <ht-checkbox
            v-model="orgAuth.layoutPerms"
            :options="checkValue"
            :validate="{ required: false }"
            @input="checkClick"
          />
        </ht-form-item> -->
        <ht-form-item label="组织角色权限" prop="code" label-width="100px">
          <ht-checkbox
            v-model="orgAuth.rolePerms"
            :options="
              checkValue.filter(item => {
                return item.key != 'edit'
              })
            "
            :validate="{required: false}"
            @input="handleRolePermsChange"
          ></ht-checkbox>
        </ht-form-item>
        <ht-form-item
          label="可选角色"
          prop="role"
          label-width="100px"
          v-if="orgAuth.rolePerms"
        >
          <div style="display: inline-block">
            <el-tag
              type="info"
              v-for="(item, index) in selectedRoles"
              :key="'roles_' + index"
              style="margin: 0 5px;"
              closable
              @close="handleRemoveRole(item.code)"
            >
              {{ item.name }}
            </el-tag>
          </div>
          <el-button @click="showRoleDialog">选择</el-button>
        </ht-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!readOnly">
        <el-button @click="dialogCancle('dialogVisible')">{{
          $t('eip.common.cancel')
        }}</el-button>
        <ht-submit-button
          :url="saveRoleUrl"
          :model="orgAuth"
          :isSubmit="isSubmit"
          :requestMethod="requestMethod"
          scopeName="editDemForm"
          @before-save-data="beforeSaveData"
          @after-save-data="afterSaveData"
          >{{ $t('eip.common.save') }}</ht-submit-button
        >
      </div>
    </el-dialog>

    <ht-load-data
      :url="loadDataUrl"
      context="uc"
      @after-load-data="afterLoadData"
    ></ht-load-data>
    <ht-user-dialog
      ref="eipUserDialog"
      @on-confirm="addUnderUser"
      single
      append-to-body
    />
    <ht-role-dialog
      ref="eipRoleSelector"
      append-to-body
      @on-confirm="roleDialogConfirm"
    />
  </div>
</template>
<script>
//分级组织管理
import org from '@/api/org.js'
import EipUserDialog from '@/components/dialog/EipUserDialog.vue'
import EipRoleDialog from '@/components/dialog/EipRoleDialog.vue'

export default {
  name: 'org-auth-page',
  props: ['orgCode', 'demCode'],
  components: {
    EipUserDialog,
    EipRoleDialog
  },
  computed: {
    demDeleteUrl: function() {
      return window.context.uc + '/api/org/v1/orgAuth/deleteOrgAuth'
    },
    saveRoleUrl: function() {
      let preUrl = window.context.uc + '/api/org/v1/orgAuth'
      preUrl += '/saveOrgAuth'
      if (this.orgAuth.id) {
        this.orgAuth.account = this.orgAuth.userAccount
        this.orgAuth.orgCode = this.orgCode
        this.orgAuth.demCode = this.demCode
      }
      return preUrl
    },
    requestMethod: function() {
      return 'POST'
    }
  },
  data() {
    return {
      dialogVisible: false,
      dialogVisibleMenuPerm: false,
      isSubmit: true,
      data: [],
      pageResult: {
        page: 1,
        pageSize: 50,
        total: 0
      },
      loadDataUrl: '',
      menuPerm: {},
      allowRoles: [],
      readOnly: false,
      orgAuth: {
        account: '', //登录账号
        demCode: '',
        layoutPerms: 'show',
        orgCode: '',
        orgPerms: '',
        orgauthPerms: '',
        posPerms: '',
        userId: '',
        userName: '',
        userPerms: '',
        roleConfig: ''
      },
      checkValue: [
        {key: 'add', value: '增加'},
        {key: 'delete', value: '删除'},
        {key: 'edit', value: '修改'}
      ],
      userCheckValue: [
        {key: 'add', value: '增加'},
        {key: 'delete', value: '删除'},
        {key: 'edit', value: '修改'},
        {key: 'setMaster', value: '设置主组织'},
        {key: 'setPos', value: '设置岗位'}
      ],
      isSelectAll: '全选',
      dialogTitle: '',
      selectedRoles: [],
      selectedList: [],
      isDisabled: true
    }
  },
  watch: {
    selectedList: {
      handler(val) {
        this.isDisabled = val.length < 1 ? true : false
      },
      deep: true
    }
  },
  mounted() {
    this.$validator = this.$root.$validator
  },
  methods: {
    rowClick(row, column, event) {
      this.$refs.htTable.$refs.htTable.toggleRowSelection(row)
    },
    checkClick() {
      let checkBoxs = document
        .getElementById('authForm')
        .querySelectorAll('input[type="checkbox"]')
      for (let index = 0; index < checkBoxs.length; index++) {
        if (!checkBoxs[index].checked) {
          this.isSelectAll = '全选'
          return
        }
      }
      this.isSelectAll = '取消全选'
    },
    setDemDefault(row) {
      org.setDemDefault(row.code).then(() => {
        this.$refs.htTable.load()
      })
    },
    handleClose() {
      this.dialogVisible = false
      // this.$refs["orgAuthForm"].resetField();
      this.orgAuth = {
        account: '',
        demCode: '',
        layoutPerms: 'show',
        orgCode: '',
        orgPerms: '',
        orgauthPerms: '',
        posPerms: '',
        userId: '',
        userName: '',
        userPerms: '',
        roleConfig: ''
      }
      this.selectedRoles.splice(0)
      this.loadDataUrl = ''
    },
    handleCloseMenuPerm() {
      this.dialogVisibleMenuPerm = false
    },
    showDialog(row) {
      this.isSelectAll = '全选'
      this.dialogVisible = true
      if (row) {
        this.dialogTitle = '编辑管理员权限'
        this.loadDataUrl = `/api/org/v1/orgAuth/getOrgAuth?id=${row.id}`
      } else {
        this.dialogTitle = '添加管理员权限'
        this.orgAuth = {name: '', code: ''}
      }
    },
    dialogCancle(dialogVisible) {
      this[dialogVisible] = false
      this.orgAuth = {
        account: '',
        demCode: '',
        layoutPerms: 'show',
        orgCode: '',
        orgPerms: '',
        orgauthPerms: '',
        posPerms: '',
        userId: '',
        userName: '',
        userPerms: '',
        roleConfig: ''
      }
      this.selectedRoles.splice(0)
      this.loadDataUrl = ''
    },
    loadData(param, cb) {
      org
        .getOrgAuthPage(param, {orgCode: this.orgCode})
        .then(response => {
          this.data = response.rows
          this.$emit('orgAuthData', this.data)
          this.pageResult = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total
          }
        })
        .finally(() => cb())
    },
    handleCommand(params) {
      this.readOnly = false
      switch (params.command) {
        case 'editOrgAuthPage':
          this.isSelectAll = '全选'
          this.showDialog(params.row)
          break
        default:
          break
      }
    },
    async beforeSaveData() {
      if (this.selectedRoles) {
        this.orgAuth.roleConfig = JSON.stringify(this.selectedRoles)
      } else {
        this.orgAuth.roleConfig = '[]'
      }
      this.isSubmit = true
    },
    afterSaveData() {
      this.dialogVisible = false
      this.isSelectAll = '全选'
      this.$refs.htTable.load()
    },
    afterDelete() {
      this.$refs.htTable.load()
    },
    afterLoadData(data) {
      if (this.dialogVisible) {
        this.orgAuth = data
        if (data.roleConfig) {
          let roles = JSON.parse(data.roleConfig)
          this.$set(this, 'selectedRoles', roles)
        } else {
          this.$set(this, 'selectedRoles', [])
        }
        this.isSelectAllFun()
        setTimeout(() => this.$validator.validateAll('editDemForm'), 500)
      }
    },
    isSelectAllFun() {
      if (
        this.orgAuth['orgPerms'] !== 'add,edit,delete' ||
        this.orgAuth['userPerms'] !== 'add,edit,delete,setMaster,setPos' ||
        this.orgAuth['posPerms'] !== 'add,edit,delete' ||
        this.orgAuth['orgauthPerms'] !== 'add,edit,delete' ||
        this.orgAuth['layoutPerms'] !== 'add,edit,delete' ||
        this.orgAuth['rolePerms'] !== 'add,delete'
      ) {
        this.isSelectAll = '全选'
      } else {
        this.isSelectAll = '取消全选'
      }
    },
    selectUser() {
      this.$refs.eipUserDialog.showDialog()
    },
    addUnderUser(selection) {
      if (!selection || selection.length != 1) {
        this.$message.error('有且只能有一个用户')
        return
      }
      for (let user of selection) {
        this.orgAuth.account = user.account
        // this.orgAuth.userName = user.fullname
        this.$set(this.orgAuth, 'userName', user.fullname)
        this.orgAuth.orgCode = this.orgCode
        this.orgAuth.demCode = this.demCode
      }
    },
    selectAll() {
      //全选操作
      if (this.isSelectAll === '全选') {
        this.isSelectAll = '取消全选'
        this.$set(this.orgAuth, 'orgPerms', 'add,edit,delete')
        this.$set(this.orgAuth, 'userPerms', 'add,edit,delete,setMaster,setPos')
        this.$set(this.orgAuth, 'posPerms', 'add,edit,delete')
        this.$set(this.orgAuth, 'orgauthPerms', 'add,edit,delete')
        this.$set(this.orgAuth, 'layoutPerms', 'add,edit,delete')
        this.$set(this.orgAuth, 'rolePerms', 'add,delete')
      } else {
        this.isSelectAll = '全选'
        this.$set(this.orgAuth, 'orgPerms', '')
        this.$set(this.orgAuth, 'userPerms', '')
        this.$set(this.orgAuth, 'posPerms', '')
        this.$set(this.orgAuth, 'orgauthPerms', '')
        this.$set(this.orgAuth, 'layoutPerms', '')
        this.$set(this.orgAuth, 'rolePerms', '')
      }
    },
    valueChange() {
      this.orgAuth.orgCode = this.orgCode
      this.orgAuth.demCode = this.demCode
    },
    showRoleDialog() {
      this.$refs['eipRoleSelector'].showDialog()
    },
    roleDialogConfirm(selection) {
      if (!selection || selection.length == 0) {
        this.$set(this, 'selectedRoles', [])
        return
      }
      this.$set(
        this,
        'selectedRoles',
        selection.map(item => {
          let {code, name} = item
          return {code, name}
        })
      )
    },
    handleRemoveRole(code) {
      this.$set(
        this,
        'selectedRoles',
        this.selectedRoles.filter(item => {
          return !(item.code === code)
        })
      )
    },
    handleRolePermsChange() {
      if (!this.orgAuth.rolePerms) {
        this.selectedRoles.splice(0)
      }
      this.checkClick()
    },
    handleSelectionChange(selection) {
      this.selectedList = selection
    }
  }
}
</script>
<style scoped lang="scss">
div[aria-invalid='true'] >>> .el-input__inner,
div[aria-invalid='true'] >>> .el-input__inner:focus {
  border-color: #f56c6c;
}
::v-deep .el-table {
  .cell {
    padding: 7px 10px;
    .el-tag.el-tag--info {
      margin-right: 7px;
      margin-bottom: 10px;
    }
  }
  .el-table__cell.is-center {
    text-align: left;
  }
}
::v-deep .pagination-panel {
  display: flex;
  justify-content: end;
}
::v-deep .inputs.ht-form-inputs__inline {
  display: inline-block;
  width: 100%;
}
</style>