2025-07-15 15:16:03 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="chat-wrap">
|
2025-07-16 18:49:28 +08:00
|
|
|
<span class="" @click="goChatIndex"> <icon-left /> 返回空间 </span>
|
|
|
|
|
|
2025-07-15 15:16:03 +08:00
|
|
|
<div class="chat-contain">
|
|
|
|
|
<a-layout>
|
|
|
|
|
<a-layout>
|
|
|
|
|
<a-layout-sider width="20%">
|
|
|
|
|
<HistoryChat :cozeInfo="cozeInfo" />
|
|
|
|
|
</a-layout-sider>
|
|
|
|
|
<a-layout-sider class="layout-sider" width="17%">
|
2025-07-16 18:49:28 +08:00
|
|
|
<DynamicForm :formFields="formFields" :formData="formData" :loading="loading" @submit="handleSubmit" />
|
2025-07-15 15:16:03 +08:00
|
|
|
</a-layout-sider>
|
|
|
|
|
<a-layout-content ref="contentRef" class="content-container">
|
2025-07-16 18:49:28 +08:00
|
|
|
<a-spin v-if="loading" class="spin-center" tip="生成中。。。" />
|
2025-07-24 19:07:46 +08:00
|
|
|
<div v-if="workFlowRes?.output != ''" class="work-res" v-html="renderedMarkdown"></div>
|
|
|
|
|
<NoData v-else />
|
2025-07-15 15:16:03 +08:00
|
|
|
</a-layout-content>
|
|
|
|
|
</a-layout>
|
|
|
|
|
</a-layout>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, reactive } from 'vue';
|
|
|
|
|
import HistoryChat from './components/historyChat.vue';
|
|
|
|
|
import DynamicForm from './components/DynamicForm.vue';
|
2025-07-24 19:07:46 +08:00
|
|
|
import { executeWorkFlow, getWorkFlowInfo } from '@/api/all/agent';
|
2025-07-16 18:49:28 +08:00
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2025-07-24 19:07:46 +08:00
|
|
|
import { marked } from 'marked';
|
|
|
|
|
import DOMPurify from 'dompurify';
|
2025-07-15 15:16:03 +08:00
|
|
|
|
|
|
|
|
const formFields = ref([]);
|
|
|
|
|
|
|
|
|
|
// 表单数据对象(动态生成初始值)
|
|
|
|
|
const formData = ref({});
|
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const id = route.query.id;
|
|
|
|
|
const query = reactive({
|
|
|
|
|
id: id,
|
|
|
|
|
});
|
2025-07-16 18:49:28 +08:00
|
|
|
const router = useRouter();
|
|
|
|
|
const goChatIndex = async () => {
|
|
|
|
|
router.push({
|
|
|
|
|
path: '/agent/index',
|
|
|
|
|
});
|
|
|
|
|
};
|
2025-07-15 15:16:03 +08:00
|
|
|
const loading = ref(false);
|
|
|
|
|
|
|
|
|
|
const cozeInfo = reactive({
|
2025-07-24 19:07:46 +08:00
|
|
|
name: '',
|
2025-07-15 15:16:03 +08:00
|
|
|
description: '',
|
|
|
|
|
icon_url: '',
|
|
|
|
|
workflow_id: '',
|
|
|
|
|
});
|
|
|
|
|
const getData = async () => {
|
|
|
|
|
const { code, data } = await getWorkFlowInfo(query.id);
|
|
|
|
|
Object.assign(cozeInfo, data.info);
|
|
|
|
|
formFields.value = data.form_config;
|
|
|
|
|
};
|
2025-07-24 19:07:46 +08:00
|
|
|
const workFlowRes = reactive({
|
|
|
|
|
output: '',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 渲染 Markdown 的计算属性
|
|
|
|
|
const renderedMarkdown = computed(() => {
|
|
|
|
|
if (workFlowRes?.output) {
|
|
|
|
|
const rawHtml = marked.parse(workFlowRes.output || '');
|
|
|
|
|
return DOMPurify.sanitize(rawHtml); // 防止 XSS 攻击
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-15 15:16:03 +08:00
|
|
|
// 提交表单
|
|
|
|
|
const handleSubmit = async (formData) => {
|
|
|
|
|
console.log(formData, 'formData');
|
2025-07-16 18:49:28 +08:00
|
|
|
try {
|
|
|
|
|
const param = { form_data: formData, workflow_id: cozeInfo.workflow_id };
|
|
|
|
|
loading.value = true;
|
|
|
|
|
const { code, data } = await executeWorkFlow(param);
|
|
|
|
|
if (code === 200) {
|
|
|
|
|
Object.assign(workFlowRes, data.data);
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error, 'error');
|
2025-07-15 15:16:03 +08:00
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
getData();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
@import './style.scss';
|
|
|
|
|
</style>
|