index.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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
  31. :model="queryParams"
  32. ref="queryForm"
  33. :inline="true"
  34. v-show="showSearch"
  35. label-width="68px"
  36. >
  37. <el-form-item label="用户名称" prop="userName">
  38. <el-input
  39. v-model="queryParams.userName"
  40. placeholder="请输入用户名称"
  41. clearable
  42. size="small"
  43. style="width: 240px"
  44. @keyup.enter.native="handleQuery"
  45. />
  46. </el-form-item>
  47. <el-form-item label="手机号码" prop="phonenumber">
  48. <el-input
  49. v-model="queryParams.phonenumber"
  50. placeholder="请输入手机号码"
  51. clearable
  52. size="small"
  53. style="width: 240px"
  54. @keyup.enter.native="handleQuery"
  55. />
  56. </el-form-item>
  57. <el-form-item label="状态" prop="status">
  58. <el-select
  59. v-model="queryParams.status"
  60. placeholder="用户状态"
  61. clearable
  62. size="small"
  63. style="width: 240px"
  64. >
  65. <el-option
  66. v-for="dict in dict.type.sys_normal_disable"
  67. :key="dict.value"
  68. :label="dict.label"
  69. :value="dict.value"
  70. class="input_xiala"
  71. />
  72. </el-select>
  73. </el-form-item>
  74. <el-form-item label="创建时间">
  75. <el-date-picker
  76. v-model="dateRange"
  77. size="small"
  78. style="
  79. width: 200px;
  80. height: 36px;
  81. background: #00365f;
  82. border: 1px solid white;
  83. "
  84. value-format="yyyy-MM-dd"
  85. type="daterange"
  86. range-separator="-"
  87. start-placeholder="开始日期"
  88. end-placeholder="结束日期"
  89. ></el-date-picker>
  90. </el-form-item>
  91. <el-form-item>
  92. <el-button
  93. type="primary"
  94. icon="el-icon-search"
  95. size="btn"
  96. @click="handleQuery"
  97. >搜索</el-button
  98. >
  99. <el-button icon="el-icon-refresh" size="btr" @click="resetQuery"
  100. >重置</el-button
  101. >
  102. </el-form-item>
  103. </el-form>
  104. <el-row :gutter="10" class="mb8">
  105. <el-col :span="1.5">
  106. <el-button
  107. type="primary"
  108. plain
  109. icon="el-icon-plus"
  110. size="mini"
  111. @click="handleAdd"
  112. v-hasPermi="['system:user:add']"
  113. >新增</el-button
  114. >
  115. </el-col>
  116. <el-col :span="1.5">
  117. <el-button
  118. type="success"
  119. plain
  120. icon="el-icon-edit"
  121. size="mini"
  122. :disabled="single"
  123. @click="handleUpdate"
  124. v-hasPermi="['system:user:edit']"
  125. >修改</el-button
  126. >
  127. </el-col>
  128. <el-col :span="1.5">
  129. <el-button
  130. type="danger"
  131. plain
  132. icon="el-icon-delete"
  133. size="mini"
  134. :disabled="multiple"
  135. @click="handleDelete"
  136. v-hasPermi="['system:user:remove']"
  137. >删除</el-button
  138. >
  139. </el-col>
  140. <el-col :span="1.5">
  141. <el-button
  142. type="info"
  143. plain
  144. icon="el-icon-upload2"
  145. size="mini"
  146. @click="handleImport"
  147. v-hasPermi="['system:user:import']"
  148. >导入</el-button
  149. >
  150. </el-col>
  151. <el-col :span="1.5">
  152. <el-button
  153. type="warning"
  154. plain
  155. icon="el-icon-download"
  156. size="mini"
  157. :loading="exportLoading"
  158. @click="handleExport"
  159. v-hasPermi="['system:user:export']"
  160. >导出</el-button
  161. >
  162. </el-col>
  163. <right-toolbar
  164. :showSearch.sync="showSearch"
  165. @queryTable="getList"
  166. :columns="columns"
  167. ></right-toolbar>
  168. </el-row>
  169. <el-table
  170. v-loading="loading"
  171. :data="userList"
  172. @selection-change="handleSelectionChange"
  173. :header-cell-style="{ background: '#003c69', color: 'white' }"
  174. >
  175. <el-table-column type="selection" width="50" align="center" />
  176. <el-table-column
  177. label="用户编号"
  178. align="center"
  179. key="userId"
  180. prop="userId"
  181. v-if="columns[0].visible"
  182. />
  183. <el-table-column
  184. label="用户名称"
  185. align="center"
  186. key="userName"
  187. prop="userName"
  188. v-if="columns[1].visible"
  189. :show-overflow-tooltip="true"
  190. />
  191. <el-table-column
  192. label="用户昵称"
  193. align="center"
  194. key="nickName"
  195. prop="nickName"
  196. v-if="columns[2].visible"
  197. :show-overflow-tooltip="true"
  198. />
  199. <el-table-column
  200. label="部门"
  201. align="center"
  202. key="deptName"
  203. prop="dept.deptName"
  204. v-if="columns[3].visible"
  205. :show-overflow-tooltip="true"
  206. />
  207. <el-table-column
  208. label="手机号码"
  209. align="center"
  210. key="phonenumber"
  211. prop="phonenumber"
  212. v-if="columns[4].visible"
  213. width="120"
  214. />
  215. <el-table-column
  216. label="状态"
  217. align="center"
  218. key="status"
  219. v-if="columns[5].visible"
  220. >
  221. <template slot-scope="scope">
  222. <el-switch
  223. v-model="scope.row.status"
  224. active-value="0"
  225. inactive-value="1"
  226. @change="handleStatusChange(scope.row)"
  227. ></el-switch>
  228. </template>
  229. </el-table-column>
  230. <el-table-column
  231. label="创建时间"
  232. align="center"
  233. prop="createTime"
  234. v-if="columns[6].visible"
  235. width="160"
  236. >
  237. <template slot-scope="scope">
  238. <span>{{ parseTime(scope.row.createTime) }}</span>
  239. </template>
  240. </el-table-column>
  241. <el-table-column
  242. label="操作"
  243. align="center"
  244. width="200"
  245. class-name="small-padding fixed-width"
  246. >
  247. <template slot-scope="scope" v-if="scope.row.userId !== 1">
  248. <el-button
  249. size="mini"
  250. type="text"
  251. @click="handleUpdate(scope.row)"
  252. v-hasPermi="['system:user:edit']"
  253. >
  254. <span class="edit">修改</span>
  255. </el-button>
  256. <el-button
  257. size="mini"
  258. type="text"
  259. @click="handleDelete(scope.row)"
  260. v-hasPermi="['system:user:remove']"
  261. >
  262. <span class="delete">删除</span>
  263. </el-button>
  264. <el-dropdown
  265. size="mini"
  266. @command="command => handleCommand(command, scope.row)"
  267. v-hasPermi="['system:user:resetPwd', 'system:user:edit']"
  268. >
  269. <span class="more">更多</span>
  270. <el-dropdown-menu slot="dropdown">
  271. <el-dropdown-item
  272. command="handleResetPwd"
  273. icon="el-icon-key"
  274. v-hasPermi="['system:user:resetPwd']"
  275. >重置密码</el-dropdown-item
  276. >
  277. <el-dropdown-item
  278. command="handleAuthRole"
  279. icon="el-icon-circle-check"
  280. v-hasPermi="['system:user:edit']"
  281. >分配角色</el-dropdown-item
  282. >
  283. </el-dropdown-menu>
  284. </el-dropdown>
  285. </template>
  286. </el-table-column>
  287. </el-table>
  288. <pagination
  289. v-show="total > 0"
  290. :total="total"
  291. :page.sync="queryParams.pageNum"
  292. :limit.sync="queryParams.pageSize"
  293. @pagination="getList"
  294. />
  295. </el-col>
  296. </el-row>
  297. <!-- 添加或修改参数配置对话框 -->
  298. <el-dialog
  299. :title="title"
  300. :visible.sync="open"
  301. width="1016px"
  302. append-to-body
  303. >
  304. <div class="jiben">基本信息</div>
  305. <el-form
  306. ref="form"
  307. :model="form"
  308. :rules="rules"
  309. label-width="80px"
  310. :inline="true"
  311. >
  312. <el-row>
  313. <el-col :span="8">
  314. <!-- <el-form-item label="归属部门" prop="deptId">
  315. <treeselect
  316. v-model="form.deptId"
  317. :options="deptOptions"
  318. :show-count="true"
  319. placeholder="请选择归属部门"
  320. @node-click="deptIdClick"
  321. />
  322. </el-form-item>-->
  323. <el-form-item label="归属部门" prop="deptId">
  324. <el-select
  325. v-model="form.deptId"
  326. @change="deptIdClick"
  327. clearable
  328. placeholder="请选择归属部门"
  329. >
  330. <el-option
  331. v-for="dict in unitId"
  332. :key="dict.deptId"
  333. :label="dict.deptName"
  334. :value="dict.deptId"
  335. ></el-option>
  336. </el-select>
  337. </el-form-item>
  338. </el-col>
  339. <el-col :span="8">
  340. <el-form-item label="用户昵称" prop="nickName">
  341. <el-select
  342. v-model="form.nickName"
  343. filterable
  344. clearable
  345. placeholder
  346. @change="unitNamechange"
  347. >
  348. <el-option
  349. v-for="item in nickNamelist"
  350. :key="item.id"
  351. :label="item.name"
  352. :value="item"
  353. ></el-option>
  354. </el-select>
  355. </el-form-item>
  356. </el-col>
  357. <el-col :span="8">
  358. <el-form-item label="手机号码" prop="phonenumber">
  359. <el-input
  360. v-model="form.phonenumber"
  361. placeholder="请输入手机号码"
  362. maxlength="11"
  363. />
  364. </el-form-item>
  365. </el-col>
  366. </el-row>
  367. <el-row>
  368. <el-col :span="8">
  369. <el-form-item label="邮箱" prop="email">
  370. <el-input
  371. v-model="form.email"
  372. placeholder="请输入邮箱"
  373. maxlength="50"
  374. />
  375. </el-form-item>
  376. </el-col>
  377. <el-col :span="8">
  378. <el-form-item
  379. v-if="form.userId == undefined"
  380. label="账户名称"
  381. prop="userName"
  382. >
  383. <el-input
  384. v-model="form.userName"
  385. placeholder="请输入账户名称"
  386. maxlength="30"
  387. />
  388. </el-form-item>
  389. </el-col>
  390. <el-col :span="8">
  391. <el-form-item
  392. v-if="form.userId == undefined"
  393. label="账户密码"
  394. prop="password"
  395. >
  396. <el-input
  397. v-model="form.password"
  398. placeholder="请输入账户密码"
  399. type="password"
  400. maxlength="20"
  401. show-password
  402. />
  403. </el-form-item>
  404. </el-col>
  405. </el-row>
  406. <el-row></el-row>
  407. <el-row>
  408. <el-col :span="8">
  409. <el-form-item label="用户性别">
  410. <el-select v-model="form.sex" placeholder="请选择">
  411. <el-option
  412. v-for="dict in dict.type.sys_user_sex"
  413. :key="dict.value"
  414. :label="dict.label"
  415. :value="dict.value"
  416. ></el-option>
  417. </el-select>
  418. </el-form-item>
  419. </el-col>
  420. <el-col :span="8">
  421. <el-form-item label="角色">
  422. <el-select v-model="form.roleIds" multiple placeholder="请选择">
  423. <el-option
  424. v-for="item in roleOptions"
  425. :key="item.roleId"
  426. :label="item.roleName"
  427. :value="item.roleId"
  428. :disabled="item.status == 1"
  429. ></el-option>
  430. </el-select>
  431. </el-form-item>
  432. </el-col>
  433. <el-col :span="8">
  434. <el-form-item label="岗位">
  435. <el-select v-model="form.postIds" multiple placeholder="请选择">
  436. <el-option
  437. v-for="item in postOptions"
  438. :key="item.postId"
  439. :label="item.postName"
  440. :value="item.postId"
  441. :disabled="item.status == 1"
  442. ></el-option>
  443. </el-select>
  444. </el-form-item>
  445. </el-col>
  446. </el-row>
  447. <el-row>
  448. <el-col :span="16">
  449. <el-form-item label="权限">
  450. <el-select
  451. v-model="form.permissions"
  452. style="width:400px;"
  453. placeholder="请选择权限"
  454. >
  455. <el-option
  456. v-for="dict in permissionslist"
  457. :key="dict.dictValue"
  458. :label="dict.dictLabel"
  459. :value="dict.dictValue"
  460. ></el-option>
  461. </el-select>
  462. </el-form-item>
  463. </el-col>
  464. <el-col :span="8">
  465. <el-form-item label="状态">
  466. <el-radio-group v-model="form.status">
  467. <el-radio
  468. v-for="dict in dict.type.sys_normal_disable"
  469. :key="dict.value"
  470. :label="dict.value"
  471. >{{ dict.label }}</el-radio
  472. >
  473. </el-radio-group>
  474. </el-form-item>
  475. </el-col>
  476. </el-row>
  477. <div class="jiben">备注</div>
  478. <el-row>
  479. <el-col :span="24">
  480. <el-form-item label style="width: 100%" class="textareas">
  481. <el-input
  482. v-model="form.remark"
  483. type="textarea"
  484. placeholder="请输入内容"
  485. ></el-input>
  486. </el-form-item>
  487. </el-col>
  488. </el-row>
  489. </el-form>
  490. <div slot="footer" class="dialog-footer">
  491. <el-button type="primary" @click="submitForm">确 定</el-button>
  492. <el-button @click="cancel">取 消</el-button>
  493. </div>
  494. </el-dialog>
  495. <!-- 用户导入对话框 -->
  496. <el-dialog
  497. :title="upload.title"
  498. :visible.sync="upload.open"
  499. width="400px"
  500. append-to-body
  501. >
  502. <el-upload
  503. ref="upload"
  504. :limit="1"
  505. accept=".xlsx, .xls"
  506. :headers="upload.headers"
  507. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  508. :disabled="upload.isUploading"
  509. :on-progress="handleFileUploadProgress"
  510. :on-success="handleFileSuccess"
  511. :auto-upload="false"
  512. drag
  513. >
  514. <i class="el-icon-upload"></i>
  515. <div class="el-upload__text">
  516. 将文件拖到此处,或
  517. <em>点击上传</em>
  518. </div>
  519. <div class="el-upload__tip text-center" slot="tip">
  520. <div class="el-upload__tip" slot="tip">
  521. <el-checkbox
  522. v-model="upload.updateSupport"
  523. />是否更新已经存在的用户数据
  524. </div>
  525. <span>仅允许导入xls、xlsx格式文件。</span>
  526. <el-link
  527. type="primary"
  528. :underline="false"
  529. style="font-size: 12px; vertical-align: baseline"
  530. @click="importTemplate"
  531. >下载模板</el-link
  532. >
  533. </div>
  534. </el-upload>
  535. <div slot="footer" class="dialog-footer">
  536. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  537. <el-button @click="upload.open = false">取 消</el-button>
  538. </div>
  539. </el-dialog>
  540. </div>
  541. </template>
  542. <script>
  543. import {
  544. listUser,
  545. getUser,
  546. delUser,
  547. addUser,
  548. updateUser,
  549. exportUser,
  550. resetUserPwd,
  551. changeUserStatus,
  552. importTemplate,
  553. yhlist,
  554. getDept
  555. } from "@/api/system/user";
  556. import { getToken } from "@/utils/auth";
  557. import { treeselect } from "@/api/system/dept";
  558. import Treeselect from "@riophae/vue-treeselect";
  559. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  560. export default {
  561. name: "User",
  562. dicts: ["sys_normal_disable", "sys_user_sex"],
  563. components: { Treeselect },
  564. data() {
  565. return {
  566. // 遮罩层
  567. loading: true,
  568. // 导出遮罩层
  569. exportLoading: false,
  570. // 选中数组
  571. ids: [],
  572. // 非单个禁用
  573. single: true,
  574. // 非多个禁用
  575. multiple: true,
  576. // 显示搜索条件
  577. showSearch: true,
  578. // 总条数
  579. total: 0,
  580. // 用户表格数据
  581. userList: null,
  582. // 弹出层标题
  583. title: "",
  584. // 部门树选项
  585. deptOptions: undefined,
  586. // 是否显示弹出层
  587. open: false,
  588. // 部门名称
  589. deptName: undefined,
  590. // 默认密码
  591. initPassword: undefined,
  592. // 日期范围
  593. dateRange: [],
  594. // 岗位选项
  595. postOptions: [],
  596. // 角色选项
  597. roleOptions: [],
  598. // 表单参数
  599. form: {},
  600. defaultProps: {
  601. label: "label",
  602. children: "children"
  603. },
  604. // 用户导入参数
  605. upload: {
  606. // 是否显示弹出层(用户导入)
  607. open: false,
  608. // 弹出层标题(用户导入)
  609. title: "",
  610. // 是否禁用上传
  611. isUploading: false,
  612. // 是否更新已经存在的用户数据
  613. updateSupport: 0,
  614. // 设置上传的请求头部
  615. headers: { Authorization: "Bearer " + getToken() },
  616. // 上传的地址
  617. url: process.env.VUE_APP_BASE_API + "/system/user/importData"
  618. },
  619. // 查询参数
  620. queryParams: {
  621. pageNum: 1,
  622. pageSize: 10,
  623. userName: undefined,
  624. phonenumber: undefined,
  625. status: undefined,
  626. deptId: undefined,
  627. permissions: null
  628. },
  629. // 列信息
  630. columns: [
  631. { key: 0, label: `用户编号`, visible: true },
  632. { key: 1, label: `用户名称`, visible: true },
  633. { key: 2, label: `用户昵称`, visible: true },
  634. { key: 3, label: `部门`, visible: true },
  635. { key: 4, label: `手机号码`, visible: true },
  636. { key: 5, label: `状态`, visible: true },
  637. { key: 6, label: `创建时间`, visible: true }
  638. ],
  639. // 表单校验
  640. rules: {
  641. userName: [
  642. { required: true, message: "用户名称不能为空", trigger: "blur" },
  643. {
  644. min: 2,
  645. max: 20,
  646. message: "用户名称长度必须介于 2 和 20 之间",
  647. trigger: "blur"
  648. }
  649. ],
  650. nickName: [
  651. { required: true, message: "用户昵称不能为空", trigger: "change" }
  652. ],
  653. deptId: [
  654. { required: true, message: "归属部门不能为空", trigger: "change" }
  655. ],
  656. password: [
  657. { required: true, message: "用户密码不能为空", trigger: "blur" },
  658. {
  659. min: 5,
  660. max: 20,
  661. message: "用户密码长度必须介于 5 和 20 之间",
  662. trigger: "blur"
  663. }
  664. ],
  665. email: [
  666. {
  667. type: "email",
  668. message: "'请输入正确的邮箱地址",
  669. trigger: ["blur", "change"]
  670. }
  671. ],
  672. phonenumber: [
  673. {
  674. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  675. message: "请输入正确的手机号码",
  676. trigger: "blur"
  677. }
  678. ]
  679. },
  680. //用户昵称数组
  681. nickNamelist: [],
  682. //归属部门
  683. unitId: [],
  684. //权限
  685. permissionslist: []
  686. };
  687. },
  688. updated() {
  689. this.changeColor();
  690. },
  691. watch: {
  692. // 根据名称筛选部门树
  693. deptName(val) {
  694. this.$refs.tree.filter(val);
  695. }
  696. },
  697. created() {
  698. this.getList();
  699. this.getTreeselect();
  700. this.getConfigKey("sys.user.initPassword").then(response => {
  701. this.initPassword = response.msg;
  702. });
  703. //归属部门数据
  704. getDept().then(res => {
  705. if (res.code == 200) {
  706. this.unitId = res.data;
  707. }
  708. });
  709. //权限
  710. this.getDicts("sys_permissions").then(response => {
  711. console.log(response.data);
  712. this.permissionslist = response.data;
  713. });
  714. },
  715. methods: {
  716. /** 查询用户列表 */
  717. getList() {
  718. this.loading = true;
  719. listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
  720. response => {
  721. this.userList = response.rows;
  722. this.total = response.total;
  723. this.loading = false;
  724. }
  725. );
  726. },
  727. /** 查询部门下拉树结构 */
  728. getTreeselect() {
  729. treeselect().then(response => {
  730. this.deptOptions = response.data;
  731. });
  732. },
  733. // 筛选节点
  734. filterNode(value, data) {
  735. if (!value) return true;
  736. return data.label.indexOf(value) !== -1;
  737. },
  738. // 节点单击事件
  739. handleNodeClick(data) {
  740. this.queryParams.deptId = data.id;
  741. this.getList();
  742. },
  743. // 用户状态修改
  744. handleStatusChange(row) {
  745. let text = row.status === "0" ? "启用" : "停用";
  746. this.$modal
  747. .confirm('确认要"' + text + '""' + row.userName + '"用户吗?')
  748. .then(function() {
  749. return changeUserStatus(row.userId, row.status);
  750. })
  751. .then(() => {
  752. this.$modal.msgSuccess(text + "成功");
  753. })
  754. .catch(function() {
  755. row.status = row.status === "0" ? "1" : "0";
  756. });
  757. },
  758. // 取消按钮
  759. cancel() {
  760. this.open = false;
  761. this.reset();
  762. },
  763. // 表单重置
  764. reset() {
  765. this.form = {
  766. userId: undefined,
  767. deptId: undefined,
  768. userName: undefined,
  769. nickName: undefined,
  770. password: undefined,
  771. phonenumber: undefined,
  772. email: undefined,
  773. sex: undefined,
  774. status: "0",
  775. remark: undefined,
  776. postIds: [],
  777. roleIds: [],
  778. permissions: null
  779. };
  780. this.resetForm("form");
  781. },
  782. /** 搜索按钮操作 */
  783. handleQuery() {
  784. this.queryParams.pageNum = 1;
  785. this.getList();
  786. },
  787. /** 重置按钮操作 */
  788. resetQuery() {
  789. this.dateRange = [];
  790. this.resetForm("queryForm");
  791. this.handleQuery();
  792. },
  793. // 多选框选中数据
  794. handleSelectionChange(selection) {
  795. this.ids = selection.map(item => item.userId);
  796. this.single = selection.length != 1;
  797. this.multiple = !selection.length;
  798. },
  799. // 更多操作触发
  800. handleCommand(command, row) {
  801. switch (command) {
  802. case "handleResetPwd":
  803. this.handleResetPwd(row);
  804. break;
  805. case "handleAuthRole":
  806. this.handleAuthRole(row);
  807. break;
  808. default:
  809. break;
  810. }
  811. },
  812. /** 新增按钮操作 */
  813. handleAdd() {
  814. this.reset();
  815. this.getTreeselect();
  816. getUser().then(response => {
  817. this.postOptions = response.posts;
  818. this.roleOptions = response.roles;
  819. this.open = true;
  820. this.title = "添加用户";
  821. this.form.password = this.initPassword;
  822. });
  823. },
  824. /** 修改按钮操作 */
  825. handleUpdate(row) {
  826. this.reset();
  827. this.getTreeselect();
  828. const userId = row.userId || this.ids;
  829. getUser(userId).then(response => {
  830. this.form = response.data;
  831. // if(this.form.permissions){
  832. // this.form.permissions = this.form.permissions.split(",");
  833. // }
  834. this.deptIdClick();
  835. this.postOptions = response.posts;
  836. this.roleOptions = response.roles;
  837. this.form.postIds = response.postIds;
  838. this.form.roleIds = response.roleIds;
  839. this.open = true;
  840. this.title = "修改用户";
  841. this.form.password = "";
  842. });
  843. },
  844. /** 重置密码按钮操作 */
  845. handleResetPwd(row) {
  846. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  847. confirmButtonText: "确定",
  848. cancelButtonText: "取消",
  849. closeOnClickModal: false,
  850. inputPattern: /^.{5,20}$/,
  851. inputErrorMessage: "用户密码长度必须介于 5 和 20 之间"
  852. })
  853. .then(({ value }) => {
  854. resetUserPwd(row.userId, value).then(response => {
  855. this.$modal.msgSuccess("修改成功,新密码是:" + value);
  856. });
  857. })
  858. .catch(() => {});
  859. },
  860. /** 分配角色操作 */
  861. handleAuthRole: function(row) {
  862. const userId = row.userId;
  863. this.$router.push("/system/user-auth/role/" + userId);
  864. },
  865. /** 提交按钮 */
  866. submitForm: function() {
  867. this.$refs["form"].validate(valid => {
  868. if (valid) {
  869. // this.form.permissions = this.form.permissions.join(",");
  870. if (this.form.userId != undefined) {
  871. updateUser(this.form).then(response => {
  872. if (response.code == 200) {
  873. this.$modal.msgSuccess("修改成功");
  874. this.open = false;
  875. this.getList();
  876. }
  877. // else {
  878. // this.open=false;
  879. // }
  880. });
  881. } else {
  882. addUser(this.form).then(response => {
  883. if (response.code == 200) {
  884. this.$modal.msgSuccess("新增成功");
  885. this.open = false;
  886. this.getList();
  887. }
  888. // else {
  889. // this.open=false;
  890. // }
  891. });
  892. }
  893. }
  894. });
  895. },
  896. /** 删除按钮操作 */
  897. handleDelete(row) {
  898. const userIds = row.userId || this.ids;
  899. this.$modal
  900. .confirm('是否确认删除用户编号为"' + userIds + '"的数据项?')
  901. .then(function() {
  902. return delUser(userIds);
  903. })
  904. .then(() => {
  905. this.getList();
  906. this.$modal.msgSuccess("删除成功");
  907. })
  908. .catch(() => {});
  909. },
  910. /** 导出按钮操作 */
  911. handleExport() {
  912. const queryParams = this.queryParams;
  913. this.$modal
  914. .confirm("是否确认导出所有用户数据项?")
  915. .then(() => {
  916. this.exportLoading = true;
  917. return exportUser(queryParams);
  918. })
  919. .then(response => {
  920. this.$download.name(response.msg);
  921. this.exportLoading = false;
  922. })
  923. .catch(() => {});
  924. },
  925. /** 导入按钮操作 */
  926. handleImport() {
  927. this.upload.title = "用户导入";
  928. this.upload.open = true;
  929. },
  930. /** 下载模板操作 */
  931. importTemplate() {
  932. importTemplate().then(response => {
  933. this.$download.name(response.msg);
  934. });
  935. },
  936. // 文件上传中处理
  937. handleFileUploadProgress(event, file, fileList) {
  938. this.upload.isUploading = true;
  939. },
  940. // 文件上传成功处理
  941. handleFileSuccess(response, file, fileList) {
  942. this.upload.open = false;
  943. this.upload.isUploading = false;
  944. this.$refs.upload.clearFiles();
  945. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  946. this.getList();
  947. },
  948. // 提交上传文件
  949. submitFileForm() {
  950. this.$refs.upload.submit();
  951. },
  952. // 隔行变色
  953. changeColor() {
  954. var content = document.getElementsByClassName("el-tree-node__content");
  955. for (var i = 0; i < content.length; i++) {
  956. if (i % 2 === 0) {
  957. content[i].style.background = "#00365F ";
  958. } else {
  959. content[i].style.background = "#003C69";
  960. }
  961. }
  962. },
  963. //获取用户昵称数组
  964. deptIdClick() {
  965. yhlist(this.form.deptId).then(res => {
  966. if (res.code == 200) {
  967. this.nickNamelist = res.data;
  968. }
  969. });
  970. },
  971. //获取相关信息
  972. unitNamechange(val) {
  973. this.form.phonenumber = val.phone;
  974. this.form.sex = val.sex;
  975. this.form.nickName = val.name;
  976. }
  977. }
  978. };
  979. </script>
  980. <style scoped>
  981. ::v-deep .el-tree-node__content {
  982. color: #fff;
  983. height: 30px;
  984. text-align: center;
  985. }
  986. ::v-deep .el-tree-node__content:hover {
  987. background-color: #004d86 !important;
  988. }
  989. /* 对话框背景颜色 */
  990. ::v-deep .el-dialog {
  991. background: #004d86 !important;
  992. }
  993. ::v-deep .el-textarea__inner {
  994. width: 930px;
  995. height: 104px;
  996. margin: auto !important;
  997. }
  998. ::v-deep .el-dialog__header {
  999. border-bottom: 1px solid #718a9d;
  1000. }
  1001. ::v-deep .el-dialog__title {
  1002. color: #fff;
  1003. font: 18px;
  1004. }
  1005. ::v-deep .el-dialog__headerbtn .el-dialog__close {
  1006. color: #fff;
  1007. }
  1008. ::v-deep .el-form-item__label {
  1009. font: 16px;
  1010. color: #fff;
  1011. width: 100px !important;
  1012. }
  1013. ::v-deep .el-input__inner {
  1014. /* width: 200px !important;
  1015. height: 36px; */
  1016. background: transparent;
  1017. color: #fff;
  1018. }
  1019. /* 单位框背景颜色 */
  1020. ::v-deep .vue-treeselect__control {
  1021. background: #004d86 !important;
  1022. }
  1023. /* 基本信息背景 */
  1024. .jiben {
  1025. width: 952px;
  1026. height: 32px;
  1027. background-image: url(../../../images/小标题底.png);
  1028. margin-bottom: 25px;
  1029. color: #fff;
  1030. padding-left: 16px;
  1031. line-height: 32px;
  1032. }
  1033. /*调整表单间距 */
  1034. ::v-deep .el-form-item__content {
  1035. width: 200px;
  1036. }
  1037. .contents {
  1038. padding: 0px 40px !important;
  1039. }
  1040. /* 下拉菜单 */
  1041. .el-dropdown-link {
  1042. cursor: pointer;
  1043. color: #409eff;
  1044. }
  1045. .el-icon-arrow-down {
  1046. font-size: 12px;
  1047. }
  1048. /* 刷新图标 */
  1049. /* .el-icon-refresh {
  1050. width: 76px;
  1051. height: 36px;
  1052. color: #fff;
  1053. background-color: #1d96ff !important;
  1054. border-radius: 4px;
  1055. border: none;
  1056. margin-left: 20px;
  1057. font-size: 14px;
  1058. } */
  1059. /* 下拉菜单字体/背景颜色 */
  1060. .el-select-dropdown__item.hover,
  1061. .el-select-dropdown__item:hover {
  1062. background-color: #004d86;
  1063. color: #fff;
  1064. }
  1065. .el-select-dropdown__item {
  1066. color: #fff;
  1067. }
  1068. /* 时间选择 */
  1069. ::v-deep .el-input--small .el-input__inner {
  1070. width: 200px;
  1071. height: 36px;
  1072. line-height: 36px;
  1073. }
  1074. .el-date-editor.el-input {
  1075. width: 200px;
  1076. height: 36px;
  1077. line-height: 36px;
  1078. }
  1079. ::v-deep .el-date-editor.el-input .el-input__inner {
  1080. height: 36px;
  1081. line-height: 36px;
  1082. }
  1083. /* 单位框背景颜色 */
  1084. ::v-deep .vue-treeselect__control {
  1085. background: #004d86 !important;
  1086. color: #fff;
  1087. }
  1088. /* 单位下拉菜单选中字体颜色 */
  1089. ::v-deep .vue-treeselect__single-value {
  1090. color: #fff !important;
  1091. }
  1092. /* 分页按钮 */
  1093. ::v-deep .el-pagination.is-background .el-pager li {
  1094. background-color: #004d86;
  1095. color: #fff;
  1096. }
  1097. ::v-deep .el-pagination.is-background .btn-next {
  1098. background-color: #004d86;
  1099. color: #fff;
  1100. }
  1101. ::v-deep .el-pagination.is-background .btn-prev,
  1102. .el-pagination.is-background .btn-next,
  1103. .el-pagination.is-background .el-pager li {
  1104. background: #004d86 !important;
  1105. color: #fff !important;
  1106. }
  1107. /* 备注输入框 */
  1108. .textareas ::v-deep .el-form-item__content {
  1109. width: 100%;
  1110. }
  1111. /* 日期背景颜色 */
  1112. ::v-deep .el-date-editor .el-range-input {
  1113. background: #00365f;
  1114. }
  1115. /* 状态 */
  1116. .el-radio {
  1117. color: rgb(204, 198, 198);
  1118. }
  1119. </style>