accountEdit.vue 19 KB

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