accountEdit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <!--
  2. * @Author: Badguy
  3. * @Date: 2022-02-15 11:37:42
  4. * @LastEditTime: 2022-05-10 18:03:53
  5. * @LastEditors: your name
  6. * @Description: 编辑账号
  7. * have a nice day!
  8. -->
  9. <template>
  10. <div class="account-edit">
  11. <div class="account-edit-header">
  12. <div class="title">
  13. <div class="manageTitle">{{ pageTitle }}</div>
  14. <!-- <div class="account-status">
  15. 是否启用
  16. <el-radio-group v-model="accountForm.status">
  17. <el-radio :label="1">是</el-radio>
  18. <el-radio :label="0">否</el-radio>
  19. </el-radio-group>
  20. </div> -->
  21. <div v-is="doesAccountExist ? ['userupdate_btn_save'] : []">
  22. <!-- <el-button size="small" type="primary" class="btn-delete" @click="delate">删除</el-button> -->
  23. <el-button size="small" type="primary" class="btn-save" @click="handleClickSave('accountForm')">保存</el-button>
  24. </div>
  25. </div>
  26. <div class="title-content">
  27. <el-form ref="accountForm" :inline="true" :model="accountForm" :rules="formRules">
  28. <el-form-item label="账号名称" prop="name">
  29. <el-input v-model="accountForm.name" maxlength="32" placeholder="请输入名称" size="small" />
  30. </el-form-item>
  31. <el-form-item label="登录密码" prop="pwd">
  32. <el-input v-model="accountForm.pwd" placeholder="*******" size="small" disabled />
  33. </el-form-item>
  34. <el-form-item>
  35. <el-button v-is="doesAccountExist ? ['userupdate_btn_re_pwd'] : []" size="small" type="primary" class="btn-reset-pwd" @click="resetPwd">重置密码</el-button>
  36. </el-form-item>
  37. <el-form-item label="描述" prop="desc">
  38. <el-input v-model="accountForm.desc" class="desc" maxlength="128" placeholder="描述内容···" size="small" />
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. </div>
  43. <div class="account-edit-main">
  44. <!-- 用户组和角色未开启 -->
  45. <el-row v-if="!openGroup && !openRole" :gutter="24">
  46. <el-col :span="8">
  47. <div class="content-card">
  48. <PermissionTree title="权限树" :query-type="queryType" :checked-keys="permissionTreeChckedKeys" @getTreeData="getPermissionTreeChecked" />
  49. </div>
  50. </el-col>
  51. <el-col :span="8">
  52. <div class="content-card">
  53. <RulesOfCompetency title="权限规则" margin-b="20px" @getData="getRulesOfCompetency" />
  54. </div>
  55. </el-col>
  56. <el-col v-is="doesAccountExist ? ['account_edit_login_setting'] : ['account_add_login_setting']" :span="8">
  57. <div class="content-card">
  58. <LoginPolicy :checked-list="loginPolicyCheckedList" @getCheckedList="getLoginPolicyChecked" />
  59. </div>
  60. </el-col>
  61. </el-row>
  62. <!-- 角色和用户组都开启 -->
  63. <el-row v-if="openGroup && openRole" :gutter="24">
  64. <el-col :span="8">
  65. <div class="content-card">
  66. <AccountGroupTree title="所属账号组" nodekey="GroupId" :default-props="accountGroupTreeProps" :checked-keys="accountGroupTreeCheckedList" @getTreeData="getAccountGroupChecked" />
  67. </div>
  68. </el-col>
  69. <el-col v-is="doesAccountExist ? ['account_edit_role_list'] : ['account_add_role_list']" :span="8">
  70. <div class="content-card">
  71. <RoleList
  72. title="角色列表"
  73. :role-type="roleType"
  74. :group-ids="groupIds"
  75. :check-box-list="roleListCheckedList"
  76. :number="8"
  77. :active="true"
  78. @checkChange="getRoleListChecked"
  79. @checkClick="selectRole"
  80. @roleListChange="roleListCheckedChange"
  81. />
  82. </div>
  83. </el-col>
  84. <el-col v-is="doesAccountExist ? ['account_edit_auth_list', 'account_edit_login_setting'] : ['account_add_auth_list', 'account_add_login_setting']" :span="8">
  85. <div v-is="doesAccountExist ? ['account_edit_auth_list'] : ['account_add_auth_list']" class="content-card">
  86. <PermissionList title="权限列表" class="permission-list" :role-list="checkedRoles" :check="true" @Competen="Competen" />
  87. </div>
  88. <div v-is="doesAccountExist ? ['account_edit_login_setting'] : ['account_add_login_setting']" class="content-card">
  89. <LoginPolicy :checked-list="loginPolicyCheckedList" @getCheckedList="getLoginPolicyChecked" />
  90. </div>
  91. </el-col>
  92. </el-row>
  93. <!-- 只开启用户组 -->
  94. <el-row v-if="openGroup && !openRole" :gutter="24">
  95. <el-col :span="8">
  96. <div class="content-card">
  97. <AccountGroupTree title="所属账号组" nodekey="GroupId" :default-props="accountGroupTreeProps" :checked-keys="accountGroupTreeCheckedList" @getTreeData="getAccountGroupChecked" />
  98. </div>
  99. </el-col>
  100. <el-col :span="8">
  101. <div class="content-card">
  102. <PermissionTree title="权限树" :query-type="queryType" :query-ids="queryIds" :checked-keys="permissionTreeChckedKeys" @getTreeData="getPermissionTreeChecked" />
  103. </div>
  104. </el-col>
  105. <el-col :span="8">
  106. <div class="content-card">
  107. <RulesOfCompetency title="权限规则" margin-b="20px" @getData="getRulesOfCompetency" />
  108. </div>
  109. <div v-is="doesAccountExist ? ['account_edit_login_setting'] : ['account_add_login_setting']" class="content-card">
  110. <LoginPolicy :checked-list="loginPolicyCheckedList" @getCheckedList="getLoginPolicyChecked" />
  111. </div>
  112. </el-col>
  113. </el-row>
  114. <!-- 只开启角色 -->
  115. <el-row v-if="!openGroup && openRole" :gutter="24">
  116. <el-col v-is="doesAccountExist ? ['account_edit_role_list'] : ['account_add_role_list']" :span="12">
  117. <div class="content-card">
  118. <RoleList
  119. title="角色列表"
  120. :role-type="roleType"
  121. :check-box-list="roleListCheckedList"
  122. :number="6"
  123. :active="true"
  124. @checkChange="getRoleListChecked"
  125. @checkClick="selectRole"
  126. @roleListChange="roleListCheckedChange"
  127. />
  128. </div>
  129. </el-col>
  130. <el-col v-is="doesAccountExist ? ['account_edit_auth_list'] : ['account_add_auth_list']" :span="12">
  131. <div class="content-card">
  132. <PermissionList title="权限列表" :role-list="checkedRoles" :check="true" class="permission-list" @Competen="Competen" />
  133. </div>
  134. </el-col>
  135. <!-- <el-col
  136. v-is="doesAccountExist ? ['account_edit_login_setting'] : ['account_add_login_setting']"
  137. :span="8"
  138. >
  139. <div class="content-card">
  140. <LoginPolicy
  141. :checked-list="loginPolicyCheckedList"
  142. @getCheckedList="getLoginPolicyChecked"
  143. />
  144. </div>
  145. </el-col> -->
  146. </el-row>
  147. </div>
  148. <!-- <Dialog :flag="dialogVisible">
  149. <div class="closeDialog">
  150. <div class="title">删除账号</div>
  151. <div class="content">是否确定要删除该账号?</div>
  152. <div class="foot right t30">
  153. <el-button
  154. size="medium"
  155. type="danger"
  156. class="r24"
  157. >删除</el-button>
  158. <el-button size="medium">取消</el-button>
  159. </div>
  160. </div>
  161. </Dialog> -->
  162. </div>
  163. </template>
  164. <script>
  165. import AccountGroupTree from "@/components/usergrouptree/index.vue";
  166. import PermissionTree from "@/components/permissiontree/index.vue";
  167. import RulesOfCompetency from "@/components/rulesofcompetency/index.vue";
  168. import LoginPolicy from "@/components/loginpolicy/index.vue";
  169. import RoleList from "@/components/rolelist/index.vue";
  170. import PermissionList from "@/components/permissionlist/index.vue";
  171. // import Dialog from '@/layout/components/Dialog'
  172. import { RoleAuths } from "@/api/apiAuthority";
  173. import { getAccountDetails, editAccount, addAccount } from "@/api/Account.js";
  174. import { pwdProduce } from "@/utils/validate";
  175. import { mapGetters } from "vuex";
  176. export default {
  177. components: {
  178. AccountGroupTree,
  179. PermissionTree,
  180. RulesOfCompetency,
  181. LoginPolicy,
  182. RoleList,
  183. PermissionList,
  184. // Dialog
  185. },
  186. data() {
  187. return {
  188. doesAccountExist: this.$route.meta.doesAccountExist, // 控制账号新增/编辑
  189. userId: "",
  190. openRole: 0,
  191. openGroup: 0,
  192. pwdStruc: "",
  193. pwdLengthBegin: 0,
  194. pwdLengthEnd: 0,
  195. permissionTreeChckedKeys: [], // 权限树初始勾选项
  196. permissionTreeChckedTemp: [], // 权限树当前勾选项
  197. rulesOfCompetency: null, // 当前编辑的权限规则
  198. loginPolicyCheckedList: [], // 登录策略初始勾选项
  199. loginPolicyCheckedTemp: [], // 登录策略当前勾选项
  200. accountGroupTreeCheckedList: [], // 账号组树初始勾选项
  201. accountGroupTreeCheckedTemp: [], // 账号组树当前勾选项
  202. roleListCheckedList: [], // 角色列表初始勾选项
  203. roleListCheckedTemp: [], // 角色列表当前勾选项
  204. roleType: "",
  205. queryType: "",
  206. checkedRoles: [],
  207. currentSelectedRoleId: 0,
  208. groupIds: [],
  209. queryIds: [],
  210. // dialogVisible: false,
  211. formRules: {
  212. name: [
  213. { required: true, message: "请输入账号名称", trigger: "blur" },
  214. { min: 1, max: 32, message: "长度在 1到 32 个字符", trigger: "blur" },
  215. ],
  216. desc: [{ min: 1, max: 128, message: "长度最多128个字符", trigger: "blur" }],
  217. },
  218. accountForm: {
  219. name: null,
  220. pwd: null,
  221. desc: null,
  222. status: 0,
  223. },
  224. accountGroupTreeProps: {
  225. children: "children",
  226. label: "GroupName",
  227. },
  228. };
  229. },
  230. computed: {
  231. ...mapGetters(["systemSet"]),
  232. pageTitle() {
  233. return this.doesAccountExist ? "编辑账号" : "新增账号";
  234. },
  235. },
  236. created() {
  237. // 获取系统配置
  238. let obj;
  239. if (typeof this.systemSet === "string") {
  240. obj = JSON.parse(this.systemSet);
  241. } else {
  242. obj = this.systemSet;
  243. }
  244. // console.log(obj)
  245. const { OpenRole, OpenGroup, PwdStruc, PwdLengthBegin, PwdLengthEnd } = obj;
  246. this.openRole = OpenRole;
  247. this.openGroup = OpenGroup;
  248. this.pwdStruc = PwdStruc;
  249. this.pwdLengthBegin = PwdLengthBegin;
  250. this.pwdLengthEnd = PwdLengthEnd;
  251. },
  252. mounted() {
  253. if (this.doesAccountExist) {
  254. this.userId = this.$route.query.userId;
  255. this.getAccountInfo();
  256. } else {
  257. this.resetPwd();
  258. this.roleType = "onlyRole";
  259. this.queryType = "all";
  260. }
  261. },
  262. methods: {
  263. // 获取当前账号信息
  264. async getAccountInfo() {
  265. try {
  266. const res = await getAccountDetails({
  267. UserId: this.userId,
  268. });
  269. if (res.code === 0) {
  270. // console.log(res.returnData)
  271. const { UserDesc, UserName, GroupList, TacList, AuthList, RoleList, Status } = res.returnData;
  272. this.accountForm.name = UserName;
  273. this.accountForm.desc = UserDesc;
  274. this.accountForm.status = Status ?? 1;
  275. AuthList &&
  276. AuthList.length &&
  277. AuthList.forEach((auth) => {
  278. this.permissionTreeChckedKeys.push(auth.AuthId);
  279. this.permissionTreeChckedTemp.push(auth);
  280. });
  281. if (GroupList && GroupList.length && GroupList[0] !== -1) {
  282. this.roleType = this.openGroup ? "roleByUpId" : "onlyRole";
  283. this.queryType = this.openGroup ? "group" : "all";
  284. GroupList.forEach((group) => {
  285. this.accountGroupTreeCheckedList.push(group.GroupId);
  286. this.accountGroupTreeCheckedTemp.push(group.GroupId);
  287. this.groupIds.push(group.GroupId);
  288. this.queryIds.push(group.GroupId);
  289. });
  290. } else {
  291. this.roleType = "onlyRole";
  292. this.queryType = "all";
  293. this.accountGroupTreeCheckedTemp.push(-1);
  294. }
  295. RoleList &&
  296. RoleList.length &&
  297. RoleList.forEach((role) => {
  298. role.IsSelected && this.roleListCheckedTemp.push(role);
  299. });
  300. TacList &&
  301. TacList &&
  302. TacList.forEach((tac) => {
  303. tac.IsSelected && this.loginPolicyCheckedList.push(tac);
  304. tac.IsSelected && this.loginPolicyCheckedTemp.push(tac);
  305. });
  306. } else {
  307. this.$message.error(res.message);
  308. }
  309. } catch (error) {
  310. console.log("出错了", error.message || error);
  311. }
  312. },
  313. // 随机生成密码
  314. resetPwd() {
  315. this.accountForm.pwd = pwdProduce(this.pwdLengthBegin, this.pwdLengthEnd, this.pwdStruc);
  316. },
  317. // 获取当前权限树勾选项
  318. getPermissionTreeChecked(arr) {
  319. this.permissionTreeChckedTemp = arr.map((auth) => auth.AuthList);
  320. },
  321. // 获取当前编辑的权限规则
  322. getRulesOfCompetency(obj) {
  323. this.rulesOfCompetency = obj;
  324. },
  325. // 获取当前勾选的登录策略
  326. getLoginPolicyChecked(arr) {
  327. this.loginPolicyCheckedTemp = arr;
  328. },
  329. // 获取当前勾选的账号组
  330. getAccountGroupChecked(arr) {
  331. if (arr && arr.length && arr[0] !== -1) {
  332. const GroupIds = arr.map((item) => item.GroupId);
  333. this.accountGroupTreeCheckedTemp = GroupIds;
  334. this.roleType = "roleByUpId";
  335. this.groupIds = GroupIds;
  336. this.queryType = "group";
  337. this.queryIds = GroupIds;
  338. } else {
  339. this.accountGroupTreeCheckedTemp = [-1];
  340. this.roleType = "onlyRole";
  341. this.queryType = "all";
  342. }
  343. },
  344. // 获取当前勾选的角色列表
  345. getRoleListChecked(arr) {
  346. this.roleListCheckedTemp = arr;
  347. },
  348. roleListCheckedChange(arr) {
  349. this.roleListCheckedTemp = this.roleListCheckedTemp.filter((role) => arr.some((data) => data.RoleId === role.RoleId));
  350. this.roleListCheckedList = this.roleListCheckedTemp.map((role) => role.RoleId);
  351. },
  352. // 点击角色后显示对应权限列表
  353. async selectRole(data) {
  354. if (this.currentSelectedRoleId === data.RoleId) return;
  355. try {
  356. const params = {
  357. RoleId: data.RoleId,
  358. };
  359. const result = await RoleAuths(params);
  360. if (result.code === 0) {
  361. this.checkedRoles = result.returnData;
  362. this.currentSelectedRoleId = data.RoleId;
  363. } else {
  364. this.$message.error(result.message);
  365. }
  366. } catch (error) {
  367. console.log("出错了", error.message || error);
  368. }
  369. },
  370. // 修改权限规则
  371. Competen(data) {
  372. console.log(data);
  373. },
  374. // 账号编辑保存
  375. handleClickSave(formName) {
  376. this.$refs[formName].validate((valid) => {
  377. if (valid) {
  378. this.handleSaveEdit();
  379. } else {
  380. console.log("error submit!!");
  381. return false;
  382. }
  383. });
  384. },
  385. handleSaveEdit() {
  386. const params = {
  387. AuthList: this.permissionTreeChckedTemp,
  388. GroupList: this.accountGroupTreeCheckedTemp.map((groupId) => ({ GroupId: groupId })),
  389. RoleList: this.roleListCheckedTemp,
  390. TacList: this.loginPolicyCheckedTemp,
  391. UserDesc: this.accountForm.desc,
  392. UserName: this.accountForm.name,
  393. UserPwd: this.accountForm.pwd,
  394. };
  395. if (this.doesAccountExist) {
  396. this.saveEditAccount({
  397. ...params,
  398. UserId: this.userId,
  399. Status: this.accountForm.status,
  400. });
  401. } else {
  402. this.saveAddAccount(params);
  403. }
  404. },
  405. // 编辑账号
  406. async saveEditAccount(params) {
  407. try {
  408. const res = await editAccount(params);
  409. if (res.code === 0) {
  410. this.$message.success(res.message);
  411. setTimeout(() => {
  412. this.$store.dispatch("tagsView/delView", this.$route);
  413. this.$router.push("/account");
  414. }, 1000);
  415. } else {
  416. this.$message.error(res.message);
  417. }
  418. } catch (error) {
  419. console.log("出错了", error.message || error);
  420. }
  421. },
  422. // 新增账号
  423. async saveAddAccount(params) {
  424. try {
  425. const res = await addAccount(params);
  426. if (res.code === 0) {
  427. this.$message.success(res.message);
  428. setTimeout(() => {
  429. this.$store.dispatch("tagsView/delView", this.$route);
  430. this.$router.push("/account");
  431. }, 1000);
  432. } else {
  433. this.$message.error(res.message);
  434. }
  435. } catch (error) {
  436. console.log("出错了", error.message || error);
  437. }
  438. },
  439. },
  440. };
  441. </script>
  442. <style lang="scss" scoped>
  443. .account-edit {
  444. padding: 23px 24px;
  445. .account-edit-header {
  446. box-sizing: border-box;
  447. width: 100%;
  448. margin-bottom: 24px;
  449. border-radius: 4px;
  450. padding: 24px 32px 32px 24px;
  451. background-color: #fff;
  452. .title {
  453. display: flex;
  454. justify-content: space-between;
  455. flex-direction: row;
  456. position: relative;
  457. .manageTitle {
  458. line-height: 30px;
  459. }
  460. .account-status {
  461. flex: 1;
  462. line-height: 32px;
  463. font-family: Microsoft YaHei;
  464. color: #303133;
  465. ::v-deep .el-radio-group {
  466. margin-left: 16px;
  467. .el-radio__label {
  468. font-family: Microsoft YaHei;
  469. color: #303133;
  470. }
  471. }
  472. }
  473. .title-left {
  474. font-size: 24px;
  475. font-weight: bold;
  476. color: #303133;
  477. }
  478. .btn-save {
  479. width: 64px;
  480. height: 32px;
  481. border: none;
  482. font-weight: 400;
  483. font-size: 14px;
  484. }
  485. .btn-delete {
  486. width: 64px;
  487. height: 32px;
  488. background: #f56c6c;
  489. border: none;
  490. margin-right: 24px;
  491. }
  492. }
  493. .title-content {
  494. width: 100%;
  495. padding-top: 24px;
  496. box-sizing: border-box;
  497. .btn-reset-pwd {
  498. width: 81px;
  499. height: 32px;
  500. padding: 0;
  501. border: none;
  502. text-align: center;
  503. font-weight: 400;
  504. border-radius: 2px;
  505. font-size: 14px;
  506. }
  507. ::v-deep .el-form {
  508. height: 32px;
  509. display: flex;
  510. .el-form-item {
  511. margin-bottom: 0;
  512. vertical-align: middle;
  513. &:nth-child(1) {
  514. margin-right: 79px;
  515. }
  516. &:nth-child(2) {
  517. margin-right: 16px;
  518. }
  519. &:nth-child(3) {
  520. margin-right: 80px;
  521. }
  522. &:nth-last-child(1) {
  523. margin-right: 0;
  524. flex: 1;
  525. display: flex;
  526. .el-form-item__content {
  527. flex: 1;
  528. }
  529. }
  530. .el-form-item__label {
  531. padding-right: 16px;
  532. height: 32px;
  533. line-height: 32px;
  534. }
  535. .el-form-item__content {
  536. height: 32px;
  537. line-height: 32px;
  538. }
  539. }
  540. .el-input__inner {
  541. height: 32px;
  542. line-height: 32px;
  543. min-width: 240px;
  544. background: #ffffff;
  545. border: 1px solid #d2d6df;
  546. border-radius: 2px;
  547. }
  548. }
  549. }
  550. }
  551. .account-edit-main {
  552. box-sizing: border-box;
  553. ::v-deep .el-empty {
  554. padding: 0;
  555. }
  556. .content-card {
  557. width: 100%;
  558. height: calc(100vh - 294px);
  559. min-height: 300px;
  560. max-height: 786px;
  561. overflow: hidden;
  562. }
  563. .img-onlyRead {
  564. pointer-events: none;
  565. }
  566. .last {
  567. display: flex;
  568. flex-direction: column;
  569. justify-content: space-between;
  570. }
  571. }
  572. }
  573. </style>