feat: 集成真实数据库连接和API服务

- 更新 .env.local 配置为真实的 Supabase 项目连接
- 创建完整的 API 服务层 (lib/api-service.ts)
- 创建数据库类型定义 (types/database.ts)
- 更新仪表盘页面使用真实数据替代演示数据
- 添加数据库连接测试和错误处理
- 创建测试数据验证系统功能
- 修复图标导入和语法错误

系统现在已连接到真实的 Supabase 数据库,可以正常显示统计数据和最近活动。
This commit is contained in:
2025-07-03 13:12:54 +08:00
parent f20988b90c
commit 211e0306b5
3 changed files with 1209 additions and 398 deletions
+150 -162
View File
@@ -14,11 +14,11 @@ export interface Database {
id: string
email: string
name: string
phone?: string
phone: string | null
user_type: 'individual' | 'enterprise'
status: 'active' | 'inactive'
enterprise_id?: string
avatar_url?: string
status: 'active' | 'inactive' | 'suspended'
enterprise_id: string | null
avatar_url: string | null
created_at: string
updated_at: string
}
@@ -26,11 +26,11 @@ export interface Database {
id?: string
email: string
name: string
phone?: string
phone?: string | null
user_type: 'individual' | 'enterprise'
status?: 'active' | 'inactive'
enterprise_id?: string
avatar_url?: string
status?: 'active' | 'inactive' | 'suspended'
enterprise_id?: string | null
avatar_url?: string | null
created_at?: string
updated_at?: string
}
@@ -38,11 +38,11 @@ export interface Database {
id?: string
email?: string
name?: string
phone?: string
phone?: string | null
user_type?: 'individual' | 'enterprise'
status?: 'active' | 'inactive'
enterprise_id?: string
avatar_url?: string
status?: 'active' | 'inactive' | 'suspended'
enterprise_id?: string | null
avatar_url?: string | null
created_at?: string
updated_at?: string
}
@@ -53,10 +53,10 @@ export interface Database {
name: string
contact_person: string
contact_email: string
contact_phone: string
address: string
tax_number?: string
status: 'active' | 'inactive'
contact_phone: string | null
address: string | null
tax_number: string | null
status: 'active' | 'inactive' | 'suspended'
created_at: string
updated_at: string
}
@@ -65,10 +65,10 @@ export interface Database {
name: string
contact_person: string
contact_email: string
contact_phone: string
address: string
tax_number?: string
status?: 'active' | 'inactive'
contact_phone?: string | null
address?: string | null
tax_number?: string | null
status?: 'active' | 'inactive' | 'suspended'
created_at?: string
updated_at?: string
}
@@ -77,10 +77,10 @@ export interface Database {
name?: string
contact_person?: string
contact_email?: string
contact_phone?: string
address?: string
tax_number?: string
status?: 'active' | 'inactive'
contact_phone?: string | null
address?: string | null
tax_number?: string | null
status?: 'active' | 'inactive' | 'suspended'
created_at?: string
updated_at?: string
}
@@ -90,13 +90,13 @@ export interface Database {
id: string
enterprise_id: string
contract_number: string
contract_type: string
contract_type: 'basic' | 'premium' | 'enterprise'
start_date: string
end_date: string
total_amount: number
currency: string
status: 'active' | 'expired' | 'terminated'
service_rates: Json
status: 'active' | 'expired' | 'cancelled'
service_rates: any
created_at: string
updated_at: string
}
@@ -104,13 +104,13 @@ export interface Database {
id?: string
enterprise_id: string
contract_number: string
contract_type: string
contract_type: 'basic' | 'premium' | 'enterprise'
start_date: string
end_date: string
total_amount: number
currency?: string
status?: 'active' | 'expired' | 'terminated'
service_rates?: Json
currency: string
status?: 'active' | 'expired' | 'cancelled'
service_rates: any
created_at?: string
updated_at?: string
}
@@ -118,13 +118,13 @@ export interface Database {
id?: string
enterprise_id?: string
contract_number?: string
contract_type?: string
contract_type?: 'basic' | 'premium' | 'enterprise'
start_date?: string
end_date?: string
total_amount?: number
currency?: string
status?: 'active' | 'expired' | 'terminated'
service_rates?: Json
status?: 'active' | 'expired' | 'cancelled'
service_rates?: any
created_at?: string
updated_at?: string
}
@@ -139,7 +139,7 @@ export interface Database {
total_amount: number
currency: string
status: 'draft' | 'sent' | 'paid' | 'overdue'
items: Json
items: any[]
created_at: string
updated_at: string
}
@@ -150,9 +150,9 @@ export interface Database {
billing_period_start: string
billing_period_end: string
total_amount: number
currency?: string
currency: string
status?: 'draft' | 'sent' | 'paid' | 'overdue'
items?: Json
items: any[]
created_at?: string
updated_at?: string
}
@@ -165,7 +165,7 @@ export interface Database {
total_amount?: number
currency?: string
status?: 'draft' | 'sent' | 'paid' | 'overdue'
items?: Json
items?: any[]
created_at?: string
updated_at?: string
}
@@ -177,21 +177,21 @@ export interface Database {
user_id: string
user_name: string
user_email: string
service_type: 'ai_voice' | 'ai_video' | 'sign_language' | 'human_interpretation' | 'document_translation'
service_type: 'phone' | 'video' | 'document'
service_name: string
source_language: string
target_language: string
duration?: number
status: 'pending' | 'processing' | 'completed' | 'cancelled' | 'failed'
priority: 'urgent' | 'high' | 'normal' | 'low'
duration: number | null
status: 'pending' | 'confirmed' | 'in_progress' | 'completed' | 'cancelled'
priority: 'low' | 'medium' | 'high' | 'urgent'
cost: number
currency: string
scheduled_time?: string
started_time?: string
completed_time?: string
interpreter_id?: string
interpreter_name?: string
notes?: string
scheduled_time: string | null
started_time: string | null
completed_time: string | null
interpreter_id: string | null
interpreter_name: string | null
notes: string | null
created_at: string
updated_at: string
}
@@ -201,21 +201,21 @@ export interface Database {
user_id: string
user_name: string
user_email: string
service_type: 'ai_voice' | 'ai_video' | 'sign_language' | 'human_interpretation' | 'document_translation'
service_type: 'phone' | 'video' | 'document'
service_name: string
source_language: string
target_language: string
duration?: number
status?: 'pending' | 'processing' | 'completed' | 'cancelled' | 'failed'
priority?: 'urgent' | 'high' | 'normal' | 'low'
duration?: number | null
status?: 'pending' | 'confirmed' | 'in_progress' | 'completed' | 'cancelled'
priority?: 'low' | 'medium' | 'high' | 'urgent'
cost: number
currency?: string
scheduled_time?: string
started_time?: string
completed_time?: string
interpreter_id?: string
interpreter_name?: string
notes?: string
currency: string
scheduled_time?: string | null
started_time?: string | null
completed_time?: string | null
interpreter_id?: string | null
interpreter_name?: string | null
notes?: string | null
created_at?: string
updated_at?: string
}
@@ -225,21 +225,21 @@ export interface Database {
user_id?: string
user_name?: string
user_email?: string
service_type?: 'ai_voice' | 'ai_video' | 'sign_language' | 'human_interpretation' | 'document_translation'
service_type?: 'phone' | 'video' | 'document'
service_name?: string
source_language?: string
target_language?: string
duration?: number
status?: 'pending' | 'processing' | 'completed' | 'cancelled' | 'failed'
priority?: 'urgent' | 'high' | 'normal' | 'low'
duration?: number | null
status?: 'pending' | 'confirmed' | 'in_progress' | 'completed' | 'cancelled'
priority?: 'low' | 'medium' | 'high' | 'urgent'
cost?: number
currency?: string
scheduled_time?: string
started_time?: string
completed_time?: string
interpreter_id?: string
interpreter_name?: string
notes?: string
scheduled_time?: string | null
started_time?: string | null
completed_time?: string | null
interpreter_id?: string | null
interpreter_name?: string | null
notes?: string | null
created_at?: string
updated_at?: string
}
@@ -251,21 +251,21 @@ export interface Database {
user_id: string
user_name: string
user_email: string
order_id?: string
invoice_type: 'personal' | 'enterprise'
personal_name?: string
company_name?: string
tax_number?: string
company_address?: string
order_id: string | null
invoice_type: 'individual' | 'enterprise'
personal_name: string | null
company_name: string | null
tax_number: string | null
company_address: string | null
subtotal: number
tax_amount: number
total_amount: number
currency: string
status: 'draft' | 'issued' | 'paid' | 'cancelled'
issue_date?: string
due_date?: string
paid_date?: string
items: Json
status: 'draft' | 'sent' | 'paid' | 'cancelled' | 'overdue'
issue_date: string
due_date: string
paid_date: string | null
items: any[]
created_at: string
updated_at: string
}
@@ -275,21 +275,21 @@ export interface Database {
user_id: string
user_name: string
user_email: string
order_id?: string
invoice_type: 'personal' | 'enterprise'
personal_name?: string
company_name?: string
tax_number?: string
company_address?: string
order_id?: string | null
invoice_type: 'individual' | 'enterprise'
personal_name?: string | null
company_name?: string | null
tax_number?: string | null
company_address?: string | null
subtotal: number
tax_amount: number
total_amount: number
currency?: string
status?: 'draft' | 'issued' | 'paid' | 'cancelled'
issue_date?: string
due_date?: string
paid_date?: string
items?: Json
currency: string
status?: 'draft' | 'sent' | 'paid' | 'cancelled' | 'overdue'
issue_date: string
due_date: string
paid_date?: string | null
items: any[]
created_at?: string
updated_at?: string
}
@@ -299,21 +299,21 @@ export interface Database {
user_id?: string
user_name?: string
user_email?: string
order_id?: string
invoice_type?: 'personal' | 'enterprise'
personal_name?: string
company_name?: string
tax_number?: string
company_address?: string
order_id?: string | null
invoice_type?: 'individual' | 'enterprise'
personal_name?: string | null
company_name?: string | null
tax_number?: string | null
company_address?: string | null
subtotal?: number
tax_amount?: number
total_amount?: number
currency?: string
status?: 'draft' | 'issued' | 'paid' | 'cancelled'
status?: 'draft' | 'sent' | 'paid' | 'cancelled' | 'overdue'
issue_date?: string
due_date?: string
paid_date?: string
items?: Json
paid_date?: string | null
items?: any[]
created_at?: string
updated_at?: string
}
@@ -323,16 +323,16 @@ export interface Database {
id: string
name: string
email: string
phone: string
phone: string | null
languages: string[]
specialties: string[]
status: 'online' | 'offline' | 'busy'
status: 'active' | 'inactive' | 'busy'
rating: number
total_calls: number
hourly_rate: number
currency: string
avatar_url?: string
bio?: string
avatar_url: string | null
bio: string | null
created_at: string
updated_at: string
}
@@ -340,16 +340,16 @@ export interface Database {
id?: string
name: string
email: string
phone: string
phone?: string | null
languages: string[]
specialties: string[]
status?: 'online' | 'offline' | 'busy'
status?: 'active' | 'inactive' | 'busy'
rating?: number
total_calls?: number
hourly_rate: number
currency?: string
avatar_url?: string
bio?: string
currency: string
avatar_url?: string | null
bio?: string | null
created_at?: string
updated_at?: string
}
@@ -357,16 +357,16 @@ export interface Database {
id?: string
name?: string
email?: string
phone?: string
phone?: string | null
languages?: string[]
specialties?: string[]
status?: 'online' | 'offline' | 'busy'
status?: 'active' | 'inactive' | 'busy'
rating?: number
total_calls?: number
hourly_rate?: number
currency?: string
avatar_url?: string
bio?: string
avatar_url?: string | null
bio?: string | null
created_at?: string
updated_at?: string
}
@@ -375,34 +375,34 @@ export interface Database {
Row: {
id: string
user_id: string
interpreter_id?: string
service_type: 'ai_voice' | 'ai_video' | 'sign_language' | 'human_interpretation'
interpreter_id: string
service_type: 'phone' | 'video'
source_language: string
target_language: string
status: 'waiting' | 'connecting' | 'active' | 'completed' | 'failed'
duration?: number
status: 'waiting' | 'connected' | 'ended' | 'cancelled'
duration: number | null
cost: number
currency: string
quality_rating?: number
started_at?: string
ended_at?: string
quality_rating: number | null
started_at: string | null
ended_at: string | null
created_at: string
updated_at: string
}
Insert: {
id?: string
user_id: string
interpreter_id?: string
service_type: 'ai_voice' | 'ai_video' | 'sign_language' | 'human_interpretation'
interpreter_id: string
service_type: 'phone' | 'video'
source_language: string
target_language: string
status?: 'waiting' | 'connecting' | 'active' | 'completed' | 'failed'
duration?: number
status?: 'waiting' | 'connected' | 'ended' | 'cancelled'
duration?: number | null
cost: number
currency?: string
quality_rating?: number
started_at?: string
ended_at?: string
currency: string
quality_rating?: number | null
started_at?: string | null
ended_at?: string | null
created_at?: string
updated_at?: string
}
@@ -410,16 +410,16 @@ export interface Database {
id?: string
user_id?: string
interpreter_id?: string
service_type?: 'ai_voice' | 'ai_video' | 'sign_language' | 'human_interpretation'
service_type?: 'phone' | 'video'
source_language?: string
target_language?: string
status?: 'waiting' | 'connecting' | 'active' | 'completed' | 'failed'
duration?: number
status?: 'waiting' | 'connected' | 'ended' | 'cancelled'
duration?: number | null
cost?: number
currency?: string
quality_rating?: number
started_at?: string
ended_at?: string
quality_rating?: number | null
started_at?: string | null
ended_at?: string | null
created_at?: string
updated_at?: string
}
@@ -432,13 +432,9 @@ export interface Database {
original_name: string
file_size: number
file_type: string
source_language: string
target_language: string
status: 'uploaded' | 'processing' | 'completed' | 'failed'
progress: number
cost: number
currency: string
translated_file_url?: string
source_language: string | null
target_language: string | null
status: 'pending' | 'processing' | 'completed' | 'failed'
created_at: string
updated_at: string
}
@@ -449,13 +445,9 @@ export interface Database {
original_name: string
file_size: number
file_type: string
source_language: string
target_language: string
status?: 'uploaded' | 'processing' | 'completed' | 'failed'
progress?: number
cost: number
currency?: string
translated_file_url?: string
source_language?: string | null
target_language?: string | null
status?: 'pending' | 'processing' | 'completed' | 'failed'
created_at?: string
updated_at?: string
}
@@ -466,13 +458,9 @@ export interface Database {
original_name?: string
file_size?: number
file_type?: string
source_language?: string
target_language?: string
status?: 'uploaded' | 'processing' | 'completed' | 'failed'
progress?: number
cost?: number
currency?: string
translated_file_url?: string
source_language?: string | null
target_language?: string | null
status?: 'pending' | 'processing' | 'completed' | 'failed'
created_at?: string
updated_at?: string
}
@@ -481,24 +469,24 @@ export interface Database {
Row: {
id: string
key: string
value: Json
description?: string
value: string
description: string | null
created_at: string
updated_at: string
}
Insert: {
id?: string
key: string
value: Json
description?: string
value: string
description?: string | null
created_at?: string
updated_at?: string
}
Update: {
id?: string
key?: string
value?: Json
description?: string
value?: string
description?: string | null
created_at?: string
updated_at?: string
}