index.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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="mobile">
  42. <el-input
  43. v-model="queryParams.mobile"
  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 statusDictDatas"
  61. :key="parseInt(dict.value)"
  62. :label="dict.label"
  63. :value="parseInt(dict.value)"
  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="info"
  97. icon="el-icon-upload2"
  98. size="mini"
  99. @click="handleImport"
  100. v-hasPermi="['system:user:import']"
  101. >导入</el-button>
  102. </el-col>
  103. <el-col :span="1.5">
  104. <el-button
  105. type="warning"
  106. icon="el-icon-download"
  107. size="mini"
  108. @click="handleExport"
  109. v-hasPermi="['system:user:export']"
  110. >导出</el-button>
  111. </el-col>
  112. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  113. </el-row>
  114. <el-table v-loading="loading" :data="userList">
  115. <el-table-column label="用户编号" align="center" prop="id" />
  116. <el-table-column label="用户名称" align="center" prop="username" :show-overflow-tooltip="true" />
  117. <el-table-column label="用户昵称" align="center" prop="nickname" :show-overflow-tooltip="true" />
  118. <el-table-column label="部门" align="center" prop="dept.name" :show-overflow-tooltip="true" />
  119. <el-table-column label="手机号码" align="center" prop="mobile" width="120" />
  120. <el-table-column label="状态" align="center">
  121. <template slot-scope="scope">
  122. <el-switch
  123. v-model="scope.row.status"
  124. :active-value="0"
  125. :inactive-value="1"
  126. @change="handleStatusChange(scope.row)"
  127. ></el-switch>
  128. </template>
  129. </el-table-column>
  130. <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  131. <template slot-scope="scope">
  132. <span>{{ parseTime(scope.row.createTime) }}</span>
  133. </template>
  134. </el-table-column>
  135. <el-table-column
  136. label="操作"
  137. align="center"
  138. width="160"
  139. class-name="small-padding fixed-width"
  140. >
  141. <template slot-scope="scope">
  142. <el-button
  143. size="large"
  144. type="text"
  145. icon="el-icon-edit"
  146. @click="handleUpdate(scope.row)"
  147. v-hasPermi="['system:role:edit']"
  148. >修改</el-button>
  149. <el-dropdown @command="(command) => handleCommand(command, scope.$index, scope.row)">
  150. <span class="el-dropdown-link">
  151. 更多操作<i class="el-icon-arrow-down el-icon--right"></i>
  152. </span>
  153. <el-dropdown-menu slot="dropdown">
  154. <el-dropdown-item
  155. command="handleDelete"
  156. v-if="scope.row.id !== 1"
  157. size="mini"
  158. type="text"
  159. icon="el-icon-delete"
  160. v-hasPermi="['system:user:remove']"
  161. >删除</el-dropdown-item>
  162. <el-dropdown-item
  163. command="handleResetPwd"
  164. size="mini"
  165. type="text"
  166. icon="el-icon-key"
  167. v-hasPermi="['system:user:resetPwd']"
  168. >重置</el-dropdown-item>
  169. <el-dropdown-item
  170. command="handleRole"
  171. size="mini"
  172. type="text"
  173. icon="el-icon-circle-check"
  174. v-hasPermi="['system:permission:assign-user-role']"
  175. >分配角色</el-dropdown-item>
  176. </el-dropdown-menu>
  177. </el-dropdown>
  178. </template>
  179. </el-table-column>
  180. </el-table>
  181. <pagination
  182. v-show="total>0"
  183. :total="total"
  184. :page.sync="queryParams.pageNo"
  185. :limit.sync="queryParams.pageSize"
  186. @pagination="getList"
  187. />
  188. </el-col>
  189. </el-row>
  190. <!-- 添加或修改参数配置对话框 -->
  191. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  192. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  193. <el-row>
  194. <el-col :span="12">
  195. <el-form-item label="用户昵称" prop="nickname">
  196. <el-input v-model="form.nickname" placeholder="请输入用户昵称" />
  197. </el-form-item>
  198. </el-col>
  199. <el-col :span="12">
  200. <el-form-item label="归属部门" prop="deptId">
  201. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true"
  202. placeholder="请选择归属部门" :normalizer="normalizer"
  203. />
  204. </el-form-item>
  205. </el-col>
  206. </el-row>
  207. <el-row>
  208. <el-col :span="12">
  209. <el-form-item label="手机号码" prop="mobile">
  210. <el-input v-model="form.mobile" placeholder="请输入手机号码" maxlength="11" />
  211. </el-form-item>
  212. </el-col>
  213. <el-col :span="12">
  214. <el-form-item label="邮箱" prop="email">
  215. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  216. </el-form-item>
  217. </el-col>
  218. </el-row>
  219. <el-row>
  220. <el-col :span="12">
  221. <el-form-item v-if="form.id === undefined" label="用户名称" prop="username">
  222. <el-input v-model="form.username" placeholder="请输入用户名称" />
  223. </el-form-item>
  224. </el-col>
  225. <el-col :span="12">
  226. <el-form-item v-if="form.id === undefined" label="用户密码" prop="password">
  227. <el-input v-model="form.password" placeholder="请输入用户密码" type="password" />
  228. </el-form-item>
  229. </el-col>
  230. </el-row>
  231. <el-row>
  232. <el-col :span="12">
  233. <el-form-item label="用户性别">
  234. <el-select v-model="form.sex" placeholder="请选择">
  235. <el-option
  236. v-for="dict in sexDictDatas"
  237. :key="parseInt(dict.value)"
  238. :label="dict.label"
  239. :value="parseInt(dict.value)"
  240. ></el-option>
  241. </el-select>
  242. </el-form-item>
  243. </el-col>
  244. <el-col :span="12">
  245. <el-form-item label="岗位">
  246. <el-select v-model="form.postIds" multiple placeholder="请选择">
  247. <el-option
  248. v-for="item in postOptions"
  249. :key="item.id"
  250. :label="item.name"
  251. :value="item.id"
  252. ></el-option>
  253. </el-select>
  254. </el-form-item>
  255. </el-col>
  256. </el-row>
  257. <el-row>
  258. <el-col :span="24">
  259. <el-form-item label="备注">
  260. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  261. </el-form-item>
  262. </el-col>
  263. </el-row>
  264. </el-form>
  265. <div slot="footer" class="dialog-footer">
  266. <el-button type="primary" @click="submitForm">确 定</el-button>
  267. <el-button @click="cancel">取 消</el-button>
  268. </div>
  269. </el-dialog>
  270. <!-- 用户导入对话框 -->
  271. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  272. <el-upload
  273. ref="upload"
  274. :limit="1"
  275. accept=".xlsx, .xls"
  276. :headers="upload.headers"
  277. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  278. :disabled="upload.isUploading"
  279. :on-progress="handleFileUploadProgress"
  280. :on-success="handleFileSuccess"
  281. :auto-upload="false"
  282. drag
  283. >
  284. <i class="el-icon-upload"></i>
  285. <div class="el-upload__text">
  286. 将文件拖到此处,或
  287. <em>点击上传</em>
  288. </div>
  289. <div class="el-upload__tip" slot="tip">
  290. <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
  291. <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
  292. </div>
  293. <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  294. </el-upload>
  295. <div slot="footer" class="dialog-footer">
  296. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  297. <el-button @click="upload.open = false">取 消</el-button>
  298. </div>
  299. </el-dialog>
  300. <!-- 分配角色 -->
  301. <el-dialog title="分配角色" :visible.sync="openRole" width="500px" append-to-body>
  302. <el-form :model="form" label-width="80px">
  303. <el-form-item label="用户名称">
  304. <el-input v-model="form.username" :disabled="true" />
  305. </el-form-item>
  306. <el-form-item label="用户昵称">
  307. <el-input v-model="form.nickname" :disabled="true" />
  308. </el-form-item>
  309. <el-form-item label="角色">
  310. <el-select v-model="form.roleIds" multiple placeholder="请选择">
  311. <el-option
  312. v-for="item in roleOptions"
  313. :key="parseInt(item.id)"
  314. :label="item.name"
  315. :value="parseInt(item.id)"
  316. ></el-option>
  317. </el-select>
  318. </el-form-item>
  319. </el-form>
  320. <div slot="footer" class="dialog-footer">
  321. <el-button type="primary" @click="submitRole">确 定</el-button>
  322. <el-button @click="cancelRole">取 消</el-button>
  323. </div>
  324. </el-dialog>
  325. </div>
  326. </template>
  327. <script>
  328. import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus, importTemplate } from "@/api/system/user";
  329. import { getToken } from "@/utils/auth";
  330. import Treeselect from "@riophae/vue-treeselect";
  331. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  332. import {listSimpleDepts} from "@/api/system/dept";
  333. import {listSimplePosts} from "@/api/system/post";
  334. import {SysCommonStatusEnum} from "@/utils/constants";
  335. import {DICT_TYPE, getDictDatas} from "@/utils/dict";
  336. import {assignUserRole, listUserRoles} from "@/api/system/permission";
  337. import {listSimpleRoles} from "@/api/system/role";
  338. export default {
  339. name: "User",
  340. components: { Treeselect },
  341. data() {
  342. return {
  343. // 遮罩层
  344. loading: true,
  345. // 显示搜索条件
  346. showSearch: true,
  347. // 总条数
  348. total: 0,
  349. // 用户表格数据
  350. userList: null,
  351. // 弹出层标题
  352. title: "",
  353. // 部门树选项
  354. deptOptions: undefined,
  355. // 是否显示弹出层
  356. open: false,
  357. // 部门名称
  358. deptName: undefined,
  359. // 默认密码
  360. initPassword: undefined,
  361. // 日期范围
  362. dateRange: [],
  363. // 状态数据字典
  364. statusOptions: [],
  365. // 性别状态字典
  366. sexOptions: [],
  367. // 岗位选项
  368. postOptions: [],
  369. // 角色选项
  370. roleOptions: [],
  371. // 表单参数
  372. form: {},
  373. defaultProps: {
  374. children: "children",
  375. label: "name"
  376. },
  377. // 用户导入参数
  378. upload: {
  379. // 是否显示弹出层(用户导入)
  380. open: false,
  381. // 弹出层标题(用户导入)
  382. title: "",
  383. // 是否禁用上传
  384. isUploading: false,
  385. // 是否更新已经存在的用户数据
  386. updateSupport: 0,
  387. // 设置上传的请求头部
  388. headers: { Authorization: "Bearer " + getToken() },
  389. // 上传的地址
  390. url: process.env.VUE_APP_BASE_API + '/api/' + "/system/user/import"
  391. },
  392. // 查询参数
  393. queryParams: {
  394. pageNo: 1,
  395. pageSize: 10,
  396. username: undefined,
  397. mobile: undefined,
  398. status: undefined,
  399. deptId: undefined
  400. },
  401. // 表单校验
  402. rules: {
  403. username: [
  404. { required: true, message: "用户名称不能为空", trigger: "blur" }
  405. ],
  406. nickname: [
  407. { required: true, message: "用户昵称不能为空", trigger: "blur" }
  408. ],
  409. password: [
  410. { required: true, message: "用户密码不能为空", trigger: "blur" }
  411. ],
  412. email: [
  413. {
  414. type: "email",
  415. message: "'请输入正确的邮箱地址",
  416. trigger: ["blur", "change"]
  417. }
  418. ],
  419. mobile: [
  420. {
  421. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  422. message: "请输入正确的手机号码",
  423. trigger: "blur"
  424. }
  425. ]
  426. },
  427. // 是否显示弹出层(角色权限)
  428. openRole: false,
  429. // 枚举
  430. SysCommonStatusEnum: SysCommonStatusEnum,
  431. // 数据字典
  432. statusDictDatas: getDictDatas(DICT_TYPE.SYS_COMMON_STATUS),
  433. sexDictDatas: getDictDatas(DICT_TYPE.SYS_USER_SEX),
  434. };
  435. },
  436. watch: {
  437. // 根据名称筛选部门树
  438. deptName(val) {
  439. this.$refs.tree.filter(val);
  440. }
  441. },
  442. created() {
  443. this.getList();
  444. this.getTreeselect();
  445. this.getConfigKey("sys.user.initPassword").then(response => {
  446. this.initPassword = response.msg;
  447. });
  448. },
  449. methods: {
  450. // 更多操作
  451. handleCommand(command, index, row) {
  452. switch (command) {
  453. case 'handleUpdate':
  454. this.handleUpdate(row);//修改客户信息
  455. break;
  456. case 'handleDelete':
  457. this.handleDelete(row);//红号变更
  458. break;
  459. case 'handleResetPwd':
  460. this.handleResetPwd(row);
  461. break;
  462. case 'handleRole':
  463. this.handleRole(row);
  464. break;
  465. default:
  466. break;
  467. }
  468. },
  469. /** 查询用户列表 */
  470. getList() {
  471. this.loading = true;
  472. listUser(this.addDateRange(this.queryParams, [
  473. this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
  474. this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
  475. ])).then(response => {
  476. this.userList = response.data.list;
  477. this.total = response.data.total;
  478. this.loading = false;
  479. }
  480. );
  481. },
  482. /** 查询部门下拉树结构 + 岗位下拉 */
  483. getTreeselect() {
  484. listSimpleDepts().then(response => {
  485. // 处理 deptOptions 参数
  486. this.deptOptions = [];
  487. this.deptOptions.push(...this.handleTree(response.data, "id"));
  488. });
  489. listSimplePosts().then(response => {
  490. // 处理 postOptions 参数
  491. this.postOptions = [];
  492. this.postOptions.push(...response.data);
  493. });
  494. },
  495. // 筛选节点
  496. filterNode(value, data) {
  497. if (!value) return true;
  498. return data.name.indexOf(value) !== -1;
  499. },
  500. // 节点单击事件
  501. handleNodeClick(data) {
  502. this.queryParams.deptId = data.id;
  503. this.getList();
  504. },
  505. // 用户状态修改
  506. handleStatusChange(row) {
  507. let text = row.status === SysCommonStatusEnum.ENABLE ? "启用" : "停用";
  508. this.$confirm('确认要"' + text + '""' + row.username + '"用户吗?', "警告", {
  509. confirmButtonText: "确定",
  510. cancelButtonText: "取消",
  511. type: "warning"
  512. }).then(function() {
  513. return changeUserStatus(row.id, row.status);
  514. }).then(() => {
  515. this.msgSuccess(text + "成功");
  516. }).catch(function() {
  517. row.status = row.status === SysCommonStatusEnum.ENABLE ? SysCommonStatusEnum.DISABLE
  518. : SysCommonStatusEnum.ENABLE;
  519. });
  520. },
  521. // 取消按钮
  522. cancel() {
  523. this.open = false;
  524. this.reset();
  525. },
  526. // 取消按钮(角色权限)
  527. cancelRole() {
  528. this.openRole = false;
  529. this.reset();
  530. },
  531. // 表单重置
  532. reset() {
  533. this.form = {
  534. id: undefined,
  535. deptId: undefined,
  536. username: undefined,
  537. nickname: undefined,
  538. password: undefined,
  539. mobile: undefined,
  540. email: undefined,
  541. sex: undefined,
  542. status: "0",
  543. remark: undefined,
  544. postIds: [],
  545. roleIds: []
  546. };
  547. this.resetForm("form");
  548. },
  549. /** 搜索按钮操作 */
  550. handleQuery() {
  551. this.queryParams.pageNo = 1;
  552. this.getList();
  553. },
  554. /** 重置按钮操作 */
  555. resetQuery() {
  556. this.dateRange = [];
  557. this.resetForm("queryForm");
  558. this.handleQuery();
  559. },
  560. /** 新增按钮操作 */
  561. handleAdd() {
  562. this.reset();
  563. // 获得下拉数据
  564. this.getTreeselect();
  565. // 打开表单,并设置初始化
  566. this.open = true;
  567. this.title = "添加用户";
  568. this.form.password = this.initPassword;
  569. },
  570. /** 修改按钮操作 */
  571. handleUpdate(row) {
  572. this.reset();
  573. this.getTreeselect();
  574. const id = row.id;
  575. getUser(id).then(response => {
  576. this.form = response.data;
  577. this.open = true;
  578. this.title = "修改用户";
  579. this.form.password = "";
  580. });
  581. },
  582. /** 重置密码按钮操作 */
  583. handleResetPwd(row) {
  584. this.$prompt('请输入"' + row.username + '"的新密码', "提示", {
  585. confirmButtonText: "确定",
  586. cancelButtonText: "取消"
  587. }).then(({ value }) => {
  588. resetUserPwd(row.id, value).then(response => {
  589. this.msgSuccess("修改成功,新密码是:" + value);
  590. });
  591. }).catch(() => {});
  592. },
  593. /** 分配用户角色操作 */
  594. handleRole(row) {
  595. this.reset();
  596. const id = row.id
  597. // 处理了 form 的用户 username 和 nickname 的展示
  598. this.form.id = id;
  599. this.form.username = row.username;
  600. this.form.nickname = row.nickname;
  601. // 打开弹窗
  602. this.openRole = true;
  603. // 获得角色列表
  604. listSimpleRoles().then(response => {
  605. // 处理 roleOptions 参数
  606. this.roleOptions = [];
  607. this.roleOptions.push(...response.data);
  608. });
  609. // 获得角色拥有的菜单集合
  610. listUserRoles(id).then(response => {
  611. // 设置选中
  612. this.form.roleIds = response.data;
  613. })
  614. },
  615. /** 提交按钮 */
  616. submitForm: function() {
  617. this.$refs["form"].validate(valid => {
  618. if (valid) {
  619. if (this.form.id !== undefined) {
  620. updateUser(this.form).then(response => {
  621. this.msgSuccess("修改成功");
  622. this.open = false;
  623. this.getList();
  624. });
  625. } else {
  626. addUser(this.form).then(response => {
  627. this.msgSuccess("新增成功");
  628. this.open = false;
  629. this.getList();
  630. });
  631. }
  632. }
  633. });
  634. },
  635. /** 提交按钮(角色权限) */
  636. submitRole: function() {
  637. if (this.form.id !== undefined) {
  638. assignUserRole({
  639. userId: this.form.id,
  640. roleIds: this.form.roleIds,
  641. }).then(response => {
  642. this.msgSuccess("分配角色成功");
  643. this.openRole = false;
  644. this.getList();
  645. });
  646. }
  647. },
  648. /** 删除按钮操作 */
  649. handleDelete(row) {
  650. const ids = row.id || this.ids;
  651. this.$confirm('是否确认删除用户编号为"' + ids + '"的数据项?', "警告", {
  652. confirmButtonText: "确定",
  653. cancelButtonText: "取消",
  654. type: "warning"
  655. }).then(function() {
  656. return delUser(ids);
  657. }).then(() => {
  658. this.getList();
  659. this.msgSuccess("删除成功");
  660. })
  661. },
  662. /** 导出按钮操作 */
  663. handleExport() {
  664. const queryParams = this.addDateRange(this.queryParams, [
  665. this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
  666. this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
  667. ]);
  668. this.$confirm('是否确认导出所有用户数据项?', "警告", {
  669. confirmButtonText: "确定",
  670. cancelButtonText: "取消",
  671. type: "warning"
  672. }).then(function() {
  673. return exportUser(queryParams);
  674. }).then(response => {
  675. this.downloadExcel(response, '用户数据.xls');
  676. })
  677. },
  678. /** 导入按钮操作 */
  679. handleImport() {
  680. this.upload.title = "用户导入";
  681. this.upload.open = true;
  682. },
  683. /** 下载模板操作 */
  684. importTemplate() {
  685. importTemplate().then(response => {
  686. this.downloadExcel(response, '用户导入模板.xls');
  687. });
  688. },
  689. // 文件上传中处理
  690. handleFileUploadProgress(event, file, fileList) {
  691. this.upload.isUploading = true;
  692. },
  693. // 文件上传成功处理
  694. handleFileSuccess(response, file, fileList) {
  695. this.upload.open = false;
  696. this.upload.isUploading = false;
  697. this.$refs.upload.clearFiles();
  698. // 拼接提示语
  699. let data = response.data;
  700. let text = '创建成功数量:' + data.createUsernames.length;
  701. for (const username of data.createUsernames) {
  702. text += '<br />&nbsp;&nbsp;&nbsp;&nbsp;' + username;
  703. }
  704. text += '<br />更新成功数量:' + data.updateUsernames.length;
  705. for (const username of data.updateUsernames) {
  706. text += '<br />&nbsp;&nbsp;&nbsp;&nbsp;' + username;
  707. }
  708. text += '<br />更新失败数量:' + Object.keys(data.failureUsernames).length;
  709. for (const username in data.failureUsernames) {
  710. text += '<br />&nbsp;&nbsp;&nbsp;&nbsp;' + username + ':' + data.failureUsernames[username];
  711. }
  712. this.$alert(text, "导入结果", { dangerouslyUseHTMLString: true });
  713. this.getList();
  714. },
  715. // 提交上传文件
  716. submitFileForm() {
  717. this.$refs.upload.submit();
  718. },
  719. // 格式化部门的下拉框
  720. normalizer(node) {
  721. return {
  722. id: node.id,
  723. label: node.name,
  724. children: node.children
  725. }
  726. }
  727. }
  728. };
  729. </script>
  730. <style>
  731. .el-dropdown-link {
  732. cursor: pointer;
  733. color: #1890ff;
  734. margin-left: 5px;
  735. }
  736. .el-icon-arrow-down {
  737. font-size: 14px;
  738. }
  739. </style>