Files
users/lib/db-connector.ts
v0 2408d50cb0 refactor: overhaul UI for streamlined user experience
Redesign navigation, home overview, user portrait, and valuation pages
with improved functionality and responsive design.

Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
2025-07-18 13:47:12 +00:00

306 lines
16 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 模拟数据库结构数据
// 由于v0不支持mysql2我们使用模拟数据来展示功能
// 模拟数据库列表
const mockDatabases = [
{ Database: "user_data_platform" },
{ Database: "traffic_analysis" },
{ Database: "content_library" },
{ Database: "wechat_accounts" },
{ Database: "device_management" },
]
// 模拟表结构数据
const mockDatabaseStructure: Record<string, Record<string, any[]>> = {
user_data_platform: {
users: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "username", Type: "varchar(50)", Null: "NO", Key: "UNI", Default: null, Extra: "" },
{ Field: "email", Type: "varchar(100)", Null: "YES", Key: "UNI", Default: null, Extra: "" },
{ Field: "phone", Type: "varchar(20)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{
Field: "updated_at",
Type: "datetime",
Null: "YES",
Key: "",
Default: null,
Extra: "on update CURRENT_TIMESTAMP",
},
{ Field: "last_login", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "status", Type: "tinyint(1)", Null: "NO", Key: "", Default: "1", Extra: "" },
],
user_tags: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "user_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "tag_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
],
tags: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "name", Type: "varchar(50)", Null: "NO", Key: "UNI", Default: null, Extra: "" },
{ Field: "category", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "description", Type: "text", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
],
user_profiles: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "user_id", Type: "int(11)", Null: "NO", Key: "UNI", Default: null, Extra: "" },
{ Field: "full_name", Type: "varchar(100)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "gender", Type: "enum('male','female','other')", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "birth_date", Type: "date", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "address", Type: "text", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "city", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "province", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "country", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "avatar_url", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "bio", Type: "text", Null: "YES", Key: "", Default: null, Extra: "" },
],
user_activities: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "user_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "activity_type", Type: "varchar(50)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "activity_data", Type: "json", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{ Field: "ip_address", Type: "varchar(45)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "user_agent", Type: "text", Null: "YES", Key: "", Default: null, Extra: "" },
],
},
traffic_analysis: {
traffic_sources: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "name", Type: "varchar(100)", Null: "NO", Key: "UNI", Default: null, Extra: "" },
{ Field: "source_type", Type: "varchar(50)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "description", Type: "text", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
],
traffic_records: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "source_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "user_id", Type: "int(11)", Null: "YES", Key: "MUL", Default: null, Extra: "" },
{ Field: "visit_time", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{ Field: "referrer", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "landing_page", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "exit_page", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "duration_seconds", Type: "int(11)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "device_type", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "os", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "browser", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
],
traffic_campaigns: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "name", Type: "varchar(100)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "source_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "start_date", Type: "date", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "end_date", Type: "date", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "budget", Type: "decimal(10,2)", Null: "YES", Key: "", Default: null, Extra: "" },
{
Field: "status",
Type: "enum('active','paused','completed')",
Null: "NO",
Key: "",
Default: "'active'",
Extra: "",
},
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{
Field: "updated_at",
Type: "datetime",
Null: "YES",
Key: "",
Default: null,
Extra: "on update CURRENT_TIMESTAMP",
},
],
},
content_library: {
content_items: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "title", Type: "varchar(255)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "content_type", Type: "varchar(50)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "content_data", Type: "json", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "created_by", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{
Field: "updated_at",
Type: "datetime",
Null: "YES",
Key: "",
Default: null,
Extra: "on update CURRENT_TIMESTAMP",
},
{
Field: "status",
Type: "enum('draft','published','archived')",
Null: "NO",
Key: "",
Default: "'draft'",
Extra: "",
},
],
content_categories: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "name", Type: "varchar(100)", Null: "NO", Key: "UNI", Default: null, Extra: "" },
{ Field: "parent_id", Type: "int(11)", Null: "YES", Key: "MUL", Default: null, Extra: "" },
{ Field: "description", Type: "text", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
],
content_item_categories: [
{ Field: "content_id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "" },
{ Field: "category_id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
],
content_tags: [
{ Field: "content_id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "" },
{ Field: "tag_id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
],
},
wechat_accounts: {
accounts: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "wechat_id", Type: "varchar(100)", Null: "NO", Key: "UNI", Default: null, Extra: "" },
{ Field: "nickname", Type: "varchar(100)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "avatar_url", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "qr_code_url", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{
Field: "status",
Type: "enum('active','inactive','blocked')",
Null: "NO",
Key: "",
Default: "'active'",
Extra: "",
},
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{ Field: "last_sync", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
],
friends: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "account_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "friend_wechat_id", Type: "varchar(100)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "nickname", Type: "varchar(100)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "remark", Type: "varchar(100)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "avatar_url", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{
Field: "gender",
Type: "enum('male','female','unknown')",
Null: "YES",
Key: "",
Default: "'unknown'",
Extra: "",
},
{ Field: "region", Type: "varchar(100)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "added_at", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "last_interaction", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
],
groups: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "account_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "group_name", Type: "varchar(100)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "group_avatar_url", Type: "varchar(255)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "member_count", Type: "int(11)", Null: "YES", Key: "", Default: "0", Extra: "" },
{ Field: "created_at", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "last_active", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
],
group_members: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "group_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "friend_id", Type: "int(11)", Null: "YES", Key: "MUL", Default: null, Extra: "" },
{ Field: "wechat_id", Type: "varchar(100)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "nickname", Type: "varchar(100)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "joined_at", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "is_admin", Type: "tinyint(1)", Null: "NO", Key: "", Default: "0", Extra: "" },
],
},
device_management: {
devices: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "device_name", Type: "varchar(100)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "device_type", Type: "varchar(50)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "model", Type: "varchar(100)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "os_version", Type: "varchar(50)", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "imei", Type: "varchar(50)", Null: "YES", Key: "UNI", Default: null, Extra: "" },
{ Field: "serial_number", Type: "varchar(100)", Null: "YES", Key: "UNI", Default: null, Extra: "" },
{
Field: "status",
Type: "enum('online','offline','maintenance')",
Null: "NO",
Key: "",
Default: "'offline'",
Extra: "",
},
{ Field: "last_online", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
{ Field: "registered_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
],
device_accounts: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "device_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "account_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "binding_time", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{ Field: "status", Type: "enum('active','inactive')", Null: "NO", Key: "", Default: "'active'", Extra: "" },
{ Field: "last_sync", Type: "datetime", Null: "YES", Key: "", Default: null, Extra: "" },
],
device_logs: [
{ Field: "id", Type: "int(11)", Null: "NO", Key: "PRI", Default: null, Extra: "auto_increment" },
{ Field: "device_id", Type: "int(11)", Null: "NO", Key: "MUL", Default: null, Extra: "" },
{ Field: "log_type", Type: "varchar(50)", Null: "NO", Key: "", Default: null, Extra: "" },
{ Field: "log_message", Type: "text", Null: "NO", Key: "", Default: null, Extra: "" },
{
Field: "log_level",
Type: "enum('info','warning','error','critical')",
Null: "NO",
Key: "",
Default: "'info'",
Extra: "",
},
{ Field: "created_at", Type: "datetime", Null: "NO", Key: "", Default: "CURRENT_TIMESTAMP", Extra: "" },
{ Field: "additional_data", Type: "json", Null: "YES", Key: "", Default: null, Extra: "" },
],
},
}
// 获取所有数据库
export async function getDatabases() {
return mockDatabases
}
// 获取指定数据库中的所有表
export async function getTables(database: string) {
if (!mockDatabaseStructure[database]) {
return []
}
return Object.keys(mockDatabaseStructure[database]).map((tableName) => {
return { Tables_in_database: tableName }
})
}
// 获取表结构
export async function getTableStructure(database: string, table: string) {
if (!mockDatabaseStructure[database] || !mockDatabaseStructure[database][table]) {
return []
}
return mockDatabaseStructure[database][table]
}
// 获取表的创建语句
export async function getTableCreateStatement(database: string, table: string) {
// 这里只返回一个模拟的创建语句
return [
{
Table: table,
"Create Table": `CREATE TABLE ${table} (...)`,
},
]
}
// 获取数据库完整结构信息
export async function getDatabaseStructure(database: string) {
if (!mockDatabaseStructure[database]) {
return {}
}
return mockDatabaseStructure[database]
}