<template>
	<fs-page>
		<fs-crud ref="crudRef" v-bind="crudBinding" />
		<!-- <WorkflowDialog v-model:visible="dialogVisible" :editData="editData" :mode="dialogModesss" @success="onDialogSuccess" /> -->
	</fs-page>
</template>
<script  lang="ts" setup>
import { ref, onMounted, onBeforeUnmount ,onActivated,onDeactivated} from 'vue';
import { useFs } from '@fast-crud/fast-crud';
import { createCrudOptions } from './curd';
import WorkflowDialog from './WorkflowDialog/index.vue';

const { crudBinding, crudRef, crudExpose, crudOptions, resetCrudOptions } = useFs({ createCrudOptions });
// const dialogVisible = ref(false);
// const editData = ref(null);
// const dialogModesss = ref<'view' | 'edit' | 'add'>('add');


// function onAdd() {
// 	editData.value = null;
// 	dialogModesss.value = 'add';
// 	dialogVisible.value = true;
// }
function onDialogSuccess() {
	dialogVisible.value = false;
	crudExpose.doRefresh();
}

// function onView(e: Event) {
// 	const ce = e as CustomEvent;
// 	editData.value = ce.detail;
// 	dialogModesss.value = 'view';
// 	dialogVisible.value = true;
// }
// function onEdit(e: Event) {
// 	const ce = e as CustomEvent;
// 	editData.value = ce.detail;
// 	dialogModesss.value = 'edit';
// 	dialogVisible.value = true;
// }





// 1. 激活时：刷新列表 + 绑定事件
// function activate() {
//   crudExpose.doRefresh();
//   console.log("绑定")
//   window.addEventListener('workflow-add', onAdd);
//   window.addEventListener('workflow-view', onView);
//   window.addEventListener('workflow-edit', onEdit);
// }

// // 2. 停用/销毁时：解绑事件
// function deactivate() {
// 	console.log("解绑")
//   window.removeEventListener('workflow-add', onAdd);
//   window.removeEventListener('workflow-view', onView);
//   window.removeEventListener('workflow-edit', onEdit);
//   console.log("解绑完成")
// }

// 3. 注册钩子
// onActivated(activate);
// onDeactivated(deactivate);

// 4. 首次挂载也要激活一次
// onMounted(activate);

// // // 5. 组件真正销毁前再解绑，额外保险
// onBeforeUnmount(deactivate);

// onActivated(activate);
// onDeactivated(deactivate);

// onMounted(() => {
// 	crudExpose.doRefresh();
// 	console.log("流程页面首次！！");
// 	window.addEventListener('workflow-add',onAdd);
// 	window.addEventListener('workflow-view', onView);
// 	window.addEventListener('workflow-edit', onEdit);
// });
// onBeforeUnmount(() => {
// 	console.log("流程页面离开！！");
// 	window.removeEventListener('workflow-add',onAdd);
// 	window.removeEventListener('workflow-view', onView);
// 	window.removeEventListener('workflow-edit', onEdit);
// });



onMounted(async () => {
	// 设置列权限
	// const newOptions = await handleColumnPermission(GetPermission, crudOptions);
	//重置crudBinding
	// resetCrudOptions(newOptions);
	// 刷新
	crudExpose.doRefresh();
});

</script>

<style  scoped>


</style>