|
|
|
|
@ -1,25 +1,10 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div class="flow-app-container">
|
|
|
|
|
<micro-app
|
|
|
|
|
v-if="baseUrl"
|
|
|
|
|
name="flow-app"
|
|
|
|
|
:url="baseUrl"
|
|
|
|
|
iframe
|
|
|
|
|
style="display: block; width: 100%; height: 100%"
|
|
|
|
|
@created="onCreated"
|
|
|
|
|
@beforemount="onBeforeMount"
|
|
|
|
|
@mounted="onMountedHandler"
|
|
|
|
|
@error="onError"
|
|
|
|
|
/>
|
|
|
|
|
<div v-else class="loading-container">
|
|
|
|
|
<el-icon class="is-loading"><Loading /></el-icon>
|
|
|
|
|
<span>加载中...</span>
|
|
|
|
|
</div>
|
|
|
|
|
<micro-app name="flow-app" :url="baseUrl" style="display: block; width: 100%;height:100%"/>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { Loading } from '@element-plus/icons-vue';
|
|
|
|
|
import {useRoute} from 'vue-router';
|
|
|
|
|
import {useMicroApptore} from '@/stores/modules/micro-app';
|
|
|
|
|
import {ElMessage} from 'element-plus';
|
|
|
|
|
@ -27,85 +12,40 @@ import microAppX from '@micro-zoe/micro-app';
|
|
|
|
|
import {useUserStore} from '@/stores/modules/user';
|
|
|
|
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
const { getAppDetail } = useMicroApptore();
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const baseUrl = ref('');
|
|
|
|
|
|
|
|
|
|
const postData = reactive({
|
|
|
|
|
userStoreData: userStore.$state
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// micro-app 生命周期事件
|
|
|
|
|
const onCreated = () => {
|
|
|
|
|
console.log('[flow-app] created');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onBeforeMount = () => {
|
|
|
|
|
console.log('[flow-app] beforemount');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onMountedHandler = () => {
|
|
|
|
|
console.log('[flow-app] mounted');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onError = (e: CustomEvent) => {
|
|
|
|
|
console.error('[flow-app] error:', e.detail);
|
|
|
|
|
ElMessage.error('子应用加载失败');
|
|
|
|
|
};
|
|
|
|
|
const {getAppDetail} = useMicroApptore();
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const baseUrl = ref('');
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
const agentId = route.params.id;
|
|
|
|
|
console.log('[flow-app] agentId:', agentId);
|
|
|
|
|
|
|
|
|
|
const commonUrl = `agent/${route.params.id}`;
|
|
|
|
|
if (import.meta.env.VITE_USER_NODE_ENV === 'production') {
|
|
|
|
|
const appUrl = getAppDetail('flow-app')?.appUrl;
|
|
|
|
|
const appUrl = getAppDetail('flow-app')?.appUrl; // 提取线上地址
|
|
|
|
|
|
|
|
|
|
if (!appUrl) {
|
|
|
|
|
ElMessage.warning('微应用路径获取失败');
|
|
|
|
|
return;
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: '微应用路径获取失败'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
baseUrl.value = appUrl + 'agent/' + agentId;
|
|
|
|
|
microAppX.setData('flow-app', {
|
|
|
|
|
...postData,
|
|
|
|
|
server_ip: location.origin,
|
|
|
|
|
isTemplate: route.query.isTemplate,
|
|
|
|
|
agentId
|
|
|
|
|
});
|
|
|
|
|
// 线上环境
|
|
|
|
|
baseUrl.value = appUrl ? appUrl + commonUrl : '';
|
|
|
|
|
microAppX.setData('flow-app', {...postData, server_ip: location.origin, isTemplate: route.query.isTemplate}); // 指定后端服务地址
|
|
|
|
|
} else {
|
|
|
|
|
// 开发环境:通过基座代理访问子应用
|
|
|
|
|
baseUrl.value = '/flowapp/agent/' + agentId;
|
|
|
|
|
console.log('[flow-app] baseUrl:', baseUrl.value);
|
|
|
|
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
microAppX.setData('flow-app', {
|
|
|
|
|
...postData,
|
|
|
|
|
server_ip: undefined,
|
|
|
|
|
isTemplate: route.query.isTemplate,
|
|
|
|
|
agentId
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
// 本地测试环境
|
|
|
|
|
baseUrl.value = 'http://localhost:9222/flowapp/' + commonUrl;
|
|
|
|
|
microAppX.setData('flow-app', {...postData, server_ip: undefined, isTemplate: route.query.isTemplate}); // 使用默认
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
|
|
|
|
.flow-app-container {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.loading-container {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
height: 100%;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
color: #909399;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|