format[treeTable]: format code
This commit is contained in:
@@ -1,39 +1,34 @@
|
||||
<template>
|
||||
<el-table :data="formatData" :row-style="showRow">
|
||||
<el-table-column v-if="columns.length===0" width="150">
|
||||
<template slot-scope="scope">
|
||||
<span v-for="space in scope.row._level"
|
||||
class="ms-tree-space"></span>
|
||||
<span class="tree-ctrl" v-if="iconShow(0,scope.row)"
|
||||
@click="toggleExpanded(scope.$index)">
|
||||
<i v-if="!scope.row._expanded" class="el-icon-plus"></i>
|
||||
<i v-else class="el-icon-minus"></i>
|
||||
</span>
|
||||
{{scope.$index}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else v-for="(column, index) in columns" :key="column.value"
|
||||
:label="column.text" :width="column.width">
|
||||
<template slot-scope="scope">
|
||||
<span v-if="index === 0" v-for="space in scope.row._level"
|
||||
class="ms-tree-space"></span>
|
||||
<span class="tree-ctrl" v-if="iconShow(index,scope.row)"
|
||||
@click="toggleExpanded(scope.$index)">
|
||||
<i v-if="!scope.row._expanded" class="el-icon-plus"></i>
|
||||
<i v-else class="el-icon-minus"></i>
|
||||
</span>
|
||||
{{scope.row[column.value]}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<slot></slot>
|
||||
</el-table>
|
||||
<el-table :data="formatData" :row-style="showRow">
|
||||
<el-table-column v-if="columns.length===0" width="150">
|
||||
<template slot-scope="scope">
|
||||
<span v-for="space in scope.row._level" class="ms-tree-space" :key="space"></span>
|
||||
<span class="tree-ctrl" v-if="iconShow(0,scope.row)" @click="toggleExpanded(scope.$index)">
|
||||
<i v-if="!scope.row._expanded" class="el-icon-plus"></i>
|
||||
<i v-else class="el-icon-minus"></i>
|
||||
</span>
|
||||
{{scope.$index}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else v-for="(column, index) in columns" :key="column.value" :label="column.text" :width="column.width">
|
||||
<template slot-scope="scope">
|
||||
<span v-if="index === 0" v-for="space in scope.row._level" class="ms-tree-space" :key="space"></span>
|
||||
<span class="tree-ctrl" v-if="iconShow(index,scope.row)" @click="toggleExpanded(scope.$index)">
|
||||
<i v-if="!scope.row._expanded" class="el-icon-plus"></i>
|
||||
<i v-else class="el-icon-minus"></i>
|
||||
</span>
|
||||
{{scope.row[column.value]}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<slot></slot>
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
Auth: Lei.j1ang
|
||||
Created: 2018/1/19-13:59
|
||||
*/
|
||||
/**
|
||||
Auth: Lei.j1ang
|
||||
Created: 2018/1/19-13:59
|
||||
*/
|
||||
import treeToArray from './eval'
|
||||
export default {
|
||||
name: 'treeTable',
|
||||
|
@@ -1,39 +1,43 @@
|
||||
## 写在前面
|
||||
此组件仅提供一个创建TreeTable的解决方案
|
||||
|
||||
##prop说明
|
||||
###data
|
||||
必输
|
||||
|
||||
###data
|
||||
**必填**
|
||||
|
||||
原始数据,要求是一个数组或者对象
|
||||
```javascript
|
||||
[{
|
||||
key1:value1,
|
||||
key2:value2,
|
||||
children:[{
|
||||
key1:value1
|
||||
},{
|
||||
key1:value1
|
||||
[{
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
children: [{
|
||||
key1: value1
|
||||
},
|
||||
{
|
||||
key1: value1
|
||||
}]
|
||||
},
|
||||
{
|
||||
key1: value1
|
||||
}]
|
||||
},{
|
||||
key1:value1
|
||||
}]
|
||||
```
|
||||
或者
|
||||
```javascript
|
||||
{
|
||||
key1:value1,
|
||||
key2:value2,
|
||||
children:[{
|
||||
key1:value1
|
||||
},{
|
||||
key1:value1
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
children: [{
|
||||
key1: value1
|
||||
},
|
||||
{
|
||||
key1: value1
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
###columns
|
||||
列属性,要求是一个数组
|
||||
|
||||
|
||||
1. text: 显示在表头
|
||||
2. value: 对应data的key,treeTable将显示相应的value
|
||||
3. width: 每列的宽度,为一个数字
|
||||
@@ -49,25 +53,26 @@
|
||||
width:number
|
||||
}]
|
||||
```
|
||||
|
||||
|
||||
### expandAll
|
||||
是否默认全部展开,boolean值,默认为false
|
||||
|
||||
### evalFunc
|
||||
解析函数,function,非必须
|
||||
|
||||
如果不提供,将使用默认的evalFunc
|
||||
|
||||
|
||||
如果不提供,将使用默认的evalFunc
|
||||
|
||||
如果提供了evalFunc,那么会用提供的evalFunc去解析data,并返回treeTable渲染所需要的值。如何编写一个evalFunc,请参考此目录下的*eval.js*
|
||||
|
||||
|
||||
### evalArgs
|
||||
解析函数的参数,是一个数组
|
||||
|
||||
|
||||
**请注意,自定义的解析函数参数第一个为this.data,你不需要在evalArgs填写。**
|
||||
|
||||
|
||||
如你的解析函数需要的参数为`(this.data,1,2,3,4)`,那么你只需要将`[1,2,3,4]`赋值给`evalArgs`就可以了
|
||||
|
||||
## slot
|
||||
请参考`customTreeTable`
|
||||
|
||||
|
||||
## 其他
|
||||
如果有其他的需求,请参考[el-table](http://element-cn.eleme.io/#/en-US/component/table)的api自行修改index.vue
|
||||
如果有其他的需求,请参考[el-table](http://element-cn.eleme.io/#/en-US/component/table)的api自行修改index.vue
|
||||
|
Reference in New Issue
Block a user