UserList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <a-card :bordered="false">
  3. <!-- 查询区域 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="searchQuery">
  6. <a-row :gutter="24">
  7. <a-col :md="6" :sm="12">
  8. <a-form-item label="账号">
  9. <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
  10. <j-input placeholder="输入账号模糊查询" v-model="queryParam.username"></j-input>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="12">
  14. <a-form-item label="用户姓名">
  15. <j-input placeholder="输入用户姓名模糊查询" v-model="queryParam.realname"></j-input>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="12">
  19. <a-form-item label="归属部门">
  20. <j-input placeholder="输入归属部门模糊查询" v-model="queryParam.departName"></j-input>
  21. </a-form-item>
  22. </a-col>
  23. <a-form-model-item label="角色分配" :md="6" :sm="12">
  24. <j-multi-select-tag
  25. v-model="queryParam.selectedroles"
  26. :options="rolesOptions"
  27. placeholder="请选择角色">
  28. </j-multi-select-tag>
  29. </a-form-model-item>
  30. <!-- <a-col :md="6" :sm="8">-->
  31. <!-- <a-form-item label="性别">-->
  32. <!-- <a-select v-model="queryParam.sex" placeholder="请选择性别">-->
  33. <!-- <a-select-option value="">请选择</a-select-option>-->
  34. <!-- <a-select-option value="1">男</a-select-option>-->
  35. <!-- <a-select-option value="2">女</a-select-option>-->
  36. <!-- </a-select>-->
  37. <!-- </a-form-item>-->
  38. <!-- </a-col>-->
  39. <template v-if="toggleSearchStatus">
  40. <!-- <a-col :md="6" :sm="8">-->
  41. <!-- <a-form-item label="真实名字">-->
  42. <!-- <a-input placeholder="请输入真实名字" v-model="queryParam.realname"></a-input>-->
  43. <!-- </a-form-item>-->
  44. <!-- </a-col>-->
  45. <a-col :md="6" :sm="8">
  46. <a-form-item label="手机号码">
  47. <a-input placeholder="请输入手机号码查询" v-model="queryParam.phone"></a-input>
  48. </a-form-item>
  49. </a-col>
  50. <a-col :md="6" :sm="8">
  51. <a-form-item label="用户状态">
  52. <a-select v-model="queryParam.status" placeholder="请选择">
  53. <a-select-option value="">请选择</a-select-option>
  54. <a-select-option value="1">正常</a-select-option>
  55. <a-select-option value="2">冻结</a-select-option>
  56. </a-select>
  57. </a-form-item>
  58. </a-col>
  59. </template>
  60. <a-col :md="6" :sm="8">
  61. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  62. <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
  63. <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
  64. <a @click="handleToggleSearch" style="margin-left: 8px">
  65. {{ toggleSearchStatus ? '收起' : '展开' }}
  66. <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
  67. </a>
  68. </span>
  69. </a-col>
  70. </a-row>
  71. </a-form>
  72. </div>
  73. <!-- 操作按钮区域 -->
  74. <div class="table-operator" style="border-top: 5px">
  75. <a-button @click="handleAdd" type="primary" icon="plus" >添加用户</a-button>
  76. <a-button type="primary" icon="download" @click="handleExportXls('用户信息')">导出</a-button>
  77. <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
  78. <a-button type="primary" icon="import">导入</a-button>
  79. </a-upload>
  80. <!-- <a-button type="primary" icon="hdd" @click="recycleBinVisible=true">回收站</a-button>-->
  81. <a-dropdown v-if="selectedRowKeys.length > 0">
  82. <a-menu slot="overlay" @click="handleMenuClick">
  83. <a-menu-item key="1">
  84. <a-icon type="delete" @click="batchDel"/>
  85. 删除
  86. </a-menu-item>
  87. <a-menu-item key="2">
  88. <a-icon type="lock" @click="batchFrozen('2')"/>
  89. 冻结
  90. </a-menu-item>
  91. <a-menu-item key="3">
  92. <a-icon type="unlock" @click="batchFrozen('1')"/>
  93. 解冻
  94. </a-menu-item>
  95. </a-menu>
  96. <a-button style="margin-left: 8px">
  97. 批量操作
  98. <a-icon type="down"/>
  99. </a-button>
  100. </a-dropdown>
  101. </div>
  102. <!-- table区域-begin -->
  103. <div>
  104. <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
  105. <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
  106. <a style="margin-left: 24px" @click="onClearSelected">清空</a>
  107. </div>
  108. <a-table
  109. ref="table"
  110. bordered
  111. size="middle"
  112. rowKey="id"
  113. :columns="columns"
  114. :dataSource="dataSource"
  115. :pagination="ipagination"
  116. :loading="loading"
  117. :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
  118. @change="handleTableChange">
  119. <template slot="avatarslot" slot-scope="text, record, index">
  120. <div class="anty-img-wrap">
  121. <a-avatar shape="square" :src="getAvatarView(record.avatar)" icon="user"/>
  122. </div>
  123. </template>
  124. <template v-slot:statusSlot="status">
  125. <a-badge :color="status | statusColorFilter" :text="status | statusFilter" />
  126. </template>
  127. <span slot="action" slot-scope="text, record">
  128. <a @click="handleEdit(record)" >编辑</a>
  129. <a-divider type="vertical" />
  130. <a-dropdown>
  131. <a class="ant-dropdown-link">
  132. 更多 <a-icon type="down"/>
  133. </a>
  134. <a-menu slot="overlay">
  135. <a-menu-item>
  136. <a href="javascript:;" @click="handleDetail(record)">详情</a>
  137. </a-menu-item>
  138. <a-menu-item>
  139. <a href="javascript:;" @click="handleChangePassword(record.username)">密码</a>
  140. </a-menu-item>
  141. <a-menu-item>
  142. <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
  143. <a>删除</a>
  144. </a-popconfirm>
  145. </a-menu-item>
  146. <a-menu-item v-if="record.status==1">
  147. <a-popconfirm title="确定冻结吗?" @confirm="() => handleFrozen(record.id,2,record.username)">
  148. <a>冻结</a>
  149. </a-popconfirm>
  150. </a-menu-item>
  151. <a-menu-item v-if="record.status==2">
  152. <a-popconfirm title="确定解冻吗?" @confirm="() => handleFrozen(record.id,1,record.username)">
  153. <a>解冻</a>
  154. </a-popconfirm>
  155. </a-menu-item>
  156. </a-menu>
  157. </a-dropdown>
  158. </span>
  159. </a-table>
  160. </div>
  161. <!-- table区域-end -->
  162. <user-modal ref="modalForm" @ok="modalFormOk"></user-modal>
  163. <password-modal ref="passwordmodal" @ok="passwordModalOk"></password-modal>
  164. <!-- 用户回收站 -->
  165. <user-recycle-bin-modal :visible.sync="recycleBinVisible" @ok="modalFormOk"/>
  166. </a-card>
  167. </template>
  168. <script>
  169. import UserModal from './modules/UserModal'
  170. import PasswordModal from './modules/PasswordModal'
  171. import {putAction,getFileAccessHttpUrl} from '@/api/manage';
  172. import { addUser,editUser,queryall } from '@/api/api'
  173. import { frozenBatch, queryUserRole } from '@/api/api'
  174. import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  175. import SysUserAgentModal from "./modules/SysUserAgentModal";
  176. import JInput from '@/components/jeecg/JInput'
  177. import UserRecycleBinModal from './modules/UserRecycleBinModal'
  178. import JSuperQuery from '@/components/jeecg/JSuperQuery'
  179. const statusMap = {
  180. 1: {
  181. color: 'green',
  182. text: '正常'
  183. },
  184. 2: {
  185. color: 'red',
  186. text: '冻结'
  187. }
  188. }
  189. export default {
  190. name: "UserList",
  191. mixins: [JeecgListMixin],
  192. components: {
  193. SysUserAgentModal,
  194. UserModal,
  195. PasswordModal,
  196. JInput,
  197. UserRecycleBinModal,
  198. JSuperQuery
  199. },
  200. data() {
  201. return {
  202. description: '这是用户管理页面',
  203. queryParam: {},
  204. recycleBinVisible: false,
  205. rolesOptions:[],
  206. columns: [
  207. {
  208. title: '#',
  209. dataIndex: '',
  210. key:'rowIndex',
  211. width:60,
  212. align:"center",
  213. customRender:function (t,r,index) {
  214. return parseInt(index)+1;
  215. }
  216. },
  217. {
  218. title: '用户账号',
  219. align: "center",
  220. dataIndex: 'username',
  221. width: 120,
  222. sorter: true
  223. },
  224. {
  225. title: '用户姓名',
  226. align: "center",
  227. width: 100,
  228. dataIndex: 'realname',
  229. },
  230. // {
  231. // title: '头像',
  232. // align: "center",
  233. // visible:false,
  234. // width: 120,
  235. // dataIndex: 'avatar',
  236. // scopedSlots: {customRender: "avatarslot"}
  237. // },
  238. // {
  239. // title: '性别',
  240. // align: "center",
  241. // width: 80,
  242. // dataIndex: 'sex_dictText',
  243. // sorter: true
  244. // },
  245. // {
  246. // title: '生日',
  247. // align: "center",
  248. // visible:false,
  249. // width: 100,
  250. // dataIndex: 'birthday'
  251. // },
  252. {
  253. title: '手机号码',
  254. align: "center",
  255. width: 110,
  256. dataIndex: 'phone'
  257. }, {
  258. title: '岗位',
  259. align: "center",
  260. width: 100,
  261. dataIndex: 'position'
  262. },
  263. {
  264. title: '归属部门',
  265. align: "center",
  266. width: 180,
  267. dataIndex: 'orgCodeTxt'
  268. },
  269. {
  270. title: '角色',
  271. align: "center",
  272. width: 180,
  273. dataIndex: 'roleName'
  274. },
  275. // {
  276. // title: '负责部门',
  277. // align: "center",
  278. // width: 180,
  279. // dataIndex: 'departIds_dictText'
  280. // },
  281. {
  282. title: '状态',
  283. align: "center",
  284. width: 80,
  285. dataIndex: 'status',
  286. scopedSlots: { customRender: 'statusSlot' }
  287. },
  288. {
  289. title: '操作',
  290. dataIndex: 'action',
  291. scopedSlots: {customRender: 'action'},
  292. align: "center",
  293. width: 170
  294. }
  295. ],
  296. url: {
  297. syncUser: "/act/process/extActProcess/doSyncUser",
  298. list: "/sys/user/list",
  299. delete: "/sys/user/delete",
  300. deleteBatch: "/sys/user/deleteBatch",
  301. exportXlsUrl: "/sys/user/exportXls",
  302. importExcelUrl: "sys/user/importExcel",
  303. },
  304. }
  305. },
  306. created() {
  307. this.initRoleList();
  308. this.getUserRoles();
  309. },
  310. computed: {
  311. importExcelUrl: function(){
  312. return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
  313. }
  314. },
  315. filters: {
  316. statusColorFilter (type) {
  317. return statusMap[type].color
  318. },
  319. statusFilter (type) {
  320. return statusMap[type].text
  321. }
  322. },
  323. methods: {
  324. getAvatarView: function (avatar) {
  325. return getFileAccessHttpUrl(avatar)
  326. },
  327. batchFrozen: function (status) {
  328. if (this.selectedRowKeys.length <= 0) {
  329. this.$message.warning('请选择一条记录!');
  330. return false;
  331. } else {
  332. let ids = "";
  333. let that = this;
  334. let isAdmin = false;
  335. that.selectionRows.forEach(function (row) {
  336. if (row.username == 'admin') {
  337. isAdmin = true;
  338. }
  339. });
  340. if (isAdmin) {
  341. that.$message.warning('管理员账号不允许此操作,请重新选择!');
  342. return;
  343. }
  344. that.selectedRowKeys.forEach(function (val) {
  345. ids += val + ",";
  346. });
  347. that.$confirm({
  348. title: "确认操作",
  349. content: "是否" + (status == 1 ? "解冻" : "冻结") + "选中账号?",
  350. onOk: function () {
  351. frozenBatch({ids: ids, status: status}).then((res) => {
  352. if (res.success) {
  353. that.$message.success(res.message);
  354. that.loadData();
  355. that.onClearSelected();
  356. } else {
  357. that.$message.warning(res.message);
  358. }
  359. });
  360. }
  361. });
  362. }
  363. },
  364. handleMenuClick(e) {
  365. if (e.key == 1) {
  366. this.batchDel();
  367. } else if (e.key == 2) {
  368. this.batchFrozen(2);
  369. } else if (e.key == 3) {
  370. this.batchFrozen(1);
  371. }
  372. },
  373. handleFrozen: function (id, status, username) {
  374. let that = this;
  375. //TODO 后台校验管理员角色
  376. if ('admin' == username) {
  377. that.$message.warning('管理员账号不允许此操作!');
  378. return;
  379. }
  380. frozenBatch({ids: id, status: status}).then((res) => {
  381. if (res.success) {
  382. that.$message.success(res.message);
  383. that.loadData();
  384. } else {
  385. that.$message.warning(res.message);
  386. }
  387. });
  388. },
  389. handleChangePassword(username) {
  390. this.$refs.passwordmodal.show(username);
  391. },
  392. passwordModalOk() {
  393. //TODO 密码修改完成 不需要刷新页面,可以把datasource中的数据更新一下
  394. },
  395. onSyncFinally({isToLocal}) {
  396. // 同步到本地时刷新下数据
  397. if (isToLocal) {
  398. this.loadData()
  399. }
  400. },
  401. getUserRoles(userid){
  402. queryUserRole( ).then((res)=>{
  403. if(res.success){
  404. this.model.selectedroles = res.result.join(",");
  405. console.log('that.model.selectedroles=',this.model.selectedroles)
  406. }
  407. });
  408. },
  409. //初始化角色字典
  410. initRoleList(){
  411. queryall().then((res)=>{
  412. if(res.success){
  413. this.rolesOptions = res.result.map((item,index,arr)=>{
  414. let c = {label:item.roleName, value:item.id}
  415. return c;
  416. })
  417. console.log('this.rolesOptions: ',this.rolesOptions)
  418. }
  419. });
  420. },
  421. }
  422. }
  423. </script>
  424. <style scoped>
  425. @import '~@assets/less/common.less'
  426. </style>