roleList.vue 8.8 KB

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