roleList.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <a-card size="small" :bordered="false">
  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 v-if="$hasPermissions('B_powerMD_role_add')" type="primary" 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', wordBreak: 'break-all' }"
  37. size="small"
  38. rowKey="id"
  39. :columns="columns"
  40. :data="loadData"
  41. :scroll="{ y: tableHeight }"
  42. :defaultLoadData="false"
  43. bordered>
  44. <!-- 启用禁用 -->
  45. <span slot="status" slot-scope="text, record">
  46. <a-switch
  47. v-if="$hasPermissions('B_powerMD_role_enable')"
  48. checkedChildren="启用"
  49. unCheckedChildren="禁用"
  50. id="roleList-isEnable"
  51. v-model="record.isEnable"
  52. @change="changeFlagHandle(text, record)" />
  53. <span v-else>{{ record.isEnable==1?'已启用':'已禁用' }}</span>
  54. </span>
  55. <!-- 角色描述 -->
  56. <template slot="remarks" slot-scope="text, record">
  57. <span class="text-overflows" :title="record.remarks">{{ record.remarks ?record.remarks : '--' }}</span>
  58. </template>
  59. <!-- 操作 -->
  60. <span slot="action" slot-scope="text, record">
  61. <a-icon v-if="$hasPermissions('M_powerMD_role_menu')" type="setting" title="菜单权限" :style="{ fontSize: '20px', color: '#e29e14', padding: '0 10px' }" @click="openMenuModal(record)" />
  62. <a-icon v-if="$hasPermissions('B_powerMD_role_edit')" type="edit" title="编辑" :style="{fontSize: '20px',color:' #1890FF',padding:' 0 10px'}" @click="handleEdit(record)" />
  63. <a-icon
  64. type="delete"
  65. title="删除"
  66. :style="{fontSize: '20px',color: '#f00',padding: '0 10px'}"
  67. v-if="!record.isEnable && $hasPermissions('B_powerMD_role_del')"
  68. @click="delect(record)" />
  69. </span>
  70. </s-table>
  71. </a-spin>
  72. <roleModal :visible="showModal" :data="itemData" @refresh="refreshTable" @close="showModal = false"></roleModal>
  73. <menuModal ref="menuData" :visible="showMenuModal" @close="closeMenu"></menuModal>
  74. </a-card>
  75. </template>
  76. <script>
  77. import {
  78. STable,
  79. VSelect
  80. } from '@/components'
  81. import roleModal from './roleModal.vue'
  82. import menuModal from './menuModal.vue'
  83. import {
  84. getPowerRoleList,
  85. updateEnableStatus,
  86. delectRolePower
  87. } from '@/api/powerRole-md.js'
  88. export default {
  89. name: 'RoleList',
  90. components: {
  91. STable,
  92. VSelect,
  93. roleModal,
  94. menuModal
  95. },
  96. data () {
  97. return {
  98. spinning: false,
  99. tableHeight: 0,
  100. // 查询参数
  101. queryParam: {
  102. name: '',
  103. isEnable: ''
  104. },
  105. showModal: false,
  106. showMenuModal: false,
  107. itemData: {}, // 编辑行数据
  108. // 表头
  109. columns: [
  110. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  111. { title: '创建时间', dataIndex: 'createDate', width: '15%', align: 'center' },
  112. { title: '角色名称', dataIndex: 'name', width: '25%', align: 'center' },
  113. { title: '角色描述', dataIndex: 'remarks', width: '25%', align: 'center', scopedSlots: { customRender: 'remarks' } },
  114. { title: '启用状态', width: '15%', align: 'center', scopedSlots: { customRender: 'status' } },
  115. { title: '操作', width: '15%', align: 'center', scopedSlots: { customRender: 'action' } }
  116. ],
  117. // 加载数据方法 必须为 Promise 对象
  118. loadData: parameter => {
  119. this.spinning = true
  120. return getPowerRoleList(Object.assign(parameter, this.queryParam)).then(res => {
  121. let data
  122. if (res.status == 200) {
  123. data = res.data
  124. const no = (data.pageNo - 1) * data.pageSize
  125. for (let i = 0; i < data.list.length; i++) {
  126. const _item = data.list[i]
  127. _item.no = no + i + 1
  128. _item.isEnable = _item.isEnable + '' === '1'
  129. }
  130. }
  131. this.spinning = false
  132. return 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.showMenuModal = true
  162. this.$nextTick(()=>{
  163. this.$refs.menuData.getmenuData(row.id)
  164. })
  165. },
  166. closeMenu(){
  167. this.showMenuModal = false
  168. },
  169. // 删除
  170. delect (row) {
  171. const _this = this
  172. this.$confirm({
  173. title: '警告',
  174. content: '删除后无法恢复,确认删除?',
  175. centered: true,
  176. onOk () {
  177. _this.spinning = true
  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. _this.spinning = false
  185. } else {
  186. _this.spinning = false
  187. }
  188. })
  189. }
  190. })
  191. },
  192. handleEdit (row) {
  193. this.showModal = true
  194. this.itemData = row
  195. },
  196. // 修改状态
  197. changeFlagHandle (text, record) {
  198. const _data = {
  199. id: record.id,
  200. flag: record.isEnable ? '1' : '0'
  201. }
  202. this.spinning = true
  203. updateEnableStatus(_data).then(res => {
  204. if (res.status == 200) {
  205. this.$message.success(res.message)
  206. this.$refs.table.refresh()
  207. this.spinning = false
  208. } else {
  209. this.$refs.table.refresh()
  210. this.spinning = false
  211. }
  212. })
  213. },
  214. pageInit () {
  215. const _this = this
  216. this.$nextTick(() => { // 页面渲染完成后的回调
  217. _this.setTableH()
  218. })
  219. },
  220. setTableH () {
  221. const tableSearchH = this.$refs.tableSearch.offsetHeight
  222. this.tableHeight = window.innerHeight - tableSearchH - 235
  223. }
  224. },
  225. watch: {
  226. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  227. this.setTableH()
  228. }
  229. },
  230. mounted () {
  231. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  232. this.pageInit()
  233. this.reset()
  234. }
  235. },
  236. activated () {
  237. // 如果是新页签打开,则重置当前页面
  238. if (this.$store.state.app.isNewTab) {
  239. this.pageInit()
  240. this.reset()
  241. }
  242. }
  243. }
  244. </script>
  245. <style scoped>
  246. .action-button {
  247. line-height: 40px;
  248. white-space: nowrap;
  249. padding: 5px 10px;
  250. background-color: #1890ff;
  251. border-radius: 4px;
  252. color: #fff;
  253. margin-right: 5px;
  254. }
  255. .red-text {
  256. background-color: red;
  257. }
  258. .menu-text {
  259. background-color: #f90;
  260. }
  261. </style>