roleList.vue 9.5 KB

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