selectUser.vue 16 KB

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