roleList.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="table-page-search-wrapper">
  4. <a-form layout="inline">
  5. <a-row :gutter="48">
  6. <a-col :md="6" :sm="24">
  7. <a-form-item label="角色名称">
  8. <a-input allowClear v-model="queryParam.name" placeholder="请输入角色名称"/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="6" :sm="24">
  12. <a-form-item label="状态">
  13. <v-select code="CHECK_ENABLE_STATE" v-model="queryParam.isEnable" allowClear placeholder="请选择状态" ></v-select>
  14. </a-form-item>
  15. </a-col>
  16. <a-col :md="4" :sm="24">
  17. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  18. </a-col>
  19. </a-row>
  20. </a-form>
  21. </div>
  22. <a-divider/>
  23. <div class="table-operator">
  24. <a-button type="primary" icon="plus" @click="openModal">新建</a-button>
  25. </div>
  26. <s-table
  27. ref="table"
  28. size="default"
  29. rowKey="id"
  30. :columns="columns"
  31. :data="loadData"
  32. bordered
  33. >
  34. <span slot="status" slot-scope="text, record">
  35. <a-switch checkedChildren="" unCheckedChildren="" v-model="record.isEnable" @change="changeFlagHandle(text, record)"/>
  36. </span>
  37. <span slot="action" slot-scope="text, record">
  38. <template>
  39. <a class="action-button menu-text" @click="openMenuModal(record)">菜单权限</a>
  40. <a class="action-button" @click="handleEdit(record)">修改</a>
  41. <a v-if="!record.isEnable" class="action-button red-text" @click="delect(record)">删除</a>
  42. </template>
  43. </span>
  44. </s-table>
  45. <roleModal :visible="showModal" :data="itemData" @refresh="refreshTable" @close="showModal = false"></roleModal>
  46. <menuModal :visible="showMenuModal" :data="menuData" @close="showMenuModal = false"></menuModal>
  47. </a-card>
  48. </template>
  49. <script>
  50. import { STable, VSelect } from '@/components'
  51. import roleModal from './roleModal.vue'
  52. import menuModal from './menuModal.vue'
  53. import { getPowerRoleList, updateEnableStatus, delectRolePower, getMenuList } from '@/api/power-role.js'
  54. export default {
  55. name: 'RoleList',
  56. components: {
  57. STable, VSelect, roleModal, menuModal
  58. },
  59. data () {
  60. return {
  61. // 查询参数
  62. queryParam: {
  63. name: '',
  64. isEnable: ''
  65. },
  66. showModal: false,
  67. showMenuModal: false,
  68. itemData: {}, // 编辑行数据
  69. menuData: {},
  70. // 表头
  71. columns: [
  72. {
  73. title: '序号',
  74. dataIndex: 'no',
  75. width: '40',
  76. align: 'center'
  77. },
  78. {
  79. title: '角色名称',
  80. dataIndex: 'name',
  81. width: '100',
  82. align: 'center'
  83. },
  84. {
  85. title: '角色描述',
  86. dataIndex: 'remarks',
  87. width: '100',
  88. align: 'center'
  89. },
  90. {
  91. title: '状态',
  92. width: '100',
  93. align: 'center',
  94. scopedSlots: { customRender: 'status' }
  95. },
  96. {
  97. title: '创建时间',
  98. dataIndex: 'createDate',
  99. width: '120',
  100. align: 'center'
  101. },
  102. {
  103. title: '操作',
  104. width: '100',
  105. align: 'center',
  106. scopedSlots: { customRender: 'action' }
  107. }
  108. ],
  109. // 加载数据方法 必须为 Promise 对象
  110. loadData: parameter => {
  111. return getPowerRoleList(Object.assign(parameter, this.queryParam)).then(res => {
  112. const no = (res.data.pageNo - 1) * res.data.pageSize
  113. for (let i = 0; i < res.data.list.length; i++) {
  114. const _item = res.data.list[i]
  115. _item.no = no + i + 1
  116. _item.isEnable = _item.isEnable + '' === '1'
  117. }
  118. return res.data
  119. })
  120. },
  121. optionAlertShow: false
  122. }
  123. },
  124. beforeRouteEnter (to, from, next) {
  125. next(vm => {
  126. // vm.$refs.table.refresh()
  127. })
  128. },
  129. methods: {
  130. // 刷新列表
  131. refreshTable () {
  132. this.$refs.table.refresh(true)
  133. },
  134. // 新建
  135. openModal () {
  136. this.showModal = true
  137. this.itemData = {}
  138. },
  139. // 打开分配权限弹窗
  140. openMenuModal (row) {
  141. this.getMenuList(row.id)
  142. },
  143. // 获取菜单树列表
  144. getMenuList (id) {
  145. const _this = this
  146. getMenuList({ id: id }).then(res => {
  147. if (res.status == 200) {
  148. _this.menuData = res.data
  149. this.showMenuModal = true
  150. }
  151. })
  152. },
  153. // 删除
  154. delect (row) {
  155. const _this = this
  156. this.$confirm({
  157. title: '警告',
  158. content: '删除后无法恢复,确认删除?',
  159. okText: '确定',
  160. cancelText: '取消',
  161. onOk () {
  162. delectRolePower({
  163. id: row.id
  164. }).then(res => {
  165. if (res.status == 200) {
  166. _this.$message.success('删除成功')
  167. _this.$refs.table.refresh()
  168. } else {
  169. this.$message.error(res.message)
  170. }
  171. }).catch(() => {
  172. _this.$message.success('删除失败, 请稍后重试')
  173. })
  174. }
  175. })
  176. },
  177. handleEdit (row) {
  178. this.showModal = true
  179. this.itemData = row
  180. },
  181. // 修改状态
  182. changeFlagHandle (text, record) {
  183. const _data = {
  184. id: record.id,
  185. flag: record.isEnable ? '1' : '0'
  186. }
  187. updateEnableStatus(_data).then(res => {
  188. if (res.status + '' === '200') {
  189. this.$message.success('修改成功')
  190. } else {
  191. record.isEnable = !record.isEnable
  192. }
  193. })
  194. }
  195. }
  196. }
  197. </script>
  198. <style scoped>
  199. .table-page-search-wrapper .ant-form-inline .ant-form-item{
  200. margin-bottom: 0;
  201. }
  202. .action-button{
  203. line-height: 40px;
  204. white-space: nowrap;
  205. padding: 5px 10px;
  206. background-color: #1890ff;
  207. border-radius: 4px;
  208. color: #fff;
  209. margin-right: 5px;
  210. }
  211. .red-text{
  212. background-color: red;
  213. }
  214. .menu-text {
  215. background-color: #f90;
  216. }
  217. </style>