index.vue 33 KB

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