Merge branch '2.0' of https://github.com/iview/iview into iview-2.0
This commit is contained in:
commit
e9287a6b87
9 changed files with 84 additions and 126 deletions
10
src/components/base/render.js
Normal file
10
src/components/base/render.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
export default {
|
||||
name: 'RenderCell',
|
||||
functional: true,
|
||||
props: {
|
||||
render: Function
|
||||
},
|
||||
render: (h, ctx) => {
|
||||
return ctx.props.render(h);
|
||||
}
|
||||
};
|
|
@ -1,30 +0,0 @@
|
|||
<template>
|
||||
<div ref="cell"></div>
|
||||
</template>
|
||||
<script>
|
||||
import Vue from 'vue';
|
||||
export default {
|
||||
name: 'RenderCell',
|
||||
props: {
|
||||
render: Function
|
||||
},
|
||||
methods: {
|
||||
compile () {
|
||||
if (this.render) {
|
||||
this.$el.innerHTML = '';
|
||||
const component = new Vue({
|
||||
functional: true,
|
||||
render: (h) => {
|
||||
return this.render(h);
|
||||
}
|
||||
});
|
||||
const Cell = component.$mount();
|
||||
this.$refs.cell.appendChild(Cell.$el);
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.compile();
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -10,17 +10,24 @@
|
|||
<Icon type="ios-arrow-right"></Icon>
|
||||
</div>
|
||||
</template>
|
||||
<Cell
|
||||
v-if="renderType === 'render'"
|
||||
:row="row"
|
||||
:column="column"
|
||||
:index="index"
|
||||
:render="column.render"></Cell>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import Vue from 'vue';
|
||||
import Cell from './expand';
|
||||
import Icon from '../icon/icon.vue';
|
||||
import Checkbox from '../checkbox/checkbox.vue';
|
||||
import { findComponentUpward } from '../../utils/assist';
|
||||
|
||||
export default {
|
||||
name: 'TableCell',
|
||||
components: { Icon, Checkbox },
|
||||
components: { Icon, Checkbox, Cell },
|
||||
props: {
|
||||
prefixCls: String,
|
||||
row: Object,
|
||||
|
@ -65,25 +72,25 @@
|
|||
methods: {
|
||||
compile () {
|
||||
if (this.column.render && this.renderType === 'render') {
|
||||
// 兼容真 Render,后期废弃旧用法
|
||||
// todo 兼容真 Render,后期废弃旧用法
|
||||
let isRealRender = true;
|
||||
const Table = findComponentUpward(this, 'Table');
|
||||
if (Table.context) isRealRender = false;
|
||||
|
||||
if (isRealRender) {
|
||||
this.$el.innerHTML = '';
|
||||
const component = new Vue({
|
||||
functional: true,
|
||||
render: (h) => {
|
||||
return this.column.render(h, {
|
||||
row: this.row,
|
||||
column: this.column,
|
||||
index: this.index
|
||||
});
|
||||
}
|
||||
});
|
||||
const Cell = component.$mount();
|
||||
this.$refs.cell.appendChild(Cell.$el);
|
||||
// this.$el.innerHTML = '';
|
||||
// const component = new Vue({
|
||||
// functional: true,
|
||||
// render: (h) => {
|
||||
// return this.column.render(h, {
|
||||
// row: this.row,
|
||||
// column: this.column,
|
||||
// index: this.index
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// const Cell = component.$mount();
|
||||
// this.$refs.cell.appendChild(Cell.$el);
|
||||
} else {
|
||||
const $parent = this.context;
|
||||
const template = this.column.render(this.row, this.column, this.index);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
export default {
|
||||
name: 'TableExpand',
|
||||
functional: true,
|
||||
|
@ -6,8 +5,17 @@ export default {
|
|||
row: Object,
|
||||
render: Function,
|
||||
index: Number,
|
||||
column: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
render: (h, ctx) => {
|
||||
return ctx.props.render(h, {row: ctx.props.row, index: ctx.props.index});
|
||||
const params = {
|
||||
row: ctx.props.row,
|
||||
index: ctx.props.index
|
||||
};
|
||||
if (ctx.props.column) params.column = ctx.props.column;
|
||||
return ctx.props.render(h, params);
|
||||
}
|
||||
};
|
|
@ -6,7 +6,6 @@
|
|||
<tbody :class="[prefixCls + '-tbody']">
|
||||
<template v-for="(row, index) in data">
|
||||
<tr
|
||||
:key="row"
|
||||
:class="rowClasses(row._index)"
|
||||
@mouseenter.stop="handleMouseIn(row._index)"
|
||||
@mouseleave.stop="handleMouseOut(row._index)"
|
||||
|
@ -17,6 +16,7 @@
|
|||
:fixed="fixed"
|
||||
:prefix-cls="prefixCls"
|
||||
:row="row"
|
||||
:key="row"
|
||||
:column="column"
|
||||
:natural-index="index"
|
||||
:index="row._index"
|
||||
|
@ -28,7 +28,7 @@
|
|||
</tr>
|
||||
<tr v-if="rowExpanded(row._index)">
|
||||
<td :colspan="columns.length" :class="prefixCls + '-expanded-cell'">
|
||||
<Expand :row="row" :render="expandRender" :index="row._index"></Expand>
|
||||
<Expand :key="row" :row="row" :render="expandRender" :index="row._index"></Expand>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
</template>
|
||||
<script>
|
||||
import Icon from '../icon/icon.vue';
|
||||
import Render from '../base/render.vue';
|
||||
import Render from '../base/render';
|
||||
import { oneOf, getStyle } from '../../utils/assist';
|
||||
import Emitter from '../../mixins/emitter';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue