user.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. <template>
  2. <el-row>
  3. <el-col :span="5">
  4. <div class="box">
  5. <el-scrollbar>
  6. <basic-container>
  7. <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick"/>
  8. </basic-container>
  9. </el-scrollbar>
  10. </div>
  11. </el-col>
  12. <el-col :span="19">
  13. <basic-container>
  14. <avue-crud :option="option"
  15. :search.sync="search"
  16. :table-loading="loading"
  17. :data="data"
  18. ref="crud"
  19. v-model="form"
  20. :permission="permissionList"
  21. @row-del="rowDel"
  22. @row-update="rowUpdate"
  23. @row-save="rowSave"
  24. :before-open="beforeOpen"
  25. :page.sync="page"
  26. @search-change="searchChange"
  27. @search-reset="searchReset"
  28. @selection-change="selectionChange"
  29. @current-change="currentChange"
  30. @size-change="sizeChange"
  31. @refresh-change="refreshChange"
  32. @on-load="onLoad">
  33. <template slot="menuLeft">
  34. <el-button type="danger"
  35. size="small"
  36. plain
  37. icon="el-icon-delete"
  38. v-if="permission.user_delete"
  39. @click="handleDelete">删 除
  40. </el-button>
  41. <el-button type="info"
  42. size="small"
  43. plain
  44. v-if="permission.user_role"
  45. icon="el-icon-user"
  46. @click="handleGrant">角色配置
  47. </el-button>
  48. <el-button type="info"
  49. size="small"
  50. plain
  51. v-if="permission.user_reset"
  52. icon="el-icon-refresh"
  53. @click="handleReset">密码重置
  54. </el-button>
  55. <el-button type="info"
  56. size="small"
  57. plain
  58. v-if="userInfo.role_name.includes('admin')"
  59. icon="el-icon-setting"
  60. @click="handlePlatform">平台配置
  61. </el-button>
  62. <el-button type="success"
  63. size="small"
  64. plain
  65. v-if="userInfo.role_name.includes('admin')"
  66. icon="el-icon-upload2"
  67. @click="handleImport">导入
  68. </el-button>
  69. <el-button type="warning"
  70. size="small"
  71. plain
  72. v-if="userInfo.role_name.includes('admin')"
  73. icon="el-icon-download"
  74. @click="handleExport">导出
  75. </el-button>
  76. </template>
  77. <template slot-scope="{row}"
  78. slot="tenantName">
  79. <el-tag>{{row.tenantName}}</el-tag>
  80. </template>
  81. <template slot-scope="{row}"
  82. slot="roleName">
  83. <el-tag>{{row.roleName}}</el-tag>
  84. </template>
  85. <template slot-scope="{row}"
  86. slot="deptName">
  87. <el-tag>{{row.deptName}}</el-tag>
  88. </template>
  89. <template slot-scope="{row}"
  90. slot="userTypeName">
  91. <el-tag>{{row.userTypeName}}</el-tag>
  92. </template>
  93. </avue-crud>
  94. <el-dialog title="用户角色配置"
  95. append-to-body
  96. :visible.sync="roleBox"
  97. width="345px">
  98. <el-tree :data="roleGrantList"
  99. show-checkbox
  100. check-strictly
  101. default-expand-all
  102. node-key="id"
  103. ref="treeRole"
  104. :default-checked-keys="roleTreeObj"
  105. :props="props">
  106. </el-tree>
  107. <span slot="footer" class="dialog-footer">
  108. <el-button @click="roleBox = false">取 消</el-button>
  109. <el-button type="primary"
  110. @click="submitRole">确 定</el-button>
  111. </span>
  112. </el-dialog>
  113. <el-dialog title="用户数据导入"
  114. append-to-body
  115. :visible.sync="excelBox"
  116. width="555px">
  117. <avue-form :option="excelOption" v-model="excelForm" :upload-after="uploadAfter">
  118. <template slot="excelTemplate">
  119. <el-button type="primary" @click="handleTemplate">
  120. 点击下载<i class="el-icon-download el-icon--right"></i>
  121. </el-button>
  122. </template>
  123. </avue-form>
  124. </el-dialog>
  125. <el-dialog title="用户平台配置"
  126. append-to-body
  127. :visible.sync="platformBox">
  128. <avue-crud :option="platformOption"
  129. :table-loading="platformLoading"
  130. :data="platformData"
  131. ref="platformCrud"
  132. v-model="platformForm"
  133. :before-open="platformBeforeOpen"
  134. :page.sync="platformPage"
  135. :permission="platformPermissionList"
  136. @row-update="platformRowUpdate"
  137. @search-change="platformSearchChange"
  138. @search-reset="platformSearchReset"
  139. @selection-change="platformSelectionChange"
  140. @current-change="platformCurrentChange"
  141. @size-change="platformSizeChange"
  142. @refresh-change="platformRefreshChange"
  143. @on-load="platformOnLoad">
  144. <template slot-scope="{row}"
  145. slot="tenantName">
  146. <el-tag>{{row.tenantName}}</el-tag>
  147. </template>
  148. <template slot-scope="{row}"
  149. slot="userTypeName">
  150. <el-tag>{{row.userTypeName}}</el-tag>
  151. </template>
  152. </avue-crud>
  153. </el-dialog>
  154. </basic-container>
  155. </el-col>
  156. </el-row>
  157. </template>
  158. <script>
  159. import {
  160. getList,
  161. getUser,
  162. getUserPlatform,
  163. remove,
  164. update,
  165. updatePlatform,
  166. add,
  167. grant,
  168. resetPassword
  169. } from "@/api/system/user";
  170. import {getDeptTree, getDeptLazyTree} from "@/api/system/dept";
  171. import {getRoleTree} from "@/api/system/role";
  172. import {getPostList} from "@/api/system/post";
  173. import {mapGetters} from "vuex";
  174. import website from '@/config/website';
  175. import {getToken} from '@/util/auth';
  176. export default {
  177. data() {
  178. const validatePass = (rule, value, callback) => {
  179. if (value === '') {
  180. callback(new Error('请输入密码'));
  181. } else {
  182. callback();
  183. }
  184. };
  185. const validatePass2 = (rule, value, callback) => {
  186. if (value === '') {
  187. callback(new Error('请再次输入密码'));
  188. } else if (value !== this.form.password) {
  189. callback(new Error('两次输入密码不一致!'));
  190. } else {
  191. callback();
  192. }
  193. };
  194. return {
  195. form: {},
  196. search:{},
  197. roleBox: false,
  198. excelBox: false,
  199. platformBox: false,
  200. initFlag: true,
  201. selectionList: [],
  202. query: {},
  203. loading: true,
  204. platformLoading: false,
  205. page: {
  206. pageSize: 10,
  207. currentPage: 1,
  208. total: 0
  209. },
  210. platformPage: {
  211. pageSize: 10,
  212. currentPage: 1,
  213. total: 0
  214. },
  215. init: {
  216. roleTree: [],
  217. deptTree: [],
  218. },
  219. props: {
  220. label: "title",
  221. value: "key"
  222. },
  223. roleGrantList: [],
  224. roleTreeObj: [],
  225. treeDeptId: '',
  226. treeData: [],
  227. treeOption: {
  228. nodeKey: 'id',
  229. lazy: true,
  230. treeLoad: function (node, resolve) {
  231. const parentId = (node.level === 0) ? 0 : node.data.id;
  232. getDeptLazyTree(parentId).then(res => {
  233. resolve(res.data.data.map(item => {
  234. return {
  235. ...item,
  236. leaf: !item.hasChildren
  237. }
  238. }))
  239. });
  240. },
  241. addBtn: false,
  242. menu: false,
  243. size: 'small',
  244. props: {
  245. labelText: '标题',
  246. label: 'title',
  247. value: 'value',
  248. children: 'children'
  249. }
  250. },
  251. option: {
  252. height: 'auto',
  253. calcHeight: 80,
  254. tip: false,
  255. searchShow: true,
  256. searchMenuSpan: 6,
  257. border: true,
  258. index: true,
  259. selection: true,
  260. viewBtn: true,
  261. //dialogType: 'drawer',
  262. dialogClickModal: false,
  263. column: [
  264. {
  265. label: "登录账号",
  266. prop: "account",
  267. search: true,
  268. display: false
  269. },
  270. {
  271. label: "所属租户",
  272. prop: "tenantName",
  273. slot: true,
  274. display: false
  275. },
  276. {
  277. label: "用户姓名",
  278. prop: "realName",
  279. search: true,
  280. display: false
  281. },
  282. {
  283. label: "所属角色",
  284. prop: "roleName",
  285. slot: true,
  286. display: false
  287. },
  288. {
  289. label: "所属部门",
  290. prop: "deptName",
  291. slot: true,
  292. display: false
  293. },
  294. {
  295. label: "用户平台",
  296. prop: "userTypeName",
  297. slot: true,
  298. display: false
  299. },
  300. {
  301. label: "用户平台",
  302. type: "select",
  303. dicUrl: "/api/blade-system/dict/dictionary?code=user_type",
  304. props: {
  305. label: "dictValue",
  306. value: "dictKey"
  307. },
  308. dataType: "number",
  309. search: true,
  310. hide: true,
  311. display: false,
  312. prop: "userType",
  313. rules: [{
  314. required: true,
  315. message: "请选择用户平台",
  316. trigger: "blur"
  317. }]
  318. },
  319. ],
  320. group: [
  321. {
  322. label: '基础信息',
  323. prop: 'baseInfo',
  324. icon: 'el-icon-user-solid',
  325. column: [
  326. {
  327. label: "所属租户",
  328. prop: "tenantId",
  329. type: "tree",
  330. dicUrl: "/api/blade-system/tenant/select",
  331. props: {
  332. label: "tenantName",
  333. value: "tenantId"
  334. },
  335. hide: !website.tenantMode,
  336. addDisplay: website.tenantMode,
  337. editDisplay: website.tenantMode,
  338. viewDisplay: website.tenantMode,
  339. rules: [{
  340. required: true,
  341. message: "请输入所属租户",
  342. trigger: "click"
  343. }],
  344. span: 24,
  345. },
  346. {
  347. label: "登录账号",
  348. prop: "account",
  349. rules: [{
  350. required: true,
  351. message: "请输入登录账号",
  352. trigger: "blur"
  353. }],
  354. },
  355. {
  356. label: "用户平台",
  357. type: "select",
  358. dicUrl: "/api/blade-system/dict/dictionary?code=user_type",
  359. props: {
  360. label: "dictValue",
  361. value: "dictKey"
  362. },
  363. dataType: "number",
  364. slot: true,
  365. prop: "userType",
  366. rules: [{
  367. required: true,
  368. message: "请选择用户平台",
  369. trigger: "blur"
  370. }]
  371. },
  372. {
  373. label: '密码',
  374. prop: 'password',
  375. hide: true,
  376. editDisplay: false,
  377. viewDisplay: false,
  378. rules: [{required: true, validator: validatePass, trigger: 'blur'}]
  379. },
  380. {
  381. label: '确认密码',
  382. prop: 'password2',
  383. hide: true,
  384. editDisplay: false,
  385. viewDisplay: false,
  386. rules: [{required: true, validator: validatePass2, trigger: 'blur'}]
  387. },
  388. ]
  389. },
  390. {
  391. label: '详细信息',
  392. prop: 'detailInfo',
  393. icon: 'el-icon-s-order',
  394. column: [
  395. {
  396. label: "用户昵称",
  397. prop: "name",
  398. hide: true,
  399. rules: [{
  400. required: true,
  401. message: "请输入用户昵称",
  402. trigger: "blur"
  403. }]
  404. },
  405. {
  406. label: "用户姓名",
  407. prop: "realName",
  408. rules: [{
  409. required: true,
  410. message: "请输入用户姓名",
  411. trigger: "blur"
  412. }, {
  413. min: 2,
  414. max: 20,
  415. message: '姓名长度在2到20个字符'
  416. }]
  417. },
  418. {
  419. label: "手机号码",
  420. prop: "phone",
  421. overHidden: true
  422. },
  423. {
  424. label: "电子邮箱",
  425. prop: "email",
  426. hide: true,
  427. overHidden: true
  428. },
  429. {
  430. label: "用户性别",
  431. prop: "sex",
  432. type: "select",
  433. dicData: [
  434. {
  435. label: "男",
  436. value: 1
  437. },
  438. {
  439. label: "女",
  440. value: 2
  441. },
  442. {
  443. label: "未知",
  444. value: 3
  445. }
  446. ],
  447. hide: true
  448. },
  449. {
  450. label: "用户生日",
  451. type: "date",
  452. prop: "birthday",
  453. format: "yyyy-MM-dd hh:mm:ss",
  454. valueFormat: "yyyy-MM-dd hh:mm:ss",
  455. hide: true
  456. },
  457. {
  458. label: "账号状态",
  459. prop: "statusName",
  460. hide: true,
  461. display: false
  462. }
  463. ]
  464. },
  465. {
  466. label: '职责信息',
  467. prop: 'dutyInfo',
  468. icon: 'el-icon-s-custom',
  469. column: [
  470. {
  471. label: "用户编号",
  472. prop: "code",
  473. },
  474. {
  475. label: "所属角色",
  476. prop: "roleId",
  477. multiple: true,
  478. type: "tree",
  479. dicData: [],
  480. props: {
  481. label: "title"
  482. },
  483. checkStrictly: true,
  484. slot: true,
  485. rules: [{
  486. required: true,
  487. message: "请选择所属角色",
  488. trigger: "click"
  489. }]
  490. },
  491. {
  492. label: "所属部门",
  493. prop: "deptId",
  494. type: "tree",
  495. multiple: true,
  496. dicData: [],
  497. props: {
  498. label: "title"
  499. },
  500. checkStrictly: true,
  501. slot: true,
  502. rules: [{
  503. required: true,
  504. message: "请选择所属部门",
  505. trigger: "click"
  506. }]
  507. },
  508. {
  509. label: "所属岗位",
  510. prop: "postId",
  511. type: "tree",
  512. multiple: true,
  513. dicData: [],
  514. props: {
  515. label: "postName",
  516. value: "id"
  517. },
  518. rules: [{
  519. required: true,
  520. message: "请选择所属岗位",
  521. trigger: "click"
  522. }],
  523. },
  524. ]
  525. },
  526. ]
  527. },
  528. data: [],
  529. platformQuery: {},
  530. platformSelectionList: [],
  531. platformData: [],
  532. platformForm: {},
  533. platformOption: {
  534. tip: false,
  535. searchShow: true,
  536. searchMenuSpan: 6,
  537. border: true,
  538. index: true,
  539. selection: true,
  540. viewBtn: true,
  541. dialogClickModal: false,
  542. menuWidth: 120,
  543. editBtnText: '配置',
  544. column: [
  545. {
  546. label: "登录账号",
  547. prop: "account",
  548. search: true,
  549. display: false
  550. },
  551. {
  552. label: "所属租户",
  553. prop: "tenantName",
  554. slot: true,
  555. display: false
  556. },
  557. {
  558. label: "用户姓名",
  559. prop: "realName",
  560. search: true,
  561. display: false
  562. },
  563. {
  564. label: "用户平台",
  565. prop: "userTypeName",
  566. slot: true,
  567. display: false
  568. },
  569. {
  570. label: "用户平台",
  571. type: "select",
  572. dicUrl: "/api/blade-system/dict/dictionary?code=user_type",
  573. props: {
  574. label: "dictValue",
  575. value: "dictKey"
  576. },
  577. dataType: "number",
  578. search: true,
  579. hide: true,
  580. display: false,
  581. prop: "userType",
  582. rules: [{
  583. required: true,
  584. message: "请选择用户平台",
  585. trigger: "blur"
  586. }]
  587. },
  588. {
  589. label: "用户拓展",
  590. prop: "userExt",
  591. type: "textarea",
  592. minRows: 8,
  593. span: 24,
  594. overHidden: true,
  595. row: true,
  596. hide: true,
  597. },
  598. ],
  599. },
  600. excelForm: {},
  601. excelOption: {
  602. submitBtn: false,
  603. emptyBtn: false,
  604. column: [
  605. {
  606. label: '模板上传',
  607. prop: 'excelFile',
  608. type: 'upload',
  609. drag: true,
  610. loadText: '模板上传中,请稍等',
  611. span: 24,
  612. propsHttp: {
  613. res: 'data'
  614. },
  615. tip: '请上传 .xls,.xlsx 标准格式文件',
  616. action: "/api/blade-user/import-user"
  617. },
  618. {
  619. label: "数据覆盖",
  620. prop: "isCovered",
  621. type: "switch",
  622. align: "center",
  623. width: 80,
  624. dicData: [
  625. {
  626. label: "否",
  627. value: 0
  628. },
  629. {
  630. label: "是",
  631. value: 1
  632. }
  633. ],
  634. value: 0,
  635. slot: true,
  636. rules: [
  637. {
  638. required: true,
  639. message: "请选择是否覆盖",
  640. trigger: "blur"
  641. }
  642. ]
  643. },
  644. {
  645. label: '模板下载',
  646. prop: 'excelTemplate',
  647. formslot: true,
  648. span: 24,
  649. }
  650. ]
  651. }
  652. };
  653. },
  654. watch: {
  655. 'form.tenantId'() {
  656. if (this.form.tenantId !== '' && this.initFlag) {
  657. this.initData(this.form.tenantId);
  658. }
  659. },
  660. 'excelForm.isCovered'() {
  661. if (this.excelForm.isCovered !== '') {
  662. const column = this.findObject(this.excelOption.column, "excelFile");
  663. column.action = `/api/blade-user/import-user?isCovered=${this.excelForm.isCovered}`;
  664. }
  665. }
  666. },
  667. computed: {
  668. ...mapGetters(["userInfo", "permission"]),
  669. permissionList() {
  670. return {
  671. addBtn: this.vaildData(this.permission.user_add, false),
  672. viewBtn: this.vaildData(this.permission.user_view, false),
  673. delBtn: this.vaildData(this.permission.user_delete, false),
  674. editBtn: this.vaildData(this.permission.user_edit, false)
  675. };
  676. },
  677. platformPermissionList() {
  678. return {
  679. addBtn: false,
  680. viewBtn: false,
  681. delBtn: false,
  682. editBtn: this.vaildData(this.permission.user_edit, false)
  683. };
  684. },
  685. ids() {
  686. let ids = [];
  687. this.selectionList.forEach(ele => {
  688. ids.push(ele.id);
  689. });
  690. return ids.join(",");
  691. },
  692. },
  693. mounted() {
  694. // 非租户模式默认加载管理组数据
  695. if (!website.tenantMode) {
  696. this.initData(website.tenantId);
  697. }
  698. },
  699. methods: {
  700. nodeClick(data) {
  701. this.treeDeptId = data.id;
  702. this.page.currentPage = 1;
  703. this.onLoad(this.page);
  704. },
  705. initData(tenantId) {
  706. getRoleTree(tenantId).then(res => {
  707. const column = this.findObject(this.option.group, "roleId");
  708. column.dicData = res.data.data;
  709. });
  710. getDeptTree(tenantId).then(res => {
  711. const column = this.findObject(this.option.group, "deptId");
  712. column.dicData = res.data.data;
  713. });
  714. getPostList(tenantId).then(res => {
  715. const column = this.findObject(this.option.group, "postId");
  716. column.dicData = res.data.data;
  717. });
  718. },
  719. submitRole() {
  720. const roleList = this.$refs.treeRole.getCheckedKeys().join(",");
  721. grant(this.ids, roleList).then(() => {
  722. this.roleBox = false;
  723. this.$message({
  724. type: "success",
  725. message: "操作成功!"
  726. });
  727. this.onLoad(this.page);
  728. });
  729. },
  730. rowSave(row, done, loading) {
  731. row.deptId = row.deptId.join(",");
  732. row.roleId = row.roleId.join(",");
  733. row.postId = row.postId.join(",");
  734. add(row).then(() => {
  735. this.initFlag = false;
  736. this.onLoad(this.page);
  737. this.$message({
  738. type: "success",
  739. message: "操作成功!"
  740. });
  741. done();
  742. }, error => {
  743. window.console.log(error);
  744. loading();
  745. });
  746. },
  747. rowUpdate(row, index, done, loading) {
  748. row.deptId = row.deptId.join(",");
  749. row.roleId = row.roleId.join(",");
  750. row.postId = row.postId.join(",");
  751. update(row).then(() => {
  752. this.initFlag = false;
  753. this.onLoad(this.page);
  754. this.$message({
  755. type: "success",
  756. message: "操作成功!"
  757. });
  758. done();
  759. }, error => {
  760. window.console.log(error);
  761. loading();
  762. });
  763. },
  764. rowDel(row) {
  765. this.$confirm("确定将选择数据删除?", {
  766. confirmButtonText: "确定",
  767. cancelButtonText: "取消",
  768. type: "warning"
  769. })
  770. .then(() => {
  771. return remove(row.id);
  772. })
  773. .then(() => {
  774. this.onLoad(this.page);
  775. this.$message({
  776. type: "success",
  777. message: "操作成功!"
  778. });
  779. });
  780. },
  781. searchReset() {
  782. this.query = {};
  783. this.treeDeptId = '';
  784. this.onLoad(this.page);
  785. },
  786. searchChange(params, done) {
  787. this.query = params;
  788. this.page.currentPage = 1;
  789. this.onLoad(this.page, params);
  790. done();
  791. },
  792. selectionChange(list) {
  793. this.selectionList = list;
  794. },
  795. selectionClear() {
  796. this.selectionList = [];
  797. this.$refs.crud.toggleSelection();
  798. },
  799. handleDelete() {
  800. if (this.selectionList.length === 0) {
  801. this.$message.warning("请选择至少一条数据");
  802. return;
  803. }
  804. this.$confirm("确定将选择数据删除?", {
  805. confirmButtonText: "确定",
  806. cancelButtonText: "取消",
  807. type: "warning"
  808. })
  809. .then(() => {
  810. return remove(this.ids);
  811. })
  812. .then(() => {
  813. this.onLoad(this.page);
  814. this.$message({
  815. type: "success",
  816. message: "操作成功!"
  817. });
  818. this.$refs.crud.toggleSelection();
  819. });
  820. },
  821. handleReset() {
  822. if (this.selectionList.length === 0) {
  823. this.$message.warning("请选择至少一条数据");
  824. return;
  825. }
  826. this.$confirm("确定将选择账号密码重置为123456?", {
  827. confirmButtonText: "确定",
  828. cancelButtonText: "取消",
  829. type: "warning"
  830. })
  831. .then(() => {
  832. return resetPassword(this.ids);
  833. })
  834. .then(() => {
  835. this.$message({
  836. type: "success",
  837. message: "操作成功!"
  838. });
  839. this.$refs.crud.toggleSelection();
  840. });
  841. },
  842. handleGrant() {
  843. if (this.selectionList.length === 0) {
  844. this.$message.warning("请选择至少一条数据");
  845. return;
  846. }
  847. this.roleTreeObj = [];
  848. if (this.selectionList.length === 1) {
  849. this.roleTreeObj = this.selectionList[0].roleId.split(",");
  850. }
  851. getRoleTree().then(res => {
  852. this.roleGrantList = res.data.data;
  853. this.roleBox = true;
  854. });
  855. },
  856. handlePlatform() {
  857. this.platformBox = true;
  858. },
  859. handleImport() {
  860. this.excelBox = true;
  861. },
  862. uploadAfter(res, done, loading, column) {
  863. window.console.log(column);
  864. this.excelBox = false;
  865. this.refreshChange();
  866. done();
  867. },
  868. handleExport() {
  869. this.$confirm("是否导出用户数据?", "提示", {
  870. confirmButtonText: "确定",
  871. cancelButtonText: "取消",
  872. type: "warning"
  873. }).then(() => {
  874. window.open(`/api/blade-user/export-user?${this.website.tokenHeader}=${getToken()}&account=${this.search.account}&realName=${this.search.realName}`);
  875. });
  876. },
  877. handleTemplate() {
  878. window.open(`/api/blade-user/export-template?${this.website.tokenHeader}=${getToken()}`);
  879. },
  880. beforeOpen(done, type) {
  881. if (["edit", "view"].includes(type)) {
  882. getUser(this.form.id).then(res => {
  883. this.form = res.data.data;
  884. if(this.form.hasOwnProperty("deptId")){
  885. this.form.deptId = this.form.deptId.split(",");
  886. }
  887. if(this.form.hasOwnProperty("roleId")){
  888. this.form.roleId = this.form.roleId.split(",");
  889. }
  890. if(this.form.hasOwnProperty("postId")){
  891. this.form.postId = this.form.postId.split(",");
  892. }
  893. });
  894. }
  895. this.initFlag = true;
  896. done();
  897. },
  898. currentChange(currentPage) {
  899. this.page.currentPage = currentPage;
  900. },
  901. sizeChange(pageSize) {
  902. this.page.pageSize = pageSize;
  903. },
  904. refreshChange() {
  905. this.onLoad(this.page, this.query);
  906. },
  907. onLoad(page, params = {}) {
  908. this.loading = true;
  909. getList(page.currentPage, page.pageSize, Object.assign(params, this.query), this.treeDeptId).then(res => {
  910. const data = res.data.data;
  911. this.page.total = data.total;
  912. this.data = data.records;
  913. this.loading = false;
  914. this.selectionClear();
  915. });
  916. },
  917. platformRowUpdate(row, index, done, loading) {
  918. updatePlatform(row.id, row.userType, row.userExt).then(() => {
  919. this.platformOnLoad(this.platformPage);
  920. this.$message({
  921. type: "success",
  922. message: "操作成功!"
  923. });
  924. done();
  925. }, error => {
  926. window.console.log(error);
  927. loading();
  928. });
  929. },
  930. platformBeforeOpen(done, type) {
  931. if (["edit", "view"].includes(type)) {
  932. getUserPlatform(this.platformForm.id).then(res => {
  933. this.platformForm = res.data.data;
  934. });
  935. }
  936. done();
  937. },
  938. platformSearchReset() {
  939. this.platformQuery = {};
  940. this.platformOnLoad(this.platformPage);
  941. },
  942. platformSearchChange(params, done) {
  943. this.platformQuery = params;
  944. this.platformPage.currentPage = 1;
  945. this.platformOnLoad(this.platformPage, params);
  946. done();
  947. },
  948. platformSelectionChange(list) {
  949. this.platformSelectionList = list;
  950. },
  951. platformSelectionClear() {
  952. this.platformSelectionList = [];
  953. this.$refs.platformCrud.toggleSelection();
  954. },
  955. platformCurrentChange(currentPage) {
  956. this.platformPage.currentPage = currentPage;
  957. },
  958. platformSizeChange(pageSize) {
  959. this.platformPage.pageSize = pageSize;
  960. },
  961. platformRefreshChange() {
  962. this.platformOnLoad(this.platformPage, this.platformQuery);
  963. },
  964. platformOnLoad(page, params = {}) {
  965. this.platformLoading = true;
  966. getList(page.currentPage, page.pageSize, Object.assign(params, this.query), this.treeDeptId).then(res => {
  967. const data = res.data.data;
  968. this.platformPage.total = data.total;
  969. this.platformData = data.records;
  970. this.platformLoading = false;
  971. this.selectionClear();
  972. });
  973. }
  974. }
  975. };
  976. </script>
  977. <style>
  978. .box {
  979. height: 800px;
  980. }
  981. .el-scrollbar {
  982. height: 100%;
  983. }
  984. .box .el-scrollbar__wrap {
  985. overflow: scroll;
  986. }
  987. </style>