menu.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="app-container">
  3. <!-- <el-tree :data="curData" :props="defaultProps"></el-tree> -->
  4. <!-- default-expand-all -->
  5. <el-tree
  6. :data="curData"
  7. node-key="id"
  8. default-expand-all
  9. :expand-on-click-node="false">
  10. <span class="custom-tree-node" slot-scope="{ node, data }">
  11. <span>{{ node.data.name }} -- {{pTypeObj[node.data.perm_type]}} ----{{node.data.path}} ---- -- {{mhObj[node.data.menu_hidden]}}/{{psObj[node.data.perm_status]}} ----{{node.data.sort}}</span>
  12. <span>
  13. <el-button
  14. type="text"
  15. size="mini"
  16. @click="() => editMenu(data)">
  17. 编辑
  18. </el-button>
  19. <el-button
  20. type="text"
  21. size="mini"
  22. @click="() => appendMenu(data)">
  23. 添加
  24. </el-button>
  25. <el-button
  26. type="text"
  27. size="mini"
  28. @click="() => removeMenu(node, data)">
  29. 删除
  30. </el-button>
  31. </span>
  32. </span>
  33. </el-tree>
  34. <popup-edit
  35. :isShow="isPopupShow"
  36. :curObj="curObj"
  37. :curType="curType"
  38. @close="closePopup"
  39. />
  40. </div>
  41. </template>
  42. <script>
  43. import { arrToObj } from '@/utils'
  44. import SearchForm from './components/searchForm/Dict'
  45. import PopupEdit from './components/popup/MenuEdit'
  46. import baseTable from '_m/baseTable.js'
  47. export default {
  48. name: 'basePublicDictSys',
  49. components: {
  50. SearchForm,
  51. PopupEdit
  52. },
  53. provide () {
  54. return {
  55. parentData: this
  56. }
  57. },
  58. mixins: [baseTable],
  59. created () {},
  60. data () {
  61. const pTypeObj = arrToObj(this.$dictData.perm_type)
  62. const mhObj = arrToObj(this.$dictData.show_hidden)
  63. const psObj = arrToObj(this.$dictData.perm_status)
  64. return {
  65. defaultProps: {
  66. children: 'children',
  67. label: 'name'
  68. },
  69. curData: [],
  70. isPopupShow: false,
  71. curObj: {},
  72. curType: '',
  73. pTypeObj,
  74. mhObj,
  75. psObj,
  76. }
  77. },
  78. mounted () {
  79. this.getMenu()
  80. },
  81. methods: {
  82. getMenu () {
  83. this.$api.base.admpermissionslist().then(res => {
  84. let curData = res || []
  85. this.curData = [...this.formatData(curData)]
  86. })
  87. },
  88. formatData (arr, ids) {
  89. let newArr = []
  90. const curArr = JSON.parse(JSON.stringify(arr))
  91. curArr.forEach(item => {
  92. let obj = {...item}
  93. if (item.perm_type === '2' || item.perm_type === '1') {}
  94. obj.label = item.name
  95. obj.value = item.id
  96. obj.ids = ids ? [...ids, item.id] : [item.id]
  97. if (item.children && item.children.length > 0) {
  98. obj.children = this.formatData(item.children, obj.ids)
  99. }
  100. if (obj.children && obj.children.length === 0) delete obj.children
  101. newArr.push(obj)
  102. })
  103. return newArr
  104. },
  105. editMenu (row) {
  106. this.openPopup(row, 'edit')
  107. },
  108. appendMenu (row) {
  109. this.openPopup(row, 'add')
  110. },
  111. removeMenu (node, row) {
  112. const msgHtml = `确定要删除吗?`
  113. this.$msg(msgHtml, 'confirm', ()=> {
  114. this.$api.base.admpermissionsdel({
  115. id: row.id,
  116. }).then(data => {
  117. this.$msgs(`删除成功!`)
  118. this.getMenu()
  119. })
  120. }, null, true)
  121. },
  122. openPopup (row, type) {
  123. this.curObj = row
  124. this.curType = type
  125. this.isPopupShow = true
  126. },
  127. closePopup (obj) {
  128. this.isPopupShow = false
  129. if (obj) {
  130. this.getMenu()
  131. }
  132. }
  133. }
  134. }
  135. </script>