RoleUserList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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 name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
  38. <a-button type="primary" icon="import">导入</a-button>
  39. </a-upload>
  40. <a-button type="primary" icon="download" @click="handleExportXls">导出</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)">用户</a>
  62. <a-divider type="vertical"/>
  63. <a-dropdown>
  64. <a class="ant-dropdown-link">
  65. 更多 <a-icon type="down"/>
  66. </a>
  67. <a-menu slot="overlay">
  68. <a-menu-item>
  69. <a @click="handlePerssion(record.id)">授权</a>
  70. </a-menu-item>
  71. <a-menu-item>
  72. <a @click="handleEdit(record)">编辑</a>
  73. </a-menu-item>
  74. <a-menu-item>
  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" style="margin: -25px 0px 10px 2px">
  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. url: {
  296. list: '/sys/role/list',
  297. delete: '/sys/role/delete',
  298. list2: '/sys/user/userRoleList',
  299. addUserRole: '/sys/user/addSysUserRole',
  300. delete2: '/sys/user/deleteUserRole',
  301. deleteBatch2: '/sys/user/deleteUserRoleBatch',
  302. exportXlsUrl: 'sys/role/exportXls',
  303. importExcelUrl: 'sys/role/importExcel'
  304. }
  305. }
  306. },
  307. computed: {
  308. importExcelUrl: function() {
  309. return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
  310. },
  311. leftColMd() {
  312. return this.selectedRowKeys1.length === 0 ? 24 : 12
  313. },
  314. rightColMd() {
  315. return this.selectedRowKeys1.length === 0 ? 0 : 12
  316. }
  317. },
  318. methods: {
  319. onSelectChange2(selectedRowKeys, selectionRows) {
  320. this.selectedRowKeys2 = selectedRowKeys
  321. this.selectionRows2 = selectionRows
  322. },
  323. onClearSelected2() {
  324. this.selectedRowKeys2 = []
  325. this.selectionRows2 = []
  326. },
  327. onClearSelected1() {
  328. this.selectedRowKeys1 = []
  329. this.selectionRows1 = []
  330. },
  331. onSelectChange1(selectedRowKeys, selectionRows) {
  332. this.rightcolval = 1
  333. this.selectedRowKeys1 = selectedRowKeys
  334. this.selectionRows1 = selectionRows
  335. this.model1 = Object.assign({}, selectionRows[0])
  336. console.log(this.model1)
  337. this.currentRoleId = selectedRowKeys[0]
  338. this.loadData2()
  339. },
  340. onClearSelected() {
  341. },
  342. getQueryParams2() {
  343. //获取查询条件
  344. let sqp = {}
  345. if (this.superQueryParams2) {
  346. sqp['superQueryParams'] = encodeURI(this.superQueryParams2)
  347. }
  348. var param = Object.assign(sqp, this.queryParam2, this.isorter2, this.filters2)
  349. param.field = this.getQueryField2()
  350. param.pageNo = this.ipagination2.current
  351. param.pageSize = this.ipagination2.pageSize
  352. return filterObj(param)
  353. },
  354. getQueryField2() {
  355. //TODO 字段权限控制
  356. var str = 'id,'
  357. this.columns2.forEach(function(value) {
  358. str += ',' + value.dataIndex
  359. })
  360. return str
  361. },
  362. handleEdit2: function(record) {
  363. this.$refs.modalForm2.title = '编辑'
  364. this.$refs.modalForm2.roleDisabled = true
  365. this.$refs.modalForm2.edit(record)
  366. },
  367. handleAdd2: function() {
  368. if (this.currentRoleId == '') {
  369. this.$message.error('请选择一个角色!')
  370. } else {
  371. this.$refs.modalForm2.roleDisabled = true
  372. this.$refs.modalForm2.selectedRole = [this.currentRoleId]
  373. this.$refs.modalForm2.add()
  374. this.$refs.modalForm2.title = '新增'
  375. }
  376. },
  377. modalFormOk2() {
  378. // 新增/修改 成功时,重载列表
  379. this.loadData2()
  380. },
  381. loadData2(arg) {
  382. if (!this.url.list2) {
  383. this.$message.error('请设置url.list2属性!')
  384. return
  385. }
  386. //加载数据 若传入参数1则加载第一页的内容
  387. if (arg === 1) {
  388. this.ipagination2.current = 1
  389. }
  390. if (this.currentRoleId === '') return
  391. let params = this.getQueryParams2()//查询条件
  392. params.roleId = this.currentRoleId
  393. this.loading2 = true
  394. getAction(this.url.list2, params).then((res) => {
  395. if (res.success) {
  396. this.dataSource2 = res.result.records
  397. this.ipagination2.total = res.result.total
  398. }
  399. this.loading2 = false
  400. })
  401. },
  402. handleDelete1: function(id) {
  403. this.handleDelete(id)
  404. this.dataSource2 = []
  405. this.currentRoleId = ''
  406. },
  407. handleDelete2: function(id) {
  408. if (!this.url.delete2) {
  409. this.$message.error('请设置url.delete2属性!')
  410. return
  411. }
  412. var that = this
  413. deleteAction(that.url.delete2, { roleId: this.currentRoleId, userId: id }).then((res) => {
  414. if (res.success) {
  415. that.$message.success(res.message)
  416. that.loadData2()
  417. } else {
  418. that.$message.warning(res.message)
  419. }
  420. })
  421. },
  422. batchDel2: function() {
  423. if (!this.url.deleteBatch2) {
  424. this.$message.error('请设置url.deleteBatch2属性!')
  425. return
  426. }
  427. if (this.selectedRowKeys2.length <= 0) {
  428. this.$message.warning('请选择一条记录!')
  429. return
  430. } else {
  431. var ids = ''
  432. for (var a = 0; a < this.selectedRowKeys2.length; a++) {
  433. ids += this.selectedRowKeys2[a] + ','
  434. }
  435. var that = this
  436. console.log(this.currentDeptId)
  437. this.$confirm({
  438. title: '确认删除',
  439. content: '是否删除选中数据?',
  440. onOk: function() {
  441. deleteAction(that.url.deleteBatch2, { roleId: that.currentRoleId, userIds: ids }).then((res) => {
  442. if (res.success) {
  443. that.$message.success(res.message)
  444. that.loadData2()
  445. that.onClearSelected()
  446. } else {
  447. that.$message.warning(res.message)
  448. }
  449. })
  450. }
  451. })
  452. }
  453. },
  454. selectOK(data) {
  455. let params = {}
  456. params.roleId = this.currentRoleId
  457. params.userIdList = []
  458. for (var a = 0; a < data.length; a++) {
  459. params.userIdList.push(data[a])
  460. }
  461. console.log(params)
  462. postAction(this.url.addUserRole, params).then((res) => {
  463. if (res.success) {
  464. this.loadData2()
  465. this.$message.success(res.message)
  466. } else {
  467. this.$message.warning(res.message)
  468. }
  469. })
  470. },
  471. handleAddUserRole() {
  472. if (this.currentRoleId == '') {
  473. this.$message.error('请选择一个角色!')
  474. } else {
  475. this.$refs.selectUserModal.visible = true
  476. }
  477. },
  478. handleOpen(record) {
  479. this.rightcolval = 1
  480. this.selectedRowKeys1 = [record.id]
  481. this.model1 = Object.assign({}, record)
  482. this.currentRoleId = record.id
  483. this.onClearSelected2()
  484. this.loadData2()
  485. },
  486. /*handleEdit: function(record) {
  487. if (this.currentRoleId == '') {
  488. this.$message.error('请选择一个角色!')
  489. } else {
  490. this.$refs.modalForm.edit(record)
  491. this.$refs.modalForm.title = '编辑'
  492. }
  493. },*/
  494. searchQuery2() {
  495. this.loadData2(1)
  496. },
  497. searchReset2() {
  498. this.queryParam2 = {}
  499. this.loadData2(1)
  500. },
  501. handleTableChange2(pagination, filters, sorter) {
  502. //分页、排序、筛选变化时触发
  503. //TODO 筛选
  504. if (Object.keys(sorter).length > 0) {
  505. this.isorter2.column = sorter.field
  506. this.isorter2.order = 'ascend' == sorter.order ? 'asc' : 'desc'
  507. }
  508. this.ipagination2 = pagination
  509. this.loadData2()
  510. },
  511. hideUserList(){
  512. //this.rightcolval = 0
  513. this.selectedRowKeys1 = []
  514. },
  515. handlePerssion(roleId){
  516. this.$refs.modalUserRole.show(roleId);
  517. },
  518. }
  519. }
  520. </script>
  521. <style scoped>
  522. /** Button按钮间距 */
  523. .ant-btn {
  524. margin-left: 8px
  525. }
  526. </style>