forked from VisActor/VTable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseCellRender.ts
33 lines (30 loc) · 991 Bytes
/
useCellRender.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { Ref } from 'vue';
import { getCurrentInstance, watchEffect } from 'vue';
import { VTableVueAttributePlugin } from '../components/custom/vtable-vue-attribute-plugin';
import { isArray } from '@visactor/vutils';
/**
* 自定义单元格渲染器
* @param props
* @param tableRef
*/
export function useCellRender(props: any, tableRef: Ref) {
/** 当前实例 */
const instance = getCurrentInstance();
/** 自定义 dom 开关 */
const createReactContainer = props?.options?.customConfig?.createReactContainer;
watchEffect(() => {
if (!createReactContainer) {
return;
}
const pluginService = tableRef.value?.scenegraph?.stage?.pluginService;
if (!pluginService) {
return;
}
const exist = pluginService.findPluginsByName('VTableVueAttributePlugin');
if (isArray(exist) && !!exist.length) {
return;
}
const plugin = new VTableVueAttributePlugin(instance?.appContext);
pluginService.register(plugin);
});
}