Some checks failed
Lint Code / Lint Code (push) Failing after 17m14s
- 将项目选择面板改为下拉选择器,简化UI交互 - 新增 `setDraftByProjectId` 和 `applyProjectSelection` 函数统一处理项目切换 - 删除分散的OpenAPI JSON文件,合并为统一的日报分析查询接口定义 - 在 `project.ts` 中添加 `getDailyReportWithAnalysisReports` API及相关类型定义 - 修复ChatGPT组件样式空格格式问题
144 lines
4.0 KiB
Vue
144 lines
4.0 KiB
Vue
<script setup lang="ts">
|
||
import "deep-chat";
|
||
import { ref, onMounted, watch } from "vue";
|
||
|
||
type HistoryItem = { text: string; role: "user" | "ai" };
|
||
|
||
const props = withDefaults(
|
||
defineProps<{
|
||
history?: HistoryItem[];
|
||
onRequest?: (messageText: string) => Promise<string> | string;
|
||
}>(),
|
||
{
|
||
history: () => []
|
||
}
|
||
);
|
||
|
||
const chatRef = ref<any>();
|
||
|
||
function normalizeUserText(rawMessage: any): string {
|
||
if (typeof rawMessage === "string") return rawMessage;
|
||
if (rawMessage?.text) return String(rawMessage.text);
|
||
return "";
|
||
}
|
||
|
||
function applyHistory() {
|
||
if (!chatRef.value) return;
|
||
chatRef.value.history = props.history || [];
|
||
}
|
||
|
||
onMounted(() => {
|
||
applyHistory();
|
||
chatRef.value.demo = {
|
||
response: async (rawMessage: any) => {
|
||
const messageText = normalizeUserText(rawMessage);
|
||
if (props.onRequest) {
|
||
const replyText = await props.onRequest(messageText);
|
||
return { text: replyText };
|
||
}
|
||
return {
|
||
text: "仅演示,如需AI服务,请参考 https://deepchat.dev/docs/connect"
|
||
};
|
||
}
|
||
};
|
||
});
|
||
|
||
watch(
|
||
() => props.history,
|
||
() => {
|
||
applyHistory();
|
||
}
|
||
);
|
||
</script>
|
||
|
||
<template>
|
||
<deep-chat
|
||
ref="chatRef"
|
||
style="width: 100%; height: 100%; border-radius: 10px"
|
||
:messageStyles="{
|
||
default: {
|
||
shared: {
|
||
bubble: {
|
||
maxWidth: '100%',
|
||
backgroundColor: 'unset',
|
||
marginTop: '10px',
|
||
marginBottom: '10px'
|
||
}
|
||
},
|
||
user: {
|
||
bubble: {
|
||
marginLeft: '0px',
|
||
color: 'black'
|
||
}
|
||
},
|
||
ai: {
|
||
outerContainer: {
|
||
backgroundColor: 'rgba(247,247,248)',
|
||
borderTop: '1px solid rgba(0,0,0,.1)',
|
||
borderBottom: '1px solid rgba(0,0,0,.1)'
|
||
}
|
||
}
|
||
}
|
||
}"
|
||
:avatars="{
|
||
default: { styles: { position: 'start' } },
|
||
ai: { src: 'https://xiaoxian521.github.io/hyperlink/svg/openai.svg' }
|
||
}"
|
||
:submitButtonStyles="{
|
||
submit: {
|
||
container: {
|
||
default: {
|
||
padding: '1px 0 0 5px',
|
||
backgroundColor: '#19c37d'
|
||
},
|
||
hover: { backgroundColor: '#0bab69' },
|
||
click: { backgroundColor: '#068e56' }
|
||
},
|
||
svg: {
|
||
content:
|
||
'<?xml version="1.0" ?> <svg viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg"> <g> <path d="M21.66,12a2,2,0,0,1-1.14,1.81L5.87,20.75A2.08,2.08,0,0,1,5,21a2,2,0,0,1-1.82-2.82L5.46,13H11a1,1,0,0,0,0-2H5.46L3.18,5.87A2,2,0,0,1,5.86,3.25h0l14.65,6.94A2,2,0,0,1,21.66,12Z"> </path> </g> </svg>',
|
||
styles: {
|
||
default: {
|
||
filter:
|
||
'brightness(0) saturate(100%) invert(100%) sepia(28%) saturate(2%) hue-rotate(69deg) brightness(107%) contrast(100%)'
|
||
}
|
||
}
|
||
}
|
||
},
|
||
loading: {
|
||
container: { default: { backgroundColor: 'white' } },
|
||
svg: {
|
||
styles: {
|
||
default: {
|
||
filter:
|
||
'brightness(0) saturate(100%) invert(72%) sepia(0%) saturate(3044%) hue-rotate(322deg) brightness(100%) contrast(96%)'
|
||
}
|
||
}
|
||
}
|
||
},
|
||
stop: {
|
||
container: {
|
||
default: { backgroundColor: 'white' },
|
||
hover: { backgroundColor: '#dadada52' }
|
||
},
|
||
svg: {
|
||
content:
|
||
'<?xml version="1.0" encoding="utf-8"?> <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> <rect width="24" height="24" rx="4" ry="4" /> </svg>',
|
||
styles: {
|
||
default: {
|
||
width: '0.95em',
|
||
marginTop: '0.32em',
|
||
filter:
|
||
'brightness(0) saturate(100%) invert(72%) sepia(0%) saturate(3044%) hue-rotate(322deg) brightness(100%) contrast(96%)'
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}"
|
||
:textInput="{ placeholder: { text: '发送消息' } }"
|
||
:history="props.history"
|
||
:demo="true"
|
||
:connect="{ stream: true }"
|
||
/>
|
||
</template>
|