accountEdit.vue 21 KB

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