roleList.vue 8.8 KB

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