[update]修改Tree组件结构

This commit is contained in:
OrangeM21 2020-05-09 12:29:52 +08:00
parent b44f15faaf
commit cf08cb1db9
3 changed files with 15 additions and 42 deletions

View File

@ -37,7 +37,8 @@ export default {
onRename: this.onRename.bind(this), onRename: this.onRename.bind(this),
onSelected: this.onSelected.bind(this), onSelected: this.onSelected.bind(this),
beforeDrop: this.beforeDrop.bind(this), beforeDrop: this.beforeDrop.bind(this),
onDrop: this.onDrop.bind(this) onDrop: this.onDrop.bind(this),
refresh: this.refresh.bind(this)
// //
// beforeClick // beforeClick
// beforeDrag // beforeDrag
@ -214,6 +215,12 @@ export default {
var node = this.zTree.getNodeByParam('id', newNode.id, parentNode) var node = this.zTree.getNodeByParam('id', newNode.id, parentNode)
this.zTree.editName(node) this.zTree.editName(node)
}) })
},
refresh: function() {
this.$axios.post(
'/api/v1/assets/nodes/00000000-0000-0000-0000-000000000000/tasks/',
{ action: 'refresh_cache' }
)
} }
} }
} }

View File

@ -18,13 +18,10 @@
import $ from '@/utils/jquery-vendor.js' import $ from '@/utils/jquery-vendor.js'
import 'ztree' import 'ztree'
import '@/styles/ztree.css' import '@/styles/ztree.css'
const merge = require('deepmerge')
const defaultObject = { const defaultObject = {
type: Object, type: Object,
default: () => { default: () => {}
}
} }
export default { export default {
name: 'ZTree', name: 'ZTree',
@ -35,18 +32,13 @@ export default {
}, },
data() { data() {
return { return {
defaultSetting: {
},
zTree: '', zTree: '',
rMenu: '' rMenu: ''
} }
}, },
computed: { computed: {
treeSetting() { treeSetting() {
const treeSetting = merge(this.defaultSetting, this.setting) return this.setting
return treeSetting
} }
}, },
mounted() { mounted() {
@ -60,15 +52,7 @@ export default {
if (this.treeSetting.showRefresh) { if (this.treeSetting.showRefresh) {
this.rootNodeAddDom( this.rootNodeAddDom(
this.zTree, this.zTree,
() => { this.treeSetting.callback.refresh
this.$axios.post(
'/api/v1/assets/nodes/00000000-0000-0000-0000-000000000000/tasks/',
{ action: 'refresh_cache' }
).then(res => {
this.initTree()
}
)
}
) )
} }
@ -81,6 +65,7 @@ export default {
}) })
}, },
rootNodeAddDom: function(ztree, callback) { rootNodeAddDom: function(ztree, callback) {
const vm = this
var refreshIcon = "<a id='tree-refresh'><i class='fa fa-refresh'></i></a>" var refreshIcon = "<a id='tree-refresh'><i class='fa fa-refresh'></i></a>"
var rootNode = ztree.getNodes()[0] var rootNode = ztree.getNodes()[0]
if (rootNode) { if (rootNode) {
@ -94,28 +79,8 @@ export default {
refreshIconRef.bind('click', function() { refreshIconRef.bind('click', function() {
ztree.destroy() ztree.destroy()
callback() callback()
vm.initTree()
}) })
},
setUrlParam: function(url, name, value) {
var urlArray = url.split('?')
if (urlArray.length === 1) {
url += '?' + name + '=' + value
} else {
var oriParam = urlArray[1].split('&')
var oriParamMap = {}
$.each(oriParam, function(index, value) {
var v = value.split('=')
oriParamMap[v[0]] = v[1]
})
oriParamMap[name] = value
url = urlArray[0] + '?'
var newParam = []
$.each(oriParamMap, function(index, value) {
newParam.push(index + '=' + value)
})
url += newParam.join('&')
}
return url
} }
} }

View File

@ -50,7 +50,8 @@ export default {
onDrag: this.defaultCallback.bind(this, 'onDrag'), onDrag: this.defaultCallback.bind(this, 'onDrag'),
beforeDrop: this.defaultCallback.bind(this, 'beforeDrop'), beforeDrop: this.defaultCallback.bind(this, 'beforeDrop'),
onDrop: this.defaultCallback.bind(this, 'onDrop'), onDrop: this.defaultCallback.bind(this, 'onDrop'),
beforeAsync: this.defaultCallback.bind(this, 'beforeAsync') beforeAsync: this.defaultCallback.bind(this, 'beforeAsync'),
refresh: this.defaultCallback.bind(this, 'refresh')
} }
} }
} }