roleList.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <a-card size="small" :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="CHECK_ENABLE_STATE" 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. style="word-break: break-all;"
  40. bordered>
  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 class="text-overflows" :title="record.remarks">{{ record.remarks ?record.remarks : '--' }}</span>
  48. </template>
  49. <!-- 操作 -->
  50. <span slot="action" slot-scope="text, record">
  51. <a-icon type="setting" title="菜单权限" :style="{ fontSize: '20px', color: '#e29e14', padding: '0 10px' }" @click="openMenuModal(record)" />
  52. <a-icon type="edit" title="编辑" :style="{fontSize: '20px',color:' #1890FF',padding:' 0 10px'}" @click="handleEdit(record)" />
  53. <a-icon
  54. type="delete"
  55. title="删除"
  56. :style="{fontSize: '20px',color: '#f00',padding: '0 10px'}"
  57. v-if="!record.isEnable"
  58. @click="delect(record)" />
  59. </span>
  60. </s-table>
  61. <roleModal :visible="showModal" :data="itemData" @refresh="refreshTable" @close="showModal = false"></roleModal>
  62. <menuModal :visible="showMenuModal" :data="menuData" @close="showMenuModal = false"></menuModal>
  63. </a-card>
  64. </template>
  65. <script>
  66. import {
  67. STable,
  68. VSelect
  69. } from '@/components'
  70. import roleModal from './roleModal.vue'
  71. import menuModal from './menuModal.vue'
  72. import {
  73. getPowerRoleList,
  74. updateEnableStatus,
  75. delectRolePower,
  76. getMenuList
  77. } from '@/api/powerRole-md.js'
  78. export default {
  79. name: 'RoleList',
  80. components: {
  81. STable,
  82. VSelect,
  83. roleModal,
  84. menuModal
  85. },
  86. data () {
  87. return {
  88. // 查询参数
  89. queryParam: {
  90. name: '',
  91. isEnable: ''
  92. },
  93. showModal: false,
  94. showMenuModal: false,
  95. itemData: {}, // 编辑行数据
  96. menuData: {},
  97. // 表头
  98. columns: [{
  99. title: '序号',
  100. dataIndex: 'no',
  101. width: 60,
  102. align: 'center'
  103. },
  104. {
  105. title: '创建时间',
  106. dataIndex: 'createDate',
  107. width: 150,
  108. align: 'center'
  109. },
  110. {
  111. title: '角色名称',
  112. dataIndex: 'name',
  113. width: 150,
  114. align: 'center'
  115. },
  116. {
  117. title: '角色描述',
  118. dataIndex: 'remarks',
  119. width: 200,
  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. content: '删除后无法恢复,确认删除?',
  202. centered: true,
  203. onOk () {
  204. delectRolePower({
  205. id: row.id
  206. }).then(res => {
  207. console.log(res, 'res1111')
  208. if (res.status == 200) {
  209. _this.$message.success(res.message)
  210. _this.$refs.table.refresh()
  211. }
  212. })
  213. }
  214. })
  215. },
  216. handleEdit (row) {
  217. console.log(row, 'row')
  218. this.showModal = true
  219. this.itemData = row
  220. },
  221. // 修改状态
  222. changeFlagHandle (text, record) {
  223. const _data = {
  224. id: record.id,
  225. flag: record.isEnable ? '1' : '0'
  226. }
  227. updateEnableStatus(_data).then(res => {
  228. if (res.status + '' === '200') {
  229. this.$message.success(res.message)
  230. } else {
  231. record.isEnable = !record.isEnable
  232. }
  233. })
  234. }
  235. }
  236. }
  237. </script>
  238. <style scoped>
  239. .table-page-search-wrapper .ant-form-inline .ant-form-item {
  240. margin-bottom: 0;
  241. }
  242. .action-button {
  243. line-height: 40px;
  244. white-space: nowrap;
  245. padding: 5px 10px;
  246. background-color: #1890ff;
  247. border-radius: 4px;
  248. color: #fff;
  249. margin-right: 5px;
  250. }
  251. .red-text {
  252. background-color: red;
  253. }
  254. .menu-text {
  255. background-color: #f90;
  256. }
  257. </style>