1.fix bug (#431)

* 1.fix bug
2.update treeTable readme
3.update args name in treetable/eval.js

* 1.treeTable animate
This commit is contained in:
Zenon 2018-01-30 09:58:25 +08:00 committed by 花裤衩
parent d754eae662
commit dc9e27e4b1
5 changed files with 24 additions and 13 deletions

View file

@ -4,11 +4,11 @@
*/ */
'use strict' 'use strict'
import Vue from 'vue' import Vue from 'vue'
export default function treeToArray(data, expandedAll, parent = null, level = null) { export default function treeToArray(data, expandAll, parent = null, level = null) {
let tmp = [] let tmp = []
Array.from(data).forEach(function(record) { Array.from(data).forEach(function(record) {
if (record._expanded === undefined) { if (record._expanded === undefined) {
Vue.set(record, '_expanded', expandedAll) Vue.set(record, '_expanded', expandAll)
} }
let _level = 1 let _level = 1
if (level !== undefined && level !== null) { if (level !== undefined && level !== null) {
@ -21,7 +21,7 @@ export default function treeToArray(data, expandedAll, parent = null, level = nu
} }
tmp.push(record) tmp.push(record)
if (record.children && record.children.length > 0) { if (record.children && record.children.length > 0) {
const children = treeToArray(record.children, expandedAll, record, _level) const children = treeToArray(record.children, expandAll, record, _level)
tmp = tmp.concat(children) tmp = tmp.concat(children)
} }
}) })

View file

@ -58,7 +58,7 @@ export default {
tmp = this.data tmp = this.data
} }
const func = this.evalFunc || treeToArray const func = this.evalFunc || treeToArray
const args = this.evalArgs ? Array.concat([tmp], this.evalArgs) : [tmp, this.expandAll] const args = this.evalArgs ? Array.concat([tmp, this.expandAll], this.evalArgs) : [tmp, this.expandAll]
return func.apply(null, args) return func.apply(null, args)
} }
}, },
@ -66,7 +66,7 @@ export default {
showRow: function(row) { showRow: function(row) {
const show = (row.row.parent ? (row.row.parent._expanded && row.row.parent._show) : true) const show = (row.row.parent ? (row.row.parent._expanded && row.row.parent._show) : true)
row.row._show = show row.row._show = show
return show ? '' : 'display:none;' return show ? 'animation:treeTableShow 1s;-webkit-animation:treeTableShow 1s;' : 'display:none;'
}, },
// //
toggleExpanded: function(trIndex) { toggleExpanded: function(trIndex) {
@ -80,6 +80,16 @@ export default {
} }
} }
</script> </script>
<style rel="stylesheet/css">
@keyframes treeTableShow {
from {opacity: 0;}
to {opacity: 1;}
}
@-webkit-keyframes treeTableShow {
from {opacity: 0;}
to {opacity: 1;}
}
</style>
<style lang="scss" rel="stylesheet/scss" scoped> <style lang="scss" rel="stylesheet/scss" scoped>
$color-blue: #2196F3; $color-blue: #2196F3;

View file

@ -70,11 +70,11 @@
#### evalArgs #### evalArgs
解析函数的参数,是一个数组 解析函数的参数,是一个数组
**请注意自定义的解析函数参数第一个为this.data你不需要在evalArgs填写。** *this.data为需要解析的数据* **请注意自定义的解析函数参数第一个为this.data第二个参数为, this.expandAll,你不需要在evalArgs填写。一定记住这两个参数是强制性的并且位置不可颠倒** *this.data为需要解析的数据this.expandAll为是否默认展开*
如你的解析函数需要的参数为`(this.data,1,2,3,4)`,那么你只需要将`[1,2,3,4]`赋值给`evalArgs`就可以了 如你的解析函数需要的参数为`(this.data, this.expandAll,1,2,3,4)`,那么你只需要将`[1,2,3,4]`赋值给`evalArgs`就可以了
如果你的解析函数参数只有一个`(this.data)`,那么就可以不用填写evalArgs了 如果你的解析函数参数只有`(this.data, this.expandAll)`,那么就可以不用填写evalArgs了
具体可参考[*customEval.js*](https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/example/table/treeTable/customEval.js)的函数参数和[customTreeTable](https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/example/table/treeTable/customTreeTable.vue)的`evalArgs`属性值 具体可参考[*customEval.js*](https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/example/table/treeTable/customEval.js)的函数参数和[customTreeTable](https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/example/table/treeTable/customTreeTable.vue)的`evalArgs`属性值

View file

@ -4,12 +4,12 @@
*/ */
'use strict' 'use strict'
import Vue from 'vue' import Vue from 'vue'
export default function treeToArray(data, parent, level, expandedAll, item) { export default function treeToArray(data, expandAll, parent, level, item) {
const marLTemp = [] const marLTemp = []
let tmp = [] let tmp = []
Array.from(data).forEach(function(record) { Array.from(data).forEach(function(record) {
if (record._expanded === undefined) { if (record._expanded === undefined) {
Vue.set(record, '_expanded', expandedAll) Vue.set(record, '_expanded', expandAll)
} }
let _level = 1 let _level = 1
if (level !== undefined && level !== null) { if (level !== undefined && level !== null) {
@ -40,7 +40,7 @@ export default function treeToArray(data, parent, level, expandedAll, item) {
} }
tmp.push(record) tmp.push(record)
if (record.children && record.children.length > 0) { if (record.children && record.children.length > 0) {
const children = treeToArray(record.children, record, _level, expandedAll, item) const children = treeToArray(record.children, expandAll, record, _level, item)
tmp = tmp.concat(children) tmp = tmp.concat(children)
} }
}) })

View file

@ -5,7 +5,7 @@
<a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/components/TreeTable" target="_blank">Documentation</a> <a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/components/TreeTable" target="_blank">Documentation</a>
</el-tag> </el-tag>
<tree-table :data="data" :evalFunc="func" :evalArgs="args" border> <tree-table :data="data" :evalFunc="func" :evalArgs="args" :expandAll="expandAll" border>
<el-table-column label="事件"> <el-table-column label="事件">
<template slot-scope="scope"> <template slot-scope="scope">
<span style="color:sandybrown">{{scope.row.event}}</span> <span style="color:sandybrown">{{scope.row.event}}</span>
@ -48,6 +48,7 @@ export default {
data() { data() {
return { return {
func: treeToArray, func: treeToArray,
expandAll: false,
data: data:
{ {
id: 1, id: 1,
@ -123,7 +124,7 @@ export default {
} }
] ]
}, },
args: [null, null, true, 'timeLine'] args: [null, null, 'timeLine']
} }
}, },
methods: { methods: {