Elizabeth's proactive approach involves introducing urinal toilet attachment , an ingenious concept that optimizes space and functionality.

EditPerview.vue 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb :crumbs='crumbs'></bread-crumb>
  5. </div>
  6. <div class="app-container">
  7. <template v-if="purviews.length > 0">
  8. <el-row>
  9. <el-col :span="24">
  10. <div style="margin-bottom: 20px;">
  11. <el-tree :props="treeProps" :data="purviews" :default-checked-keys="default_checkeds" node-key="id" ref="tree" default-expand-all show-checkbox>
  12. <span class="custom-tree-node" slot-scope="{ node, data }">
  13. <span>{{ data.name }}</span>
  14. </span>
  15. </el-tree>
  16. </div>
  17. </el-col>
  18. <el-col :span="24">
  19. <router-link :to="{ path:'/role/manage' }">
  20. <el-button>取消</el-button>
  21. </router-link>
  22. <el-button type="primary" @click="submitAction()">保存</el-button>
  23. </el-col>
  24. </el-row>
  25. </template>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import {getEditPurviewInitData, editPurview} from '@/api/role/role'
  31. import BreadCrumb from "@/xt_pages/components/bread-crumb";
  32. export default {
  33. name: 'EditPerview',
  34. components: {
  35. BreadCrumb
  36. },
  37. data() {
  38. return {
  39. crumbs:[
  40. {path:false, name:'权限管理'},
  41. {path:false, name:'角色管理'},
  42. {path:false, name:'权限设置'},
  43. ],
  44. role_id: 0,
  45. purviews: [], // [{id, pid, name, childs}]
  46. treeProps: {
  47. label: "name",
  48. children: "childs"
  49. },
  50. // role_purview_ids: '',
  51. default_checkeds: []
  52. }
  53. },
  54. created() {
  55. var id = parseInt(this.$route.query.id)
  56. if (id <= 0) {
  57. this.$message.error("参数错误")
  58. return
  59. }
  60. this.role_id = id
  61. getEditPurviewInitData(this.role_id).then(rs => {
  62. var resp = rs.data
  63. if (resp.state === 1) {
  64. this.purviews.push(...resp.data.purviews)
  65. // 初始化默认选中项
  66. var role_purview_ids = resp.data.role_purview_ids
  67. // role_purview_ids = '48,49,50'
  68. var checkeds = []
  69. if (role_purview_ids.length > 0) {
  70. var ids = role_purview_ids.split(",")
  71. this.purviews.forEach(purview => {
  72. if (purview.childs != null && purview.childs.length > 0) {
  73. purview.childs.forEach(child => {
  74. if (ids.indexOf(child.id+"") != -1) {
  75. checkeds.push(child.id)
  76. }
  77. });
  78. } else {
  79. if (ids.indexOf(purview.id+"") != -1) {
  80. checkeds.push(purview.id)
  81. }
  82. }
  83. });
  84. }
  85. this.default_checkeds = checkeds
  86. } else {
  87. this.$message.error(resp.msg)
  88. }
  89. }).catch(err => {
  90. this.$message.error(err)
  91. })
  92. },
  93. methods: {
  94. submitAction: function() {
  95. if (this.role_id <= 0) {
  96. return
  97. }
  98. var checkeds = this.$refs.tree.getCheckedKeys(true)
  99. var ids = []
  100. if (checkeds.length > 0) {
  101. this.purviews.forEach(purview => {
  102. if (purview.childs != null && purview.childs.length > 0) {
  103. purview.childs.forEach(child => {
  104. if (checkeds.indexOf(child.id) != -1) {
  105. if (ids.indexOf(purview.id) == -1) {
  106. ids.push(purview.id)
  107. }
  108. ids.push(child.id)
  109. }
  110. })
  111. } else {
  112. if (checkeds.indexOf(purview.id) != -1) {
  113. ids.push(purview.id)
  114. }
  115. }
  116. });
  117. }
  118. var idsStr = ""
  119. if (ids.length > 0) {
  120. idsStr = ids.join(",")
  121. }
  122. editPurview(this.role_id, idsStr).then(rs => {
  123. var resp = rs.data
  124. if (resp.state === 1) {
  125. this.$router.back(-1)
  126. } else {
  127. this.$message.error(resp.msg)
  128. }
  129. }).catch(err => {
  130. this.$message.error(err)
  131. })
  132. }
  133. }
  134. }
  135. </script>
  136. <style scoped>
  137. .custom-tree-node {
  138. flex: 1;
  139. display: flex;
  140. align-items: center;
  141. justify-content: space-between;
  142. font-size: 17px;
  143. padding-left: 10px;
  144. }
  145. .el-tree-node__content {
  146. height: 40px;
  147. }
  148. </style>