index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--部门数据-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input
  8. v-model="deptName"
  9. placeholder="请输入部门名称"
  10. clearable
  11. size="small"
  12. prefix-icon="el-icon-search"
  13. style="margin-bottom: 20px"
  14. />
  15. </div>
  16. <div class="head-container">
  17. <el-tree
  18. :data="deptOptions"
  19. :props="defaultProps"
  20. :expand-on-click-node="false"
  21. :filter-node-method="filterNode"
  22. ref="tree"
  23. default-expand-all
  24. @node-click="handleNodeClick"
  25. />
  26. </div>
  27. </el-col>
  28. <!--用户数据-->
  29. <el-col :span="20" :xs="24">
  30. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  31. <el-form-item label="用户名称" prop="userName">
  32. <el-input
  33. v-model="queryParams.userName"
  34. placeholder="请输入用户名称"
  35. clearable
  36. size="small"
  37. style="width: 240px"
  38. @keyup.enter.native="handleQuery"
  39. />
  40. </el-form-item>
  41. <el-form-item label="手机号码" prop="phonenumber">
  42. <el-input
  43. v-model="queryParams.phonenumber"
  44. placeholder="请输入手机号码"
  45. clearable
  46. size="small"
  47. style="width: 240px"
  48. @keyup.enter.native="handleQuery"
  49. />
  50. </el-form-item>
  51. <el-form-item label="状态" prop="status">
  52. <el-select
  53. v-model="queryParams.status"
  54. placeholder="用户状态"
  55. clearable
  56. size="small"
  57. style="width: 240px"
  58. >
  59. <el-option
  60. v-for="dict in statusOptions"
  61. :key="dict.dictValue"
  62. :label="dict.dictLabel"
  63. :value="dict.dictValue"
  64. />
  65. </el-select>
  66. </el-form-item>
  67. <el-form-item label="创建时间">
  68. <el-date-picker
  69. v-model="dateRange"
  70. size="small"
  71. style="width: 240px"
  72. value-format="yyyy-MM-dd"
  73. type="daterange"
  74. range-separator="-"
  75. start-placeholder="开始日期"
  76. end-placeholder="结束日期"
  77. ></el-date-picker>
  78. </el-form-item>
  79. <el-form-item>
  80. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  81. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  82. </el-form-item>
  83. </el-form>
  84. <el-row :gutter="10" class="mb8">
  85. <el-col :span="1.5">
  86. <el-button
  87. type="primary"
  88. icon="el-icon-plus"
  89. size="mini"
  90. @click="handleAdd"
  91. v-hasPermi="['system:user:add']"
  92. >新增</el-button>
  93. </el-col>
  94. <el-col :span="1.5">
  95. <el-button
  96. type="success"
  97. icon="el-icon-edit"
  98. size="mini"
  99. :disabled="single"
  100. @click="handleUpdate"
  101. v-hasPermi="['system:user:edit']"
  102. >修改</el-button>
  103. </el-col>
  104. <el-col :span="1.5">
  105. <el-button
  106. type="danger"
  107. icon="el-icon-delete"
  108. size="mini"
  109. :disabled="multiple"
  110. @click="handleDelete"
  111. v-hasPermi="['system:user:remove']"
  112. >删除</el-button>
  113. </el-col>
  114. <el-col :span="1.5">
  115. <el-button
  116. type="info"
  117. icon="el-icon-upload2"
  118. size="mini"
  119. @click="handleImport"
  120. v-hasPermi="['system:user:import']"
  121. >导入</el-button>
  122. </el-col>
  123. <el-col :span="1.5">
  124. <el-button
  125. type="warning"
  126. icon="el-icon-download"
  127. size="mini"
  128. @click="handleExport"
  129. v-hasPermi="['system:user:export']"
  130. >导出</el-button>
  131. </el-col>
  132. <div class="top-right-btn">
  133. <el-tooltip class="item" effect="dark" content="刷新" placement="top">
  134. <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery" />
  135. </el-tooltip>
  136. <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
  137. <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch" />
  138. </el-tooltip>
  139. </div>
  140. </el-row>
  141. <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  142. <el-table-column type="selection" width="50" align="center" />
  143. <el-table-column label="用户编号" align="center" prop="userId" />
  144. <el-table-column label="用户名称" align="center" prop="userName" :show-overflow-tooltip="true" />
  145. <el-table-column label="用户昵称" align="center" prop="nickName" :show-overflow-tooltip="true" />
  146. <el-table-column label="部门" align="center" prop="dept.deptName" :show-overflow-tooltip="true" />
  147. <el-table-column label="手机号码" align="center" prop="phonenumber" width="120" />
  148. <el-table-column label="状态" align="center">
  149. <template slot-scope="scope">
  150. <el-switch
  151. v-model="scope.row.status"
  152. active-value="0"
  153. inactive-value="1"
  154. @change="handleStatusChange(scope.row)"
  155. ></el-switch>
  156. </template>
  157. </el-table-column>
  158. <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  159. <template slot-scope="scope">
  160. <span>{{ parseTime(scope.row.createTime) }}</span>
  161. </template>
  162. </el-table-column>
  163. <el-table-column
  164. label="操作"
  165. align="center"
  166. width="180"
  167. class-name="small-padding fixed-width"
  168. >
  169. <template slot-scope="scope">
  170. <el-button
  171. size="mini"
  172. type="text"
  173. icon="el-icon-edit"
  174. @click="handleUpdate(scope.row)"
  175. v-hasPermi="['system:user:edit']"
  176. >修改</el-button>
  177. <el-button
  178. v-if="scope.row.userId !== 1"
  179. size="mini"
  180. type="text"
  181. icon="el-icon-delete"
  182. @click="handleDelete(scope.row)"
  183. v-hasPermi="['system:user:remove']"
  184. >删除</el-button>
  185. <el-button
  186. size="mini"
  187. type="text"
  188. icon="el-icon-key"
  189. @click="handleResetPwd(scope.row)"
  190. v-hasPermi="['system:user:resetPwd']"
  191. >重置</el-button>
  192. </template>
  193. </el-table-column>
  194. </el-table>
  195. <pagination
  196. v-show="total>0"
  197. :total="total"
  198. :page.sync="queryParams.pageNum"
  199. :limit.sync="queryParams.pageSize"
  200. @pagination="getList"
  201. />
  202. </el-col>
  203. </el-row>
  204. <!-- 添加或修改参数配置对话框 -->
  205. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  206. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  207. <el-row>
  208. <el-col :span="12">
  209. <el-form-item label="用户昵称" prop="nickName">
  210. <el-input v-model="form.nickName" placeholder="请输入用户昵称" />
  211. </el-form-item>
  212. </el-col>
  213. <el-col :span="12">
  214. <el-form-item label="归属部门" prop="deptId">
  215. <treeselect v-model="form.deptId" :options="deptOptions" :disable-branch-nodes="true" :show-count="true" placeholder="请选择归属部门" />
  216. </el-form-item>
  217. </el-col>
  218. </el-row>
  219. <el-row>
  220. <el-col :span="12">
  221. <el-form-item label="手机号码" prop="phonenumber">
  222. <el-input v-model="form.phonenumber" placeholder="请输入手机号码" maxlength="11" />
  223. </el-form-item>
  224. </el-col>
  225. <el-col :span="12">
  226. <el-form-item label="邮箱" prop="email">
  227. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  228. </el-form-item>
  229. </el-col>
  230. </el-row>
  231. <el-row>
  232. <el-col :span="12">
  233. <el-form-item v-if="form.userId == undefined" label="用户名称" prop="userName">
  234. <el-input v-model="form.userName" placeholder="请输入用户名称" />
  235. </el-form-item>
  236. </el-col>
  237. <el-col :span="12">
  238. <el-form-item v-if="form.userId == undefined" label="用户密码" prop="password">
  239. <el-input v-model="form.password" placeholder="请输入用户密码" type="password" />
  240. </el-form-item>
  241. </el-col>
  242. </el-row>
  243. <el-row>
  244. <el-col :span="12">
  245. <el-form-item label="用户性别">
  246. <el-select v-model="form.sex" placeholder="请选择">
  247. <el-option
  248. v-for="dict in sexOptions"
  249. :key="dict.dictValue"
  250. :label="dict.dictLabel"
  251. :value="dict.dictValue"
  252. ></el-option>
  253. </el-select>
  254. </el-form-item>
  255. </el-col>
  256. <el-col :span="12">
  257. <el-form-item label="状态">
  258. <el-radio-group v-model="form.status">
  259. <el-radio
  260. v-for="dict in statusOptions"
  261. :key="dict.dictValue"
  262. :label="dict.dictValue"
  263. >{{dict.dictLabel}}</el-radio>
  264. </el-radio-group>
  265. </el-form-item>
  266. </el-col>
  267. </el-row>
  268. <el-row>
  269. <el-col :span="12">
  270. <el-form-item label="岗位">
  271. <el-select v-model="form.postIds" multiple placeholder="请选择">
  272. <el-option
  273. v-for="item in postOptions"
  274. :key="item.postId"
  275. :label="item.postName"
  276. :value="item.postId"
  277. :disabled="item.status == 1"
  278. ></el-option>
  279. </el-select>
  280. </el-form-item>
  281. </el-col>
  282. <el-col :span="12">
  283. <el-form-item label="角色">
  284. <el-select v-model="form.roleIds" multiple placeholder="请选择">
  285. <el-option
  286. v-for="item in roleOptions"
  287. :key="item.roleId"
  288. :label="item.roleName"
  289. :value="item.roleId"
  290. :disabled="item.status == 1"
  291. ></el-option>
  292. </el-select>
  293. </el-form-item>
  294. </el-col>
  295. </el-row>
  296. <el-row>
  297. <el-col :span="24">
  298. <el-form-item label="备注">
  299. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  300. </el-form-item>
  301. </el-col>
  302. </el-row>
  303. </el-form>
  304. <div slot="footer" class="dialog-footer">
  305. <el-button type="primary" @click="submitForm">确 定</el-button>
  306. <el-button @click="cancel">取 消</el-button>
  307. </div>
  308. </el-dialog>
  309. <!-- 用户导入对话框 -->
  310. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  311. <el-upload
  312. ref="upload"
  313. :limit="1"
  314. accept=".xlsx, .xls"
  315. :headers="upload.headers"
  316. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  317. :disabled="upload.isUploading"
  318. :on-progress="handleFileUploadProgress"
  319. :on-success="handleFileSuccess"
  320. :auto-upload="false"
  321. drag
  322. >
  323. <i class="el-icon-upload"></i>
  324. <div class="el-upload__text">
  325. 将文件拖到此处,或
  326. <em>点击上传</em>
  327. </div>
  328. <div class="el-upload__tip" slot="tip">
  329. <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
  330. <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
  331. </div>
  332. <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  333. </el-upload>
  334. <div slot="footer" class="dialog-footer">
  335. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  336. <el-button @click="upload.open = false">取 消</el-button>
  337. </div>
  338. </el-dialog>
  339. </div>
  340. </template>
  341. <script>
  342. import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus, importTemplate } from "@/api/system/user";
  343. import { getToken } from "@/utils/auth";
  344. import { treeselect } from "@/api/system/dept";
  345. import Treeselect from "@riophae/vue-treeselect";
  346. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  347. export default {
  348. name: "User",
  349. components: { Treeselect },
  350. data() {
  351. return {
  352. // 遮罩层
  353. loading: true,
  354. // 选中数组
  355. ids: [],
  356. // 非单个禁用
  357. single: true,
  358. // 非多个禁用
  359. multiple: true,
  360. // 显示搜索条件
  361. showSearch: true,
  362. // 总条数
  363. total: 0,
  364. // 用户表格数据
  365. userList: null,
  366. // 弹出层标题
  367. title: "",
  368. // 部门树选项
  369. deptOptions: undefined,
  370. // 是否显示弹出层
  371. open: false,
  372. // 部门名称
  373. deptName: undefined,
  374. // 默认密码
  375. initPassword: undefined,
  376. // 日期范围
  377. dateRange: [],
  378. // 状态数据字典
  379. statusOptions: [],
  380. // 性别状态字典
  381. sexOptions: [],
  382. // 岗位选项
  383. postOptions: [],
  384. // 角色选项
  385. roleOptions: [],
  386. // 表单参数
  387. form: {},
  388. defaultProps: {
  389. children: "children",
  390. label: "label"
  391. },
  392. // 用户导入参数
  393. upload: {
  394. // 是否显示弹出层(用户导入)
  395. open: false,
  396. // 弹出层标题(用户导入)
  397. title: "",
  398. // 是否禁用上传
  399. isUploading: false,
  400. // 是否更新已经存在的用户数据
  401. updateSupport: 0,
  402. // 设置上传的请求头部
  403. headers: { Authorization: "Bearer " + getToken() },
  404. // 上传的地址
  405. url: process.env.VUE_APP_BASE_API + "/system/user/importData"
  406. },
  407. // 查询参数
  408. queryParams: {
  409. pageNum: 1,
  410. pageSize: 10,
  411. userName: undefined,
  412. phonenumber: undefined,
  413. status: undefined,
  414. deptId: undefined
  415. },
  416. // 表单校验
  417. rules: {
  418. userName: [
  419. { required: true, message: "用户名称不能为空", trigger: "blur" }
  420. ],
  421. nickName: [
  422. { required: true, message: "用户昵称不能为空", trigger: "blur" }
  423. ],
  424. deptId: [
  425. { required: true, message: "归属部门不能为空", trigger: "blur" }
  426. ],
  427. password: [
  428. { required: true, message: "用户密码不能为空", trigger: "blur" }
  429. ],
  430. email: [
  431. { required: true, message: "邮箱地址不能为空", trigger: "blur" },
  432. {
  433. type: "email",
  434. message: "'请输入正确的邮箱地址",
  435. trigger: ["blur", "change"]
  436. }
  437. ],
  438. phonenumber: [
  439. { required: true, message: "手机号码不能为空", trigger: "blur" },
  440. {
  441. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  442. message: "请输入正确的手机号码",
  443. trigger: "blur"
  444. }
  445. ]
  446. }
  447. };
  448. },
  449. watch: {
  450. // 根据名称筛选部门树
  451. deptName(val) {
  452. this.$refs.tree.filter(val);
  453. }
  454. },
  455. created() {
  456. this.getList();
  457. this.getTreeselect();
  458. this.getDicts("sys_normal_disable").then(response => {
  459. this.statusOptions = response.data;
  460. });
  461. this.getDicts("sys_user_sex").then(response => {
  462. this.sexOptions = response.data;
  463. });
  464. this.getConfigKey("sys.user.initPassword").then(response => {
  465. this.initPassword = response.msg;
  466. });
  467. },
  468. methods: {
  469. /** 查询用户列表 */
  470. getList() {
  471. this.loading = true;
  472. listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  473. this.userList = response.rows;
  474. this.total = response.total;
  475. this.loading = false;
  476. }
  477. );
  478. },
  479. /** 查询部门下拉树结构 */
  480. getTreeselect() {
  481. treeselect().then(response => {
  482. this.deptOptions = response.data;
  483. });
  484. },
  485. // 筛选节点
  486. filterNode(value, data) {
  487. if (!value) return true;
  488. return data.label.indexOf(value) !== -1;
  489. },
  490. // 节点单击事件
  491. handleNodeClick(data) {
  492. this.queryParams.deptId = data.id;
  493. this.getList();
  494. },
  495. // 用户状态修改
  496. handleStatusChange(row) {
  497. let text = row.status === "0" ? "启用" : "停用";
  498. this.$confirm('确认要"' + text + '""' + row.userName + '"用户吗?', "警告", {
  499. confirmButtonText: "确定",
  500. cancelButtonText: "取消",
  501. type: "warning"
  502. }).then(function() {
  503. return changeUserStatus(row.userId, row.status);
  504. }).then(() => {
  505. this.msgSuccess(text + "成功");
  506. }).catch(function() {
  507. row.status = row.status === "0" ? "1" : "0";
  508. });
  509. },
  510. // 取消按钮
  511. cancel() {
  512. this.open = false;
  513. this.reset();
  514. },
  515. // 表单重置
  516. reset() {
  517. this.form = {
  518. userId: undefined,
  519. deptId: undefined,
  520. userName: undefined,
  521. nickName: undefined,
  522. password: undefined,
  523. phonenumber: undefined,
  524. email: undefined,
  525. sex: undefined,
  526. status: "0",
  527. remark: undefined,
  528. postIds: [],
  529. roleIds: []
  530. };
  531. this.resetForm("form");
  532. },
  533. /** 搜索按钮操作 */
  534. handleQuery() {
  535. this.queryParams.page = 1;
  536. this.getList();
  537. },
  538. /** 重置按钮操作 */
  539. resetQuery() {
  540. this.dateRange = [];
  541. this.resetForm("queryForm");
  542. this.handleQuery();
  543. },
  544. // 多选框选中数据
  545. handleSelectionChange(selection) {
  546. this.ids = selection.map(item => item.userId);
  547. this.single = selection.length != 1;
  548. this.multiple = !selection.length;
  549. },
  550. /** 新增按钮操作 */
  551. handleAdd() {
  552. this.reset();
  553. this.getTreeselect();
  554. getUser().then(response => {
  555. this.postOptions = response.posts;
  556. this.roleOptions = response.roles;
  557. this.open = true;
  558. this.title = "添加用户";
  559. this.form.password = this.initPassword;
  560. });
  561. },
  562. /** 修改按钮操作 */
  563. handleUpdate(row) {
  564. this.reset();
  565. this.getTreeselect();
  566. const userId = row.userId || this.ids;
  567. getUser(userId).then(response => {
  568. this.form = response.data;
  569. this.postOptions = response.posts;
  570. this.roleOptions = response.roles;
  571. this.form.postIds = response.postIds;
  572. this.form.roleIds = response.roleIds;
  573. this.open = true;
  574. this.title = "修改用户";
  575. this.form.password = "";
  576. });
  577. },
  578. /** 重置密码按钮操作 */
  579. handleResetPwd(row) {
  580. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  581. confirmButtonText: "确定",
  582. cancelButtonText: "取消"
  583. }).then(({ value }) => {
  584. resetUserPwd(row.userId, value).then(response => {
  585. if (response.code === 200) {
  586. this.msgSuccess("修改成功,新密码是:" + value);
  587. }
  588. });
  589. }).catch(() => {});
  590. },
  591. /** 提交按钮 */
  592. submitForm: function() {
  593. this.$refs["form"].validate(valid => {
  594. if (valid) {
  595. if (this.form.userId != undefined) {
  596. updateUser(this.form).then(response => {
  597. if (response.code === 200) {
  598. this.msgSuccess("修改成功");
  599. this.open = false;
  600. this.getList();
  601. }
  602. });
  603. } else {
  604. addUser(this.form).then(response => {
  605. if (response.code === 200) {
  606. this.msgSuccess("新增成功");
  607. this.open = false;
  608. this.getList();
  609. }
  610. });
  611. }
  612. }
  613. });
  614. },
  615. /** 删除按钮操作 */
  616. handleDelete(row) {
  617. const userIds = row.userId || this.ids;
  618. this.$confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', "警告", {
  619. confirmButtonText: "确定",
  620. cancelButtonText: "取消",
  621. type: "warning"
  622. }).then(function() {
  623. return delUser(userIds);
  624. }).then(() => {
  625. this.getList();
  626. this.msgSuccess("删除成功");
  627. }).catch(function() {});
  628. },
  629. /** 导出按钮操作 */
  630. handleExport() {
  631. const queryParams = this.queryParams;
  632. this.$confirm('是否确认导出所有用户数据项?', "警告", {
  633. confirmButtonText: "确定",
  634. cancelButtonText: "取消",
  635. type: "warning"
  636. }).then(function() {
  637. return exportUser(queryParams);
  638. }).then(response => {
  639. this.download(response.msg);
  640. }).catch(function() {});
  641. },
  642. /** 导入按钮操作 */
  643. handleImport() {
  644. this.upload.title = "用户导入";
  645. this.upload.open = true;
  646. },
  647. /** 下载模板操作 */
  648. importTemplate() {
  649. importTemplate().then(response => {
  650. this.download(response.msg);
  651. });
  652. },
  653. // 文件上传中处理
  654. handleFileUploadProgress(event, file, fileList) {
  655. this.upload.isUploading = true;
  656. },
  657. // 文件上传成功处理
  658. handleFileSuccess(response, file, fileList) {
  659. this.upload.open = false;
  660. this.upload.isUploading = false;
  661. this.$refs.upload.clearFiles();
  662. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  663. this.getList();
  664. },
  665. // 提交上传文件
  666. submitFileForm() {
  667. this.$refs.upload.submit();
  668. }
  669. }
  670. };
  671. </script>