update
This commit is contained in:
parent
db1eece99d
commit
155a2e5cba
@ -5,7 +5,7 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: tradus-web:1.2.8
|
||||
image: tradus-web:1.2.9
|
||||
container_name: tradus-web
|
||||
ports:
|
||||
- '6000:80'
|
||||
|
||||
22
src/App.vue
22
src/App.vue
@ -2,7 +2,7 @@
|
||||
import { RouterView, useRoute } from 'vue-router'
|
||||
import { computed, ref, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { useUserStore } from './stores/user'
|
||||
import { authApi } from './services/api'
|
||||
import { authApi, http } from './services/api'
|
||||
|
||||
const route = useRoute()
|
||||
const isStandalonePage = computed(() => route.meta.standalone)
|
||||
@ -15,24 +15,13 @@ const showUserMenu = ref(false)
|
||||
const showLoginModal = ref(false)
|
||||
const loginMode = ref('login') // 'login' 或 'register'
|
||||
|
||||
// 获取最新用户数据
|
||||
// 获取用户信息
|
||||
const fetchUserInfo = async () => {
|
||||
if (!isAuthenticated.value) return
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
if (userStore.authHeader) {
|
||||
headers['Authorization'] = userStore.authHeader
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
const response = await http.get(
|
||||
`${import.meta.env.MODE === 'development' ? 'http://127.0.0.1:8000' : 'https://api.ibtc.work'}/user/me`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers,
|
||||
},
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
@ -45,10 +34,7 @@ const fetchUserInfo = async () => {
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取用户数据失败:', error)
|
||||
// 如果获取用户信息失败,可能是 token 过期,清除登录状态
|
||||
if (error instanceof Error && error.message.includes('401')) {
|
||||
userStore.logout()
|
||||
}
|
||||
// 处理在http工具中已经实现,这里不需要重复处理
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -121,10 +121,34 @@ export function createAuthenticatedFetch() {
|
||||
// 处理401错误(未授权)
|
||||
if (response.status === 401) {
|
||||
userStore.logout()
|
||||
window.location.href = '/login'
|
||||
// 使用路由跳转到首页
|
||||
window.location.href = '/'
|
||||
// 弹出提示
|
||||
alert('登录过期,需要重新登录')
|
||||
throw new Error('登录已过期,请重新登录')
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
// 导出通用的全局HTTP请求函数
|
||||
export const http = {
|
||||
async get(url: string, options: RequestInit = {}) {
|
||||
const authenticatedFetch = createAuthenticatedFetch()
|
||||
return authenticatedFetch(url, { ...options, method: 'GET' })
|
||||
},
|
||||
|
||||
async post(url: string, data: any, options: RequestInit = {}) {
|
||||
const authenticatedFetch = createAuthenticatedFetch()
|
||||
return authenticatedFetch(url, {
|
||||
...options,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, nextTick, computed, onMounted, watch } from 'vue'
|
||||
import { useUserStore } from '../stores/user'
|
||||
import { http } from '../services/api'
|
||||
|
||||
// 定义Agent类型
|
||||
interface Agent {
|
||||
@ -39,19 +40,11 @@ const apiBaseUrl =
|
||||
|
||||
// 获取Agent列表
|
||||
const fetchAgents = async () => {
|
||||
if (!isAuthenticated.value) return
|
||||
|
||||
if (isLoadingAgents.value) return
|
||||
isLoadingAgents.value = true
|
||||
try {
|
||||
const headers: Record<string, string> = {}
|
||||
if (userStore.authHeader) {
|
||||
headers['Authorization'] = userStore.authHeader
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiBaseUrl}/agent/list`, {
|
||||
method: 'GET',
|
||||
headers,
|
||||
})
|
||||
try {
|
||||
const response = await http.get(`${apiBaseUrl}/agent/list`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`)
|
||||
@ -228,23 +221,10 @@ const sendMessage = async () => {
|
||||
await scrollToBottom()
|
||||
|
||||
try {
|
||||
// 准备请求头,包含认证信息
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
if (userStore.authHeader) {
|
||||
headers['Authorization'] = userStore.authHeader
|
||||
}
|
||||
|
||||
// 调用流式接口
|
||||
const response = await fetch(`${apiBaseUrl}/agent/chat`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
user_prompt: currentInput,
|
||||
agent_id: selectedAgent.value.id,
|
||||
}),
|
||||
const response = await http.post(`${apiBaseUrl}/agent/chat`, {
|
||||
agent_id: selectedAgent.value.id,
|
||||
user_prompt: currentInput,
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, nextTick } from 'vue'
|
||||
import { useUserStore } from '../stores/user'
|
||||
import { http } from '../services/api'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const stockCode = ref('')
|
||||
const isAnalyzing = ref(false)
|
||||
const analysisContent = ref('')
|
||||
@ -52,17 +51,7 @@ const handleAnalysis = async () => {
|
||||
currentThought.value = '准备开始分析...'
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
if (userStore.authHeader) {
|
||||
headers['Authorization'] = userStore.authHeader
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiBaseUrl}/adata/${code}/analysis`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
})
|
||||
const response = await http.post(`${apiBaseUrl}/adata/${code}/analysis`, {})
|
||||
|
||||
if (!response.ok) {
|
||||
// 解析错误响应
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, nextTick } from 'vue'
|
||||
import { useUserStore } from '../stores/user'
|
||||
import { http } from '../services/api'
|
||||
|
||||
interface AnalysisRequest {
|
||||
symbol: string
|
||||
}
|
||||
|
||||
const userStore = useUserStore()
|
||||
const cryptoCode = ref('')
|
||||
const isAnalyzing = ref(false)
|
||||
const analysisContent = ref('')
|
||||
@ -50,22 +49,11 @@ const handleAnalysis = async () => {
|
||||
currentThought.value = '准备开始分析...'
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
if (userStore.authHeader) {
|
||||
headers['Authorization'] = userStore.authHeader
|
||||
}
|
||||
|
||||
const requestData: AnalysisRequest = {
|
||||
symbol: cryptoCode.value.trim().toUpperCase(),
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiBaseUrl}/crypto/analysis_v2`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(requestData),
|
||||
})
|
||||
const response = await http.post(`${apiBaseUrl}/crypto/analysis_v2`, requestData)
|
||||
|
||||
if (!response.ok) {
|
||||
// 解析错误响应
|
||||
|
||||
Loading…
Reference in New Issue
Block a user