<!-- component标签可以变换组件 -->
<template>
	<view>
		<component ref="comptRef" :is="asyncComponent" :formData="formData" :history="history" :activeKey="activeKey"
			v-if="asyncComponent" @getStampSuc="getStampSuccess"></component>
		<view v-else>该模块暂未建立审批页面！</view>
	</view>
	<wd-tabbar v-if="false">
		<wd-tabbar-item></wd-tabbar-item>
	</wd-tabbar>
	<wd-pagination v-if="false"/>
</template>
<script setup>
	const compName = ref('');
	const asyncComponent = ref(null);
	const modules = import.meta.glob('/src/pages-bpm/**/*.vue');
	const comptRef = ref();


	defineOptions({
		name: 'DynamicLink',
		options: {
			styleIsolation: 'shared',
		},
	})
	const props = defineProps({
		path: {
			type: String,
			default: ""
		},
		history: {
			type: String,
			default: ""
		},
		activeKey: {
			type: String,
			default: ""
		},
		formData: {
			type: Object,
			default: () => {},
		}

	})
	// 监听 option 变化
	watch(() => props.path, (newVal) => {
		if (newVal) {
			compName.value = newVal;
		}
		//动态加载页面
		const comp = modules[`/src/pages-bpm/${compName.value}.vue`]
		if (!comp) {
			console.log(newVal)
			if (newVal.indexOf('index') == -1) {
				compName.value = newVal + '/index'
				console.log(compName.value)
				const comp2 = modules[`/src/pages-bpm/${compName.value}.vue`]
				comp2().then((myModule) => {
					asyncComponent.value = myModule.default
				}).catch(() => {

				})
			}
		} else {
			comp().then((myModule) => {
				asyncComponent.value = myModule.default
			}).catch(() => {

			})
		}

	}, {
		deep: true,
		// #ifdef MP-WEIXIN
		immediate: true
		// #endif
	});

	const signValidator = () => {
		console.log(comptRef.value)
		//这里进行电子签章验证
		if (!comptRef.value.signValidator) {
			console.log(123124)
			return null;
		} else {
			console.log(12)
			return comptRef.value.signValidator()
		}
	}

	const getStampSuccess = (val) => {
		// this.$emit('getStampSuc', val)
		// //在<component>标签动态组件使用vuex，没有保存成功。
		// //所以先传出来再试一下
		// this.$store.commit("cache/setEsignTags", { 
		//   esignTag: val
		// });
	}

	defineExpose({ //暴露方法
		signValidator
	})
</script>

<style lang="scss" scoped>

</style>