accountGroupEdit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <div class="bf-postmanagementadd">
  3. <div class="postmanagementadd_header">
  4. <div class="postmanagementadd_top">
  5. <div class="tltleLeft">{{ pageTitle }}</div>
  6. <div
  7. v-is="doesGroupExist ? ['group_btn_edit'] : ['group_btn_save']"
  8. class="btn"
  9. style="margin-top: 20px"
  10. >
  11. <el-button
  12. type="primary"
  13. @click="handleClickSave('editForm')"
  14. >保存</el-button>
  15. </div>
  16. </div>
  17. <div class="addApp-form-content dialog-public-background">
  18. <el-form
  19. ref="editForm"
  20. :inline="true"
  21. :rules="rules"
  22. class="form"
  23. :model="editForm"
  24. >
  25. <el-form-item
  26. prop="name"
  27. :label="`${accountGroupType}名称`"
  28. >
  29. <el-input
  30. v-model.trim="editForm.name"
  31. :placeholder="`请输入${accountGroupType}名称`"
  32. />
  33. </el-form-item>
  34. <el-form-item
  35. label="描述"
  36. prop="desc"
  37. style="margin-left: 40px"
  38. >
  39. <el-input
  40. v-model.trim="editForm.desc"
  41. style="width: 640px"
  42. placeholder="请输入描述"
  43. />
  44. </el-form-item>
  45. </el-form>
  46. </div>
  47. </div>
  48. <div class="content">
  49. <el-row :gutter="24">
  50. <el-col :span="8">
  51. <div class="part">
  52. <AccountGroupTree
  53. :title="`上级${accountGroupType}`"
  54. nodekey="GroupId"
  55. :single-node="doesGroupExist ? GroupUpId : 0"
  56. :type="true"
  57. :default-props="defaultProps"
  58. :checked-keys="accountGroupTreeCheckedList"
  59. @getTreeData="getAccountGroupChecked"
  60. />
  61. </div>
  62. </el-col>
  63. <!-- 开启角色 -->
  64. <template v-if="openRole">
  65. <el-col :span="8">
  66. <div class="part">
  67. <RoleList
  68. title="角色列表"
  69. :role-type="roleType"
  70. :group-ids="groupIds"
  71. :check-box-list="roleListCheckedList"
  72. :number="8"
  73. :active="true"
  74. :selected-role-id="currentSelectedRoleId"
  75. @checkChange="getRoleListChecked"
  76. @checkClick="selectRole"
  77. @role-list-change="roleListCheckedFilter"
  78. />
  79. </div>
  80. </el-col>
  81. <el-col :span="8">
  82. <div class="part">
  83. <PermissionList
  84. title="权限列表"
  85. :role-list="checkedRoles"
  86. :check="true"
  87. @Competen="Competen"
  88. />
  89. </div>
  90. </el-col>
  91. </template>
  92. <!-- 无角色 -->
  93. <template v-else>
  94. <el-col :span="8">
  95. <div class="part">
  96. <PermissionTree
  97. title="权限树"
  98. :checked-keys="permissionTreeChckedKeys"
  99. :query-type="queryType"
  100. :query-ids="queryIds"
  101. @getTreeData="getPermissionTreeChecked"
  102. />
  103. </div>
  104. </el-col>
  105. <el-col :span="8">
  106. <div class="part">
  107. <RulesOfCompetency
  108. title="权限规则"
  109. margin-b="20px"
  110. @getData="getRulesOfCompetency"
  111. />
  112. </div>
  113. </el-col>
  114. </template>
  115. </el-row>
  116. </div>
  117. <!-- <Dialog :flag="dialogVisible">
  118. <div class="closeDialog">
  119. <div class="title">删除账号</div>
  120. <div class="content">是否确定要删除该账号?</div>
  121. <div class="foot right t30">
  122. <el-button
  123. size="medium"
  124. class="r24"
  125. >取消</el-button>
  126. <el-button
  127. size="medium"
  128. type="danger"
  129. >删除</el-button>
  130. </div>
  131. </div>
  132. </Dialog> -->
  133. </div>
  134. </template>
  135. <script>
  136. import AccountGroupTree from '@/components/usergrouptree/index.vue'
  137. import PermissionTree from '@/components/permissiontree/index.vue'
  138. import RulesOfCompetency from '@/components/rulesofcompetency/index.vue'
  139. import RoleList from '@/components/rolelist/index.vue'
  140. import PermissionList from '@/components/permissionlist/index.vue'
  141. // import Dialog from '@/layout/components/Dialog/index.vue'
  142. import { RoleAuths } from '@/api/apiAuthority'
  143. import { GetGroupDetails, EditGroup, SaveGroup } from '@/api/AccountGroup.js'
  144. // import treeData from '../minixs/treeData'
  145. import { mapGetters } from 'vuex'
  146. import { lengthValidator } from '@/utils/validate'
  147. export default {
  148. components: {
  149. AccountGroupTree,
  150. PermissionTree,
  151. RulesOfCompetency,
  152. RoleList,
  153. PermissionList
  154. // Dialog
  155. },
  156. // mixins: [treeData],
  157. data() {
  158. return {
  159. doesGroupExist: this.$route.meta.doesGroupExist, // 控制岗位新增/编辑
  160. GroupId: 0,
  161. GroupUpId: parseInt(this.$route.query.GroupUpId),
  162. // dialogVisible: false,
  163. openRole: 0,
  164. accountGroupTreeCheckedList: [], // 岗位树初始勾选项
  165. accountGroupTreeCheckedTemp: [], // 岗位树当前勾选项
  166. roleListCheckedList: [], // 角色列表初始勾选项
  167. roleListCheckedCopy: [],
  168. roleListCheckedTemp: [], // 角色列表当前勾选项
  169. permissionTreeChckedKeys: [], // 权限树初始勾选项
  170. permissionTreeChckedTemp: [], // 权限树当前勾选项
  171. rulesOfCompetency: null, // 当前编辑的权限规则
  172. queryType: '',
  173. roleType: '',
  174. groupIds: [],
  175. queryIds: [],
  176. currentSelectedRoleId: -1,
  177. checkedRoles: [],
  178. editForm: {
  179. name: '',
  180. desc: '',
  181. isUsed: 0
  182. },
  183. rules: {
  184. // 表单验证
  185. name: [
  186. { required: true, message: `请输入${this.accountGroupType}名称`, trigger: 'blur' },
  187. { validator: lengthValidator, max: 32, message: '长度在 1 到 32 个字符', trigger: ['change', 'blur'] }
  188. ],
  189. desc: [
  190. { validator: lengthValidator, max: 128, message: '长度在 1 到 128 个字符', trigger: ['change', 'blur'] }
  191. ]
  192. },
  193. defaultProps: {
  194. children: 'children',
  195. label: 'GroupName'
  196. }
  197. }
  198. },
  199. computed: {
  200. ...mapGetters(['systemSet']),
  201. pageTitle() {
  202. return this.doesGroupExist ? `编辑${this.accountGroupType}` : `新增${this.accountGroupType}`
  203. }
  204. },
  205. created() {
  206. // 获取系统配置
  207. let obj
  208. if (typeof this.systemSet === 'string') {
  209. obj = JSON.parse(this.systemSet)
  210. } else {
  211. obj = this.systemSet
  212. }
  213. // console.log(obj)
  214. const { OpenRole } = obj
  215. this.openRole = OpenRole
  216. this.accountGroupTreeCheckedTemp = [this.GroupUpId]
  217. this.queryIds = [this.GroupUpId]
  218. this.doesGroupExist && (this.GroupId = parseInt(this.$route.query.GroupId))
  219. },
  220. mounted() {
  221. if (this.GroupUpId !== -1) {
  222. this.groupIds = [this.GroupUpId]
  223. this.roleType = 'group'
  224. } else {
  225. this.groupIds = [-1]
  226. this.roleType = 'onlyRole'
  227. }
  228. if (this.doesGroupExist) {
  229. this.getGroupDetails()
  230. }
  231. this.accountGroupTreeCheckedList = [this.GroupUpId]
  232. },
  233. methods: {
  234. // 岗位详情
  235. async getGroupDetails() {
  236. try {
  237. const res = await GetGroupDetails({
  238. GroupId: this.GroupId
  239. })
  240. if (res.code === 0) {
  241. const { GroupDesc, GroupName, Status, AuthList, RoleList } = res.returnData
  242. this.editForm.name = GroupName
  243. this.editForm.desc = GroupDesc
  244. this.editForm.isUsed = Status
  245. // this.$store.dispatch('auth/changeAuthList', AuthList)
  246. RoleList &&
  247. RoleList.length &&
  248. RoleList.forEach(role => {
  249. role.IsSelected &&
  250. (this.roleListCheckedTemp.push(role),
  251. this.roleListCheckedCopy.push(role),
  252. this.roleListCheckedList.push(role.RoleId))
  253. })
  254. AuthList &&
  255. AuthList.length &&
  256. AuthList.forEach(auth => {
  257. this.permissionTreeChckedKeys.push(auth.AuthId)
  258. this.permissionTreeChckedTemp.push(auth)
  259. })
  260. } else {
  261. this.$message.error(res.message)
  262. }
  263. } catch (error) {
  264. console.log('出错了', error)
  265. }
  266. },
  267. // 保存
  268. handleClickSave(formName) {
  269. this.$refs[formName].validate(valid => {
  270. if (valid) {
  271. this.handleSaveEdit()
  272. } else {
  273. console.log('error submit!!')
  274. return false
  275. }
  276. })
  277. },
  278. // 获取当前权限树勾选项
  279. getPermissionTreeChecked(arr) {
  280. this.permissionTreeChckedTemp = arr.map(auth => auth.AuthList)
  281. },
  282. // 获取当前勾选的岗位
  283. getAccountGroupChecked(arr) {
  284. if (arr.length === 1) {
  285. if (arr[0].GroupId === -1) {
  286. this.groupIds = [-1]
  287. this.accountGroupTreeCheckedTemp = [-1]
  288. this.roleType = 'onlyRole'
  289. this.queryType = 'all'
  290. } else {
  291. const GroupIds = arr.map(item => item.GroupId)
  292. this.accountGroupTreeCheckedTemp = GroupIds
  293. this.roleType = 'group'
  294. this.groupIds = GroupIds
  295. this.queryType = 'group'
  296. this.queryIds = GroupIds
  297. }
  298. } else if (arr.length === 0) {
  299. this.accountGroupTreeCheckedList = [-1]
  300. }
  301. },
  302. // 角色选取
  303. getRoleListChecked(arr) {
  304. this.roleListCheckedTemp = arr
  305. this.roleListCheckedCopy = arr
  306. },
  307. roleListCheckedFilter(arr) {
  308. this.roleListCheckedTemp = this.roleListCheckedCopy.filter(
  309. role => arr.findIndex(item => item.RoleId === role.RoleId) > -1
  310. )
  311. this.roleListCheckedList = this.roleListCheckedCopy.map(role => role.RoleId)
  312. if (arr.findIndex(item => item.RoleId === this.currentSelectedRoleId) === -1) {
  313. this.checkedRoles = []
  314. this.currentSelectedRoleId = -1
  315. }
  316. },
  317. // 获取当前编辑的权限规则
  318. getRulesOfCompetency(obj) {
  319. this.rulesOfCompetency = obj
  320. },
  321. // 点击角色后显示对应权限列表
  322. async selectRole(data) {
  323. if (this.currentSelectedRoleId === data.RoleId) return
  324. try {
  325. const params = {
  326. RoleId: data.RoleId
  327. }
  328. const res = await RoleAuths(params)
  329. if (res.code === 0) {
  330. this.checkedRoles = res.returnData
  331. this.currentSelectedRoleId = data.RoleId
  332. } else {
  333. this.$message.error(res.message)
  334. }
  335. } catch (error) {
  336. console.log('出错了', error)
  337. }
  338. },
  339. // 删除岗位
  340. // async deleteAuth() {
  341. // this.dialogVisible = true;
  342. // },
  343. // async delAcc() {
  344. // try {
  345. // const res = await DelAccGroup({
  346. // GroupId: this.GroupId,
  347. // });
  348. // if (res.code === 0) {
  349. // this.$message.success(res.message);
  350. // setTimeout(() => {
  351. // this.$router.push("/AccountGroup");
  352. // }, 2000);
  353. // } else {
  354. // this.$message.error(res.message);
  355. // }
  356. // } catch (error) {
  357. // console.log("出错了", error);
  358. // }
  359. // },
  360. // 修改权限规则
  361. Competen(data) {
  362. console.log(data)
  363. },
  364. // 岗位编辑保存
  365. async handleSaveEdit() {
  366. const params = {
  367. AuthList: this.permissionTreeChckedTemp,
  368. GroupName: this.editForm.name,
  369. GroupDesc: this.editForm.desc,
  370. GroupUpid: this.accountGroupTreeCheckedTemp[0],
  371. RoleList: this.roleListCheckedTemp
  372. }
  373. if (this.doesGroupExist) {
  374. this.saveEditGroup({
  375. ...params,
  376. GroupId: this.GroupId,
  377. Status: this.editForm.isUsed || 0
  378. })
  379. } else {
  380. this.saveAddGroup(params)
  381. }
  382. },
  383. async saveEditGroup(params) {
  384. try {
  385. const res = await EditGroup(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('/accountGroup')
  391. }, 1000)
  392. } else {
  393. this.$message.error(res.message)
  394. }
  395. } catch (error) {
  396. console.log('出错了', error)
  397. }
  398. },
  399. async saveAddGroup(params) {
  400. try {
  401. const res = await SaveGroup(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('/accountGroup')
  407. }, 1000)
  408. } else {
  409. this.$message.error(res.message)
  410. }
  411. } catch (error) {
  412. console.log('出错了', error)
  413. }
  414. }
  415. }
  416. }
  417. </script>
  418. <style lang="scss" scoped>
  419. .bf-postmanagementadd {
  420. width: 100%;
  421. padding: 30px 64px;
  422. ::v-deep > .postmanagementadd_header {
  423. width: 100%;
  424. height: 184px;
  425. background: #ffffff;
  426. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  427. border-radius: 16px;
  428. padding: 0 32px 0 32px;
  429. margin-bottom: 24px;
  430. > .postmanagementadd_top {
  431. width: 100%;
  432. height: 88px;
  433. display: flex;
  434. position: relative;
  435. justify-content: space-between;
  436. margin-bottom: 16px;
  437. .tltleLeft {
  438. font-size: 24px;
  439. font-weight: bold;
  440. color: #303133;
  441. margin-top: 20px;
  442. }
  443. .isUsed {
  444. margin-top: 20px;
  445. position: absolute;
  446. left: 194px;
  447. top: 6px;
  448. }
  449. > .but {
  450. height: 40px;
  451. }
  452. }
  453. > .postmanagementadd_list {
  454. width: 100%;
  455. display: flex;
  456. > .list_up {
  457. display: flex;
  458. margin-right: 40px;
  459. > p {
  460. white-space: nowrap;
  461. text-overflow: ellipsis;
  462. font-size: 14px;
  463. font-family: Microsoft YaHei;
  464. font-weight: 400;
  465. color: #303133;
  466. margin-top: 0;
  467. margin-bottom: 0;
  468. display: flex;
  469. align-items: center;
  470. margin-right: 16px;
  471. }
  472. > .el-input {
  473. width: 184px;
  474. height: 32px;
  475. background: #f9fbff;
  476. border-radius: 6px;
  477. > .el-input__inner {
  478. width: 100%;
  479. height: 100%;
  480. background: #f9fbff;
  481. border-radius: 6px;
  482. }
  483. }
  484. > .el-textarea {
  485. width: 640px;
  486. height: 33px;
  487. border-radius: 4px;
  488. .el-textarea__inner {
  489. width: 100%;
  490. height: 100%;
  491. background: #f9fbff;
  492. border: 1px solid #d7dae3;
  493. border-radius: 4px;
  494. resize: none;
  495. }
  496. }
  497. }
  498. }
  499. }
  500. .content {
  501. width: 100%;
  502. height: calc(100% - 184px);
  503. padding-top: 24px;
  504. box-sizing: border-box;
  505. // .el-row {
  506. // height: 100%;
  507. // .el-col {
  508. // height: 100%;
  509. // }
  510. // }
  511. .part {
  512. width: 100%;
  513. height: 856px;
  514. background: #ffffff;
  515. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  516. border-radius: 16px;
  517. }
  518. .last {
  519. display: flex;
  520. flex-direction: column;
  521. justify-content: space-between;
  522. }
  523. .part2 {
  524. width: 100%;
  525. height: 512px;
  526. background: #ffffff;
  527. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  528. border-radius: 16px;
  529. }
  530. .part3 {
  531. width: 100%;
  532. height: 320px;
  533. background: #ffffff;
  534. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  535. border-radius: 16px;
  536. margin-top: 25px;
  537. overflow: hidden;
  538. }
  539. }
  540. }
  541. </style>