roleList.vue 6.9 KB

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