index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="table-page-search-wrapper" v-if="hasPerm('sysRole:page')">
  4. <a-form layout="inline">
  5. <a-row :gutter="48">
  6. <a-col :md="8" :sm="24">
  7. <a-form-item label="角色名">
  8. <a-input v-model="queryParam.name" allow-clear placeholder="请输入角色名"/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="8" :sm="24">
  12. <a-form-item label="唯一编码">
  13. <a-input v-model="queryParam.code" allow-clear placeholder="请输入唯一编码"/>
  14. </a-form-item>
  15. </a-col>
  16. <a-col :md="8" :sm="24">
  17. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  18. <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
  19. </a-col>
  20. </a-row>
  21. </a-form>
  22. </div>
  23. <div class="table-operator" v-if="hasPerm('sysRole:add')" >
  24. <a-button type="primary" v-if="hasPerm('sysRole:add')" icon="plus" @click="$refs.addForm.add()">新增角色</a-button>
  25. </div>
  26. <s-table
  27. ref="table"
  28. size="default"
  29. :columns="columns"
  30. :data="loadData"
  31. :alert="true"
  32. :rowKey="(record) => record.code"
  33. :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  34. >
  35. <span slot="action" slot-scope="text, record">
  36. <a v-if="hasPerm('sysRole:edit')" @click="$refs.editForm.edit(record)">编辑</a>
  37. <a-divider type="vertical" v-if="hasPerm('sysRole:edit')"/>
  38. <a-dropdown v-if="hasPerm('sysRole:grantMenu') || hasPerm('sysRole:grantData') || hasPerm('sysRole:delete')">
  39. <a class="ant-dropdown-link">
  40. 更多 <a-icon type="down" />
  41. </a>
  42. <a-menu slot="overlay">
  43. <a-menu-item v-if="hasPerm('sysRole:grantMenu')">
  44. <a @click="$refs.roleMenuForm.roleMenu(record)">授权菜单</a>
  45. </a-menu-item>
  46. <a-menu-item v-if="hasPerm('sysRole:grantData')">
  47. <a @click="$refs.roleOrgForm.roleOrg(record)">授权数据</a>
  48. </a-menu-item>
  49. <a-menu-item v-if="hasPerm('sysRole:delete')">
  50. <a-popconfirm placement="topRight" title="确认删除?" @confirm="() => sysRoleDelete(record)">
  51. <a>删除</a>
  52. </a-popconfirm>
  53. </a-menu-item>
  54. </a-menu>
  55. </a-dropdown>
  56. </span>
  57. </s-table>
  58. <add-form ref="addForm" @ok="handleOk" />
  59. <edit-form ref="editForm" @ok="handleOk" />
  60. <role-menu-form ref="roleMenuForm" @ok="handleOk"/>
  61. <role-org-form ref="roleOrgForm" @ok="handleOk"/>
  62. </a-card>
  63. </template>
  64. <script>
  65. import { STable } from '@/components'
  66. import { getRolePage, sysRoleDelete } from '@/api/modular/system/roleManage'
  67. import addForm from './addForm'
  68. import editForm from './editForm'
  69. import roleMenuForm from './roleMenuForm'
  70. import roleOrgForm from './roleOrgForm'
  71. export default {
  72. components: {
  73. STable,
  74. addForm,
  75. editForm,
  76. roleMenuForm,
  77. roleOrgForm
  78. },
  79. data () {
  80. return {
  81. // 查询参数
  82. queryParam: {},
  83. // 表头
  84. columns: [
  85. {
  86. title: '角色名',
  87. dataIndex: 'name'
  88. },
  89. {
  90. title: '唯一编码',
  91. dataIndex: 'code'
  92. },
  93. {
  94. title: '排序',
  95. dataIndex: 'sort'
  96. }
  97. ],
  98. // 加载数据方法 必须为 Promise 对象
  99. loadData: parameter => {
  100. return getRolePage(Object.assign(parameter, this.queryParam)).then((res) => {
  101. return res.data
  102. })
  103. },
  104. selectedRowKeys: [],
  105. selectedRows: []
  106. }
  107. },
  108. created () {
  109. if (this.hasPerm('sysRole:edit') || this.hasPerm('sysRole:grantMenu') || this.hasPerm('sysRole:grantData') || this.hasPerm('sysRole:delete')) {
  110. this.columns.push({
  111. title: '操作',
  112. width: '150px',
  113. dataIndex: 'action',
  114. scopedSlots: { customRender: 'action' }
  115. })
  116. }
  117. },
  118. methods: {
  119. sysRoleDelete (record) {
  120. sysRoleDelete(record).then((res) => {
  121. if (res.success) {
  122. this.$message.success('删除成功')
  123. this.$refs.table.refresh()
  124. } else {
  125. this.$message.error('删除失败:' + res.message)
  126. }
  127. }).catch((err) => {
  128. this.$message.error('删除错误:' + err.message)
  129. })
  130. },
  131. handleOk () {
  132. this.$refs.table.refresh()
  133. },
  134. onSelectChange (selectedRowKeys, selectedRows) {
  135. this.selectedRowKeys = selectedRowKeys
  136. this.selectedRows = selectedRows
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="less">
  142. .table-operator {
  143. margin-bottom: 18px;
  144. }
  145. button {
  146. margin-right: 8px;
  147. }
  148. </style>