RoleUserList.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <a-row :gutter="10">
  3. <a-col :md="leftColMd" :sm="24" style="margin-bottom: 20px">
  4. <a-card :bordered="false">
  5. <!-- 查询区域 -->
  6. <div class="table-page-search-wrapper">
  7. <!-- 搜索区域 -->
  8. <a-form layout="inline" @keyup.enter.native="searchQuery">
  9. <a-row :gutter="24">
  10. <a-col :md="12" :sm="8">
  11. <a-form-item label="角色名称" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
  12. <a-input placeholder="" v-model="queryParam.roleName"></a-input>
  13. </a-form-item>
  14. </a-col>
  15. <!--
  16. <a-col :md="11" :sm="12">
  17. <a-form-item label="创建时间" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
  18. <j-date v-model="queryParam.createTime_begin" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择开始时间" ></j-date>
  19. <span style="width: 10px;">~</span>
  20. <j-date v-model="queryParam.createTime_end" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择结束时间"></j-date>
  21. </a-form-item>
  22. </a-col>
  23. -->
  24. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  25. <a-col :md="12" :sm="24">
  26. <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 21px">查询</a-button>
  27. <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
  28. </a-col>
  29. </span>
  30. </a-row>
  31. </a-form>
  32. </div>
  33. <!-- 操作按钮区域 -->
  34. <div class="table-operator" style="margin: 5px 0 10px 2px">
  35. <a-button @click="handleAdd" type="primary" icon="plus" v-has='"role:add"'>新建角色</a-button>
  36. <!--<a-button @click="handleEdit(model1)" type="primary" icon="plus">角色编辑</a-button>-->
  37. <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel" v-has='"role:import"'>
  38. <a-button type="primary" icon="import">导入</a-button>
  39. </a-upload>
  40. <a-button type="primary" icon="download" @click="handleExportXls('角色管理')" v-has='"role:export"'>导出</a-button>
  41. </div>
  42. <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
  43. <i class="anticon anticon-info-circle ant-alert-icon">
  44. </i> 已选择 <a><b>{{ selectedRowKeys1.length }}</b></a>项
  45. <a style="margin-left: 24px" @click="onClearSelected1">清空</a>
  46. </div>
  47. <div style="margin-top: 15px">
  48. <a-table
  49. style="height:500px"
  50. ref="table"
  51. size="middle"
  52. bordered
  53. rowKey="id"
  54. :columns="columns"
  55. :dataSource="dataSource"
  56. :pagination="ipagination"
  57. :loading="loading"
  58. :rowSelection="{selectedRowKeys: selectedRowKeys1, onChange: onSelectChange1, type:'radio'}"
  59. @change="handleTableChange">
  60. <span slot="action" slot-scope="text, record">
  61. <a @click="handleOpen(record)" v-has='"role:user"'>用户</a>
  62. <a-divider type="vertical"/>
  63. <a-dropdown v-has='"role:more"'>
  64. <a class="ant-dropdown-link">
  65. 更多 <a-icon type="down"/>
  66. </a>
  67. <a-menu slot="overlay">
  68. <a-menu-item v-has='"role:jurisdiction"'>
  69. <a @click="handlePerssion(record.id)">授权</a>
  70. </a-menu-item>
  71. <a-menu-item v-has='"role:edit"'>
  72. <a @click="handleEdit(record)">编辑</a>
  73. </a-menu-item>
  74. <a-menu-item v-has='"role:delete"'>
  75. <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete1(record.id)">
  76. <a>删除</a>
  77. </a-popconfirm>
  78. </a-menu-item>
  79. </a-menu>
  80. </a-dropdown>
  81. </span>
  82. </a-table>
  83. </div>
  84. <!-- 右侧的角色权限配置 -->
  85. <user-role-modal ref="modalUserRole"></user-role-modal>
  86. <role-modal ref="modalForm" @ok="modalFormOk"></role-modal>
  87. </a-card>
  88. </a-col>
  89. <a-col :md="rightColMd" :sm="24" v-if="this.rightcolval == 1">
  90. <a-card :bordered="false">
  91. <div style="text-align: right;">
  92. <a-icon type="close-circle" @click="hideUserList" />
  93. </div>
  94. <!-- 查询区域 -->
  95. <div class="table-page-search-wrapper">
  96. <a-form layout="inline">
  97. <a-row :gutter="24">
  98. <a-col :md="12" :sm="12">
  99. <a-form-item label="用户账号">
  100. <a-input placeholder="" v-model="queryParam2.username"></a-input>
  101. </a-form-item>
  102. </a-col>
  103. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  104. <a-col :md="9" :sm="24">
  105. <a-button type="primary" @click="searchQuery2" icon="search" style="margin-left: 21px">查询</a-button>
  106. <a-button type="primary" @click="searchReset2" icon="reload" style="margin-left: 8px">重置</a-button>
  107. </a-col>
  108. </span>
  109. </a-row>
  110. </a-form>
  111. </div>
  112. <!-- 操作按钮区域 -->
  113. <div class="table-operator" :md="24" :sm="24">
  114. <a-button @click="handleAdd2" type="primary" icon="plus" style="margin-top: 16px">新增用户</a-button>
  115. <!--<a-button @click="handleEdit2" type="primary" icon="edit" style="margin-top: 16px">用户编辑</a-button>-->
  116. <a-button @click="handleAddUserRole" type="primary" icon="plus" style="margin-top: 16px">已有用户</a-button>
  117. <a-dropdown v-if="selectedRowKeys2.length > 0">
  118. <a-menu slot="overlay">
  119. <a-menu-item key="1" @click="batchDel2">
  120. <a-icon type="delete"/>
  121. 删除
  122. </a-menu-item>
  123. </a-menu>
  124. <a-button style="margin-left: 8px"> 批量操作
  125. <a-icon type="down"/>
  126. </a-button>
  127. </a-dropdown>
  128. </div>
  129. <!-- table区域-begin -->
  130. <div>
  131. <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
  132. <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
  133. selectedRowKeys2.length }}</a>项
  134. <a style="margin-left: 24px" @click="onClearSelected2">清空</a>
  135. </div>
  136. <a-table
  137. style="height:500px"
  138. ref="table2"
  139. bordered
  140. size="middle"
  141. rowKey="id"
  142. :columns="columns2"
  143. :dataSource="dataSource2"
  144. :pagination="ipagination2"
  145. :loading="loading2"
  146. :rowSelection="{selectedRowKeys: selectedRowKeys2, onChange: onSelectChange2}"
  147. @change="handleTableChange2">
  148. <span slot="action" slot-scope="text, record">
  149. <a @click="handleEdit2(record)">编辑</a>
  150. <a-divider type="vertical"/>
  151. <a-dropdown>
  152. <a class="ant-dropdown-link">
  153. 更多 <a-icon type="down"/>
  154. </a>
  155. <a-menu slot="overlay">
  156. <a-menu-item>
  157. <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete2(record.id)">
  158. <a>删除</a>
  159. </a-popconfirm>
  160. </a-menu-item>
  161. </a-menu>
  162. </a-dropdown>
  163. </span>
  164. </a-table>
  165. </div>
  166. <!-- 表单区域 -->
  167. <role-modal ref="modalForm" @ok="modalFormOk"></role-modal>
  168. <user-modal ref="modalForm2" @ok="modalFormOk2"></user-modal>
  169. <Select-User-Modal ref="selectUserModal" @selectFinished="selectOK"></Select-User-Modal>
  170. </a-card>
  171. </a-col>
  172. </a-row>
  173. </template>
  174. <script>
  175. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  176. import { deleteAction, postAction, getAction } from '@/api/manage'
  177. import SelectUserModal from './modules/SelectUserModal'
  178. import RoleModal from './modules/RoleModal'
  179. import UserModal from './modules/UserModal'
  180. import { filterObj } from '@/utils/util'
  181. import UserRoleModal from './modules/UserRoleModal'
  182. import moment from 'moment'
  183. export default {
  184. name: 'RoleUserList',
  185. mixins: [JeecgListMixin],
  186. components: {
  187. UserRoleModal,
  188. SelectUserModal,
  189. RoleModal,
  190. UserModal,
  191. moment
  192. },
  193. data() {
  194. return {
  195. model1: {},
  196. model2: {},
  197. currentRoleId: '',
  198. queryParam1: {},
  199. queryParam2: {},
  200. dataSource1: [],
  201. dataSource2: [],
  202. ipagination1: {
  203. current: 1,
  204. pageSize: 10,
  205. pageSizeOptions: ['10', '20', '30'],
  206. showTotal: (total, range) => {
  207. return range[0] + '-' + range[1] + ' 共' + total + '条'
  208. },
  209. showQuickJumper: true,
  210. showSizeChanger: true,
  211. total: 0
  212. },
  213. ipagination2: {
  214. current: 1,
  215. pageSize: 10,
  216. pageSizeOptions: ['10', '20', '30'],
  217. showTotal: (total, range) => {
  218. return range[0] + '-' + range[1] + ' 共' + total + '条'
  219. },
  220. showQuickJumper: true,
  221. showSizeChanger: true,
  222. total: 0
  223. },
  224. isorter1: {
  225. column: 'createTime',
  226. order: 'desc'
  227. },
  228. isorter2: {
  229. column: 'createTime',
  230. order: 'desc'
  231. },
  232. filters1: {},
  233. filters2: {},
  234. loading1: false,
  235. loading2: false,
  236. selectedRowKeys1: [],
  237. selectedRowKeys2: [],
  238. selectionRows1: [],
  239. selectionRows2: [],
  240. test:{},
  241. rightcolval:0,
  242. columns:
  243. [
  244. {
  245. title: '角色编码',
  246. align: 'center',
  247. dataIndex: 'roleCode'
  248. },
  249. {
  250. title: '角色名称',
  251. align: 'center',
  252. dataIndex: 'roleName'
  253. },
  254. {
  255. title: '创建时间',
  256. dataIndex: 'createTime',
  257. align:"center",
  258. sorter: true,
  259. customRender: (text) => {
  260. return moment(text).format('YYYY-MM-DD')
  261. }
  262. },
  263. {
  264. title: '操作',
  265. dataIndex: 'action',
  266. align: 'center',
  267. scopedSlots: { customRender: 'action' }
  268. }
  269. ],
  270. columns2: [{
  271. title: '用户账号',
  272. align: 'center',
  273. dataIndex: 'username',
  274. width: 120
  275. },
  276. {
  277. title: '用户名称',
  278. align: 'center',
  279. width: 100,
  280. dataIndex: 'realname'
  281. },
  282. {
  283. title: '状态',
  284. align: 'center',
  285. width: 80,
  286. dataIndex: 'status_dictText'
  287. },
  288. {
  289. title: '操作',
  290. dataIndex: 'action',
  291. scopedSlots: { customRender: 'action' },
  292. align: 'center',
  293. width: 120
  294. }],
  295. // 高级查询参数
  296. superQueryParams2: '',
  297. // 高级查询拼接条件
  298. superQueryMatchType2: 'and',
  299. url: {
  300. list: '/sys/role/list',
  301. delete: '/sys/role/delete',
  302. list2: '/sys/user/userRoleList',
  303. addUserRole: '/sys/user/addSysUserRole',
  304. delete2: '/sys/user/deleteUserRole',
  305. deleteBatch2: '/sys/user/deleteUserRoleBatch',
  306. exportXlsUrl: 'sys/role/exportXls',
  307. importExcelUrl: 'sys/role/importExcel'
  308. }
  309. }
  310. },
  311. computed: {
  312. importExcelUrl: function() {
  313. return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
  314. },
  315. leftColMd() {
  316. return this.selectedRowKeys1.length === 0 ? 24 : 12
  317. },
  318. rightColMd() {
  319. return this.selectedRowKeys1.length === 0 ? 0 : 12
  320. }
  321. },
  322. methods: {
  323. onSelectChange2(selectedRowKeys, selectionRows) {
  324. this.selectedRowKeys2 = selectedRowKeys
  325. this.selectionRows2 = selectionRows
  326. },
  327. onClearSelected2() {
  328. this.selectedRowKeys2 = []
  329. this.selectionRows2 = []
  330. },
  331. onClearSelected1() {
  332. this.selectedRowKeys1 = []
  333. this.selectionRows1 = []
  334. },
  335. onSelectChange1(selectedRowKeys, selectionRows) {
  336. this.rightcolval = 1
  337. this.selectedRowKeys1 = selectedRowKeys
  338. this.selectionRows1 = selectionRows
  339. this.model1 = Object.assign({}, selectionRows[0])
  340. console.log(this.model1)
  341. this.currentRoleId = selectedRowKeys[0]
  342. this.loadData2()
  343. },
  344. onClearSelected() {
  345. },
  346. getQueryParams2() {
  347. //获取查询条件
  348. let sqp = {}
  349. if (this.superQueryParams2) {
  350. sqp['superQueryParams'] = encodeURI(this.superQueryParams2)
  351. sqp['superQueryMatchType'] = this.superQueryMatchType2
  352. }
  353. var param = Object.assign(sqp, this.queryParam2, this.isorter2, this.filters2)
  354. param.field = this.getQueryField2()
  355. param.pageNo = this.ipagination2.current
  356. param.pageSize = this.ipagination2.pageSize
  357. return filterObj(param)
  358. },
  359. getQueryField2() {
  360. //TODO 字段权限控制
  361. var str = 'id,'
  362. this.columns2.forEach(function(value) {
  363. str += ',' + value.dataIndex
  364. })
  365. return str
  366. },
  367. handleEdit2: function(record) {
  368. this.$refs.modalForm2.title = '编辑'
  369. this.$refs.modalForm2.roleDisabled = true
  370. this.$refs.modalForm2.edit(record)
  371. },
  372. handleAdd2: function() {
  373. if (this.currentRoleId == '') {
  374. this.$message.error('请选择一个角色!')
  375. } else {
  376. this.$refs.modalForm2.roleDisabled = true
  377. this.$refs.modalForm2.selectedRole = [this.currentRoleId]
  378. this.$refs.modalForm2.add()
  379. this.$refs.modalForm2.title = '新增'
  380. }
  381. },
  382. modalFormOk2() {
  383. // 新增/修改 成功时,重载列表
  384. this.loadData2()
  385. },
  386. loadData2(arg) {
  387. if (!this.url.list2) {
  388. this.$message.error('请设置url.list2属性!')
  389. return
  390. }
  391. //加载数据 若传入参数1则加载第一页的内容
  392. if (arg === 1) {
  393. this.ipagination2.current = 1
  394. }
  395. if (this.currentRoleId === '') return
  396. let params = this.getQueryParams2()//查询条件
  397. params.roleId = this.currentRoleId
  398. this.loading2 = true
  399. getAction(this.url.list2, params).then((res) => {
  400. if (res.success) {
  401. this.dataSource2 = res.result.records
  402. this.ipagination2.total = res.result.total
  403. }
  404. this.loading2 = false
  405. })
  406. },
  407. handleDelete1: function(id) {
  408. this.handleDelete(id)
  409. this.dataSource2 = []
  410. this.currentRoleId = ''
  411. },
  412. handleDelete2: function(id) {
  413. if (!this.url.delete2) {
  414. this.$message.error('请设置url.delete2属性!')
  415. return
  416. }
  417. var that = this
  418. deleteAction(that.url.delete2, { roleId: this.currentRoleId, userId: id }).then((res) => {
  419. if (res.success) {
  420. that.$message.success(res.message)
  421. that.loadData2()
  422. } else {
  423. that.$message.warning(res.message)
  424. }
  425. })
  426. },
  427. batchDel2: function() {
  428. if (!this.url.deleteBatch2) {
  429. this.$message.error('请设置url.deleteBatch2属性!')
  430. return
  431. }
  432. if (this.selectedRowKeys2.length <= 0) {
  433. this.$message.warning('请选择一条记录!')
  434. return
  435. } else {
  436. var ids = ''
  437. for (var a = 0; a < this.selectedRowKeys2.length; a++) {
  438. ids += this.selectedRowKeys2[a] + ','
  439. }
  440. var that = this
  441. console.log(this.currentDeptId)
  442. this.$confirm({
  443. title: '确认删除',
  444. content: '是否删除选中数据?',
  445. onOk: function() {
  446. deleteAction(that.url.deleteBatch2, { roleId: that.currentRoleId, userIds: ids }).then((res) => {
  447. if (res.success) {
  448. that.$message.success(res.message)
  449. that.loadData2()
  450. that.onClearSelected()
  451. } else {
  452. that.$message.warning(res.message)
  453. }
  454. })
  455. }
  456. })
  457. }
  458. },
  459. selectOK(data) {
  460. let params = {}
  461. params.roleId = this.currentRoleId
  462. params.userIdList = []
  463. for (var a = 0; a < data.length; a++) {
  464. params.userIdList.push(data[a])
  465. }
  466. console.log(params)
  467. postAction(this.url.addUserRole, params).then((res) => {
  468. if (res.success) {
  469. this.loadData2()
  470. this.$message.success(res.message)
  471. } else {
  472. this.$message.warning(res.message)
  473. }
  474. })
  475. },
  476. handleAddUserRole() {
  477. if (this.currentRoleId == '') {
  478. this.$message.error('请选择一个角色!')
  479. } else {
  480. this.$refs.selectUserModal.visible = true
  481. }
  482. },
  483. handleOpen(record) {
  484. this.rightcolval = 1
  485. this.selectedRowKeys1 = [record.id]
  486. this.model1 = Object.assign({}, record)
  487. this.currentRoleId = record.id
  488. this.onClearSelected2()
  489. this.loadData2()
  490. },
  491. /*handleEdit: function(record) {
  492. if (this.currentRoleId == '') {
  493. this.$message.error('请选择一个角色!')
  494. } else {
  495. this.$refs.modalForm.edit(record)
  496. this.$refs.modalForm.title = '编辑'
  497. }
  498. },*/
  499. searchQuery2() {
  500. this.loadData2(1)
  501. },
  502. searchReset2() {
  503. this.queryParam2 = {}
  504. this.loadData2(1)
  505. },
  506. handleTableChange2(pagination, filters, sorter) {
  507. //分页、排序、筛选变化时触发
  508. //TODO 筛选
  509. if (Object.keys(sorter).length > 0) {
  510. this.isorter2.column = sorter.field
  511. this.isorter2.order = 'ascend' == sorter.order ? 'asc' : 'desc'
  512. }
  513. this.ipagination2 = pagination
  514. this.loadData2()
  515. },
  516. hideUserList(){
  517. //this.rightcolval = 0
  518. this.selectedRowKeys1 = []
  519. },
  520. handlePerssion(roleId){
  521. this.$refs.modalUserRole.show(roleId);
  522. },
  523. }
  524. }
  525. </script>
  526. <style scoped>
  527. /** Button按钮间距 */
  528. .ant-btn {
  529. margin-left: 8px
  530. }
  531. </style>