Commit b6f82d5f by liwk

修改树组件

1 parent 4111ff86
<template> <template>
<div class="tree" :style="treeStyle"> <div class="tree" :style="treeStyle">
<<<<<<< HEAD
<gl-tree ref='tree' highlight-current :data='data' :show-checkbox='showCheckbox' node-key='id' :props='props' :default-expand-all='defaultExpandAll' @check='check' @node-click='nodeClick'></gl-tree>
=======
<gl-tree <gl-tree
ref='tree' ref='tree'
highlight-current highlight-current
...@@ -15,34 +12,17 @@ ...@@ -15,34 +12,17 @@
@check='check' @check='check'
@node-click='nodeClick' @node-click='nodeClick'
></gl-tree> ></gl-tree>
>>>>>>> 9bf4d2fc7a08913f8a8bbac501752e7dc6d5f705
</div> </div>
</template> </template>
<script> <script>
import { findMenuTree } from '@/api/api' import { findMenuTree, findDepartTree } from '@/api/api'
function fn(data, pid) {
var result = []
let temp = null
for (var i in data) {
if (data[i].parent == pid) {
result.push(data[i])
temp = fn(data, data[i].id)
if (temp.length > 0) {
data[i].children = temp
}
}
}
return result
}
export default { export default {
name: 'Tree', name: 'Tree',
data() { data() {
return { return {
// data: this.$get_session_config().resources || this.$get_session_config(), data: null,
data: [Array, Function],
props: { props: {
// label: 'title'
label: 'text' label: 'text'
} }
} }
...@@ -55,17 +35,8 @@ export default { ...@@ -55,17 +35,8 @@ export default {
defaultCheckedKeys: { defaultCheckedKeys: {
type: Array, type: Array,
default: () => [] default: () => []
} },
}, isDepart: Boolean
mounted() {
findMenuTree.req().then(res => {
// this.data = res
// this.data = this.$get_menus(res, '#', 'parent')
this.data = fn(res, '#')
// console.log(this.data)
}).catch(err => {
console.log(err)
})
}, },
methods: { methods: {
nodeClick(data, treeData, vue) { nodeClick(data, treeData, vue) {
...@@ -74,7 +45,34 @@ export default { ...@@ -74,7 +45,34 @@ export default {
check(data, treeData) { check(data, treeData) {
this.$emit('input', { data, treeData }) this.$emit('input', { data, treeData })
} }
},
mounted() {
!this.isDepart
? findMenuTree.req().then(res => {
this.data = fn(res, '#')
}).catch(err => {
console.log(err)
})
: findDepartTree.req().then(res => {
this.data = fn(res, '#')
}).catch(err => {
console.log(err)
})
}
}
function fn(data, pid) {
var result = []
var temp = null
for (var i in data) {
if (data[i].parent == pid) {
result.push(data[i])
temp = fn(data, data[i].id)
if (temp.length > 0) {
data[i].children = temp
}
}
} }
return result
} }
</script> </script>
<style scoped> <style scoped>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!