index.vue 33 KB

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