accountGroupEdit.vue 14 KB

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