Files
xinghuoapi/frontend/src/components/layout
IanShaw 254f12543c feat(frontend): 前端界面优化与使用统计功能增强 (#46)
* feat(frontend): 前端界面优化与使用统计功能增强

主要改动:

1. 表格布局统一优化
   - 新增 TablePageLayout 通用布局组件
   - 统一所有管理页面的表格样式和交互
   - 优化 DataTable、Pagination、Select 等通用组件

2. 使用统计功能增强
   - 管理端: 添加完整的筛选和显示功能
   - 用户端: 完善 API Key 列显示
   - 后端: 优化使用统计数据结构和查询

3. 账户组件优化
   - 优化 AccountStatsModal、AccountUsageCell 等组件
   - 统一进度条和统计显示样式

4. 其他改进
   - 完善中英文国际化
   - 统一页面样式和交互体验
   - 优化各视图页面的响应式布局

* fix(test): 修复 stubUsageLogRepo.ListWithFilters 测试 stub

测试用例 GET /api/v1/usage 返回 500 是因为 stub 方法未实现,
现在正确返回基于 UserID 过滤的日志数据。

* feat(frontend): 统一日期时间显示格式

**主要改动**:
1. 增强 utils/format.ts:
   - 新增 formatDateOnly() - 格式: YYYY-MM-DD
   - 新增 formatDateTime() - 格式: YYYY-MM-DD HH:mm:ss

2. 全局替换视图中的格式化函数:
   - 移除各视图中的自定义 formatDate 函数
   - 统一导入使用 @/utils/format 中的函数
   - created_at/updated_at 使用 formatDateTime
   - expires_at 使用 formatDateOnly

3. 受影响的视图 (8个):
   - frontend/src/views/user/KeysView.vue
   - frontend/src/views/user/DashboardView.vue
   - frontend/src/views/user/UsageView.vue
   - frontend/src/views/user/RedeemView.vue
   - frontend/src/views/admin/UsersView.vue
   - frontend/src/views/admin/UsageView.vue
   - frontend/src/views/admin/RedeemView.vue
   - frontend/src/views/admin/SubscriptionsView.vue

**效果**:
- 日期统一显示为 YYYY-MM-DD
- 时间统一显示为 YYYY-MM-DD HH:mm:ss
- 提升可维护性,避免格式不一致

* fix(frontend): 补充遗漏的时间格式化统一

**补充修复**(基于 code review 发现的遗漏):

1. 增强 utils/format.ts:
   - 新增 formatTime() - 格式: HH:mm

2. 修复 4 个遗漏的文件:
   - src/views/admin/UsersView.vue
     * 删除 formatExpiresAt(),改用 formatDateTime()
     * 修复订阅过期时间 tooltip 显示格式不一致问题

   - src/views/user/ProfileView.vue
     * 删除 formatMemberSince(),改用 formatDate(date, 'YYYY-MM')
     * 统一会员起始时间显示格式

   - src/views/user/SubscriptionsView.vue
     * 修改 formatExpirationDate() 使用 formatDateOnly()
     * 保留天数计算逻辑

   - src/components/account/AccountStatusIndicator.vue
     * 删除本地 formatTime(),改用 utils/format 中的统一函数
     * 修复 rate limit 和 overload 重置时间显示

**验证**:
- TypeScript 类型检查通过 ✓
- 前端构建成功 ✓
- 所有剩余的 toLocaleString() 都是数字格式化,属于正确用法 ✓

**效果**:
- 订阅过期时间统一为 YYYY-MM-DD HH:mm:ss
- 会员起始时间统一为 YYYY-MM
- 重置时间统一为 HH:mm
- 消除所有不规范的原生 locale 方法调用
2025-12-27 10:50:25 +08:00
..

Layout Components

Vue 3 layout components for the Sub2API frontend, built with Composition API, TypeScript, and TailwindCSS.

Components

1. AppLayout.vue

Main application layout with sidebar and header.

Usage:

<template>
  <AppLayout>
    <!-- Your page content here -->
    <h1>Dashboard</h1>
    <p>Welcome to your dashboard!</p>
  </AppLayout>
</template>

<script setup lang="ts">
import { AppLayout } from '@/components/layout'
</script>

Features:

  • Responsive sidebar (collapsible)
  • Fixed header at top
  • Main content area with slot
  • Automatically adjusts margin based on sidebar state

2. AppSidebar.vue

Navigation sidebar with user and admin sections.

Features:

  • Logo/brand at top
  • User navigation links:
    • Dashboard
    • API Keys
    • Usage
    • Redeem
    • Profile
  • Admin navigation links (shown only if user is admin):
    • Admin Dashboard
    • Users
    • Groups
    • Accounts
    • Proxies
    • Redeem Codes
  • Collapsible sidebar with toggle button
  • Active route highlighting
  • Icons using HTML entities
  • Responsive (mobile-friendly)

Used automatically by AppLayout - no need to import separately.


3. AppHeader.vue

Top header with user info and actions.

Features:

  • Mobile menu toggle button
  • Page title (from route meta or slot)
  • User balance display (desktop only)
  • User dropdown menu with:
    • Profile link
    • Logout button
  • User avatar with initials
  • Click-outside handling for dropdown
  • Responsive design

Usage with custom title:

<template>
  <AppLayout>
    <template #title> Custom Page Title </template>

    <!-- Your content -->
  </AppLayout>
</template>

Used automatically by AppLayout - no need to import separately.


4. AuthLayout.vue

Simple centered layout for authentication pages (login/register).

Usage:

<template>
  <AuthLayout>
    <!-- Login/Register form content -->
    <h2 class="mb-6 text-2xl font-bold">Login</h2>

    <form @submit.prevent="handleLogin">
      <!-- Form fields -->
    </form>

    <!-- Optional footer slot -->
    <template #footer>
      <p>
        Don't have an account?
        <router-link to="/register" class="text-indigo-600 hover:underline"> Sign up </router-link>
      </p>
    </template>
  </AuthLayout>
</template>

<script setup lang="ts">
import { AuthLayout } from '@/components/layout'

function handleLogin() {
  // Login logic
}
</script>

Features:

  • Centered card container
  • Gradient background
  • Logo/brand at top
  • Main content slot
  • Optional footer slot for links
  • Fully responsive

Route Configuration

To set page titles in the header, add meta to your routes:

// router/index.ts
const routes = [
  {
    path: '/dashboard',
    component: DashboardView,
    meta: { title: 'Dashboard' }
  },
  {
    path: '/api-keys',
    component: ApiKeysView,
    meta: { title: 'API Keys' }
  }
  // ...
]

Store Dependencies

These components use the following Pinia stores:

  • useAuthStore: For user authentication state, role checking, and logout
  • useAppStore: For sidebar state management and toast notifications

Make sure these stores are properly initialized in your app.


Styling

All components use TailwindCSS utility classes. Make sure your tailwind.config.js includes the component paths:

module.exports = {
  content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}']
  // ...
}

Icons

Components use HTML entity icons for simplicity:

  • 📈 Chart (Dashboard)
  • 🔑 Key (API Keys)
  • 📊 Bar Chart (Usage)
  • 🎁 Gift (Redeem)
  • 👤 User (Profile)
  • 🔌 Admin
  • 👥 Users
  • 📁 Folder (Groups)
  • 🌐 Globe (Accounts)
  • 🔄 Network (Proxies)
  • 🏷 Ticket (Redeem Codes)

You can replace these with your preferred icon library (e.g., Heroicons, Font Awesome) if needed.


Mobile Responsiveness

All components are fully responsive:

  • AppSidebar: Fixed positioning on desktop, hidden by default on mobile
  • AppHeader: Shows mobile menu toggle on small screens, hides balance display
  • AuthLayout: Adapts padding and card size for mobile devices

The sidebar uses Tailwind's responsive breakpoints (md:) to adjust behavior.