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