roleList.vue 7.5 KB

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