|
|
@@ -29,32 +29,24 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
init () {
|
|
|
- const rootOption = {
|
|
|
- checked: false,
|
|
|
- indeterminate: false
|
|
|
- }
|
|
|
- rootOption.children = this.groups.map(this.transfromGroup)
|
|
|
- rootOption.disabled = !rootOption.children.some(({ disabled }) => !disabled)
|
|
|
+ const rootOption = this.createNode()
|
|
|
+ this.setNodes(rootOption, this.groups.map(item => this.transfromGroup(item, rootOption)))
|
|
|
this.defaultExpand = rootOption.children.length <= 1
|
|
|
this.rootOption = rootOption
|
|
|
},
|
|
|
- transfromGroup ({ id, name, children }) {
|
|
|
- const list = children.map(this.transformDevice).sort(this.sort)
|
|
|
- const group = {
|
|
|
- id, name,
|
|
|
- checked: false,
|
|
|
- indeterminate: false,
|
|
|
- disabled: !list.some(({ disabled }) => !disabled),
|
|
|
- children: list
|
|
|
- }
|
|
|
+ transfromGroup ({ id, name, children }, parent) {
|
|
|
+ const group = this.createNode({
|
|
|
+ id,
|
|
|
+ name
|
|
|
+ }, parent)
|
|
|
+ this.setNodes(group, children.map(item => this.transformDevice(item, group)).sort(this.sort))
|
|
|
return group
|
|
|
},
|
|
|
- transformDevice ({ id, name, productId, lastOnline, onlineStatus }) {
|
|
|
- return {
|
|
|
+ transformDevice ({ id, name, productId, lastOnline, onlineStatus }, parent) {
|
|
|
+ return this.createLeafNode(parent, {
|
|
|
id, name, productId, lastOnline,
|
|
|
- checked: false,
|
|
|
disabled: onlineStatus !== 1
|
|
|
- }
|
|
|
+ })
|
|
|
},
|
|
|
sort (a, b) {
|
|
|
if (a.disabled === b.disabled) {
|