index.vue 31 KB

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