import { ref, h, reactive, PropType, watch, inject, onMounted, onUnmounted } from 'vue' import { defineVxeComponent } from '../../ui/src/comp' import XEUtils from 'xe-utils' import { VxeUI } from '@vxe-ui/core' import { assembleTabItem, destroyTabItem } from './util' import type { VxeTabPanePropTypes, TabPaneReactData, TabPaneMethods, TabPanePrivateMethods, VxeTabPaneEmits, ValueOf, TabPanePrivateRef, VxeTabPanePrivateComputed, VxeTabPaneConstructor, VxeTabPanePrivateMethods, VxeTabPaneDefines, VxeTabsConstructor, VxeTabsPrivateMethods } from '../../../types' const { createEvent } = VxeUI export default /* define-vxe-component start */ defineVxeComponent({ name: 'VxeTabPane', props: { title: [String, Number] as PropType, name: [String, Number] as PropType, icon: String as PropType, titleWidth: [String, Number] as PropType, titleAlign: [String, Number] as PropType, preload: Boolean as PropType, permissionCode: [String, Number] as PropType }, emits: [] as VxeTabPaneEmits, setup(props, context) { const { slots, emit } = context const xID = XEUtils.uniqueId() const refElem = ref() const $xeTabs = inject<(VxeTabsConstructor & VxeTabsPrivateMethods) | null>('$xeTabs', null) const reactData = reactive({}) const tabConfig = reactive({ id: xID, title: props.title, name: props.name, icon: props.icon, titleWidth: props.titleWidth, titleAlign: props.titleAlign, preload: props.preload, permissionCode: props.permissionCode, slots: slots }) const refMaps: TabPanePrivateRef = { refElem } const computeMaps: VxeTabPanePrivateComputed = {} const $xeTabPane = { xID, props, context, reactData, getRefMaps: () => refMaps, getComputeMaps: () => computeMaps } as unknown as VxeTabPaneConstructor & VxeTabPanePrivateMethods const dispatchEvent = (type: ValueOf, params: Record, evnt: Event | null) => { emit(type, createEvent(evnt, { $tabPane: $xeTabPane }, params)) } const tabPaneMethods: TabPaneMethods = { dispatchEvent } const tabPanePrivateMethods: TabPanePrivateMethods = {} Object.assign($xeTabPane, tabPaneMethods, tabPanePrivateMethods) watch( () => props.title, (val) => { tabConfig.title = val } ) watch( () => props.name, (val) => { tabConfig.name = val } ) watch( () => props.icon, (val) => { tabConfig.icon = val } ) watch( () => props.permissionCode, (val) => { tabConfig.permissionCode = val } ) onMounted(() => { const elem = refElem.value if ($xeTabs && elem) { assembleTabItem($xeTabs, elem, tabConfig) } }) onUnmounted(() => { if ($xeTabs) { destroyTabItem($xeTabs, tabConfig) } }) const renderVN = () => { return h( 'div', { ref: refElem }, [] ) } $xeTabPane.renderVN = renderVN return $xeTabPane }, render() { return this.renderVN() } }) /* define-vxe-component end */