6f728e39328f5ab5542e6e31a99ef82ce9bbd3a4.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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">
  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.title = '新增'
  378. this.$refs.modalForm2.edit({activitiSync:'1',userIdentity:1,selectedroles:this.currentRoleId})
  379. }
  380. },
  381. modalFormOk2() {
  382. // 新增/修改 成功时,重载列表
  383. this.loadData2()
  384. },
  385. loadData2(arg) {
  386. if (!this.url.list2) {
  387. this.$message.error('请设置url.list2属性!')
  388. return
  389. }
  390. //加载数据 若传入参数1则加载第一页的内容
  391. if (arg === 1) {
  392. this.ipagination2.current = 1
  393. }
  394. if (this.currentRoleId === '') return
  395. let params = this.getQueryParams2()//查询条件
  396. params.roleId = this.currentRoleId
  397. this.loading2 = true
  398. getAction(this.url.list2, params).then((res) => {
  399. if (res.success) {
  400. this.dataSource2 = res.result.records
  401. this.ipagination2.total = res.result.total
  402. }
  403. this.loading2 = false
  404. })
  405. },
  406. handleDelete1: function(id) {
  407. this.handleDelete(id)
  408. this.dataSource2 = []
  409. this.currentRoleId = ''
  410. },
  411. handleDelete2: function(id) {
  412. if (!this.url.delete2) {
  413. this.$message.error('请设置url.delete2属性!')
  414. return
  415. }
  416. var that = this
  417. deleteAction(that.url.delete2, { roleId: this.currentRoleId, userId: id }).then((res) => {
  418. if (res.success) {
  419. that.$message.success(res.message)
  420. that.loadData2()
  421. } else {
  422. that.$message.warning(res.message)
  423. }
  424. })
  425. },
  426. batchDel2: function() {
  427. if (!this.url.deleteBatch2) {
  428. this.$message.error('请设置url.deleteBatch2属性!')
  429. return
  430. }
  431. if (this.selectedRowKeys2.length <= 0) {
  432. this.$message.warning('请选择一条记录!')
  433. return
  434. } else {
  435. var ids = ''
  436. for (var a = 0; a < this.selectedRowKeys2.length; a++) {
  437. ids += this.selectedRowKeys2[a] + ','
  438. }
  439. var that = this
  440. console.log(this.currentDeptId)
  441. this.$confirm({
  442. title: '确认删除',
  443. content: '是否删除选中数据?',
  444. onOk: function() {
  445. deleteAction(that.url.deleteBatch2, { roleId: that.currentRoleId, userIds: ids }).then((res) => {
  446. if (res.success) {
  447. that.$message.success(res.message)
  448. that.loadData2()
  449. that.onClearSelected()
  450. } else {
  451. that.$message.warning(res.message)
  452. }
  453. })
  454. }
  455. })
  456. }
  457. },
  458. selectOK(data) {
  459. let params = {}
  460. params.roleId = this.currentRoleId
  461. params.userIdList = []
  462. for (var a = 0; a < data.length; a++) {
  463. params.userIdList.push(data[a])
  464. }
  465. console.log(params)
  466. postAction(this.url.addUserRole, params).then((res) => {
  467. if (res.success) {
  468. this.loadData2()
  469. this.$message.success(res.message)
  470. } else {
  471. this.$message.warning(res.message)
  472. }
  473. })
  474. },
  475. handleAddUserRole() {
  476. if (this.currentRoleId == '') {
  477. this.$message.error('请选择一个角色!')
  478. } else {
  479. this.$refs.selectUserModal.visible = true
  480. }
  481. },
  482. handleOpen(record) {
  483. this.rightcolval = 1
  484. this.selectedRowKeys1 = [record.id]
  485. this.model1 = Object.assign({}, record)
  486. this.currentRoleId = record.id
  487. this.onClearSelected2()
  488. this.loadData2()
  489. },
  490. /*handleEdit: function(record) {
  491. if (this.currentRoleId == '') {
  492. this.$message.error('请选择一个角色!')
  493. } else {
  494. this.$refs.modalForm.edit(record)
  495. this.$refs.modalForm.title = '编辑'
  496. }
  497. },*/
  498. searchQuery2() {
  499. this.loadData2(1)
  500. },
  501. searchReset2() {
  502. this.queryParam2 = {}
  503. this.loadData2(1)
  504. },
  505. handleTableChange2(pagination, filters, sorter) {
  506. //分页、排序、筛选变化时触发
  507. //TODO 筛选
  508. if (Object.keys(sorter).length > 0) {
  509. this.isorter2.column = sorter.field
  510. this.isorter2.order = 'ascend' == sorter.order ? 'asc' : 'desc'
  511. }
  512. this.ipagination2 = pagination
  513. this.loadData2()
  514. },
  515. hideUserList(){
  516. //this.rightcolval = 0
  517. this.selectedRowKeys1 = []
  518. },
  519. handlePerssion(roleId){
  520. this.$refs.modalUserRole.show(roleId);
  521. },
  522. }
  523. }
  524. </script>
  525. <style scoped>
  526. /** Button按钮间距 */
  527. .ant-btn {
  528. margin-left: 8px
  529. }
  530. </style>