admin-vben5/apps/web-antd/src/views/workflow/components/flow-designer.vue

53 lines
1.4 KiB
Vue
Raw Normal View History

2024-12-11 21:33:59 +08:00
<script setup lang="ts">
2024-12-17 08:15:08 +08:00
import { onMounted, onUnmounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
2024-12-11 21:33:59 +08:00
2024-12-17 08:15:08 +08:00
import { useAppConfig, useTabs } from '@vben/hooks';
2024-12-11 21:33:59 +08:00
import { stringify } from '@vben/request';
import { useAccessStore } from '@vben/stores';
defineOptions({ name: 'FlowDesigner' });
const route = useRoute();
const definitionId = route.query.definitionId as string;
const disabled = route.query.disabled === 'true';
2024-12-17 08:09:47 +08:00
const { clientId } = useAppConfig(import.meta.env, import.meta.env.PROD);
2024-12-11 21:33:59 +08:00
const accessStore = useAccessStore();
const params = {
Authorization: `Bearer ${accessStore.accessToken}`,
id: definitionId,
2024-12-17 08:09:47 +08:00
clientId,
2024-12-11 21:33:59 +08:00
disabled,
};
2024-12-17 08:15:08 +08:00
/**
* iframe设计器的地址
*/
2024-12-11 21:33:59 +08:00
const url = `${import.meta.env.VITE_GLOB_API_URL}/warm-flow-ui/index.html?${stringify(params)}`;
2024-12-17 08:15:08 +08:00
const { closeCurrentTab } = useTabs();
const router = useRouter();
function messageHandler(event: MessageEvent) {
switch (event.data.method) {
case 'close': {
// 关闭当前tab
closeCurrentTab();
// 跳转到流程定义列表
router.push('/workflow/processDefinition');
break;
}
}
}
// iframe监听组件内设计器保存事件
onMounted(() => window.addEventListener('message', messageHandler));
onUnmounted(() => window.removeEventListener('message', messageHandler));
2024-12-11 21:33:59 +08:00
</script>
<template>
<iframe :src="url" class="size-full"></iframe>
</template>