index.vue 35 KB

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