accountGroupEdit.vue 15 KB

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