format[treeTable]: format code

This commit is contained in:
Pan 2018-01-23 15:03:09 +08:00
parent fea6e5feee
commit 3253a91a7e
5 changed files with 100 additions and 103 deletions

View File

@ -1,39 +1,34 @@
<template> <template>
<el-table :data="formatData" :row-style="showRow"> <el-table :data="formatData" :row-style="showRow">
<el-table-column v-if="columns.length===0" width="150"> <el-table-column v-if="columns.length===0" width="150">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-for="space in scope.row._level" <span v-for="space in scope.row._level" class="ms-tree-space" :key="space"></span>
class="ms-tree-space"></span> <span class="tree-ctrl" v-if="iconShow(0,scope.row)" @click="toggleExpanded(scope.$index)">
<span class="tree-ctrl" v-if="iconShow(0,scope.row)" <i v-if="!scope.row._expanded" class="el-icon-plus"></i>
@click="toggleExpanded(scope.$index)"> <i v-else class="el-icon-minus"></i>
<i v-if="!scope.row._expanded" class="el-icon-plus"></i> </span>
<i v-else class="el-icon-minus"></i> {{scope.$index}}
</span> </template>
{{scope.$index}} </el-table-column>
</template> <el-table-column v-else v-for="(column, index) in columns" :key="column.value" :label="column.text" :width="column.width">
</el-table-column> <template slot-scope="scope">
<el-table-column v-else v-for="(column, index) in columns" :key="column.value" <span v-if="index === 0" v-for="space in scope.row._level" class="ms-tree-space" :key="space"></span>
:label="column.text" :width="column.width"> <span class="tree-ctrl" v-if="iconShow(index,scope.row)" @click="toggleExpanded(scope.$index)">
<template slot-scope="scope"> <i v-if="!scope.row._expanded" class="el-icon-plus"></i>
<span v-if="index === 0" v-for="space in scope.row._level" <i v-else class="el-icon-minus"></i>
class="ms-tree-space"></span> </span>
<span class="tree-ctrl" v-if="iconShow(index,scope.row)" {{scope.row[column.value]}}
@click="toggleExpanded(scope.$index)"> </template>
<i v-if="!scope.row._expanded" class="el-icon-plus"></i> </el-table-column>
<i v-else class="el-icon-minus"></i> <slot></slot>
</span> </el-table>
{{scope.row[column.value]}}
</template>
</el-table-column>
<slot></slot>
</el-table>
</template> </template>
<script> <script>
/** /**
Auth: Lei.j1ang Auth: Lei.j1ang
Created: 2018/1/19-13:59 Created: 2018/1/19-13:59
*/ */
import treeToArray from './eval' import treeToArray from './eval'
export default { export default {
name: 'treeTable', name: 'treeTable',

View File

@ -1,32 +1,36 @@
## 写在前面 ## 写在前面
此组件仅提供一个创建TreeTable的解决方案 此组件仅提供一个创建TreeTable的解决方案
##prop说明 ##prop说明
###data ###data
必输 **必填**
原始数据,要求是一个数组或者对象 原始数据,要求是一个数组或者对象
```javascript ```javascript
[{ [{
key1:value1, key1: value1,
key2:value2, key2: value2,
children:[{ children: [{
key1:value1 key1: value1
},{ },
key1:value1 {
key1: value1
}]
},
{
key1: value1
}] }]
},{
key1:value1
}]
``` ```
或者 或者
```javascript ```javascript
{ {
key1:value1, key1: value1,
key2:value2, key2: value2,
children:[{ children: [{
key1:value1 key1: value1
},{ },
key1:value1 {
key1: value1
}] }]
} }
``` ```
@ -66,6 +70,7 @@
**请注意自定义的解析函数参数第一个为this.data你不需要在evalArgs填写。** **请注意自定义的解析函数参数第一个为this.data你不需要在evalArgs填写。**
如你的解析函数需要的参数为`(this.data,1,2,3,4)`,那么你只需要将`[1,2,3,4]`赋值给`evalArgs`就可以了 如你的解析函数需要的参数为`(this.data,1,2,3,4)`,那么你只需要将`[1,2,3,4]`赋值给`evalArgs`就可以了
## slot ## slot
请参考`customTreeTable` 请参考`customTreeTable`

View File

@ -151,9 +151,9 @@ export const asyncRouterMap = [
{ path: 'dynamic-table', component: _import('example/table/dynamicTable/index'), name: 'dynamicTable', meta: { title: 'dynamicTable' }}, { path: 'dynamic-table', component: _import('example/table/dynamicTable/index'), name: 'dynamicTable', meta: { title: 'dynamicTable' }},
{ path: 'drag-table', component: _import('example/table/dragTable'), name: 'dragTable', meta: { title: 'dragTable' }}, { path: 'drag-table', component: _import('example/table/dragTable'), name: 'dragTable', meta: { title: 'dragTable' }},
{ path: 'inline-edit-table', component: _import('example/table/inlineEditTable'), name: 'inlineEditTable', meta: { title: 'inlineEditTable' }}, { path: 'inline-edit-table', component: _import('example/table/inlineEditTable'), name: 'inlineEditTable', meta: { title: 'inlineEditTable' }},
{ path: 'complex-table', component: _import('example/table/complexTable'), name: 'complexTable', meta: { title: 'complexTable' }}, { path: 'tree-table', component: _import('example/table/treeTable/treeTable'), name: 'treeTable', meta: { title: 'treeTable' }},
{ path: 'treeTable', component: _import('example/table/treeTable/treeTable'), name: 'treeTable', meta: { title: 'treeTable' }}, { path: 'custom-tree-table', component: _import('example/table/treeTable/customTreeTable'), name: 'customTreeTable', meta: { title: 'customTreeTable' }},
{ path: 'customTreeTable', component: _import('example/table/treeTable/customTreeTable'), name: 'customTreeTable', meta: { title: 'customTreeTable' }} { path: 'complex-table', component: _import('example/table/complexTable'), name: 'complexTable', meta: { title: 'complexTable' }}
] ]
}, },
{ path: 'tab/index', icon: 'tab', component: _import('example/tab/index'), name: 'tab', meta: { title: 'tab' }} { path: 'tab/index', icon: 'tab', component: _import('example/tab/index'), name: 'tab', meta: { title: 'tab' }}

View File

@ -1,39 +1,40 @@
<template> <template>
<tree-table :data="data" :evalFunc="func" :evalArgs="args"> <tree-table :data="data" :evalFunc="func" :evalArgs="args">
<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>
<el-tag>{{scope.row.timeLine+'ms'}}</el-tag> <el-tag>{{scope.row.timeLine+'ms'}}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="时间线"> <el-table-column label="时间线">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tooltip effect="dark" :content="scope.row.timeLine+'ms'" placement="left"> <el-tooltip effect="dark" :content="scope.row.timeLine+'ms'" placement="left">
<div class="processContainer"> <div class="processContainer">
<div class="process" :style= "{ width:scope.row._width * 500+'px', <div class="process" :style="{ width:scope.row._width * 500+'px',
background:scope.row._width>0.5?'rgba(233,0,0,.5)':'rgba(0,0,233,0.5)', background:scope.row._width>0.5?'rgba(233,0,0,.5)':'rgba(0,0,233,0.5)',
marginLeft:scope.row._marginLeft * 500+'px' }"> marginLeft:scope.row._marginLeft * 500+'px' }">
<span style="display:inline-block"></span> <span style="display:inline-block"></span>
</div>
</div> </div>
</el-tooltip> </div>
</template> </el-tooltip>
</el-table-column> </template>
<el-table-column label="操作" width="200"> </el-table-column>
<template slot-scope="scope"> <el-table-column label="操作" width="200">
<el-button type="text" @click="message(scope.row)">点击</el-button> <template slot-scope="scope">
</template> <el-button type="text" @click="message(scope.row)">点击</el-button>
</el-table-column> </template>
</tree-table> </el-table-column>
</tree-table>
</template> </template>
<script> <script>
/** /**
Auth: Lei.j1ang Auth: Lei.j1ang
Created: 2018/1/19-14:54 Created: 2018/1/19-14:54
*/ */
import treeTable from '@/components/TreeTable' import treeTable from '@/components/TreeTable'
import treeToArray from './customEval' import treeToArray from './customEval'
export default { export default {
name: 'tree', name: 'tree',
components: { treeTable }, components: { treeTable },
@ -125,7 +126,3 @@ export default {
} }
} }
</script> </script>
<style scoped>
</style>

View File

@ -1,14 +1,14 @@
<template> <template>
<tree-table :data="data" :columns="columns"> <tree-table :data="data" :columns="columns"></tree-table>
</tree-table>
</template> </template>
<script> <script>
/** /**
Auth: Lei.j1ang Auth: Lei.j1ang
Created: 2018/1/19-14:54 Created: 2018/1/19-14:54
*/ */
import treeTable from '@/components/TreeTable' import treeTable from '@/components/TreeTable'
export default { export default {
name: 'tree', name: 'tree',
components: { treeTable }, components: { treeTable },