roleList.vue 7.0 KB

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