Commit e52639b8 by zhangxingmin

p

parent 76387c42
......@@ -14,9 +14,6 @@ export function randList(data) {
/**
* 查询输出流信息(流式响应)
* @param {string} question 用户问题
* @param {number} timeout 超时时间(毫秒),默认 300000
* @returns {Promise<Response>} fetch 响应对象
*/
export function getStream(question, timeout = 300000) {
const userStore = useUserStore()
......@@ -31,12 +28,9 @@ export function getStream(question, timeout = 300000) {
headers['X-Tenant-ID'] = tenantId
}
// 从环境变量获取基础 URL
const baseUrl = import.meta.env.VITE_APP_BASE_API
// 拼接完整 URL(注意:后端实际路径为 /ai/api/ai/stream)
const url = `${baseUrl}/ai/api/api/ai/stream?question=${encodeURIComponent(question)}`
// 使用 AbortController 实现超时控制
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), timeout)
......@@ -47,4 +41,49 @@ export function getStream(question, timeout = 300000) {
}).finally(() => {
clearTimeout(timeoutId)
})
}
/**
* 获取服务卡片列表(产品列表)
*/
export async function getServiceCardList() {
const userStore = useUserStore()
const token = getToken()
// 根据实际 store 获取 userId,如果不存在则使用默认值(示例中为 '30')
const userId = userStore.userInfo?.userId || userStore.userId || '30'
// 处理 token 格式(去掉 "Bearer " 前缀)
let cleanToken = token
if (token && token.startsWith('Bearer ')) {
cleanToken = token.slice(7)
}
const headers = {
'Content-Type': 'application/json',
'x-authorization': `sfpfamilyfinancialplanning ${cleanToken}`
}
const url = 'https://hoservice.ydhomeoffice.cn/hoserviceApi/ydServiceCard/serviceCardList'
const body = {
userId: String(userId),
cardType: '11'
}
try {
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(body)
})
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
}
const data = await response.json()
return data
} catch (error) {
console.error('获取服务卡片列表失败:', error)
throw error
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment