selectUser.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <!-- 授权用户 -->
  3. <el-dialog
  4. title="添加分组管理员"
  5. :visible.sync="open"
  6. width="800px"
  7. top="5vh"
  8. append-to-body
  9. custom-class="el-dialog2"
  10. >
  11. <div class="dialog-main">
  12. <el-row :gutter="20">
  13. <!--部门数据-->
  14. <el-col :span="6" :xs="24">
  15. <div class="head-container">
  16. <el-input
  17. v-model="deptName"
  18. placeholder="请输入部门名称"
  19. clearable
  20. size="small"
  21. prefix-icon="el-icon-search"
  22. style="margin-bottom: 20px"
  23. />
  24. </div>
  25. <div class="head-container">
  26. <el-tree
  27. :data="deptOptions"
  28. :props="defaultProps"
  29. :expand-on-click-node="false"
  30. :filter-node-method="filterNode"
  31. ref="tree"
  32. node-key="id"
  33. default-expand-all
  34. highlight-current
  35. @node-click="handleNodeClick"
  36. />
  37. </div>
  38. </el-col>
  39. <!--用户数据-->
  40. <el-col :span="18" :xs="24">
  41. <el-form
  42. :model="queryParams"
  43. ref="queryForm"
  44. size="small"
  45. :inline="true"
  46. v-show="showSearch"
  47. label-width="68px"
  48. >
  49. <el-form-item label="用户名称" prop="userName">
  50. <el-input
  51. v-model="queryParams.userName"
  52. placeholder="请输入用户名称"
  53. clearable
  54. style="width: 240px"
  55. @keyup.enter.native="handleQuery"
  56. />
  57. </el-form-item>
  58. <el-form-item>
  59. <el-button
  60. type="primary"
  61. icon="el-icon-search"
  62. size="mini"
  63. @click="handleQuery"
  64. class="aaa"
  65. >搜索</el-button
  66. >
  67. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" class="bbb"
  68. >重置</el-button
  69. >
  70. </el-form-item>
  71. </el-form>
  72. <el-table
  73. v-loading="loading"
  74. :data="userList"
  75. @selection-change="handleSelectionChange"
  76. >
  77. <el-table-column type="selection" width="50" align="center" />
  78. <el-table-column
  79. label="用户名称"
  80. align="center"
  81. key="userName"
  82. prop="userName"
  83. v-if="columns[1].visible"
  84. :show-overflow-tooltip="true"
  85. />
  86. <el-table-column
  87. label="用户昵称"
  88. align="center"
  89. key="nickName"
  90. prop="nickName"
  91. v-if="columns[2].visible"
  92. :show-overflow-tooltip="true"
  93. />
  94. <el-table-column
  95. label="部门"
  96. align="center"
  97. key="deptName"
  98. prop="dept.deptName"
  99. v-if="columns[3].visible"
  100. :show-overflow-tooltip="true"
  101. />
  102. </el-table>
  103. <pagination
  104. v-show="total > 0"
  105. :total="total"
  106. :page.sync="queryParams.pageNum"
  107. :limit.sync="queryParams.pageSize"
  108. @pagination="getList"
  109. />
  110. </el-col>
  111. </el-row>
  112. <div slot="footer" class="dialog-footer">
  113. <el-button @click="submitForm()">确 定</el-button>
  114. <el-button @click="open = false">取 消</el-button>
  115. </div>
  116. </div>
  117. </el-dialog>
  118. </template>
  119. <script>
  120. import {
  121. listUser,
  122. getUser,
  123. delUser,
  124. addUser,
  125. updateUser,
  126. resetUserPwd,
  127. changeUserStatus,
  128. deptTreeSelect,
  129. } from "@/api/system/user";
  130. import { getToken } from "@/utils/auth";
  131. import Treeselect from "@riophae/vue-treeselect";
  132. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  133. export default {
  134. name: "User",
  135. dicts: ["sys_normal_disable", "sys_user_sex"],
  136. components: { Treeselect },
  137. data() {
  138. return {
  139. // 遮罩层
  140. loading: true,
  141. // 选中数组
  142. ids: [],
  143. // 非单个禁用
  144. single: true,
  145. // 非多个禁用
  146. multiple: true,
  147. // 显示搜索条件
  148. showSearch: true,
  149. // 总条数
  150. total: 0,
  151. // 用户表格数据
  152. userList: null,
  153. // 弹出层标题
  154. title: "",
  155. // 部门树选项
  156. deptOptions: undefined,
  157. // 是否显示弹出层
  158. open: false,
  159. // 部门名称
  160. deptName: undefined,
  161. // 默认密码
  162. initPassword: undefined,
  163. // 日期范围
  164. dateRange: [],
  165. // 岗位选项
  166. postOptions: [],
  167. // 角色选项
  168. roleOptions: [],
  169. // 表单参数
  170. form: {},
  171. defaultProps: {
  172. children: "children",
  173. label: "label",
  174. },
  175. // 用户导入参数
  176. upload: {
  177. // 是否显示弹出层(用户导入)
  178. open: false,
  179. // 弹出层标题(用户导入)
  180. title: "",
  181. // 是否禁用上传
  182. isUploading: false,
  183. // 是否更新已经存在的用户数据
  184. updateSupport: 0,
  185. // 设置上传的请求头部
  186. headers: { Authorization: "Bearer " + getToken() },
  187. // 上传的地址
  188. url: process.env.VUE_APP_BASE_API + "/system/user/importData",
  189. },
  190. // 查询参数
  191. queryParams: {
  192. pageNum: 1,
  193. pageSize: 10,
  194. userName: undefined,
  195. phonenumber: undefined,
  196. status: undefined,
  197. deptId: undefined,
  198. },
  199. // 列信息
  200. columns: [
  201. { key: 0, label: `用户编号`, visible: true },
  202. { key: 1, label: `用户名称`, visible: true },
  203. { key: 2, label: `用户昵称`, visible: true },
  204. { key: 3, label: `部门`, visible: true },
  205. { key: 4, label: `手机号码`, visible: true },
  206. { key: 5, label: `状态`, visible: true },
  207. { key: 6, label: `创建时间`, visible: true },
  208. ],
  209. // 表单校验
  210. rules: {
  211. userName: [
  212. { required: true, message: "用户名称不能为空", trigger: "blur" },
  213. {
  214. min: 2,
  215. max: 20,
  216. message: "用户名称长度必须介于 2 和 20 之间",
  217. trigger: "blur",
  218. },
  219. ],
  220. nickName: [
  221. { required: true, message: "用户昵称不能为空", trigger: "blur" },
  222. ],
  223. password: [
  224. { required: true, message: "用户密码不能为空", trigger: "blur" },
  225. {
  226. min: 5,
  227. max: 20,
  228. message: "用户密码长度必须介于 5 和 20 之间",
  229. trigger: "blur",
  230. },
  231. ],
  232. email: [
  233. {
  234. type: "email",
  235. message: "请输入正确的邮箱地址",
  236. trigger: ["blur", "change"],
  237. },
  238. ],
  239. phonenumber: [
  240. {
  241. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  242. message: "请输入正确的手机号码",
  243. trigger: "blur",
  244. },
  245. ],
  246. },
  247. };
  248. },
  249. watch: {
  250. // 根据名称筛选部门树
  251. deptName(val) {
  252. this.$refs.tree.filter(val);
  253. },
  254. },
  255. created() {
  256. this.getList();
  257. this.getDeptTree();
  258. this.getConfigKey("sys.user.initPassword").then((response) => {
  259. this.initPassword = response.msg;
  260. });
  261. },
  262. methods: {
  263. // 显示弹框
  264. show() {
  265. this.queryParams.roleId = this.roleId;
  266. this.getList();
  267. this.open= true;
  268. },
  269. /** 查询用户列表 */
  270. getList() {
  271. this.loading = true;
  272. listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
  273. (response) => {
  274. this.userList = response.rows;
  275. this.total = response.total;
  276. this.loading = false;
  277. }
  278. );
  279. },
  280. /** 查询部门下拉树结构 */
  281. getDeptTree() {
  282. deptTreeSelect().then((response) => {
  283. this.deptOptions = response.data;
  284. });
  285. },
  286. // 筛选节点
  287. filterNode(value, data) {
  288. if (!value) return true;
  289. return data.label.indexOf(value) !== -1;
  290. },
  291. // 节点单击事件
  292. handleNodeClick(data) {
  293. this.queryParams.deptId = data.id;
  294. this.handleQuery();
  295. },
  296. // 用户状态修改
  297. handleStatusChange(row) {
  298. let text = row.status === "0" ? "启用" : "停用";
  299. this.$modal
  300. .confirm('确认要"' + text + '""' + row.userName + '"用户吗?')
  301. .then(function () {
  302. return changeUserStatus(row.userId, row.status);
  303. })
  304. .then(() => {
  305. this.$modal.msgSuccess(text + "成功");
  306. })
  307. .catch(function () {
  308. row.status = row.status === "0" ? "1" : "0";
  309. });
  310. },
  311. // 取消按钮
  312. cancel() {
  313. this.open = false;
  314. this.reset();
  315. },
  316. // 表单重置
  317. reset() {
  318. this.form = {
  319. userId: undefined,
  320. deptId: undefined,
  321. userName: undefined,
  322. nickName: undefined,
  323. password: undefined,
  324. phonenumber: undefined,
  325. email: undefined,
  326. sex: undefined,
  327. status: "0",
  328. remark: undefined,
  329. postIds: [],
  330. roleIds: [],
  331. };
  332. this.resetForm("form");
  333. },
  334. /** 搜索按钮操作 */
  335. handleQuery() {
  336. this.queryParams.pageNum = 1;
  337. this.getList();
  338. },
  339. /** 重置按钮操作 */
  340. resetQuery() {
  341. this.dateRange = [];
  342. this.resetForm("queryForm");
  343. this.queryParams.deptId = undefined;
  344. this.$refs.tree.setCurrentKey(null);
  345. this.handleQuery();
  346. },
  347. // 多选框选中数据
  348. handleSelectionChange(selection) {
  349. this.ids = selection.map((item) => item.userId);
  350. this.single = selection.length != 1;
  351. this.multiple = !selection.length;
  352. // console.log(selection[0].userName);
  353. },
  354. /** 提交按钮 */
  355. submitForm() {
  356. this.open = false;
  357. },
  358. // 更多操作触发
  359. handleCommand(command, row) {
  360. switch (command) {
  361. case "handleResetPwd":
  362. this.handleResetPwd(row);
  363. break;
  364. case "handleAuthRole":
  365. this.handleAuthRole(row);
  366. break;
  367. default:
  368. break;
  369. }
  370. },
  371. /** 新增按钮操作 */
  372. handleAdd() {
  373. this.reset();
  374. getUser().then((response) => {
  375. this.postOptions = response.posts;
  376. this.roleOptions = response.roles;
  377. this.open = true;
  378. this.title = "添加用户";
  379. this.form.password = this.initPassword;
  380. });
  381. },
  382. /** 修改按钮操作 */
  383. handleUpdate(row) {
  384. this.reset();
  385. const userId = row.userId || this.ids;
  386. getUser(userId).then((response) => {
  387. this.form = response.data;
  388. this.postOptions = response.posts;
  389. this.roleOptions = response.roles;
  390. this.$set(this.form, "postIds", response.postIds);
  391. this.$set(this.form, "roleIds", response.roleIds);
  392. this.open = true;
  393. this.title = "修改用户";
  394. this.form.password = "";
  395. });
  396. },
  397. /** 重置密码按钮操作 */
  398. handleResetPwd(row) {
  399. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  400. confirmButtonText: "确定",
  401. cancelButtonText: "取消",
  402. closeOnClickModal: false,
  403. inputPattern: /^.{5,20}$/,
  404. inputErrorMessage: "用户密码长度必须介于 5 和 20 之间",
  405. })
  406. .then(({ value }) => {
  407. resetUserPwd(row.userId, value).then((response) => {
  408. this.$modal.msgSuccess("修改成功,新密码是:" + value);
  409. });
  410. })
  411. .catch(() => {});
  412. },
  413. /** 分配角色操作 */
  414. handleAuthRole: function (row) {
  415. const userId = row.userId;
  416. this.$router.push("/system/user-auth/role/" + userId);
  417. },
  418. /** 删除按钮操作 */
  419. handleDelete(row) {
  420. const userIds = row.userId || this.ids;
  421. this.$modal
  422. .confirm(
  423. '删除用户时会删除该用户的存储空间!是否确认删除 登录名为"' +
  424. row.userName +
  425. '"的用户?'
  426. )
  427. .then(function () {
  428. return delUser(userIds);
  429. })
  430. .then(() => {
  431. this.getList();
  432. this.$modal.msgSuccess("删除成功");
  433. })
  434. .catch(() => {});
  435. },
  436. /** 导出按钮操作 */
  437. handleExport() {
  438. this.download(
  439. "system/user/export",
  440. {
  441. ...this.queryParams,
  442. },
  443. `user_${new Date().getTime()}.xlsx`
  444. );
  445. },
  446. /** 导入按钮操作 */
  447. handleImport() {
  448. this.upload.title = "用户导入";
  449. this.upload.open = true;
  450. },
  451. /** 下载模板操作 */
  452. importTemplate() {
  453. this.download(
  454. "system/user/importTemplate",
  455. {},
  456. `user_template_${new Date().getTime()}.xlsx`
  457. );
  458. },
  459. // 文件上传中处理
  460. handleFileUploadProgress(event, file, fileList) {
  461. this.upload.isUploading = true;
  462. },
  463. // 文件上传成功处理
  464. handleFileSuccess(response, file, fileList) {
  465. this.upload.open = false;
  466. this.upload.isUploading = false;
  467. this.$refs.upload.clearFiles();
  468. this.$alert(
  469. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  470. response.msg +
  471. "</div>",
  472. "导入结果",
  473. { dangerouslyUseHTMLString: true }
  474. );
  475. this.getList();
  476. },
  477. // 提交上传文件
  478. submitFileForm() {
  479. this.$refs.upload.submit();
  480. },
  481. },
  482. };
  483. </script>
  484. <style scoped lang='scss'>
  485. //弹窗样式
  486. ::v-deep .el-dialog2{
  487. width: calc(100vw * (1000 / 1920)) !important;
  488. height: calc(100vh * (900 / 1080)) !important;
  489. background: url(../../../assets/img/Group-585.png);
  490. background-size: calc(100vw * (1000 / 1920)) calc(100vh * (1000 / 1080));
  491. .el-dialog__headerbtn {
  492. top: 3%;
  493. right: 4%;
  494. font-size: 20px;
  495. }
  496. .dialog-main{
  497. width: calc(100vw * (815 / 1920));
  498. height: calc(100vh * (820 / 1080));
  499. // background: salmon;
  500. margin-left: calc(100vw * (15 / 1920));
  501. margin-top: calc(100vh * (20 / 1080));
  502. .head-container{
  503. .el-input{
  504. width: calc(100vw * (190 / 1920)) !important;
  505. }
  506. }
  507. .aaa,.bbb{
  508. background-color: #002a5cff;
  509. color: #1890ff;
  510. border: none;
  511. }
  512. .dialog-footer{
  513. position: absolute;
  514. right: 10%;
  515. bottom: 8%;
  516. }
  517. .el-table{
  518. background: transparent;
  519. color: #7EA4C8FF;
  520. border: 1px solid #006C9AFF;
  521. }
  522. }
  523. }
  524. ::v-deep .el-dialog:not(.is-fullscreen) {
  525. margin-top: 20px !important;
  526. }
  527. //下面跳转
  528. ::v-deep .pagination-container .el-pagination {
  529. width: calc(100vw * (490 / 1920)) !important;
  530. }
  531. ::v-deep .el-pagination .el-select .el-input {
  532. width: calc(100vw * (100 / 1920)) !important;
  533. }
  534. ::v-deep .el-pagination .el-select .el-input .el-input__inner {
  535. width: calc(100vw * (100 / 1920)) !important;
  536. }
  537. //前往第几页
  538. ::v-deep .el-pagination__editor.el-input {
  539. width: calc(100vw * (50 / 1920)) !important;
  540. }
  541. //左边下拉框背景
  542. ::v-deep .el-tree {
  543. background: transparent;
  544. color: #7EA4C8FF;
  545. border: 1px solid #006C9AFF;
  546. }
  547. //选中时的样式
  548. ::v-deep .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  549. background: #002659FF;
  550. color: #2E8AECFF;
  551. }
  552. ::v-deep .el-tree-node__content:hover{
  553. background: #002659FF;
  554. color: #2E8AECFF;
  555. }
  556. //右边用户名称
  557. ::v-deep .el-dialog .el-form-item {
  558. margin: 0;
  559. .el-input{
  560. width: calc(100vw * (320 / 1920)) !important;
  561. }
  562. }
  563. </style>