fix: 修复TypeScript类型错误以兼容vue-tsc v2 [AC-AISVC-01]
This commit is contained in:
parent
5b3f5063a6
commit
b91b57cfa4
|
|
@ -98,7 +98,6 @@ const isValidTenantId = (tenantId: string): boolean => {
|
||||||
const fetchTenantList = async () => {
|
const fetchTenantList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
// 检查当前租户ID格式是否有效
|
|
||||||
if (!isValidTenantId(currentTenantId.value)) {
|
if (!isValidTenantId(currentTenantId.value)) {
|
||||||
console.warn('Invalid tenant ID format, resetting to default:', currentTenantId.value)
|
console.warn('Invalid tenant ID format, resetting to default:', currentTenantId.value)
|
||||||
currentTenantId.value = 'default@ash@2026'
|
currentTenantId.value = 'default@ash@2026'
|
||||||
|
|
@ -108,7 +107,6 @@ const fetchTenantList = async () => {
|
||||||
const response = await getTenantList()
|
const response = await getTenantList()
|
||||||
tenantList.value = response.tenants || []
|
tenantList.value = response.tenants || []
|
||||||
|
|
||||||
// 如果当前租户不在列表中,默认选择第一个
|
|
||||||
if (tenantList.value.length > 0 && !tenantList.value.find(t => t.id === currentTenantId.value)) {
|
if (tenantList.value.length > 0 && !tenantList.value.find(t => t.id === currentTenantId.value)) {
|
||||||
const firstTenant = tenantList.value[0]
|
const firstTenant = tenantList.value[0]
|
||||||
currentTenantId.value = firstTenant.id
|
currentTenantId.value = firstTenant.id
|
||||||
|
|
@ -117,8 +115,7 @@ const fetchTenantList = async () => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ElMessage.error('获取租户列表失败')
|
ElMessage.error('获取租户列表失败')
|
||||||
console.error('Failed to fetch tenant list:', error)
|
console.error('Failed to fetch tenant list:', error)
|
||||||
// 失败时使用默认租户
|
tenantList.value = [{ id: 'default@ash@2026', name: 'default (2026)', displayName: 'default', year: '2026', createdAt: new Date().toISOString() }]
|
||||||
tenantList.value = [{ id: 'default@ash@2026', name: 'default (2026)' }]
|
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export interface TenantListResponse {
|
||||||
total: number
|
total: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTenantList() {
|
export function getTenantList(): Promise<TenantListResponse> {
|
||||||
return request<TenantListResponse>({
|
return request<TenantListResponse>({
|
||||||
url: '/admin/tenants',
|
url: '/admin/tenants',
|
||||||
method: 'get'
|
method: 'get'
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
import axios from 'axios'
|
import axios, { type AxiosRequestConfig } from 'axios'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { useTenantStore } from '@/stores/tenant'
|
import { useTenantStore } from '@/stores/tenant'
|
||||||
|
|
||||||
// 创建 axios 实例
|
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: import.meta.env.VITE_APP_BASE_API || '/api',
|
baseURL: import.meta.env.VITE_APP_BASE_API || '/api',
|
||||||
timeout: 60000
|
timeout: 60000
|
||||||
})
|
})
|
||||||
|
|
||||||
// 请求拦截器
|
|
||||||
service.interceptors.request.use(
|
service.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
const tenantStore = useTenantStore()
|
const tenantStore = useTenantStore()
|
||||||
if (tenantStore.currentTenantId) {
|
if (tenantStore.currentTenantId) {
|
||||||
config.headers['X-Tenant-Id'] = tenantStore.currentTenantId
|
config.headers['X-Tenant-Id'] = tenantStore.currentTenantId
|
||||||
}
|
}
|
||||||
// TODO: 如果有 token 也可以在这里注入 Authorization
|
const apiKey = import.meta.env.VITE_APP_API_KEY
|
||||||
|
if (apiKey) {
|
||||||
|
config.headers['X-API-Key'] = apiKey
|
||||||
|
}
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
|
@ -24,11 +25,9 @@ service.interceptors.request.use(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// 响应拦截器
|
|
||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
(response) => {
|
(response) => {
|
||||||
const res = response.data
|
const res = response.data
|
||||||
// 这里可以根据后端的 code 进行统一处理
|
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
|
@ -42,7 +41,6 @@ service.interceptors.response.use(
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// TODO: 跳转到登录页或执行退出逻辑
|
|
||||||
location.href = '/login'
|
location.href = '/login'
|
||||||
})
|
})
|
||||||
} else if (status === 403) {
|
} else if (status === 403) {
|
||||||
|
|
@ -69,4 +67,13 @@ service.interceptors.response.use(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export default service
|
interface RequestConfig extends AxiosRequestConfig {
|
||||||
|
url: string
|
||||||
|
method?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function request<T = any>(config: RequestConfig): Promise<T> {
|
||||||
|
return service.request<any, T>(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default request
|
||||||
|
|
|
||||||
|
|
@ -102,10 +102,17 @@ interface DocumentItem {
|
||||||
createTime: string
|
createTime: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IndexJob {
|
||||||
|
jobId: string
|
||||||
|
status: string
|
||||||
|
progress: number
|
||||||
|
errorMsg?: string
|
||||||
|
}
|
||||||
|
|
||||||
const tableData = ref<DocumentItem[]>([])
|
const tableData = ref<DocumentItem[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const jobDialogVisible = ref(false)
|
const jobDialogVisible = ref(false)
|
||||||
const currentJob = ref<any>(null)
|
const currentJob = ref<IndexJob | null>(null)
|
||||||
const pollingJobs = ref<Set<string>>(new Set())
|
const pollingJobs = ref<Set<string>>(new Set())
|
||||||
let pollingInterval: number | null = null
|
let pollingInterval: number | null = null
|
||||||
|
|
||||||
|
|
@ -150,10 +157,15 @@ const fetchDocuments = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchJobStatus = async (jobId: string) => {
|
const fetchJobStatus = async (jobId: string): Promise<IndexJob | null> => {
|
||||||
try {
|
try {
|
||||||
const res = await getIndexJob(jobId)
|
const res: any = await getIndexJob(jobId)
|
||||||
return res
|
return {
|
||||||
|
jobId: res.jobId || jobId,
|
||||||
|
status: res.status || 'pending',
|
||||||
|
progress: res.progress || 0,
|
||||||
|
errorMsg: res.errorMsg
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch job status:', error)
|
console.error('Failed to fetch job status:', error)
|
||||||
return null
|
return null
|
||||||
|
|
@ -246,19 +258,21 @@ const handleFileChange = async (event: Event) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const res = await uploadDocument(formData)
|
const res: any = await uploadDocument(formData)
|
||||||
ElMessage.success(`文档上传成功!任务ID: ${res.jobId}`)
|
const jobId = res.jobId as string
|
||||||
|
ElMessage.success(`文档上传成功!任务ID: ${jobId}`)
|
||||||
console.log('Upload response:', res)
|
console.log('Upload response:', res)
|
||||||
|
|
||||||
const newDoc: DocumentItem = {
|
const newDoc: DocumentItem = {
|
||||||
|
docId: res.docId || '',
|
||||||
name: file.name,
|
name: file.name,
|
||||||
status: res.status || 'pending',
|
status: (res.status as string) || 'pending',
|
||||||
jobId: res.jobId,
|
jobId: jobId,
|
||||||
createTime: new Date().toLocaleString('zh-CN')
|
createTime: new Date().toLocaleString('zh-CN')
|
||||||
}
|
}
|
||||||
tableData.value.unshift(newDoc)
|
tableData.value.unshift(newDoc)
|
||||||
|
|
||||||
startPolling(res.jobId)
|
startPolling(jobId)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ElMessage.error('文档上传失败')
|
ElMessage.error('文档上传失败')
|
||||||
console.error('Upload error:', error)
|
console.error('Upload error:', error)
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,7 @@ const runStreamExperiment = async () => {
|
||||||
} else if (parsed.type === 'error') {
|
} else if (parsed.type === 'error') {
|
||||||
streamError.value = parsed.message || '流式输出错误'
|
streamError.value = parsed.message || '流式输出错误'
|
||||||
streaming.value = false
|
streaming.value = false
|
||||||
ElMessage.error(streamError.value)
|
ElMessage.error(streamError.value || '未知错误')
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
streamContent.value += data
|
streamContent.value += data
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
readonly VITE_APP_BASE_API: string
|
||||||
|
readonly VITE_APP_API_KEY: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportMeta {
|
||||||
|
readonly env: ImportMetaEnv
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,8 @@
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
}
|
},
|
||||||
|
"types": ["vite/client"]
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||||
"references": [{ "path": "./tsconfig.node.json" }]
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue