accountEdit.vue 20 KB

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