parent
4f5766117d
commit
e40c5352a1
4 changed files with 45 additions and 105 deletions
|
@ -19,11 +19,9 @@
|
|||
</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',
|
||||
|
@ -46,7 +44,7 @@
|
|||
return {
|
||||
renderType: '',
|
||||
uid: -1,
|
||||
context: this.$parent.$parent.currentContext
|
||||
context: this.$parent.$parent.$parent.currentContext
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -70,76 +68,11 @@
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
compile () {
|
||||
if (this.column.render && this.renderType === '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);
|
||||
} else {
|
||||
const $parent = this.context;
|
||||
const template = this.column.render(this.row, this.column, this.index);
|
||||
const cell = document.createElement('div');
|
||||
cell.innerHTML = template;
|
||||
|
||||
this.$el.innerHTML = '';
|
||||
let methods = {};
|
||||
Object.keys($parent).forEach(key => {
|
||||
const func = $parent[key];
|
||||
if (typeof(func) === 'function' && (func.name === 'boundFn' || func.name === 'n')) {
|
||||
methods[key] = func;
|
||||
}
|
||||
});
|
||||
const res = Vue.compile(cell.outerHTML);
|
||||
// 获取父组件使用的局部 component
|
||||
const components = {};
|
||||
Object.getOwnPropertyNames($parent.$options.components).forEach(item => {
|
||||
components[item] = $parent.$options.components[item];
|
||||
});
|
||||
|
||||
const component = new Vue({
|
||||
render: res.render,
|
||||
staticRenderFns: res.staticRenderFns,
|
||||
methods: methods,
|
||||
data () {
|
||||
return $parent._data;
|
||||
},
|
||||
components: components
|
||||
});
|
||||
if ($parent.$store != undefined) {
|
||||
component.$store = $parent.$store;
|
||||
}
|
||||
component.row = this.row;
|
||||
component.column = this.column;
|
||||
|
||||
const Cell = component.$mount();
|
||||
this.$refs.cell.appendChild(Cell.$el);
|
||||
}
|
||||
}
|
||||
},
|
||||
destroy () {
|
||||
|
||||
},
|
||||
toggleSelect () {
|
||||
this.$parent.$parent.toggleSelect(this.index);
|
||||
this.$parent.$parent.$parent.toggleSelect(this.index);
|
||||
},
|
||||
toggleExpand () {
|
||||
this.$parent.$parent.toggleExpand(this.index);
|
||||
this.$parent.$parent.$parent.toggleExpand(this.index);
|
||||
}
|
||||
},
|
||||
created () {
|
||||
|
@ -154,20 +87,6 @@
|
|||
} else {
|
||||
this.renderType = 'normal';
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.$nextTick(() => {
|
||||
this.compile();
|
||||
});
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.destroy();
|
||||
},
|
||||
watch: {
|
||||
naturalIndex () {
|
||||
this.destroy();
|
||||
this.compile();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue