accountEdit.vue 19 KB

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