user.vue 30 KB

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