Files
OCS_service/app/components/home/OcsConfigCard.vue
T
2026-05-22 22:38:01 +08:00

68 lines
1.6 KiB
Vue

<!-- app/components/home/OcsConfigCard.vue - OCS AnswererWrapper 配置片段 -->
<script lang="ts" setup>
import {
Card,
CardAction,
CardContent,
CardHeader,
CardTitle
} from "@/components/ui/card";
import { useAuthStore } from "@/stores/auth";
const authStore = useAuthStore();
const origin = ref("http://localhost:3000");
/** 浏览器端读取当前站点地址,避免文档里写死 localhost 或生产域名 */
onMounted(() => {
origin.value = window.location.origin;
});
/** 与旧 Python 项目的 ocs_config_example.json 保持同样字段;登录后自动填入 apiToken */
const configText = computed(() => {
const data: Record<string, string> = {
title: "${title}",
type: "${type}",
options: "${options}"
};
if (authStore.user?.apiToken) {
data.token = authStore.user.apiToken;
}
return JSON.stringify(
[
{
name: "AI智能题库",
homepage: origin.value,
url: `${origin.value}/api/search`,
method: "get",
contentType: "json",
data,
handler:
"return (res)=> res.code === 1 ? [res.question, res.answer] : [res.msg, undefined]"
}
],
null,
2
);
});
</script>
<template>
<Card>
<CardHeader>
<CardTitle>OCS 配置</CardTitle>
<CardAction>
<CopyCom :text="configText" :timeout="1200" />
</CardAction>
</CardHeader>
<CardContent>
<pre
class="max-h-120 overflow-auto rounded-2xl bg-muted p-4 text-xs leading-5 text-muted-foreground"
><code>{{ configText }}</code>
</pre>
</CardContent>
</Card>
</template>