2
0
Эх сурвалжийг харах

Merge branch 'main' of https://git.d8d.fun/d8dfun/d8d-admin-mobile-starter-public

yourname 7 сар өмнө
parent
commit
9d11230e8d

+ 171 - 0
client/migrations/migrations_app.tsx

@@ -0,0 +1,171 @@
+import React, { useState } from 'react';
+import { createRoot } from 'react-dom/client';
+import { Button, Space, Alert, Spin, Typography, Table } from 'antd';
+import axios from 'axios';
+import dayjs from 'dayjs';
+import {
+  QueryClient,
+  QueryClientProvider,
+  useQuery,
+} from '@tanstack/react-query';
+
+const { Title } = Typography;
+
+// 创建QueryClient实例
+const queryClient = new QueryClient();
+
+interface MigrationResponse {
+  success: boolean;
+  error?: string;
+  failedResult?: any;
+}
+
+interface MigrationHistory {
+  id: string;
+  name: string;
+  status: string;
+  timestamp: string;
+  batch: string;
+}
+
+const MigrationsApp: React.FC = () => {
+  const [loading, setLoading] = useState(false);
+  const [migrationResult, setMigrationResult] = useState<MigrationResponse | null>(null);
+
+  const { data: historyData, isLoading: isHistoryLoading, error: historyError } = useQuery({
+    queryKey: ['migrations-history'],
+    queryFn: async () => {
+      const response = await axios.get('/api/migrations/history');
+      return response.data.history;
+    }
+  });
+
+  const runMigrations = async () => {
+    try {
+      setLoading(true);
+      setMigrationResult(null);
+      
+      const response = await axios.get('/api/migrations');
+      setMigrationResult(response.data);
+    } catch (error: any) {
+      setMigrationResult({
+        success: false,
+        error: error.response?.data?.error || '数据库迁移失败',
+        failedResult: error.response?.data?.failedResult
+      });
+    } finally {
+      setLoading(false);
+    }
+  };
+
+  const columns = [
+    {
+      title: '迁移名称',
+      dataIndex: 'name',
+      key: 'name',
+      sorter: (a: MigrationHistory, b: MigrationHistory) => a.name.localeCompare(b.name),
+    },
+    {
+      title: '批次',
+      dataIndex: 'batch',
+      key: 'batch',
+    },
+    {
+      title: '状态',
+      dataIndex: 'status',
+      key: 'status',
+      render: (status: string) => (
+        <span style={{ color: status === 'completed' ? 'green' : 'red' }}>
+          {status === 'completed' ? '已完成' : '失败'}
+        </span>
+      )
+    },
+    {
+      title: '时间',
+      dataIndex: 'timestamp',
+      key: 'timestamp',
+      render: (timestamp: string) => dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')
+    },
+  ];
+
+  return (
+    <div className="p-4">
+      <Title level={3}>数据库迁移管理</Title>
+      
+      <Space direction="vertical" size="middle" style={{ width: '100%' }}>
+        <Button
+          type="primary"
+          onClick={runMigrations}
+          loading={loading}
+          disabled={loading}
+        >
+          执行迁移
+        </Button>
+
+        {loading && <Spin tip="迁移执行中..." />}
+
+        {migrationResult && (
+          migrationResult.success ? (
+            <Alert
+              message="迁移成功"
+              type="success"
+              showIcon
+            />
+          ) : (
+            <Alert
+              message="迁移失败"
+              description={
+                <>
+                  <p>{migrationResult.error}</p>
+                  {migrationResult.failedResult && (
+                    <pre style={{ marginTop: 10 }}>
+                      {JSON.stringify(migrationResult.failedResult, null, 2)}
+                    </pre>
+                  )}
+                </>
+              }
+              type="error"
+              showIcon
+            />
+          )
+        )}
+
+        <Title level={4}>迁移历史记录</Title>
+        
+        {isHistoryLoading ? (
+          <Spin tip="加载历史记录中..." />
+        ) : historyError ? (
+          <Alert
+            message="加载历史记录失败"
+            description={historyError.message}
+            type="error"
+            showIcon
+          />
+        ) : (
+          <Table
+            columns={columns}
+            dataSource={historyData}
+            rowKey="id"
+            pagination={{
+              pageSize: 10,
+              showSizeChanger: true,
+              pageSizeOptions: ['10', '20', '50', '100'],
+              showTotal: (total) => `共 ${total} 条记录`,
+            }}
+            bordered
+            className="migration-history-table"
+            style={{ marginTop: 16 }}
+          />
+        )}
+      </Space>
+    </div>
+  );
+};
+
+// 渲染应用
+const root = createRoot(document.getElementById('root') as HTMLElement);
+root.render(
+  <QueryClientProvider client={queryClient}>
+    <MigrationsApp />
+  </QueryClientProvider>
+);

+ 8 - 11
client/mobile/api/auth.ts

@@ -1,9 +1,6 @@
 import axios from 'axios';
 import type { User } from '../../share/types.ts';
 
-// 从原api.ts导入基础配置
-const API_BASE_URL = '/api';
-
 // 定义API返回数据类型
 interface AuthLoginResponse {
   message: string;
@@ -34,7 +31,7 @@ export const AuthAPI: AuthAPIType = {
   // 登录API
   login: async (username: string, password: string, latitude?: number, longitude?: number) => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/auth/login`, {
+      const response = await axios.post('/auth/login', {
         username,
         password,
         latitude,
@@ -49,7 +46,7 @@ export const AuthAPI: AuthAPIType = {
   // 注册API
   register: async (username: string, email: string, password: string) => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/auth/register`, { username, email, password });
+      const response = await axios.post('/auth/register', { username, email, password });
       return response.data;
     } catch (error) {
       throw error;
@@ -59,7 +56,7 @@ export const AuthAPI: AuthAPIType = {
   // 登出API
   logout: async () => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/auth/logout`);
+      const response = await axios.post('/auth/logout');
       return response.data;
     } catch (error) {
       throw error;
@@ -69,7 +66,7 @@ export const AuthAPI: AuthAPIType = {
   // 获取当前用户信息
   getCurrentUser: async () => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/auth/me`);
+      const response = await axios.get('/auth/me');
       return response.data;
     } catch (error) {
       throw error;
@@ -79,7 +76,7 @@ export const AuthAPI: AuthAPIType = {
   // 更新用户信息
   updateUser: async (userId: number, userData: Partial<User>) => {
     try {
-      const response = await axios.put(`${API_BASE_URL}/auth/users/${userId}`, userData);
+      const response = await axios.put(`/auth/users/${userId}`, userData);
       return response.data;
     } catch (error) {
       throw error;
@@ -89,7 +86,7 @@ export const AuthAPI: AuthAPIType = {
   // 修改密码
   changePassword: async (oldPassword: string, newPassword: string) => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/auth/change-password`, { oldPassword, newPassword });
+      const response = await axios.post('/auth/change-password', { oldPassword, newPassword });
       return response.data;
     } catch (error) {
       throw error;
@@ -99,7 +96,7 @@ export const AuthAPI: AuthAPIType = {
   // 请求重置密码
   requestPasswordReset: async (email: string) => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/auth/request-password-reset`, { email });
+      const response = await axios.post('/auth/request-password-reset', { email });
       return response.data;
     } catch (error) {
       throw error;
@@ -109,7 +106,7 @@ export const AuthAPI: AuthAPIType = {
   // 重置密码
   resetPassword: async (token: string, newPassword: string) => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/auth/reset-password`, { token, newPassword });
+      const response = await axios.post('/auth/reset-password', { token, newPassword });
       return response.data;
     } catch (error) {
       throw error;

+ 4 - 6
client/mobile/api/chart.ts

@@ -1,7 +1,5 @@
 import axios from 'axios';
 
-const API_BASE_URL = '/api';
-
 // 图表数据API接口类型
 interface ChartDataResponse<T> {
   message: string;
@@ -35,7 +33,7 @@ export const ChartAPI = {
   // 获取用户活跃度数据
   getUserActivity: async (): Promise<ChartDataResponse<UserActivityData[]>> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/charts/user-activity`);
+      const response = await axios.get('/charts/user-activity');
       return response.data;
     } catch (error) {
       throw error;
@@ -45,7 +43,7 @@ export const ChartAPI = {
   // 获取文件上传统计数据
   getFileUploads: async (): Promise<ChartDataResponse<FileUploadsData[]>> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/charts/file-uploads`);
+      const response = await axios.get('/charts/file-uploads');
       return response.data;
     } catch (error) {
       throw error;
@@ -55,7 +53,7 @@ export const ChartAPI = {
   // 获取文件类型分布数据
   getFileTypes: async (): Promise<ChartDataResponse<FileTypesData[]>> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/charts/file-types`);
+      const response = await axios.get('/charts/file-types');
       return response.data;
     } catch (error) {
       throw error;
@@ -65,7 +63,7 @@ export const ChartAPI = {
   // 获取仪表盘概览数据
   getDashboardOverview: async (): Promise<ChartDataResponse<DashboardOverviewData>> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/charts/dashboard-overview`);
+      const response = await axios.get('/charts/dashboard-overview');
       return response.data;
     } catch (error) {
       throw error;

+ 11 - 13
client/mobile/api/file.ts

@@ -1,11 +1,9 @@
 import axios from 'axios';
 import type { MinioUploadPolicy, OSSUploadPolicy } from '@d8d-appcontainer/types';
-import type { 
+import type {
   FileLibrary, FileCategory
 } from '../../share/types.ts';
 
-const API_BASE_URL = '/api';
-
 interface FileUploadPolicyResponse {
   message: string;
   data: MinioUploadPolicy | OSSUploadPolicy;
@@ -64,7 +62,7 @@ export const FileAPI = {
   // 获取文件上传策略
   getUploadPolicy: async (filename: string, prefix: string = 'uploads/', maxSize: number = 10 * 1024 * 1024): Promise<FileUploadPolicyResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/upload/policy`, { 
+      const response = await axios.get('/upload/policy', {
         params: { filename, prefix, maxSize } 
       });
       return response.data;
@@ -76,7 +74,7 @@ export const FileAPI = {
   // 保存文件信息
   saveFileInfo: async (fileData: Partial<FileLibrary>): Promise<FileSaveResponse> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/upload/save`, fileData);
+      const response = await axios.post('/upload/save', fileData);
       return response.data;
     } catch (error) {
       throw error;
@@ -92,7 +90,7 @@ export const FileAPI = {
     keyword?: string
   }): Promise<FileListResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/upload/list`, { params });
+      const response = await axios.get('/upload/list', { params });
       return response.data;
     } catch (error) {
       throw error;
@@ -102,7 +100,7 @@ export const FileAPI = {
   // 获取单个文件信息
   getFileInfo: async (id: number): Promise<FileInfoResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/upload/${id}`);
+      const response = await axios.get(`/upload/${id}`);
       return response.data;
     } catch (error) {
       throw error;
@@ -112,7 +110,7 @@ export const FileAPI = {
   // 更新文件下载计数
   updateDownloadCount: async (id: number): Promise<FileDeleteResponse> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/upload/${id}/download`);
+      const response = await axios.post(`/upload/${id}/download`);
       return response.data;
     } catch (error) {
       throw error;
@@ -122,7 +120,7 @@ export const FileAPI = {
   // 删除文件
   deleteFile: async (id: number): Promise<FileDeleteResponse> => {
     try {
-      const response = await axios.delete(`${API_BASE_URL}/upload/${id}`);
+      const response = await axios.delete(`/upload/${id}`);
       return response.data;
     } catch (error) {
       throw error;
@@ -136,7 +134,7 @@ export const FileAPI = {
     search?: string
   }): Promise<FileCategoryListResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/file-categories`, { params });
+      const response = await axios.get('/file-categories', { params });
       return response.data;
     } catch (error) {
       throw error;
@@ -146,7 +144,7 @@ export const FileAPI = {
   // 创建文件分类
   createCategory: async (data: Partial<FileCategory>): Promise<FileCategoryCreateResponse> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/file-categories`, data);
+      const response = await axios.post('/file-categories', data);
       return response.data;
     } catch (error) {
       throw error;
@@ -156,7 +154,7 @@ export const FileAPI = {
   // 更新文件分类
   updateCategory: async (id: number, data: Partial<FileCategory>): Promise<FileCategoryUpdateResponse> => {
     try {
-      const response = await axios.put(`${API_BASE_URL}/file-categories/${id}`, data);
+      const response = await axios.put(`/file-categories/${id}`, data);
       return response.data;
     } catch (error) {
       throw error;
@@ -166,7 +164,7 @@ export const FileAPI = {
   // 删除文件分类
   deleteCategory: async (id: number): Promise<FileCategoryDeleteResponse> => {
     try {
-      const response = await axios.delete(`${API_BASE_URL}/file-categories/${id}`);
+      const response = await axios.delete(`/file-categories/${id}`);
       return response.data;
     } catch (error) {
       throw error;

+ 4 - 6
client/mobile/api/home.ts

@@ -1,10 +1,8 @@
 import axios from 'axios';
-import type { 
+import type {
   KnowInfo
 } from '../../share/types.ts';
 
-const API_BASE_URL = '/api';
-
 // 首页数据相关类型定义
 interface HomeBannersResponse {
   message: string;
@@ -43,7 +41,7 @@ export const HomeAPI = {
   // 获取轮播图
   getBanners: async (): Promise<HomeBannersResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/home/banners`);
+      const response = await axios.get('/home/banners');
       return response.data;
     } catch (error) {
       throw error;
@@ -57,7 +55,7 @@ export const HomeAPI = {
     category?: string
   }): Promise<HomeNewsResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/home/news`, { params });
+      const response = await axios.get('/home/news', { params });
       return response.data;
     } catch (error) {
       throw error;
@@ -70,7 +68,7 @@ export const HomeAPI = {
     pageSize?: number
   }): Promise<HomeNoticesResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/home/notices`, { params });
+      const response = await axios.get('/home/notices', { params });
       return response.data;
     } catch (error) {
       throw error;

+ 16 - 1
client/mobile/api/index.ts

@@ -1,3 +1,10 @@
+import axios from 'axios';
+
+// 基础配置
+const API_BASE_URL = '/api';
+// 全局axios配置
+axios.defaults.baseURL = API_BASE_URL;
+
 export * from './auth.ts';
 export * from './user.ts';
 export * from './file.ts';
@@ -7,4 +14,12 @@ export * from './home.ts';
 export * from './map.ts';
 export * from './system.ts';
 export * from './message.ts';
-export * from './classroom.ts';
+
+// 获取OSS完整URL
+export const getOssUrl = (path: string): string => {
+  // 获取全局配置中的OSS_HOST,如果不存在使用默认值
+  const ossHost = (window.CONFIG?.OSS_BASE_URL) || '';
+  // 确保path不以/开头
+  const ossPath = path.startsWith('/') ? path.substring(1) : path;
+  return `${ossHost}/${ossPath}`;
+};

+ 4 - 6
client/mobile/api/map.ts

@@ -1,10 +1,8 @@
 import axios from 'axios';
-import type { 
+import type {
   LoginLocation, LoginLocationDetail,
 } from '../../share/types.ts';
 
-const API_BASE_URL = '/api';
-
 
 // 地图相关API的接口类型定义
 export interface LoginLocationResponse {
@@ -31,7 +29,7 @@ export const MapAPI = {
     userId?: number 
   }): Promise<LoginLocationResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/map/markers`, { params });
+      const response = await axios.get('/map/markers', { params });
       return response.data;
     } catch (error) {
       throw error;
@@ -41,7 +39,7 @@ export const MapAPI = {
   // 获取登录位置详情
   getLocationDetail: async (locationId: number): Promise<LoginLocationDetailResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/map/location/${locationId}`);
+      const response = await axios.get(`/map/location/${locationId}`);
       return response.data;
     } catch (error) {
       throw error;
@@ -55,7 +53,7 @@ export const MapAPI = {
     location_name?: string; 
   }): Promise<LoginLocationUpdateResponse> => {
     try {
-      const response = await axios.put(`${API_BASE_URL}/map/location/${locationId}`, data);
+      const response = await axios.put(`/map/location/${locationId}`, data);
       return response.data;
     } catch (error) {
       throw error;

+ 7 - 9
client/mobile/api/message.ts

@@ -1,10 +1,8 @@
 import axios from 'axios';
-import type { 
+import type {
   MessageType, MessageStatus, UserMessage
 } from '../../share/types.ts';
 
-const API_BASE_URL = '/api';
-
 // 消息API响应类型
 export interface MessageResponse {
   message: string;
@@ -35,7 +33,7 @@ export const MessageAPI = {
     status?: MessageStatus
   }): Promise<MessagesResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/messages`, { params });
+      const response = await axios.get('/messages', { params });
       return response.data;
     } catch (error) {
       throw error;
@@ -45,7 +43,7 @@ export const MessageAPI = {
   // 获取消息详情
   getMessage: async (id: number): Promise<MessageResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/messages/${id}`);
+      const response = await axios.get(`/messages/${id}`);
       return response.data;
     } catch (error) {
       throw error;
@@ -60,7 +58,7 @@ export const MessageAPI = {
     receiver_ids: number[]
   }): Promise<MessageResponse> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/messages`, data);
+      const response = await axios.post('/messages', data);
       return response.data;
     } catch (error) {
       throw error;
@@ -70,7 +68,7 @@ export const MessageAPI = {
   // 删除消息(软删除)
   deleteMessage: async (id: number): Promise<MessageResponse> => {
     try {
-      const response = await axios.delete(`${API_BASE_URL}/messages/${id}`);
+      const response = await axios.delete(`/messages/${id}`);
       return response.data;
     } catch (error) {
       throw error;
@@ -80,7 +78,7 @@ export const MessageAPI = {
   // 获取未读消息数量
   getUnreadCount: async (): Promise<UnreadCountResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/messages/count/unread`);
+      const response = await axios.get('/messages/count/unread');
       return response.data;
     } catch (error) {
       throw error;
@@ -90,7 +88,7 @@ export const MessageAPI = {
   // 标记消息为已读
   markAsRead: async (id: number): Promise<MessageResponse> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/messages/${id}/read`);
+      const response = await axios.post(`/messages/${id}/read`);
       return response.data;
     } catch (error) {
       throw error;

+ 6 - 8
client/mobile/api/system.ts

@@ -1,16 +1,14 @@
 import axios from 'axios';
-import type { 
-  SystemSetting, SystemSettingGroupData, 
+import type {
+  SystemSetting, SystemSettingGroupData,
 } from '../../share/types.ts';
 
-const API_BASE_URL = '/api';
-
 // 系统设置API
 export const SystemAPI = {
   // 获取所有系统设置
   getSettings: async (): Promise<SystemSettingGroupData[]> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/settings`);
+      const response = await axios.get('/settings');
       return response.data.data;
     } catch (error) {
       throw error;
@@ -20,7 +18,7 @@ export const SystemAPI = {
   // 获取指定分组的系统设置
   getSettingsByGroup: async (group: string): Promise<SystemSetting[]> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/settings/group/${group}`);
+      const response = await axios.get(`/settings/group/${group}`);
       return response.data.data;
     } catch (error) {
       throw error;
@@ -31,7 +29,7 @@ export const SystemAPI = {
   // 更新系统设置
   updateSettings: async (settings: Partial<SystemSetting>[]): Promise<SystemSetting[]> => {
     try {
-      const response = await axios.put(`${API_BASE_URL}/settings`, settings);
+      const response = await axios.put('/settings', settings);
       return response.data.data;
     } catch (error) {
       throw error;
@@ -41,7 +39,7 @@ export const SystemAPI = {
   // 重置系统设置
   resetSettings: async (): Promise<SystemSetting[]> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/settings/reset`);
+      const response = await axios.post('/settings/reset');
       return response.data.data;
     } catch (error) {
       throw error;

+ 4 - 6
client/mobile/api/theme.ts

@@ -1,16 +1,14 @@
 import axios from 'axios';
-import type { 
+import type {
   ThemeSettings
 } from '../../share/types.ts';
 
-const API_BASE_URL = '/api';
-
 // Theme API 定义
 export const ThemeAPI = {
   // 获取主题设置
   getThemeSettings: async (): Promise<ThemeSettings> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/theme`);
+      const response = await axios.get('/theme');
       return response.data.data;
     } catch (error) {
       throw error;
@@ -20,7 +18,7 @@ export const ThemeAPI = {
   // 更新主题设置
   updateThemeSettings: async (themeData: Partial<ThemeSettings>): Promise<ThemeSettings> => {
     try {
-      const response = await axios.put(`${API_BASE_URL}/theme`, themeData);
+      const response = await axios.put('/theme', themeData);
       return response.data.data;
     } catch (error) {
       throw error;
@@ -30,7 +28,7 @@ export const ThemeAPI = {
   // 重置主题设置
   resetThemeSettings: async (): Promise<ThemeSettings> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/theme/reset`);
+      const response = await axios.post('/theme/reset');
       return response.data.data;
     } catch (error) {
       throw error;

+ 7 - 9
client/mobile/api/user.ts

@@ -1,8 +1,6 @@
 import axios from 'axios';
 import type { User } from '../../share/types.ts';
 
-const API_BASE_URL = '/api';
-
 // 为UserAPI添加的接口响应类型
 interface UsersResponse {
   data: User[];
@@ -39,7 +37,7 @@ export const UserAPI = {
   // 获取用户列表
   getUsers: async (params?: { page?: number, limit?: number, search?: string }): Promise<UsersResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/users`, { params });
+      const response = await axios.get('/users', { params });
       return response.data;
     } catch (error) {
       throw error;
@@ -49,7 +47,7 @@ export const UserAPI = {
   // 获取单个用户详情
   getUser: async (userId: number): Promise<UserResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/users/${userId}`);
+      const response = await axios.get(`/users/${userId}`);
       return response.data;
     } catch (error) {
       throw error;
@@ -59,7 +57,7 @@ export const UserAPI = {
   // 创建用户
   createUser: async (userData: Partial<User>): Promise<UserCreateResponse> => {
     try {
-      const response = await axios.post(`${API_BASE_URL}/users`, userData);
+      const response = await axios.post('/users', userData);
       return response.data;
     } catch (error) {
       throw error;
@@ -69,7 +67,7 @@ export const UserAPI = {
   // 更新用户信息
   updateUser: async (userId: number, userData: Partial<User>): Promise<UserUpdateResponse> => {
     try {
-      const response = await axios.put(`${API_BASE_URL}/users/${userId}`, userData);
+      const response = await axios.put(`/users/${userId}`, userData);
       return response.data;
     } catch (error) {
       throw error;
@@ -79,7 +77,7 @@ export const UserAPI = {
   // 删除用户
   deleteUser: async (userId: number): Promise<UserDeleteResponse> => {
     try {
-      const response = await axios.delete(`${API_BASE_URL}/users/${userId}`);
+      const response = await axios.delete(`/users/${userId}`);
       return response.data;
     } catch (error) {
       throw error;
@@ -89,7 +87,7 @@ export const UserAPI = {
   // 获取当前用户信息
   getCurrentUser: async (): Promise<UserResponse> => {
     try {
-      const response = await axios.get(`${API_BASE_URL}/users/me/profile`);
+      const response = await axios.get('/users/me/profile');
       return response.data;
     } catch (error) {
       throw error;
@@ -99,7 +97,7 @@ export const UserAPI = {
   // 更新当前用户信息
   updateCurrentUser: async (userData: Partial<User>): Promise<UserUpdateResponse> => {
     try {
-      const response = await axios.put(`${API_BASE_URL}/users/me/profile`, userData);
+      const response = await axios.put('/users/me/profile', userData);
       return response.data;
     } catch (error) {
       throw error;

+ 38 - 8
server/app.tsx

@@ -359,6 +359,15 @@ export default function({ apiClient, app, moduleDir }: ModuleParams) {
                 >
                   进入移动端
                 </a>
+
+                {/* 迁移管理入口按钮 */}
+                <a
+                  href="/migrations"
+                  className="w-full flex justify-center py-3 px-4 border border-red-600 rounded-md shadow-sm text-lg font-medium text-red-600 bg-white hover:bg-red-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500"
+                >
+                  数据库迁移
+                </a>
+                
               </div>
             </div>
           </div>
@@ -371,21 +380,25 @@ export default function({ apiClient, app, moduleDir }: ModuleParams) {
   const createHtmlWithConfig = (scriptConfig: EsmScriptConfig, title = '应用Starter') => {
     return (c: HonoContext) => {
       const isProd = GLOBAL_CONFIG.ENV === 'production';
+      const isLocalDeploy = Deno.env.get('IS_LOCAL_DEPLOY') === 'true';
       
       return c.html(
         <html lang="zh-CN">
           <head>
             <meta charset="UTF-8" />
             <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+            {isProd && <meta name="version" content={Deno.env.get('VERSION') || '0.1.0'} />}
             <title>{title}</title>
             
-            {isProd ? (
+            {isLocalDeploy ? (
               <script type="module" src={scriptConfig.prodSrc || `/client_dist/${scriptConfig.prodPath}`}></script>
             ) : (
-              <script src={scriptConfig.src} href={scriptConfig.href} deno-json={scriptConfig.denoJson} refresh={scriptConfig.refresh}></script>
+              <script src={scriptConfig.src} href={scriptConfig.href} deno-json={scriptConfig.denoJson} 
+              {...isProd ? {}:{ refresh: true }}
+              ></script>
             )}
             
-            {isProd ? (<script src="/tailwindcss@3.4.16/index.js"></script>) : (<script src="https://cdn.tailwindcss.com"></script>)}
+            {isLocalDeploy ? (<script src="/tailwindcss@3.4.16/index.js"></script>) : (<script src="https://cdn.tailwindcss.com"></script>)}
 
             <script dangerouslySetInnerHTML={{ __html: `window.CONFIG = ${JSON.stringify(GLOBAL_CONFIG)};` }} />
             
@@ -442,14 +455,31 @@ export default function({ apiClient, app, moduleDir }: ModuleParams) {
   }, GLOBAL_CONFIG.APP_NAME))
   
   honoApp.get('/mobile/*', createHtmlWithConfig({
-    src: "https://esm.d8d.fun/xb", 
-    href: "/client/mobile/mobile_app.tsx", 
-    denoJson: "/deno.json", 
-    refresh: true, 
+    src: "https://esm.d8d.fun/xb",
+    href: "/client/mobile/mobile_app.tsx",
+    denoJson: "/deno.json",
+    refresh: true,
     prodPath: "mobile/mobile_app.js"
   }, GLOBAL_CONFIG.APP_NAME))
 
-  const staticRoutes = serveStatic({ 
+  // 迁移管理路由
+  honoApp.get('/migrations', createHtmlWithConfig({
+    src: "https://esm.d8d.fun/xb",
+    href: "/client/migrations/migrations_app.tsx",
+    denoJson: "/deno.json",
+    refresh: true,
+    prodPath: "migrations/migrations_app.js"
+  }, GLOBAL_CONFIG.APP_NAME))
+
+  honoApp.get('/migrations/*', createHtmlWithConfig({
+    src: "https://esm.d8d.fun/xb",
+    href: "/client/migrations/migrations_app.tsx",
+    denoJson: "/deno.json",
+    refresh: true,
+    prodPath: "migrations/migrations_app.js"
+  }, GLOBAL_CONFIG.APP_NAME))
+
+  const staticRoutes = serveStatic({
     root: moduleDir,
     onFound: async (path: string, c: HonoContext) => {
       const fileExt = path.split('.').pop()?.toLowerCase()

+ 22 - 9
server/routes_migrations.ts

@@ -7,20 +7,15 @@ import debug from "debug";
 const log = {
   api: debug("api:migrations"),
 };
-// 初始化数据库
-const initDatabase = async (apiClient: APIClient) => {
-    log.api('正在执行数据库迁移...')
-    const migrationsResult = await apiClient.database.executeLiveMigrations(migrations)
-    // log.app('数据库迁移完成 %O',migrationsResult)
-    log.api('数据库迁移完成')
-    return migrationsResult
-}
+
 export function createMigrationsRoutes(withAuth: WithAuth) {
   const migrationsRoutes = new Hono<{ Variables: Variables }>()
 
   migrationsRoutes.get('/', async (c) => {
     const apiClient = c.get('apiClient')
-    const migrationsResult = await initDatabase(apiClient)
+    log.api('正在执行数据库迁移...')
+    const migrationsResult = await apiClient.database.executeLiveMigrations(migrations)
+    // log.app('数据库迁移完成 %O',migrationsResult)
     
     const failedResult = migrationsResult?.find((migration) => migration.status === 'failed')
     if (failedResult) {
@@ -31,5 +26,23 @@ export function createMigrationsRoutes(withAuth: WithAuth) {
     return c.json({ success: true })
   })
 
+
+  migrationsRoutes.get('/history', async (c) => {
+    const apiClient = c.get('apiClient')
+    log.api('正在执行数据库迁移...')
+    const MIRGRATIONS_TABLE = 'knex_migrations'
+    const hasTable = await apiClient.database.schema.hasTable(MIRGRATIONS_TABLE);
+
+    let history = []
+
+    if(hasTable)
+      history = await apiClient.database.table(MIRGRATIONS_TABLE).orderBy('id', 'desc')
+    
+    return c.json({
+      success: true,
+      history
+    })
+  })
+
   return migrationsRoutes
 }