roleList.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.trim="queryParam.name" @pressEnter="$refs.table.refresh(true)" id="roleList-name" placeholder="请输入角色名称30个字以内"/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="6" :sm="24">
  12. <a-form-item label="状态">
  13. <v-select code="ENABLE_FLAG" v-model="queryParam.isEnable" id="roleList-isEnable" allowClear placeholder="请选择状态" ></v-select>
  14. </a-form-item>
  15. </a-col>
  16. <a-col :md="6" :sm="24">
  17. <a-button type="primary" @click="$refs.table.refresh(true)" style="margin-right: 10px;" id="roleList-handSubmit">查询</a-button>
  18. <a-button @click="reset" id="roleList-reset">重置</a-button>
  19. </a-col>
  20. </a-row>
  21. </a-form>
  22. </div>
  23. <a-divider/>
  24. <div class="table-operator">
  25. <a-button type="primary" icon="plus" @click="openModal" v-hasPermission="'B_supervision_role_add'" id="roleList-openModal">新建</a-button>
  26. </div>
  27. <s-table
  28. ref="table"
  29. size="default"
  30. :rowKey="(row)=>row.id"
  31. :columns="columns"
  32. :data="loadData"
  33. bordered
  34. >
  35. <span slot="status" slot-scope="text, record">
  36. <a-switch
  37. checkedChildren="启用"
  38. unCheckedChildren="禁用"
  39. v-model="record.isEnable"
  40. @change="changeFlagHandle(text, record)"
  41. v-hasPermission="'B_supervision_role_enable'"
  42. id="roleList-changeFlagHandle"/>
  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 }}</span>
  47. </template>
  48. <span slot="action" slot-scope="text, record">
  49. <a class="action-button menu-text" @click="openMenuModal(record)" v-hasPermission="'M_power_role_menu'" id="roleList-openMenuModal">菜单权限</a>
  50. <a class="action-button" @click="handleEdit(record)" v-hasPermission="'B_supervision_role_edit'" id="roleList-handleEdit">修改</a>
  51. <a v-if="!record.isEnable" v-hasPermission="'B_supervision_role_del'" class="action-button red-text" @click="delect(record)" id="roleList-delect">删除</a>
  52. </span>
  53. </s-table>
  54. <!-- 新增、编辑角色弹窗 -->
  55. <roleModal :visible="showModal" :data="itemData" @refresh="refreshTable" @close="showModal = false"></roleModal>
  56. <!-- 菜单权限弹窗 -->
  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/supervision-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: 200,
  93. align: 'center'
  94. },
  95. {
  96. title: '角色名称',
  97. dataIndex: 'name',
  98. width: 150,
  99. align: 'center'
  100. },
  101. {
  102. title: '角色描述',
  103. dataIndex: 'remarks',
  104. width: 200,
  105. ellipsis: true, // 内容超过宽度 自动出现省略号
  106. align: 'center',
  107. scopedSlots: { customRender: 'remarks' }
  108. },
  109. {
  110. title: '状态',
  111. width: 150,
  112. align: 'center',
  113. scopedSlots: { customRender: 'status' }
  114. },
  115. {
  116. title: '操作',
  117. width: 200,
  118. align: 'center',
  119. scopedSlots: { customRender: 'action' }
  120. }
  121. ],
  122. // 加载数据方法 必须为 Promise 对象
  123. loadData: parameter => {
  124. return getPowerRoleList(Object.assign(parameter, this.queryParam)).then(res => {
  125. const no = (res.data.pageNo - 1) * res.data.pageSize
  126. for (let i = 0; i < res.data.list.length; i++) {
  127. const _item = res.data.list[i]
  128. _item.no = no + i + 1
  129. _item.isEnable = _item.isEnable == 1
  130. }
  131. return res.data
  132. })
  133. },
  134. optionAlertShow: false
  135. }
  136. },
  137. methods: {
  138. // 刷新列表
  139. refreshTable () {
  140. this.$refs.table.refresh(true)
  141. },
  142. // 新建
  143. openModal () {
  144. this.showModal = true
  145. this.itemData = {}
  146. },
  147. // 打开分配权限弹窗
  148. openMenuModal (row) {
  149. this.getMenuList(row.id)
  150. },
  151. // 获取菜单树列表
  152. getMenuList (id) {
  153. const _this = this
  154. getMenuList({ id: id }).then(res => {
  155. if (res.status == 200) {
  156. _this.menuData = res.data
  157. this.showMenuModal = true
  158. }
  159. })
  160. },
  161. // 重置
  162. reset () {
  163. this.queryParam = {
  164. name: '',
  165. isEnable: ''
  166. }
  167. this.$refs.table.refresh(true)
  168. },
  169. // 删除
  170. delect (row) {
  171. const _this = this
  172. this.$confirm({
  173. title: '警告',
  174. content: '删除后无法恢复,确认删除?',
  175. okText: '确定',
  176. cancelText: '取消',
  177. onOk () {
  178. delectRolePower({
  179. id: row.id
  180. }).then(res => {
  181. if (res.status == 200) {
  182. _this.$message.success(res.message)
  183. _this.$refs.table.refresh()
  184. }
  185. })
  186. }
  187. })
  188. },
  189. handleEdit (row) {
  190. this.showModal = true
  191. this.itemData = row
  192. },
  193. // 修改状态
  194. changeFlagHandle (text, record) {
  195. const _data = {
  196. id: record.id,
  197. flag: record.isEnable ? '1' : '0'
  198. }
  199. updateEnableStatus(_data).then(res => {
  200. if (res.status == 200) {
  201. this.$message.success(res.message)
  202. } else {
  203. record.isEnable = !record.isEnable
  204. }
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style scoped>
  211. .table-page-search-wrapper .ant-form-inline .ant-form-item{
  212. margin-bottom: 0;
  213. }
  214. .action-button{
  215. line-height: 40px;
  216. white-space: nowrap;
  217. padding: 5px 10px;
  218. background-color: #1890ff;
  219. border-radius: 4px;
  220. color: #fff;
  221. margin-right: 5px;
  222. }
  223. .red-text{
  224. background-color: red;
  225. }
  226. .menu-text {
  227. background-color: #f90;
  228. }
  229. </style>