user.vue 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. <template>
  2. <section class="content">
  3. <div class="box box-info">
  4. <div class="box-body">
  5. <!-- 搜索 -->
  6. <el-form inline :model="searchForm" label-width="70px">
  7. <el-form-item label="顶级机构">
  8. <el-select
  9. v-model="searchForm.rootOrgId"
  10. placeholder="请选择"
  11. :disabled="!isSuperAdmin"
  12. @change="rootOrgChanged4Search"
  13. class="input_width"
  14. >
  15. <el-option
  16. v-for="item in rootOrgList"
  17. :label="item.name"
  18. :value="item.id"
  19. :key="item.id"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="角色">
  24. <el-select
  25. clearable
  26. v-model="searchForm.roleId"
  27. placeholder="请选择"
  28. class="input_width"
  29. >
  30. <el-option
  31. v-for="item in roleList4Search"
  32. :label="item.roleName"
  33. :value="item.roleId"
  34. :key="item.roleId"
  35. />
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item label="登录名">
  39. <el-input
  40. placeholder="请输入登录名"
  41. v-model="searchForm.loginName"
  42. class="input_width"
  43. />
  44. </el-form-item>
  45. <el-form-item label="姓名">
  46. <el-input
  47. placeholder="请输入姓名"
  48. v-model="searchForm.name"
  49. class="input_width"
  50. />
  51. </el-form-item>
  52. <div></div>
  53. <el-form-item>
  54. <el-button
  55. size="small"
  56. type="primary"
  57. icon="el-icon-search"
  58. @click="handleSearchBtn"
  59. >
  60. 查询
  61. </el-button>
  62. <el-button
  63. size="small"
  64. icon="el-icon-refresh"
  65. @click="resetEcsFormSearch"
  66. >
  67. 重置
  68. </el-button>
  69. <el-button
  70. size="small"
  71. type="primary"
  72. icon="el-icon-plus"
  73. @click="openAddingDialog"
  74. >
  75. 新增
  76. </el-button>
  77. </el-form-item>
  78. </el-form>
  79. <div class="block-seperator"></div>
  80. <!-- 添加用户信息弹出框 -->
  81. <el-dialog title="新增用户" width="450px" :visible.sync="addingDialog">
  82. <el-form
  83. :inline="true"
  84. inline-message
  85. :model="userForm"
  86. ref="addingForm"
  87. :rules="rules"
  88. label-position="right"
  89. label-width="120px"
  90. >
  91. <el-row>
  92. <el-form-item label="姓名" prop="name">
  93. <el-input
  94. class="input_width_lg"
  95. v-model="userForm.name"
  96. auto-complete="off"
  97. placeholder="请输入姓名"
  98. />
  99. </el-form-item>
  100. </el-row>
  101. <el-row>
  102. <el-form-item label="登录名" prop="loginName">
  103. <el-input
  104. class="input_width_lg"
  105. v-model="userForm.loginName"
  106. auto-complete="off"
  107. placeholder="请输入登录名"
  108. />
  109. </el-form-item>
  110. </el-row>
  111. <el-row>
  112. <el-form-item label="密码" prop="password">
  113. <el-input
  114. class="input_width_lg"
  115. v-model="userForm.password"
  116. auto-complete="off"
  117. placeholder="请输入密码"
  118. />
  119. </el-form-item>
  120. </el-row>
  121. <el-row>
  122. <el-form-item label="联系方式" prop="mobile">
  123. <el-input
  124. class="input_width_lg"
  125. v-model="userForm.mobile"
  126. auto-complete="off"
  127. placeholder="请输入联系方式"
  128. />
  129. </el-form-item>
  130. </el-row>
  131. <el-row>
  132. <el-form-item label="顶级机构" prop="rootOrgId">
  133. <el-select
  134. class="input_width_lg"
  135. v-model="userForm.rootOrgId"
  136. placeholder="请选择"
  137. :disabled="!isSuperAdmin"
  138. @change="rootOrgChanged4InsertOrUpdate"
  139. >
  140. <el-option
  141. v-for="item in rootOrgList"
  142. :label="item.name"
  143. :value="item.id"
  144. :key="item.id"
  145. >
  146. </el-option>
  147. </el-select>
  148. </el-form-item>
  149. </el-row>
  150. <el-row>
  151. <el-form-item label="角色" prop="roleIds">
  152. <el-select
  153. class="input_width_lg"
  154. multiple
  155. v-model="userForm.roleIds"
  156. placeholder="请选择"
  157. @change="rolesChanged"
  158. >
  159. <el-option
  160. v-for="item in roleList4InsertOrUpdateWithoutSuperAdmin"
  161. :label="item.roleName"
  162. :value="item.roleId"
  163. :key="item.roleId"
  164. >
  165. </el-option>
  166. </el-select>
  167. </el-form-item>
  168. </el-row>
  169. <el-row>
  170. <el-form-item label="子机构" prop="orgId">
  171. <el-select
  172. class="input_width_lg"
  173. :remote-method="getOrgList4InsertOrUpdate"
  174. @focus="e => getOrgList4InsertOrUpdate(e.target.value)"
  175. :loading="orgLoading4InsertOrUpdate"
  176. remote
  177. filterable
  178. clearable
  179. v-model="userForm.orgId"
  180. placeholder="请选择"
  181. >
  182. <el-option
  183. v-for="item in orgList4InsertOrUpdate"
  184. :label="item.name"
  185. :value="item.id"
  186. :key="item.id"
  187. >
  188. </el-option>
  189. </el-select>
  190. </el-form-item>
  191. </el-row>
  192. <el-row>
  193. <el-form-item label="状态">
  194. <el-radio-group class="pull_right_sm" v-model="enableStr">
  195. <el-radio label="true">启用</el-radio>
  196. <el-radio label="false">禁用</el-radio>
  197. </el-radio-group>
  198. </el-form-item>
  199. </el-row>
  200. <el-row class="d-flex justify-content-center">
  201. <el-button type="primary" @click="add">保 存</el-button>
  202. <el-button @click="addingDialog = false">取 消</el-button>
  203. </el-row>
  204. </el-form>
  205. </el-dialog>
  206. <!-- 修改用户信息弹出框 -->
  207. <el-dialog title="编辑用户" width="450px" :visible.sync="updateDialog">
  208. <el-form
  209. :inline="true"
  210. :model="userForm"
  211. ref="updateForm"
  212. :rules="rules"
  213. label-position="right"
  214. label-width="120px"
  215. >
  216. <el-row>
  217. <el-form-item label="ID">
  218. <el-input
  219. class="input_width_lg"
  220. v-model="userForm.id"
  221. :disabled="true"
  222. />
  223. </el-form-item>
  224. </el-row>
  225. <el-row>
  226. <el-form-item label="姓名" prop="name">
  227. <el-input
  228. class="input_width_lg"
  229. v-model="userForm.name"
  230. auto-complete="off"
  231. placeholder="请输入姓名"
  232. />
  233. </el-form-item>
  234. </el-row>
  235. <el-row>
  236. <el-form-item label="登录名" prop="loginName">
  237. <el-input
  238. class="input_width_lg"
  239. v-model="userForm.loginName"
  240. auto-complete="off"
  241. placeholder="请输入登录名"
  242. />
  243. </el-form-item>
  244. </el-row>
  245. <el-row>
  246. <el-form-item label="联系方式" prop="mobile">
  247. <el-input
  248. class="input_width_lg"
  249. v-model="userForm.mobile"
  250. auto-complete="off"
  251. placeholder="请输入联系方式"
  252. />
  253. </el-form-item>
  254. </el-row>
  255. <el-row>
  256. <el-form-item label="顶级机构" prop="rootOrgId">
  257. <el-select
  258. class="input_width_lg"
  259. v-model="userForm.rootOrgId"
  260. placeholder="请选择"
  261. :disabled="true"
  262. >
  263. <el-option
  264. v-for="item in rootOrgList"
  265. :label="item.name"
  266. :value="item.id"
  267. :key="item.id"
  268. >
  269. </el-option>
  270. </el-select>
  271. </el-form-item>
  272. </el-row>
  273. <el-row>
  274. <el-form-item label="角色" prop="roleIds">
  275. <el-select
  276. class="input_width_lg"
  277. multiple
  278. v-model="userForm.roleIds"
  279. placeholder="请选择"
  280. :disabled="rowIsSuperAdmin"
  281. @change="rolesChanged"
  282. >
  283. <el-option
  284. v-for="item in roleList4InsertOrUpdate"
  285. :label="item.roleName"
  286. :disabled="item.roleCode == 'SUPER_ADMIN'"
  287. :value="item.roleId"
  288. :key="item.roleId"
  289. >
  290. </el-option>
  291. </el-select>
  292. </el-form-item>
  293. </el-row>
  294. <el-row>
  295. <el-form-item label="子机构" prop="orgId">
  296. <el-select
  297. class="input_width_lg"
  298. :remote-method="getOrgList4InsertOrUpdate"
  299. @focus="e => getOrgList4InsertOrUpdate(e.target.value)"
  300. :loading="orgLoading4InsertOrUpdate"
  301. remote
  302. filterable
  303. clearable
  304. v-model="userForm.orgId"
  305. placeholder="请选择"
  306. >
  307. <el-option
  308. v-for="item in orgList4InsertOrUpdate"
  309. :label="item.name"
  310. :value="item.id"
  311. :key="item.id"
  312. >
  313. </el-option>
  314. </el-select>
  315. </el-form-item>
  316. </el-row>
  317. <el-row>
  318. <el-form-item label="状态">
  319. <el-radio-group
  320. class="pull_right_sm"
  321. v-model="enableStr"
  322. :disabled="rowIsSuperAdmin"
  323. >
  324. <el-radio label="true">启用</el-radio>
  325. <el-radio label="false">禁用</el-radio>
  326. </el-radio-group>
  327. </el-form-item>
  328. </el-row>
  329. <el-row class="d-flex justify-content-center">
  330. <el-button type="primary" @click="update">保 存</el-button>
  331. <el-button @click="updateDialog = false">取 消</el-button>
  332. </el-row>
  333. </el-form>
  334. </el-dialog>
  335. <!-- 页面列表 -->
  336. <el-table
  337. :data="tableData"
  338. border
  339. resizable
  340. stripe
  341. style="width: 100%;"
  342. @selection-change="selectChange"
  343. >
  344. <el-table-column prop="id" width="80" label="ID" />
  345. <el-table-column prop="name" width="120" label="姓名" />
  346. <el-table-column prop="loginName" width="100" label="登录名" />
  347. <el-table-column prop="rootOrgName" label="顶级机构" />
  348. <!-- <el-table-column prop="roleNamesStr" width="110" label="角色" /> -->
  349. <el-table-column width="120" label="角色">
  350. <span
  351. slot-scope="scope"
  352. v-html="scope.row.roleNamesStr.replace(/,/g, '<br />')"
  353. >
  354. </span>
  355. </el-table-column>
  356. <el-table-column
  357. sortable
  358. prop="updateTime"
  359. width="160"
  360. label="更新时间"
  361. />
  362. <el-table-column width="50" label="状态">
  363. <span slot-scope="scope">
  364. <span v-if="scope.row.enable">
  365. <el-tooltip
  366. class="item"
  367. effect="dark"
  368. content="启用"
  369. placement="left"
  370. >
  371. <i class="el-icon-success" style="color:green;"></i>
  372. </el-tooltip>
  373. </span>
  374. <span v-else>
  375. <el-tooltip
  376. class="item"
  377. effect="dark"
  378. content="禁用"
  379. placement="left"
  380. >
  381. <i class="el-icon-error" style="color:red;"></i>
  382. </el-tooltip>
  383. </span>
  384. </span>
  385. </el-table-column>
  386. <el-table-column width="190" label="操作">
  387. <div slot-scope="scope">
  388. <el-button
  389. v-if="!scope.row.enable"
  390. size="mini"
  391. type="primary"
  392. plain
  393. @click="enableById(scope.row)"
  394. icon="el-icon-check"
  395. >
  396. 启用
  397. </el-button>
  398. <el-button
  399. v-if="scope.row.enable"
  400. size="mini"
  401. type="danger"
  402. @click="disableById(scope.row)"
  403. icon="el-icon-close"
  404. >
  405. 禁用
  406. </el-button>
  407. &nbsp;
  408. <el-dropdown>
  409. <el-button type="primary" plain size="mini">
  410. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  411. </el-button>
  412. <el-dropdown-menu slot="dropdown">
  413. <el-dropdown-item>
  414. <el-button
  415. size="mini"
  416. type="primary"
  417. plain
  418. @click="openUpdateDialog(scope.row)"
  419. icon="el-icon-edit"
  420. >编辑
  421. </el-button>
  422. </el-dropdown-item>
  423. <el-dropdown-item>
  424. <el-button
  425. v-if="false"
  426. size="mini"
  427. type="danger"
  428. @click="deleteById(scope.row)"
  429. icon="el-icon-delete"
  430. >删除
  431. </el-button>
  432. </el-dropdown-item>
  433. <el-dropdown-item>
  434. <el-button
  435. size="mini"
  436. type="danger"
  437. @click="resetPass(scope.row)"
  438. >
  439. <v-icon name="lock" scale="0.7" /> 重置密码
  440. </el-button>
  441. </el-dropdown-item>
  442. </el-dropdown-menu>
  443. </el-dropdown>
  444. </div>
  445. </el-table-column>
  446. </el-table>
  447. <div class="page pull-right">
  448. <el-pagination
  449. @current-change="handleCurrentChange"
  450. :current-page="currentPage"
  451. :page-size="10"
  452. :page-sizes="[10, 20, 50, 100]"
  453. @size-change="handleSizeChange"
  454. layout="total, sizes, prev, pager, next, jumper"
  455. :total="total"
  456. />
  457. </div>
  458. </div>
  459. </div>
  460. </section>
  461. </template>
  462. <script>
  463. import { CORE_API } from "@/constants/constants.js";
  464. import { mapState } from "vuex";
  465. export default {
  466. name: "User",
  467. data() {
  468. var validateRootOrg = (rule, value, callback) => {
  469. if (0 != value && !value) {
  470. callback(new Error("请选择顶级机构"));
  471. } else {
  472. callback();
  473. }
  474. };
  475. var validateRoles = (rule, value, callback) => {
  476. if (value.length == 0) {
  477. callback(new Error("请选择角色"));
  478. } else {
  479. callback();
  480. }
  481. };
  482. return {
  483. orgLoading4InsertOrUpdate: false,
  484. isSuperAdmin: false,
  485. roleList4Search: [],
  486. roleList4InsertOrUpdate: [],
  487. rootOrgList: [],
  488. orgList4InsertOrUpdate: [],
  489. searchForm: {
  490. name: "",
  491. loginName: "",
  492. enable: "",
  493. rootOrgId: "",
  494. roleId: ""
  495. },
  496. userForm: {
  497. id: null,
  498. name: "",
  499. loginName: "",
  500. password: "",
  501. mobile: "",
  502. enable: true,
  503. rootOrgId: null,
  504. orgId: null,
  505. roleIds: []
  506. },
  507. enableStr: "true",
  508. tempOrgList: [],
  509. userId: "",
  510. selectedUserIds: [],
  511. tableData: [],
  512. currentPage: 1,
  513. pageSize: 10,
  514. total: 10,
  515. addingDialog: false,
  516. updateDialog: false,
  517. rowIsSuperAdmin: false,
  518. rules: {
  519. name: [
  520. {
  521. required: true,
  522. message: "请输入姓名",
  523. trigger: "blur"
  524. }
  525. ],
  526. loginName: [
  527. {
  528. required: true,
  529. message: "请输入登录名",
  530. trigger: "blur"
  531. }
  532. ],
  533. password: [
  534. {
  535. required: true,
  536. message: "请输入密码",
  537. trigger: "blur"
  538. }
  539. ],
  540. mobile: [
  541. {
  542. message: "请输入联系方式",
  543. trigger: "blur"
  544. }
  545. ],
  546. rootOrgId: [
  547. {
  548. validator: validateRootOrg,
  549. trigger: "blur,change"
  550. }
  551. ],
  552. orgId: [],
  553. roleIds: [
  554. {
  555. validator: validateRoles,
  556. trigger: "blur,change"
  557. }
  558. ]
  559. }
  560. };
  561. },
  562. computed: {
  563. ...mapState({
  564. user: state => state.user
  565. }),
  566. userIds() {
  567. var userIds = "";
  568. for (let userId of this.selectedUserIds) {
  569. if (!userIds) {
  570. userIds += userId;
  571. } else {
  572. userIds += "," + userId;
  573. }
  574. }
  575. return userIds;
  576. },
  577. roleList4InsertOrUpdateWithoutSuperAdmin() {
  578. return this.roleList4InsertOrUpdate.filter(
  579. item => item.roleCode != "SUPER_ADMIN"
  580. );
  581. }
  582. },
  583. methods: {
  584. resetEcsFormSearch() {
  585. this.searchForm = Object.assign(this.searchForm, {
  586. roleId: "",
  587. loginName: "",
  588. name: ""
  589. });
  590. },
  591. handleSizeChange(val) {
  592. this.currentPage = 1;
  593. this.pageSize = val;
  594. this.search();
  595. },
  596. validateOrg(rule, value, callback) {
  597. if (0 != value && !value) {
  598. callback(new Error("请选择子机构"));
  599. } else {
  600. callback();
  601. }
  602. },
  603. rolesChanged() {
  604. var isLC = false;
  605. for (let cur of this.roleList4InsertOrUpdate) {
  606. if (
  607. cur.roleCode == "LC_USER" &&
  608. this.userForm.roleIds.includes(cur.roleId)
  609. ) {
  610. isLC = true;
  611. break;
  612. }
  613. }
  614. console.log("rolesChanged(); isLC:", isLC);
  615. if (isLC) {
  616. this.rules.orgId = [
  617. {
  618. validator: this.validateOrg,
  619. trigger: "blur,change"
  620. }
  621. ];
  622. } else {
  623. this.rules.orgId = [];
  624. }
  625. },
  626. rootOrgChanged4Search() {
  627. var url =
  628. CORE_API +
  629. "/rolePrivilege/getRoles?includeSuperAdmin=" +
  630. true +
  631. "&rootOrgId=" +
  632. this.searchForm.rootOrgId;
  633. this.$httpWithMsg.post(url).then(response => {
  634. this.roleList4Search = response.data;
  635. });
  636. },
  637. rootOrgChanged4InsertOrUpdate() {
  638. this.orgList4InsertOrUpdate = [];
  639. var url =
  640. CORE_API +
  641. "/rolePrivilege/getRoles?includeSuperAdmin=" +
  642. true +
  643. "&rootOrgId=" +
  644. this.userForm.rootOrgId;
  645. this.$httpWithMsg.post(url).then(response => {
  646. this.roleList4InsertOrUpdate = response.data;
  647. this.rolesChanged();
  648. });
  649. },
  650. getOrgList4InsertOrUpdate(query) {
  651. this.orgLoading4InsertOrUpdate = true;
  652. var url =
  653. CORE_API +
  654. "/org/query?" +
  655. new URLSearchParams({
  656. name: query,
  657. rootOrgId: this.userForm.rootOrgId
  658. });
  659. this.$httpWithMsg
  660. .get(url)
  661. .then(response => {
  662. this.orgList4InsertOrUpdate = response.data;
  663. this.orgLoading4InsertOrUpdate = false;
  664. })
  665. .catch(() => {
  666. this.orgLoading4InsertOrUpdate = false;
  667. });
  668. },
  669. getTag(status) {
  670. if (status == true) {
  671. return "success";
  672. } else if (status == false) {
  673. return "danger";
  674. }
  675. return status;
  676. },
  677. getLevel(level) {
  678. if (level == "ZSB") {
  679. return "专升本";
  680. } else if (level == "GQZ") {
  681. return "高起专";
  682. }
  683. return level;
  684. },
  685. handleSearchBtn() {
  686. this.currentPage = 1;
  687. this.search();
  688. },
  689. search() {
  690. this.loading = true;
  691. var param = new URLSearchParams(this.searchForm);
  692. var url =
  693. CORE_API +
  694. "/user/all/" +
  695. this.currentPage +
  696. "/" +
  697. this.pageSize +
  698. "?" +
  699. param;
  700. this.$httpWithMsg.get(url).then(response => {
  701. console.log(response);
  702. this.tableData = response.data.list;
  703. this.total = response.data.total;
  704. this.loading = false;
  705. });
  706. },
  707. handleCurrentChange(val) {
  708. this.currentPage = val;
  709. this.search();
  710. },
  711. selectChange(row) {
  712. this.selectedUserIds = [];
  713. row.forEach(element => {
  714. this.selectedUserIds.push(element.id);
  715. });
  716. console.log(this.selectedUserIds);
  717. },
  718. //新增
  719. openAddingDialog() {
  720. if (this.$refs.addingForm) {
  721. this.$refs.addingForm.resetFields();
  722. }
  723. if (this.$refs.updateForm) {
  724. this.$refs.updateForm.resetFields();
  725. }
  726. this.addingDialog = true;
  727. this.userForm.name = "";
  728. this.userForm.loginName = "";
  729. this.userForm.password = "";
  730. this.userForm.mobile = "";
  731. this.userForm.roleIds = [];
  732. this.userForm.orgId = null;
  733. this.enableStr = "true";
  734. this.orgList4InsertOrUpdate = [];
  735. this.rolesChanged();
  736. },
  737. //修改
  738. openUpdateDialog(row) {
  739. if (this.$refs.updateForm) {
  740. this.$refs.updateForm.resetFields();
  741. }
  742. if (this.$refs.addingForm) {
  743. this.$refs.addingForm.resetFields();
  744. }
  745. this.updateDialog = true;
  746. this.userForm.id = row.id;
  747. this.userForm.roleIds = row.roleIds;
  748. this.userForm.name = row.name;
  749. this.userForm.loginName = row.loginName;
  750. this.enableStr = row.enable ? "true" : "false";
  751. this.userForm.mobile = row.mobile;
  752. this.userForm.password = null;
  753. this.userForm.rootOrgId = row.rootOrgId;
  754. this.rowIsSuperAdmin = false;
  755. for (let roleCode of row.roleCodes) {
  756. if (roleCode == "SUPER_ADMIN") {
  757. this.rowIsSuperAdmin = true;
  758. break;
  759. }
  760. }
  761. this.rootOrgChanged4InsertOrUpdate();
  762. this.orgList4InsertOrUpdate = [{ id: row.orgId, name: row.orgName }];
  763. this.userForm.orgId = row.orgId;
  764. },
  765. exportUser() {
  766. var param = new URLSearchParams(this.searchForm);
  767. window.open(CORE_API + "/user/export?" + param);
  768. },
  769. //保存
  770. add() {
  771. var url = CORE_API + "/user";
  772. this.$refs.addingForm.validate(valid => {
  773. if (valid) {
  774. this.userForm.enable = this.enableStr == "true";
  775. this.$httpWithMsg.post(url, this.userForm).then(() => {
  776. this.$notify({
  777. type: "success",
  778. message: "添加成功"
  779. });
  780. this.search();
  781. this.addingDialog = false;
  782. });
  783. } else {
  784. return false;
  785. }
  786. });
  787. },
  788. //保存
  789. update() {
  790. var url = CORE_API + "/user";
  791. this.$refs.updateForm.validate(valid => {
  792. if (valid) {
  793. this.userForm.enable = this.enableStr == "true";
  794. this.$httpWithMsg.put(url, this.userForm).then(() => {
  795. this.$notify({
  796. type: "success",
  797. message: "添加成功"
  798. });
  799. this.search();
  800. this.updateDialog = false;
  801. });
  802. } else {
  803. return false;
  804. }
  805. });
  806. },
  807. //重置密码
  808. resetPass(row) {
  809. this.$confirm("是否重置密码?", "提示", {
  810. confirmButtonText: "确定",
  811. cancelButtonText: "取消",
  812. type: "warning"
  813. })
  814. .then(() => {
  815. var url = CORE_API + "/user/resetPass/" + row.id;
  816. this.$httpWithMsg.put(url).then(() => {
  817. this.$notify({
  818. type: "success",
  819. message: "重置成功!"
  820. });
  821. return this.search();
  822. });
  823. })
  824. .catch(e => console.log(e));
  825. },
  826. //删除单个数据
  827. deleteById(row) {
  828. this.$confirm("是否删除该用户?", "提示", {
  829. confirmButtonText: "确定",
  830. cancelButtonText: "取消",
  831. type: "warning"
  832. }).then(() => {
  833. var url = CORE_API + "/user/" + row.id;
  834. this.$httpWithMsg.delete(url).then(() => {
  835. this.$notify({
  836. type: "success",
  837. message: "删除成功!"
  838. });
  839. return this.search();
  840. });
  841. });
  842. },
  843. //删除多条数据
  844. deleteByIds() {
  845. if (this.selectedUserIds.length === 0) {
  846. this.$notify({
  847. type: "warning",
  848. message: "请选择要删除的用户"
  849. });
  850. } else {
  851. this.$confirm("是否删除这些用户?", "提示", {
  852. confirmButtonText: "确定",
  853. cancelButtonText: "取消",
  854. type: "error"
  855. }).then(() => {
  856. var url = CORE_API + "/user/" + this.userIds;
  857. this.$httpWithMsg.delete(url).then(() => {
  858. this.$notify({
  859. type: "success",
  860. message: "删除成功!"
  861. });
  862. this.search();
  863. });
  864. });
  865. }
  866. },
  867. //启用
  868. enableByIds() {
  869. if (this.selectedUserIds.length === 0) {
  870. this.$notify({
  871. type: "warning",
  872. message: "请选择要开启的用户"
  873. });
  874. } else {
  875. this.$confirm("是否启用这些用户?", "提示", {
  876. confirmButtonText: "确定",
  877. cancelButtonText: "取消",
  878. type: "warning"
  879. }).then(() => {
  880. var url = CORE_API + "/user/enable/" + this.userIds;
  881. this.$httpWithMsg.put(url, {}).then(() => {
  882. this.$notify({
  883. type: "success",
  884. message: "开启成功!"
  885. });
  886. return this.search();
  887. });
  888. });
  889. }
  890. },
  891. enableById(row) {
  892. this.$confirm("是否启用该用户?", "提示", {
  893. confirmButtonText: "确定",
  894. cancelButtonText: "取消",
  895. type: "warning"
  896. }).then(() => {
  897. var url = CORE_API + "/user/enable/" + row.id;
  898. this.$httpWithMsg.put(url, {}).then(() => {
  899. this.$notify({
  900. type: "success",
  901. message: "开启成功!"
  902. });
  903. this.search();
  904. });
  905. });
  906. },
  907. //禁用
  908. disableByIds() {
  909. if (this.selectedUserIds.length === 0) {
  910. this.$notify({
  911. type: "warning",
  912. message: "请选择要禁用的用户"
  913. });
  914. } else {
  915. this.$confirm("是否禁用这些用户?", "提示", {
  916. confirmButtonText: "确定",
  917. cancelButtonText: "取消",
  918. type: "error"
  919. }).then(() => {
  920. var url = CORE_API + "/user/disable/" + this.userIds;
  921. this.$httpWithMsg.put(url, {}).then(() => {
  922. this.$notify({
  923. type: "success",
  924. message: "禁用成功!"
  925. });
  926. this.search();
  927. });
  928. });
  929. }
  930. },
  931. //禁用
  932. disableById(row) {
  933. this.$confirm("是否禁用该用户?", "提示", {
  934. confirmButtonText: "确定",
  935. cancelButtonText: "取消",
  936. type: "error"
  937. }).then(() => {
  938. var url = CORE_API + "/user/disable/" + row.id;
  939. this.$httpWithMsg.put(url, {}).then(() => {
  940. this.$notify({
  941. type: "success",
  942. message: "禁用成功!"
  943. });
  944. this.search();
  945. });
  946. });
  947. },
  948. /*初始化*/
  949. init() {
  950. for (let role of this.user.roleList) {
  951. if (role.roleCode == "SUPER_ADMIN") {
  952. this.isSuperAdmin = true;
  953. break;
  954. }
  955. }
  956. this.searchForm.rootOrgId = this.user.rootOrgId;
  957. this.userForm.rootOrgId = this.user.rootOrgId;
  958. var url1 = CORE_API + "/org/getRootOrgList";
  959. var url2 =
  960. CORE_API +
  961. "/rolePrivilege/getRoles?includeSuperAdmin=true&rootOrgId=" +
  962. this.user.rootOrgId;
  963. Promise.all([
  964. this.$httpWithMsg.get(url1),
  965. this.$httpWithMsg.post(url2)
  966. ]).then(([resp1, resp2]) => {
  967. this.rootOrgList = resp1.data;
  968. this.roleList4Search = resp2.data;
  969. this.roleList4InsertOrUpdate = resp2.data;
  970. this.search();
  971. });
  972. }
  973. },
  974. //初始化查询
  975. created() {
  976. this.init();
  977. }
  978. };
  979. </script>
  980. <style scoped>
  981. .page {
  982. margin-top: 10px;
  983. }
  984. .input_width_lg {
  985. width: 180px;
  986. }
  987. .input_width {
  988. width: 150px;
  989. }
  990. </style>