DataPermissionList.vue 5.39 KB
<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'permission:edit'" @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button
        v-has="'permission:deleteBatch'"
        @click="batchDel"
        v-if="selectedRowKeys.length > 0"
        ghost
        type="primary"
        icon="delete">批量删除
      </a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a> 项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        :columns="columns"
        size="middle"
        bordered
        :pagination="false"
        :dataSource="dataSource"
        :loading="loading"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @expandedRowsChange="handleExpandedRowsChange">
        <span slot="action" slot-scope="text, record">
          <a v-has="'permission:edit'" @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:" @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-has="'permission:addChildren'">
                <a href="javascript:" @click="handleAddSub(record)">添加下级</a>
              </a-menu-item>
              <a-menu-item v-has="'permission:delete'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

        <span slot="status" slot-scope="status">
          <a-tag :key="status" :color="solutionStatusColor(status)">
            {{ solutionStatus(status) }}
          </a-tag>
        </span>

        <!-- 字符串超长截取省略号显示 -->
        <span slot="url" slot-scope="text">
          <j-ellipsis :value="text" :length="25" />
        </span>
        <!-- 字符串超长截取省略号显示-->
        <span slot="component" slot-scope="text">
          <j-ellipsis :value="text" />
        </span>
      </a-table>

    </div>
    <!-- table区域-end -->

    <data-permission-modal ref="modalForm" @ok="modalFormOk"></data-permission-modal>
  </a-card>
</template>

<script>
import DataPermissionModal from './modules/DataPermissionModal'
import { ajaxGetDictItems, getDataPermissionList } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'

const columns = [
  {
    title: '数据名称',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '资源类型',
    dataIndex: 'type',
    key: 'type',
    customRender: function(text) {
      if (text === 0) {
        return '标识'
      } else if (text === 1) {
        return '权限'
      } else {
        return text
      }
    }
  },
  {
    title: '授权标识',
    dataIndex: 'perms',
    key: 'perms'
  },
  {
    title: '状态',
    dataIndex: 'status',
    key: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '排序',
    dataIndex: 'sortNo',
    key: 'sortNo'
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    width: 147
  }
]

export default {
  name: 'DataPermissionList',
  mixins: [JeecgListMixin],
  components: {
    DataPermissionModal,
    JEllipsis
  },
  data() {
    return {
      description: '这是数据权限管理页面',
      // 表头
      columns: columns,
      loading: false,
      statusList: [],
      // 展开的行,受控属性
      expandedRowKeys: [],
      url: {
        list: '/sys/dataPermission/list',
        delete: '/sys/dataPermission/delete',
        deleteBatch: '/sys/dataPermission/deleteBatch'
      }
    }
  },
  methods: {
    loadData() {
      this.dataSource = []
      getDataPermissionList().then((res) => {
        if (res.success) {
          this.dataSource = res.result
        }
      })
      ajaxGetDictItems('valid_status').then((res) => {
        if (res.success) {
          this.statusList = res.result
        }
      })
    },
    handleAddSub(record) {
      this.$refs.modalForm.title = '添加子数据权限'
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.edit({ status: '1', permsType: '1', route: true, 'parentId': record.id, type: 1 })
    },
    handleExpandedRowsChange(expandedRows) {
      this.expandedRowKeys = expandedRows
    },
    solutionStatus(value) {
      let actions = []
      Object.keys(this.statusList).some(key => {
        if (this.statusList[key].value === '' + value) {
          actions.push(this.statusList[key].text)
          return true
        }
      })
      return actions.join('')
    },
    solutionStatusColor(value) {
      let color = 'blue'
      if (0 === value) {
        color = 'red'
      }
      return color
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>