feat: 前端接口代理
This commit is contained in:
@@ -12,5 +12,6 @@ VITE_WEB_BASE_API = '/dev-api'
|
||||
|
||||
# 本地接口
|
||||
# VITE_API_URL = http://122.51.75.95:6039
|
||||
VITE_API_URL = http://129.211.24.7:6039
|
||||
VITE_API_URL = http://129.211.24.7:6039
|
||||
# VITE_API_URL = https://ccnetcore.com
|
||||
# VITE_API_URL = https://mp.pandarobot.chat
|
||||
|
||||
19
Yi.Ai.Vue3/.vscode/extensions.json
vendored
Normal file
19
Yi.Ai.Vue3/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
// 扩展推荐
|
||||
"recommendations": [
|
||||
// 推荐扩展 vue 官方推荐
|
||||
"Vue.volar",
|
||||
// 推荐扩展 EditorConfig 格式化 scss 换行问题
|
||||
"EditorConfig.EditorConfig",
|
||||
// 推荐扩展 unocss 官方推荐
|
||||
"antfu.unocss",
|
||||
// 推荐扩展 eslint 官方推荐
|
||||
"dbaeumer.vscode-eslint",
|
||||
// 推荐扩展 stylelint 官方推荐 格式化 scss 代码问题
|
||||
"stylelint.vscode-stylelint"
|
||||
]
|
||||
}
|
||||
|
||||
// 最好都安装启用一下,依赖都是最新版本的
|
||||
// 规范开发
|
||||
// 配置文件都配置好了 启用拓展后 vscode 自动保存 将修复不规范的代码
|
||||
61
Yi.Ai.Vue3/.vscode/settings.json
vendored
Normal file
61
Yi.Ai.Vue3/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"eslint.useFlatConfig": true,
|
||||
|
||||
// 关闭默认的配置,我们这里默认不开启prettier格式化
|
||||
"prettier.enable": false,
|
||||
// 关闭默认格式化
|
||||
"editor.formatOnSave": false,
|
||||
// 开启 stylint
|
||||
"stylelint.enable": true,
|
||||
|
||||
// 保存自动修复
|
||||
"editor.codeActionsOnSave": {
|
||||
// 我们这里是指定自定义的修复
|
||||
"source.fixAll.eslint": "explicit",
|
||||
// 来源导入我们不需要给关闭掉
|
||||
"source.organizeImports": "never",
|
||||
// 使用 stylelint 来修复样式问题
|
||||
"source.fixAll.stylelint": "explicit"
|
||||
},
|
||||
|
||||
// 开启 stylelint
|
||||
"stylelint.validate": ["css", "less", "postcss", "scss", "vue", "sass", "html"],
|
||||
|
||||
// 静默样式规则自动修复
|
||||
"eslint.rules.customizations": [
|
||||
{ "rule": "style/*", "severity": "off", "fixable": true },
|
||||
{ "rule": "format/*", "severity": "off", "fixable": true },
|
||||
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
||||
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
||||
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
||||
{ "rule": "*-order", "severity": "off", "fixable": true },
|
||||
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
||||
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
||||
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
||||
{ "rule": "*semi", "severity": "off", "fixable": true }
|
||||
],
|
||||
|
||||
// 在eslin中开启哪些语言的校验
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
"",
|
||||
"html",
|
||||
"markdown",
|
||||
"json",
|
||||
"jsonc",
|
||||
"yaml",
|
||||
"toml",
|
||||
"xml",
|
||||
"gql",
|
||||
"graphql",
|
||||
"astro",
|
||||
"css",
|
||||
"less",
|
||||
"scss",
|
||||
"pcss",
|
||||
"postcss"
|
||||
]
|
||||
}
|
||||
BIN
Yi.Ai.Vue3/public/favicon.ico
Normal file
BIN
Yi.Ai.Vue3/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -2,7 +2,8 @@ import type { ChatMessageVo, GetChatListParams, SendDTO } from './types';
|
||||
import { get, post } from '@/utils/request';
|
||||
|
||||
// 发送消息
|
||||
export const send = (data: SendDTO) => post<null>('/chat/send', data);
|
||||
export const send = (data: SendDTO) => post<null>('/prod-api/ai/send', data);
|
||||
// export const send = (data: SendDTO) => post<null>('/chat/send', data);
|
||||
|
||||
// 新增对应会话聊天记录
|
||||
export function addChat(data: ChatMessageVo) {
|
||||
|
||||
@@ -3,5 +3,6 @@ import { get } from '@/utils/request';
|
||||
|
||||
// 获取当前用户的模型列表
|
||||
export function getModelList() {
|
||||
return get<GetSessionListVO[]>('/system/model/modelList');
|
||||
// return get<GetSessionListVO[]>('/system/model/modelList');
|
||||
return get<GetSessionListVO[]>('/prod-api/ai/model');
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ router.beforeEach(
|
||||
// // resetRouter(); // 预留
|
||||
// return next();
|
||||
// }
|
||||
console.log(`to---`,to)
|
||||
// 4、判断访问页面是否在路由白名单地址[静态路由]中,如果存在直接放行。
|
||||
if (ROUTER_WHITE_LIST.includes(to.path))
|
||||
return next();
|
||||
|
||||
@@ -18,6 +18,7 @@ export const useModelStore = defineStore('model', () => {
|
||||
const requestModelList = async () => {
|
||||
try {
|
||||
const res = await getModelList();
|
||||
console.log('res', res);
|
||||
modelList.value = res.data;
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -120,6 +120,13 @@ export const useSessionStore = defineStore('session', () => {
|
||||
|
||||
try {
|
||||
const res = await create_session(data);
|
||||
// TODO: 模拟请求
|
||||
// const res = {
|
||||
// code: 200,
|
||||
// msg: "操作成功",
|
||||
// data: "1935711019560206338"
|
||||
// };
|
||||
console.log('create_session---res--',res)
|
||||
// 创建会话后立刻查询列表会话
|
||||
// 1. 先找到被修改会话在 sessionList 中的索引(假设 sessionList 是按服务端排序的完整列表)
|
||||
const targetIndex = sessionList.value.findIndex(session => session.id === `${res.data}`);
|
||||
|
||||
@@ -12,12 +12,37 @@ interface BaseResponse {
|
||||
rows: never;
|
||||
}
|
||||
|
||||
// 修改 BaseResponse 类型,使其兼容裸数组
|
||||
type BaseResponse<T = any> =
|
||||
| { code: number; data: T; msg: string } // 标准格式
|
||||
| T[]; // 裸数组格式
|
||||
|
||||
export const request = hookFetch.create<BaseResponse, 'data' | 'rows'>({
|
||||
baseURL: import.meta.env.VITE_API_URL,
|
||||
// baseURL: import.meta.env.VITE_API_URL,
|
||||
baseURL: '', // 留空或使用'/'
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
plugins: [sseTextDecoderPlugin({ json: true, prefix: 'data:' })],
|
||||
plugins: [
|
||||
sseTextDecoderPlugin({ json: true, prefix: 'data:' }),
|
||||
{
|
||||
name: 'adapt-array-response',
|
||||
afterResponse: async (response) => {
|
||||
// 如果是数组格式,手动包裹成 { data: [...] }
|
||||
if (Array.isArray(response.result)) {
|
||||
return {
|
||||
...response,
|
||||
result: {
|
||||
code: 200,
|
||||
msg: 'success',
|
||||
data: response.result,
|
||||
},
|
||||
};
|
||||
}
|
||||
return response;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
function jwtPlugin(): HookFetchPlugin<BaseResponse> {
|
||||
|
||||
1
Yi.Ai.Vue3/types/import_meta.d.ts
vendored
1
Yi.Ai.Vue3/types/import_meta.d.ts
vendored
@@ -5,7 +5,6 @@ interface ImportMetaEnv {
|
||||
readonly VITE_WEB_TITLE_EN: string;
|
||||
readonly VITE_WEB_ENV: string;
|
||||
readonly VITE_WEB_BASE_API: string;
|
||||
readonly VITE_BUILD_COMPRESS: string;
|
||||
readonly VITE_API_URL: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,5 +23,17 @@ export default defineConfig((cnf) => {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
server: {
|
||||
proxy: {
|
||||
// 代理所有以 /prod-api 开头的请求
|
||||
"/prod-api": {
|
||||
target: "https://ccnetcore.com", // 接口域名
|
||||
changeOrigin: true, // 改变源
|
||||
secure: false, // 如果目标服务器使用 HTTPS 且证书无效,需要设置为 false
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user