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