AuthorityManagement.vue 10.2 KB
Newer Older
YazhouChen's avatar
YazhouChen 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 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
<template>
  <div id="main" class="h-all">
    <el-container class="h-all">
      <el-header height = "auto">
        <!-- 条件筛选工具栏 -->
        <div class="header-button-box">
          <el-button v-if="createUserGroupCommand.visible" size = 'mini' icon="el-icon-circle-plus-outline" type="primary"
                     @click="createUserGroup">{{$t("common.createBtn")}}</el-button>
<!--          <el-button v-if="updateUserGroupCommand.visible" size = "mini" class="el-icon-edit" type="primary"-->
<!--                     @click="updateClick">{{$t("common.updateBtn")}}</el-button>-->
          <el-button v-if="deleteUserGroupCommand.visible" size = "mini" class="el-icon-delete" type="danger"
                     @click="deleteClick">{{$t("common.deleteBtn")}}</el-button>
        </div>
      </el-header>
      <!-- table数据表格 -->
      <el-main class="adapt-height-box">
        <el-table
          :empty-text="$t('common.noData')"
          ref="multipleTable"
          :data="userGroupList"
          header-row-class-name="table-header"
          cell-class-name="table-cell"
          class="adapt-height"
          height="auto"
          border
          stripe
          tooltip-effect="dark"
          :highlight-current-row="true"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            :selectable='checkboxDisabled'
            width="28">
          </el-table-column>
          <el-table-column
            prop="usergroupName"
            :label="$t('Security.userGroupName')"
            width="200"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="description"
            :label="$t('Security.userGroupDescription')"
            width="200"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="authority"
            :label="$t('Security.functionAuthority')"
            :formatter="authorityFormatter"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="subnetKey"
            :label="$t('Security.administrativeDomain')"
            :formatter="subnetFormatter"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            width="60px"
            v-if="updateUserGroupCommand.visible"
            :label="$t('common.operation')">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.usergroupKey === '1' ? false : true"
                size="mini"
                style="background: #008000"
                :title="$t('common.updateBtn')"
                @click="updateClick(scope.row)">
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-bianji"></use>
                </svg>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
    <CommandExecuteContext v-bind:commands="commandContext"></CommandExecuteContext>
  </div>
</template>

<script>
import CommandExecuteContext from '../../commands/CommandExecuteContext'
import UserGroupCommands from '../../commands/UserGroupCommands'
import UserGroupService from '../../domain/services/UserGroupService'
import HelperUtil from '../../utils/HelperUtil'
import SubnetService from '../../domain/services/SubnetService'

let curThis = null

export default {
  name: 'AuthorityManagement',
  components: {
    CommandExecuteContext
  },

  // 创建期间
  beforeCreate () {
  },
  // vue加载初始化函数,加载数据
  created: function () {
    curThis = this
    this.getAllUserGroups()
    this.getAllSubnetAuthority()
  },
  mounted () {
  },

  data () {
    return {
      // 命令
      commandContext: {},

      // table参数
      tableHeight: window.innerHeight * 0.7,
      multipleSelection: [],

      // 修改初始化
      updateInitList: [],

      // 删除初始化
      deleteInitList: [],

      // 用户组列表
      userGroupList: [],
      userGroupCollection: {},

      // 全部子网
      subnetList: [],
      subnetCollection: {}
    }
  },

  methods: {
    /**
     * @Description  : handleSelectionChange
     * @author       : ls
     * @date         : 2020/12/22 14:47
     * @param        :
     * @return       :
     */
    handleSelectionChange (val) {
      this.multipleSelection = val
    },

    /**
     * @Description  : clickRow
     * @author       : ls
     * @date         : 2020/12/24 17:20
     * @param        :
     * @return       :
     */
    clickRow (val) {
      let currentRow
      for (let i = 0; i < this.userGroupList.length; i++) {
        if (val.usergroupKey === this.userGroupList[i].usergroupKey) {
          currentRow = i
        }
      }
      if (this.userGroupList[currentRow].editFlag !== 1) {
        this.$refs.multipleTable.toggleRowSelection(val)
      }
    },

    /* ---------------------------界面初始化--------------------------- */

    /***
       * @Description  : 获取全部用户组
       * @author       : zf
       * @date         : 2019/03/21 20:03
       */
    getAllUserGroups: function () {
      let _this = this
      UserGroupService.getAllUserGroups().then(result => {
        // 成功
        _this.userGroupList = Object.values(result)
        _this.userGroupCollection = result
      }).catch(err => {
        // 失败
        _this.InfoTip.errorTip(_this, err)
      })
    },

    /***
       * @Description  : 获取全部管辖范围权限List
       * @author       : zf
       * @date         : 2019/03/14 15:54
       */
    getAllSubnetAuthority: function () {
      let _this = this
      SubnetService.getAllSubnetCollection().then(result => {
        // 成功
        _this.subnetList = Object.values(result)
        _this.subnetCollection = result
      }).catch(err => {
        // 失败
        _this.InfoTip.errorTip(_this, err)
      })
    },

    /* ---------------------------页面显示--------------------------- */

    /***
       * @Description  : 超级用户组权限不能被删除修改
       * @author       : zf
       * @date         : 2019/04/01 15:09
       */
    checkboxDisabled: function (row, rowIndex) {
      let currentIndex
      for (let i = 0; i < this.userGroupList.length; i++) {
        if (this.userGroupList[i].editFlag === 1) {
          currentIndex = i
        }
      }
      if (rowIndex === currentIndex) {
        return false
      } else {
        return true
      }
    },

    /***
       * @Description  : 功能权限过滤
       * @author       : zf
       * @date         : 2019/04/29 14:56
       */
    authorityFormatter: function (row, columns) {
      let result = ''
      if (row.menuFlag === 1) {
        result = this.$t('Security.fullAuthority')
      } else {
        if (row.authority !== null) {
          for (let i = 0; i < row.authority.length; i++) {
            result = result + row.authority[i].authorityNameZH
            if (row.authority[i].editFlag === 0) {
              result = result + '(' + this.$t('Security.editable') + ')'
            }
            if (i !== row.authority.length - 1) {
              result = result + ';'
            }
          }
        }
      }
      return result
    },
    /**
     * @Description  : 子网过滤
     * @author       : ls
     * @date         : 2020/12/28 11:08
     * @param        :
     * @return       :
     */
    subnetFormatter: function (row, columns) {
      let result = ''
      if (row.domainFlag === 1) {
        result = this.$t('Security.fullAuthority')
      } else {
        if (row.subnetKey !== null) {
          for (let i = 0; i < row.subnetKey.length; i++) {
            let flag = 0
            for (let j = 0; j < this.subnetList.length; j++) {
              if (row.subnetKey[i] === this.subnetList[j].subnetKey) {
                result = result + this.subnetList[j].subnetName
                flag = 1
              }
            }
            if (flag === 0) {
              result = result + row.subnetKey[i]
            }
            if (i !== row.subnetKey.length - 1) {
              result = result + ';'
            }
          }
        }
      }
      return result
    },

    /* ---------------------------创建用户组--------------------------- */

    /***
       * @Description  : 点击创建按钮
       * @author       : zf
       * @date         : 2019/03/13 17:37
       */
    createUserGroup: function () {
      // 初始化表单
      this.createUserGroupCommand.execute()
    },
    /* ---------------------------删除用户组--------------------------- */

    /***
       * @Description  : 点击删除按钮
       * @author       : zf
       * @date         : 2019/03/13 17:49
       */
    deleteClick () {
      if (this.multipleSelection.length === 0) {
        this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.DELETE_SELECT_CODE))
      } else {
        this.deleteInitList = []
        for (let i = 0; i < this.multipleSelection.length; i++) {
          // this.deleteInitList.push(this.multipleSelection[i]["usergroupKey"])
          var obj = {'usergroupKey': this.multipleSelection[i]['usergroupKey']}
          this.deleteInitList.push(obj)
        }
        this.deleteUserGroupCommand.execute()
      }
    },

    /* ---------------------------修改选择--------------------------- */
    /**
     * @Description  : updateClick
     * @author       : ls
     * @date         : 2020/12/24 16:07
     * @param        :
     * @return       :
     */
    updateClick (row) {
      this.updateInitList = row
      this.updateUserGroupCommand.execute()
    }
  },

  computed: {
    createUserGroupCommand () {
      return UserGroupCommands.createUserGroupCommand(this.commandContext)
    },
    deleteUserGroupCommand () {
      return UserGroupCommands.deleteUserGroupCommand(this.deleteInitList, this.commandContext)
    },
    updateUserGroupCommand () {
      return UserGroupCommands.updateUserGroupCommand(this.updateInitList, this.commandContext)
    }
  },

  watch: {
    commandContext (newVal, oldVal) {
      if (JSON.stringify(newVal) === '{}') {
        this.getAllUserGroups()
        this.$refs.multipleTable.clearSelection()
      }
      deep: true
    }
  }
}
</script>

<style scoped>

</style>