feat: 新增api接口

This commit is contained in:
ccnetcore
2026-02-07 01:28:05 +08:00
parent 19b27d8e9a
commit 9550ed57c0
6 changed files with 283 additions and 247 deletions

View File

@@ -6,7 +6,7 @@
*/ */
// 主版本号 - 修改此处即可同步更新所有地方的版本显示 // 主版本号 - 修改此处即可同步更新所有地方的版本显示
export const APP_VERSION = '3.6.1'; export const APP_VERSION = '3.7.0';
// 应用名称 // 应用名称
export const APP_NAME = '意心AI'; export const APP_NAME = '意心AI';

View File

@@ -1,305 +1,335 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue'; import { computed, ref } from 'vue';
import { CopyDocument } from '@element-plus/icons-vue'; import { CopyDocument, Connection, Monitor, ChatLineRound, VideoPlay } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
// API配置 // API Configuration
const apiList = [ const apiList = [
{ url: '/v1/chat/completions', name: 'OpenAi Completions' }, {
{ url: '/v1/messages', name: 'Claude Messages' }, id: 'openai',
{ url: '/v1/responses', name: 'OpenAi Responses' }, name: 'OpenAI Completions',
{ url: '/v1beta/models/{model}/streamGenerateContent', name: 'Gemini GenerateContent' }, url: '/v1/chat/completions',
method: 'POST',
description: 'OpenAI 经典的对话补全接口。虽然官方正逐步转向新标准,但它仍是目前生态中最通用的标准,绝大多数第三方 AI 工具和库都默认支持此协议。',
icon: ChatLineRound,
requestBody: {
"messages": [
{
"role": "user",
"content": "hi"
}
],
"stream": true,
"model": "gpt-5.3-codex"
}
},
{
id: 'claude',
name: 'Claude Messages',
url: '/v1/messages',
method: 'POST',
description: 'Anthropic 官方统一的消息接口。专为 Claude 系列模型设计,支持复杂的对话交互,完美适配 Claude Code 等新一代开发工具。',
icon: Connection,
requestBody: {
"messages": [
{
"role": "user",
"content": "hi"
}
],
"max_tokens": 32000,
"stream": true,
"model": "claude-opus-4-6"
}
},
{
id: 'openai-resp',
name: 'OpenAI Responses',
url: '/v1/responses',
method: 'POST',
description: 'OpenAI 推出的最新一代统一响应接口。旨在提供更灵活、强大的交互能力,是未来对接 Codex 等高级模型和新特性的首选方式。',
icon: Monitor,
requestBody: {
"model": "gpt-5.3-codex",
"stream": true,
"input": [
{"content":"hi","role":"user"}
]
}
},
{
id: 'gemini',
name: 'Gemini GenerateContent',
url: '/v1beta/models/{model}/streamGenerateContent',
method: 'POST',
description: 'Google Gemini 原生生成接口。专为 Gemini 系列多模态模型打造,支持流式生成,是使用 Gemini CLI 及谷歌生态工具的最佳入口。',
icon: VideoPlay,
requestBody: {
"contents": [
{
"role": "user",
"parts": [
{
"text": "hi"
}
]
}
]
}
},
]; ];
const baseUrl = 'https://yxai.chat'; const baseUrl = 'https://yxai.chat';
const currentIndex = ref(0); const activeIndex = ref('0');
let autoPlayTimer: ReturnType<typeof setInterval> | null = null;
// 当前选中的API const currentApi = computed(() => apiList[Number(activeIndex.value)]);
const currentApi = computed(() => apiList[currentIndex.value]);
// 完整URL
const fullUrl = computed(() => `${baseUrl}${currentApi.value.url}`); const fullUrl = computed(() => `${baseUrl}${currentApi.value.url}`);
// 切换API function handleSelect(key: string) {
function selectApi(index: number) { activeIndex.value = key;
currentIndex.value = index;
resetAutoPlay();
} }
// 复制URL async function copyText(text: string) {
async function copyUrl() {
try { try {
await navigator.clipboard.writeText(fullUrl.value); await navigator.clipboard.writeText(text);
ElMessage.success('复制成功'); ElMessage.success('复制成功');
} catch { } catch {
ElMessage.error('复制失败'); ElMessage.error('复制失败');
} }
} }
// 自动轮播
function startAutoPlay() {
autoPlayTimer = setInterval(() => {
currentIndex.value = (currentIndex.value + 1) % apiList.length;
}, 3000);
}
function resetAutoPlay() {
if (autoPlayTimer) {
clearInterval(autoPlayTimer);
}
startAutoPlay();
}
onMounted(() => {
startAutoPlay();
});
onUnmounted(() => {
if (autoPlayTimer) {
clearInterval(autoPlayTimer);
}
});
</script> </script>
<template> <template>
<div class="api-page"> <div class="api-page">
<div class="api-container"> <el-container class="h-full">
<!-- 标题 --> <!-- Desktop Sidebar -->
<h1 class="page-title">AI 接口地址</h1> <el-aside width="280px" class="api-sidebar hidden-sm-and-down">
<p class="page-subtitle">支持多种主流AI接口协议一键切换</p> <div class="sidebar-header">
<h2 class="text-lg font-bold m-0">API 接口文档</h2>
<!-- 主内容区 --> <p class="text-xs text-gray-500 mt-1">开发者接入指南</p>
<div class="content-wrapper">
<!-- 左侧URL展示 -->
<div class="url-section">
<div class="url-card">
<div class="url-label">接口地址</div>
<div class="url-display">
<span class="base-url">{{ baseUrl }}</span>
<span class="api-path">{{ currentApi.url }}</span>
</div>
<button class="copy-btn" @click="copyUrl">
<el-icon><CopyDocument /></el-icon>
复制
</button>
</div>
</div> </div>
<el-menu
<!-- 右侧按钮列表 --> :default-active="activeIndex"
<div class="api-buttons"> class="api-menu"
<button @select="handleSelect"
>
<el-menu-item
v-for="(api, index) in apiList" v-for="(api, index) in apiList"
:key="index" :key="index"
class="api-btn" :index="index.toString()"
:class="{ active: currentIndex === index }"
@click="selectApi(index)"
> >
{{ api.name }} <el-icon><component :is="api.icon" /></el-icon>
</button> <span>{{ api.name }}</span>
</div> </el-menu-item>
</div> </el-menu>
</el-aside>
<!-- 进度指示器 --> <el-main class="api-main">
<div class="progress-dots"> <!-- Mobile Select -->
<span <div class="hidden-md-and-up mb-6">
v-for="(_, index) in apiList" <h2 class="text-lg font-bold mb-4">API 接口文档</h2>
:key="index" <el-select v-model="activeIndex" placeholder="Select API" class="w-full" @change="handleSelect">
class="dot" <el-option
:class="{ active: currentIndex === index }" v-for="(api, index) in apiList"
@click="selectApi(index)" :key="index"
/> :label="api.name"
</div> :value="index.toString()"
</div> />
</el-select>
</div>
<div class="content-container">
<el-alert
title="接口兼容性重要提示"
type="warning"
show-icon
:closable="false"
class="api-warning-alert"
>
<template #default>
<div class="leading-normal text-sm">
2025 年末起AI 领域接口标准逐渐分化原有的统一接口 <code class="bg-yellow-100 dark:bg-yellow-900 px-1 rounded">/v1/chat/completions</code> 已不再兼容所有模型各厂商推出的新接口差异较大接入第三方工具时请务必根据具体模型选择正确的 API 类型您可前往
<router-link to="/model-library" class="text-primary font-bold hover:underline">模型库</router-link>
查看各模型对应的 API 信息
</div>
</template>
</el-alert>
<div class="mb-6">
<div class="flex items-center gap-3 mb-2">
<el-icon :size="24" class="text-primary"><component :is="currentApi.icon" /></el-icon>
<h1 class="text-xl font-bold m-0">{{ currentApi.name }}</h1>
</div>
<p class="text-gray-500 dark:text-gray-400 leading-relaxed text-sm">{{ currentApi.description }}</p>
</div>
<el-card class="box-card mb-4" shadow="hover">
<template #header>
<div class="card-header flex justify-between items-center py-1">
<span class="font-bold text-sm">接口详情</span>
<el-tag :type="currentApi.method === 'POST' ? 'success' : 'warning'" effect="dark" round size="small">
{{ currentApi.method }}
</el-tag>
</div>
</template>
<div class="api-detail-item">
<div class="label mb-2 text-xs font-medium text-gray-500">请求地址 (Endpoint)</div>
<div class="url-box">
<div class="url-content">
<span class="base-url" title="Base URL">{{ baseUrl }}</span>
<span class="api-path" title="Path">{{ currentApi.url }}</span>
</div>
<div class="url-actions">
<el-tooltip content="复制 Base URL" placement="top">
<el-button link @click="copyText(baseUrl)" size="small">
<span class="text-xs font-mono">Base</span>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
<el-tooltip content="复制完整地址" placement="top">
<el-button link type="primary" @click="copyText(fullUrl)" size="small">
<el-icon><CopyDocument /></el-icon>
</el-button>
</el-tooltip>
</div>
</div>
</div>
</el-card>
<el-card class="box-card" shadow="hover">
<template #header>
<div class="card-header py-1">
<span class="font-bold text-sm">调用示例 (cURL)</span>
</div>
</template>
<div class="code-block bg-gray-50 dark:bg-[#161b22] p-3 rounded-md border border-gray-200 dark:border-gray-700">
<pre class="text-xs overflow-x-auto font-mono m-0"><code class="language-bash">curl {{ fullUrl }} \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{{ JSON.stringify(currentApi.requestBody, null, 2) }}'</code></pre>
</div>
</el-card>
</div>
</el-main>
</el-container>
</div> </div>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss">
.api-page { .api-page {
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.api-container {
width: 100%;
max-width: 900px;
padding: 50px;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(20px);
border-radius: 24px;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
.page-title {
text-align: center;
font-size: 36px;
font-weight: 700;
color: #fff;
margin: 0 0 10px 0;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.page-subtitle {
text-align: center;
font-size: 16px;
color: rgba(255, 255, 255, 0.8);
margin: 0 0 40px 0;
}
.content-wrapper {
display: flex;
gap: 30px;
align-items: stretch;
}
.url-section {
flex: 1;
}
.url-card {
position: relative;
background: rgba(255, 255, 255, 0.95);
border-radius: 16px;
padding: 30px;
height: 100%; height: 100%;
background-color: var(--bg-color-tertiary);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); overflow: hidden;
} }
.url-label { .api-sidebar {
font-size: 14px; background-color: var(--bg-color-primary);
color: #666; border-right: 1px solid var(--border-color-light);
margin-bottom: 15px;
font-weight: 500;
}
.url-display {
flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 8px;
font-family: 'Monaco', 'Menlo', monospace; .sidebar-header {
word-break: break-all; padding: 16px 20px;
border-bottom: 1px solid var(--border-color-light);
}
.api-menu {
border-right: none;
background-color: transparent;
flex: 1;
overflow-y: auto;
padding: 8px 0;
:deep(.el-menu-item) {
border-radius: 8px;
margin: 2px 10px;
height: 40px;
&.is-active {
background-color: var(--el-color-primary-light-9);
color: var(--el-color-primary);
font-weight: 600;
}
&:hover:not(.is-active) {
background-color: var(--el-fill-color-light);
}
}
}
} }
.base-url { .api-main {
font-size: 18px; padding: 24px;
color: #409eff; overflow-y: auto;
font-weight: 600;
} }
.api-path { .content-container {
font-size: 16px; max-width: 900px;
color: #333; margin: 0 auto;
padding: 12px;
background: #f5f7fa;
border-radius: 8px;
transition: all 0.3s ease;
} }
.copy-btn { .text-primary {
position: absolute; color: var(--el-color-primary);
top: 15px; }
right: 15px;
.url-box {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 6px; justify-content: space-between;
padding: 8px 16px; background-color: var(--el-fill-color-light);
background: #409eff; border: 1px solid var(--el-border-color);
color: #fff;
border: none;
border-radius: 8px; border-radius: 8px;
cursor: pointer; padding: 12px 16px;
font-size: 14px;
transition: all 0.3s ease;
&:hover {
background: #66b1ff;
transform: translateY(-2px);
}
}
.api-buttons {
display: flex;
flex-direction: column;
gap: 12px; gap: 12px;
min-width: 220px;
} .url-content {
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
.api-btn { font-size: 14px;
padding: 16px 24px; word-break: break-all;
background: rgba(255, 255, 255, 0.2); line-height: 1.5;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 12px; .base-url {
color: #fff; color: var(--el-text-color-secondary);
font-size: 15px; }
font-weight: 500;
cursor: pointer; .api-path {
transition: all 0.3s ease; color: var(--el-color-primary);
text-align: left; font-weight: 600;
}
&:hover {
background: rgba(255, 255, 255, 0.3);
transform: translateX(5px);
} }
&.active { .url-actions {
background: #fff; display: flex;
color: #667eea; align-items: center;
border-color: #fff; flex-shrink: 0;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}
}
.progress-dots {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 30px;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.4);
cursor: pointer;
transition: all 0.3s ease;
&:hover {
background: rgba(255, 255, 255, 0.7);
}
&.active {
background: #fff;
transform: scale(1.3);
} }
} }
/* Utility classes for responsiveness if unocss/tailwind not fully available in this scope */
@media (max-width: 768px) { @media (max-width: 768px) {
.api-container { .hidden-sm-and-down {
padding: 30px 20px; display: none !important;
} }
.hidden-md-and-up {
display: block !important;
}
.api-main {
padding: 20px;
}
}
.page-title { @media (min-width: 769px) {
font-size: 28px; .hidden-md-and-up {
display: none !important;
} }
}
.content-wrapper { .api-warning-alert {
flex-direction: column; margin-bottom: 20px;
}
.api-buttons {
min-width: auto;
}
.api-btn {
text-align: center;
}
} }
</style> </style>

View File

@@ -15,6 +15,7 @@ const navItems = [
{ name: 'image', label: 'AI图片', icon: 'Picture', path: '/chat/image' }, { name: 'image', label: 'AI图片', icon: 'Picture', path: '/chat/image' },
{ name: 'video', label: 'AI视频', icon: 'VideoCamera', path: '/chat/video' }, { name: 'video', label: 'AI视频', icon: 'VideoCamera', path: '/chat/video' },
{ name: 'monitor', label: 'AI智能体', icon: 'Monitor', path: '/chat/agent' }, { name: 'monitor', label: 'AI智能体', icon: 'Monitor', path: '/chat/agent' },
{ name: 'ChatLineRound', label: 'AI接口', icon: 'ChatLineRound', path: '/chat/api' },
]; ];
// 当前激活的菜单 // 当前激活的菜单

View File

@@ -2062,4 +2062,7 @@
.marked-markdown.theme-light .code-block-wrapper .code-block-body .line-numbers{ .marked-markdown.theme-light .code-block-wrapper .code-block-body .line-numbers{
@include dark-theme-div; @include dark-theme-div;
} }
.url-box{
@include dark-theme-div;
}
} }

View File

@@ -18,6 +18,7 @@ declare module 'vue' {
DeepThinking: typeof import('./../src/components/DeepThinking/index.vue')['default'] DeepThinking: typeof import('./../src/components/DeepThinking/index.vue')['default']
Demo: typeof import('./../src/components/FontAwesomeIcon/demo.vue')['default'] Demo: typeof import('./../src/components/FontAwesomeIcon/demo.vue')['default']
ElAlert: typeof import('element-plus/es')['ElAlert'] ElAlert: typeof import('element-plus/es')['ElAlert']
ElAside: typeof import('element-plus/es')['ElAside']
ElAvatar: typeof import('element-plus/es')['ElAvatar'] ElAvatar: typeof import('element-plus/es')['ElAvatar']
ElButton: typeof import('element-plus/es')['ElButton'] ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import('element-plus/es')['ElCard'] ElCard: typeof import('element-plus/es')['ElCard']

View File

@@ -7,6 +7,7 @@ interface ImportMetaEnv {
readonly VITE_WEB_BASE_API: string; readonly VITE_WEB_BASE_API: string;
readonly VITE_API_URL: string; readonly VITE_API_URL: string;
readonly VITE_FILE_UPLOAD_API: string; readonly VITE_FILE_UPLOAD_API: string;
readonly VITE_BUILD_COMPRESS: string;
readonly VITE_SSO_SEVER_URL: string; readonly VITE_SSO_SEVER_URL: string;
readonly VITE_APP_VERSION: string; readonly VITE_APP_VERSION: string;
} }