# 分页面板组件

一个全面的分页控制面板，集成了页面导航、每页行数选择和总记录数显示，提供统一的界面。

## 功能

- **完整分页**：包括页面导航、行数选择器和摘要信息
- **可自定义行数选项**：配置可用的每页行数选项
- **总信息显示**：显示总记录数，支持自定义格式
- **多种对齐方式**：支持左对齐、右对齐和居中对齐
- **尺寸变体**：提供普通和大尺寸选项
- **样式集成**：继承基础分页组件的样式
- **自定义信息生成器**：支持灵活的总信息显示格式
- **事件处理**：分别处理页面更改和行数更改事件

## 安装

```bash
npm install @ticatec/uniface-element
```

## 基本用法

```svelte
<script>
  import PaginationPanel from '@ticatec/uniface-element/PaginationPanel';
  
  let currentPage = 1;
  let totalPages = 10;
  let totalRecords = 250;
  let rowsPerPage = 25;
  
  function handlePageChange(page) {
    currentPage = page;
    console.log('页面更改为：', page);
  }
  
  function handleRowCountChange(rows) {
    rowsPerPage = rows;
    // 根据新的行数重新计算总页数
    totalPages = Math.ceil(totalRecords / rows);
    currentPage = 1; // 重置为第一页
    console.log('每页行数更改为：', rows);
  }
</script>

<PaginationPanel
  pageNo={currentPage}
  pageCount={totalPages}
  total={totalRecords}
  rowCount={rowsPerPage}
  onPageChange={handlePageChange}
  onRowCountChanged={handleRowCountChange}
/>
```

## API 参考

### 属性

| 属性 | 类型 | 默认值 | 描述 |
|------|------|---------|-------------|
| `pageNo` | `number` | `1` | 当前活动页面编号 |
| `pageCount` | `number` | `0` | 总页面数 |
| `total` | `number` | `null` | 总记录数 |
| `rowCount` | `number` | `25` | 当前每页行数设置 |
| `rowsSet` | `Array<number>` | `[25, 50, 100]` | 可用的每页行数选项 |
| `type` | `'plain' \| 'round' \| 'circle'` | `'round'` | 视觉样式变体 |
| `page$style` | `string` | `''` | 分页组件的自定义 CSS 样式 |
| `big` | `boolean` | `false` | 启用较大尺寸变体 |
| `rowCountLabel` | `string` | `'Rows/Page'` | 每页行数选择器的标签 |
| `align` | `'left' \| 'right' \| ''` | `''` | 面板对齐方式 |
| `generateInfo` | `GenerateTotalInfo \| null` | `null` | 自定义生成总信息文本的函数 |
| `onPageChange` | `OnPageChange` | `undefined` | 页面更改事件处理程序 |
| `onRowCountChanged` | `OnRowCountChanged` | `undefined` | 行数更改事件处理程序 |

### 类型

```typescript
export type OnPageChange = (page: number) => void;
export type OnRowCountChanged = (rows: number) => void;
export type GenerateTotalInfo = (total: number, pageCount: number, pageNo: number, rows: number) => string;
```

## 示例

### 带完整分页的数据表格

```svelte
<script>
  import PaginationPanel from '@ticatec/uniface-element/PaginationPanel';
  
  let users = [];
  let currentPage = 1;
  let totalPages = 1;
  let totalUsers = 0;
  let rowsPerPage = 25;
  let loading = false;
  
  async function loadUsers(page = 1, rows = 25) {
    loading = true;
    
    try {
      // 模拟 API 调用
      await new Promise(resolve => setTimeout(resolve, 500));
      
      // 模拟数据
      totalUsers = 237; // API 返回的总记录数
      totalPages = Math.ceil(totalUsers / rows);
      currentPage = page;
      
      const startIndex = (page - 1) * rows;
      users = Array.from({ length: Math.min(rows, totalUsers - startIndex) }, (_, i) => ({
        id: startIndex + i + 1,
        name: `用户 ${startIndex + i + 1}`,
        email: `user${startIndex + i + 1}@example.com`,
        role: ['管理员', '用户', '审核者'][Math.floor(Math.random() * 3)],
        status: Math.random() > 0.2 ? '活跃' : '非活跃'
      }));
    } finally {
      loading = false;
    }
  }
  
  function handlePageChange(page) {
    loadUsers(page, rowsPerPage);
  }
  
  function handleRowCountChange(rows) {
    rowsPerPage = rows;
    loadUsers(1, rows); // 重置为第一页
  }
  
  // 自定义用户信息生成器
  function generateUserInfo(total, pageCount, pageNo, rows) {
    const start = (pageNo - 1) * rows + 1;
    const end = Math.min(pageNo * rows, total);
    return `显示 <b>${start}-${end}</b> 共 <b>${total}</b> 个用户`;
  }
  
  // 加载初始数据
  loadUsers(currentPage, rowsPerPage);
</script>

<div class="user-management">
  <h2>用户管理</h2>
  
  {#if loading}
    <div class="loading">加载用户中...</div>
  {:else}
    <table class="users-table">
      <thead>
        <tr>
          <th>ID</th>
          <th>姓名</th>
          <th>邮箱</th>
          <th>角色</th>
          <th>状态</th>
        </tr>
      </thead>
      <tbody>
        {#each users as user}
          <tr>
            <td>{user.id}</td>
            <td>{user.name}</td>
            <td>{user.email}</td>
            <td>{user.role}</td>
            <td class="status {user.status === '活跃' ? 'active' : 'inactive'}">{user.status}</td>
          </tr>
        {/each}
      </tbody>
    </table>
  {/if}
  
  <PaginationPanel
    pageNo={currentPage}
    pageCount={totalPages}
    total={totalUsers}
    rowCount={rowsPerPage}
    rowsSet={[10, 25, 50, 100]}
    rowCountLabel="每页用户数"
    generateInfo={generateUserInfo}
    onPageChange={handlePageChange}
    onRowCountChanged={handleRowCountChange}
    align="right"
  />
</div>

<style>
  .user-management {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
  }
  
  .loading {
    text-align: center;
    padding: 40px;
    color: #666;
  }
  
  .users-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
  }
  
  .users-table th,
  .users-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
  }
  
  .users-table th {
    background-color: #f8f9fa;
    font-weight: 600;
  }
  
  .status.active {
    color: #28a745;
  }
  
  .status.inactive {
    color: #dc3545;
  }
</style>
```

### 带自定义样式的产品目录

```svelte
<script>
  import PaginationPanel from '@ticatec/uniface-element/PaginationPanel';
  
  let products = [];
  let currentPage = 1;
  let totalPages = 1;
  let totalProducts = 0;
  let rowsPerPage = 12;
  let category = 'all';
  
  const categories = {
    all: '所有产品',
    electronics: '电子产品',
    clothing: '服装',
    books: '书籍'
  };
  
  async function loadProducts(page = 1, rows = 12, cat = 'all') {
    // 模拟带类别过滤的 API 调用
    const categoryTotals = {
      all: 180,
      electronics: 45,
      clothing: 67,
      books: 68
    };
    
    totalProducts = categoryTotals[cat];
    totalPages = Math.ceil(totalProducts / rows);
    currentPage = page;
    
    const startIndex = (page - 1) * rows;
    products = Array.from({ length: Math.min(rows, totalProducts - startIndex) }, (_, i) => ({
      id: startIndex + i + 1,
      name: `${categories[cat]} 产品 ${startIndex + i + 1}`,
      price: (Math.random() * 200 + 20).toFixed(2),
      image: `https://picsum.photos/200/200?random=${startIndex + i + 1}`,
      rating: (Math.random() * 2 + 3).toFixed(1)
    }));
  }
  
  function handlePageChange(page) {
    loadProducts(page, rowsPerPage, category);
  }
  
  function handleRowCountChange(rows) {
    rowsPerPage = rows;
    loadProducts(1, rows, category);
  }
  
  function handleCategoryChange() {
    loadProducts(1, rowsPerPage, category);
  }
  
  // 自定义产品信息生成器
  function generateProductInfo(total, pageCount, pageNo, rows) {
    return `
      <span style="color: #007bff;">第 ${pageNo} 页</span> 共 
      <span style="color: #007bff;">${pageCount} 页</span> • 
      <span style="color: #28a745;">${total}</span> 个产品
    `;
  }
  
  // 加载初始产品
  loadProducts(currentPage, rowsPerPage, category);
</script>

<div class="product-catalog">
  <div class="catalog-header">
    <h2>产品目录</h2>
    <div class="category-filter">
      <label>类别：</label>
      <select bind:value={category} on:change={handleCategoryChange}>
        {#each Object.entries(categories) as [key, value]}
          <option value={key}>{value}</option>
        {/each}
      </select>
    </div>
  </div>
  
  <div class="products-grid">
    {#each products as product}
      <div class="product-card">
        <img src={product.image} alt={product.name} />
        <h3>{product.name}</h3>
        <div class="product-info">
          <span class="price">${product.price}</span>
          <span class="rating">⭐ {product.rating}</span>
        </div>
      </div>
    {/each}
  </div>
  
  <PaginationPanel
    pageNo={currentPage}
    pageCount={totalPages}
    total={totalProducts}
    rowCount={rowsPerPage}
    rowsSet={[6, 12, 24, 48]}
    rowCountLabel="每页产品数"
    generateInfo={generateProductInfo}
    onPageChange={handlePageChange}
    onRowCountChanged={handleRowCountChange}
    type="round"
    big
  />
</div>

<style>
  .product-catalog {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
  }
  
  .catalog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
  }
  
  .category-filter {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  
  .category-filter select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  
  .products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
    min-height: 400px;
  }
  
  .product-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    transition: transform 0.2s;
  }
  
  .product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  }
  
  .product-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 12px;
  }
  
  .product-card h3 {
    margin: 0 0 12px 0;
    font-size: 16px;
  }
  
  .product-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .price {
    font-size: 18px;
    font-weight: bold;
    color: #007bff;
  }
  
  .rating {
    color: #ff9500;
  }
</style>
```

### 报告仪表盘

```svelte
<script>
  import PaginationPanel from '@ticatec/uniface-element/PaginationPanel';
  
  let reports = [];
  let currentPage = 1;
  let totalPages = 1;
  let totalReports = 0;
  let rowsPerPage = 15;
  let dateRange = 'week';
  
  async function loadReports(page = 1, rows = 15, range = 'week') {
    // 模拟根据日期范围加载报告
    const rangeTotals = {
      today: 23,
      week: 156,
      month: 642,
      year: 7834
    };
    
    totalReports = rangeTotals[range];
    totalPages = Math.ceil(totalReports / rows);
    currentPage = page;
    
    const startIndex = (page - 1) * rows;
    reports = Array.from({ length: Math.min(rows, totalReports - startIndex) }, (_, i) => ({
      id: `RPT-${String(startIndex + i + 1).padStart(4, '0')}`,
      title: `报告 ${startIndex + i + 1}`,
      type: ['销售', '分析', '性能', '用户活动'][Math.floor(Math.random() * 4)],
      createdAt: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000).toLocaleDateString(),
      status: ['已完成', '处理中', '失败'][Math.floor(Math.random() * 3)],
      size: `${(Math.random() * 10 + 0.5).toFixed(1)} MB`
    }));
  }
  
  function handlePageChange(page) {
    loadReports(page, rowsPerPage, dateRange);
  }
  
  function handleRowCountChange(rows) {
    rowsPerPage = rows;
    loadReports(1, rows, dateRange);
  }
  
  function handleDateRangeChange() {
    loadReports(1, rowsPerPage, dateRange);
  }
  
  // 自定义报告信息生成器
  function generateReportInfo(total, pageCount, pageNo, rows) {
    const start = (pageNo - 1) * rows + 1;
    const end = Math.min(pageNo * rows, total);
    return `
      <div style="display: flex; align-items: center; gap: 16px;">
        <span>报告 <b>${start}-${end}</b> 共 <b>${total}</b></span>
        <span style="color: #666;">•</span>
        <span style="color: #007bff;">第 ${pageNo}/${pageCount} 页</span>
      </div>
    `;
  }
  
  // 加载初始报告
  loadReports(currentPage, rowsPerPage, dateRange);
</script>

<div class="reports-dashboard">
  <div class="dashboard-header">
    <h2>报告仪表盘</h2>
    <div class="date-filter">
      <label>时间范围：</label>
      <select bind:value={dateRange} on:change={handleDateRangeChange}>
        <option value="today">今天</option>
        <option value="week">本周</option>
        <option value="month">本月</option>
        <option value="year">本年</option>
      </select>
    </div>
  </div>
  
  <div class="reports-table-container">
    <table class="reports-table">
      <thead>
        <tr>
          <th>报告 ID</th>
          <th>标题</th>
          <th>类型</th>
          <th>创建时间</th>
          <th>状态</th>
          <th>大小</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        {#each reports as report}
          <tr>
            <td><code>{report.id}</code></td>
            <td>{report.title}</td>
            <td><span class="badge type-{report.type.toLowerCase().replace(' ', '-')}">{report.type}</span></td>
            <td>{report.createdAt}</td>
            <td><span class="status status-{report.status === '已完成' ? 'completed' : report.status === '处理中' ? 'processing' : 'failed'}">{report.status}</span></td>
            <td>{report.size}</td>
            <td>
              <button class="action-btn download">下载</button>
              <button class="action-btn delete">删除</button>
            </td>
          </tr>
        {/each}
      </tbody>
    </table>
  </div>
  
  <PaginationPanel
    pageNo={currentPage}
    pageCount={totalPages}
    total={totalReports}
    rowCount={rowsPerPage}
    rowsSet={[10, 15, 25, 50]}
    rowCountLabel="每页报告数"
    generateInfo={generateReportInfo}
    onPageChange={handlePageChange}
    onRowCountChanged={handleRowCountChange}
    type="plain"
    align="left"
  />
</div>

<style>
  .reports-dashboard {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
  }
  
  .dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
  }
  
  .date-filter {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  
  .date-filter select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  
  .reports-table-container {
    overflow-x: auto;
    margin-bottom: 20px;
  }
  
  .reports-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
  }
  
  .reports-table th,
  .reports-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
  }
  
  .reports-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    position: sticky;
    top: 0;
  }
  
  .badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
  }
  
  .badge.type-销售 { background: #e3f2fd; color: #1976d2; }
  .badge.type-分析 { background: #f3e5f5; color: #7b1fa2; }
  .badge.type-性能 { background: #e8f5e8; color: #388e3c; }
  .badge.type-用户活动 { background: #fff3e0; color: #f57c00; }
  
  .status {
    font-weight: 600;
  }
  
  .status.status-completed { color: #28a745; }
  .status.status-processing { color: #ffc107; }
  .status.status-failed { color: #dc3545; }
  
  .action-btn {
    padding: 4px 8px;
    margin: 0 2px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
  }
  
  .action-btn.download {
    background: #007bff;
    color: white;
  }
  
  .action-btn.delete {
    background: #dc3545;
    color: white;
  }
</style>
```

### 大数据集日志查看器

```svelte
<script>
  import PaginationPanel from '@ticatec/uniface-element/PaginationPanel';
  
  let logs = [];
  let currentPage = 1;
  let totalPages = 1;
  let totalLogs = 0;
  let rowsPerPage = 50;
  let logLevel = 'all';
  let searchTerm = '';
  
  const logLevels = ['all', 'error', 'warning', 'info', 'debug'];
  
  async function loadLogs(page = 1, rows = 50, level = 'all', search = '') {
    // 模拟大型日志数据集
    const levelMultipliers = {
      all: 1,
      error: 0.1,
      warning: 0.15,
      info: 0.6,
      debug: 0.15
    };
    
    const baseLogs = 15000;
    totalLogs = Math.floor(baseLogs * (level === 'all' ? 1 : levelMultipliers[level]));
    
    if (search) {
      totalLogs = Math.floor(totalLogs * 0.2); // 模拟搜索过滤
    }
    
    totalPages = Math.ceil(totalLogs / rows);
    currentPage = page;
    
    const startIndex = (page - 1) * rows;
    logs = Array.from({ length: Math.min(rows, totalLogs - startIndex) }, (_, i) => {
      const logIndex = startIndex + i + 1;
      const levels = level === 'all' ? ['error', 'warning', 'info', 'debug'] : [level];
      const randomLevel = levels[Math.floor(Math.random() * levels.length)];
      
      return {
        id: logIndex,
        timestamp: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000).toISOString(),
        level: randomLevel,
        message: search 
          ? `日志消息 ${logIndex} 包含 "${search}" 及附加详情`
          : `日志消息 ${logIndex} - ${randomLevel} 级别事件发生`,
        source: ['认证', 'API', '数据库', '缓存', '队列'][Math.floor(Math.random() * 5)]
      };
    });
  }
  
  function handlePageChange(page) {
    loadLogs(page, rowsPerPage, logLevel, searchTerm);
  }
  
  function handleRowCountChange(rows) {
    rowsPerPage = rows;
    loadLogs(1, rows, logLevel, searchTerm);
  }
  
  function handleLevelChange() {
    loadLogs(1, rowsPerPage, logLevel, searchTerm);
  }
  
  function handleSearch() {
    loadLogs(1, rowsPerPage, logLevel, searchTerm);
  }
  
  // 自定义日志信息生成器
  function generateLogInfo(total, pageCount, pageNo, rows) {
    const start = (pageNo - 1) * rows + 1;
    const end = Math.min(pageNo * rows, total);
    return `
      <div style="font-family: monospace; font-size: 12px;">
        日志 ${start.toLocaleString()}-${end.toLocaleString()} 共 ${total.toLocaleString()} • 第 ${pageNo}/${pageCount} 页
      </div>
    `;
  }
  
  // 加载初始日志
  loadLogs(currentPage, rowsPerPage, logLevel, searchTerm);
</script>

<div class="log-viewer">
  <div class="log-controls">
    <h2>系统日志</h2>
    <div class="filters">
      <div class="filter-group">
        <label>级别：</label>
        <select bind:value={logLevel} on:change={handleLevelChange}>
          {#each logLevels as level}
            <option value={level}>{level.toUpperCase()}</option>
          {/each}
        </select>
      </div>
      <div class="filter-group">
        <label>搜索：</label>
        <input 
          type="text" 
          bind:value={searchTerm}
          placeholder="搜索日志..."
          on:keydown={(e) => e.key === 'Enter' && handleSearch()}
        />
        <button on:click={handleSearch}>搜索</button>
      </div>
    </div>
  </div>
  
  <div class="logs-container">
    {#each logs as log}
      <div class="log-entry level-{log.level}">
        <div class="log-header">
          <span class="timestamp">{new Date(log.timestamp).toLocaleString()}</span>
          <span class="level level-{log.level}">{log.level.toUpperCase()}</span>
          <span class="source">[{log.source}]</span>
        </div>
        <div class="log-message">{log.message}</div>
      </div>
    {/each}
  </div>
  
  <PaginationPanel
    pageNo={currentPage}
    pageCount={totalPages}
    total={totalLogs}
    rowCount={rowsPerPage}
    rowsSet={[25, 50, 100, 200]}
    rowCountLabel="每页日志数"
    generateInfo={generateLogInfo}
    onPageChange={handlePageChange}
    onRowCountChanged={handleRowCountChange}
    type="circle"
  />
</div>

<style>
  .log-viewer {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
  }
  
  .log-controls {
    margin-bottom: 20px;
  }
  
  .log-controls h2 {
    margin: 0 0 16px 0;
  }
  
  .filters {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
  }
  
  .filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .filter-group select,
  .filter-group input {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  
  .filter-group button {
    padding: 6px 12px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }
  
  .logs-container {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    max-height: 600px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
  }
  
  .log-entry {
    margin-bottom: 12px;
    padding: 8px;
    border-radius: 4px;
    border-left: 4px solid;
  }
  
  .log-entry.level-error {
    background: rgba(220, 53, 69, 0.1);
    border-left-color: #dc3545;
  }
  
  .log-entry.level-warning {
    background: rgba(255, 193, 7, 0.1);
    border-left-color: #ffc107;
  }
  
  .log-entry.level-info {
    background: rgba(0, 123, 255, 0.1);
    border-left-color: #007bff;
  }
  
  .log-entry.level-debug {
    background: rgba(108, 117, 125, 0.1);
    border-left-color: #6c757d;
  }
  
  .log-header {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 4px;
    font-size: 12px;
  }
  
  .timestamp {
    color: #adb5bd;
  }
  
  .level {
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
  }
  
  .level.level-error { background: #dc3545; color: white; }
  .level.level-warning { background: #ffc107; color: black; }
  .level.level-info { background: #007bff; color: white; }
  .level.level-debug { background: #6c757d; color: white; }
  
  .source {
    color: #28a745;
  }
  
  .log-message {
    color: #f8f9fa;
    font-size: 13px;
    line-height: 1.4;
  }
</style>
```

### 移动响应式面板

```svelte
<script>
  import PaginationPanel from '@ticatec/uniface-element/PaginationPanel';
  import { onMount } from 'svelte';
  
  let currentPage = 1;
  let totalPages = 15;
  let totalItems = 300;
  let rowsPerPage = 20;
  let isMobile = false;
  
  onMount(() => {
    const checkMobile = () => {
      isMobile = window.innerWidth < 768;
    };
    
    checkMobile();
    window.addEventListener('resize', checkMobile);
    
    return () => window.removeEventListener('resize', checkMobile);
  });
  
  function handlePageChange(page) {
    currentPage = page;
  }
  
  function handleRowCountChange(rows) {
    rowsPerPage = rows;
    totalPages = Math.ceil(totalItems / rows);
    currentPage = 1;
  }
  
  // 移动端友好的信息生成器
  function generateMobileInfo(total, pageCount, pageNo, rows) {
    if (isMobile) {
      return `<div style="font-size: 12px; text-align: center;">${pageNo}/${pageCount} • ${total} 项</div>`;
    }
    return `显示 ${(pageNo - 1) * rows + 1}-${Math.min(pageNo * rows, total)} 共 ${total} 项`;
  }
</script>

<div class="mobile-demo">
  <h2>移动响应式分页</h2>
  <p>调整浏览器大小以查看移动端适配效果</p>
  
  <div class="content-grid">
    {#each Array(rowsPerPage) as _, i}
      <div class="content-item">
        项目 {(currentPage - 1) * rowsPerPage + i + 1}
      </div>
    {/each}
  </div>
  
  <PaginationPanel
    pageNo={currentPage}
    pageCount={totalPages}
    total={totalItems}
    rowCount={rowsPerPage}
    rowsSet={isMobile ? [10, 20] : [10, 20, 50]}
    rowCountLabel={isMobile ? "每页" : "每页项目数"}
    generateInfo={generateMobileInfo}
    onPageChange={handlePageChange}
    onRowCountChanged={handleRowCountChange}
    type="round"
    big={!isMobile}
    align={isMobile ? "" : "right"}
  />
</div>

<style>
  .mobile-demo {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
  }
  
  .content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
  }
  
  .content-item {
    padding: 20px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    text-align: center;
  }
  
  @media (max-width: 767px) {
    .content-grid {
      grid-template-columns: 1fr 1fr;
      gap: 12px;
    }
    
    .content-item {
      padding: 16px;
      font-size: 14px;
    }
  }
</style>
```

## 最佳实践

1. **数据加载**：在页面切换期间实现适当的加载状态
2. **URL 同步**：保持 URL 参数与分页状态同步
3. **性能**：对大型数据集使用高效的数据获取策略
4. **用户体验**：提供有关当前状态和总项目数的清晰反馈
5. **移动优化**：为移动设备适配行数选项和信息显示
6. **可访问性**：确保所有控件支持键盘操作
7. **错误处理**：优雅处理 API 失败，提供重试选项

## 样式

分页面板组件结合了多个子组件的样式：

```css
.uniface-pagination-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
}

.uniface-pagination-panel.left {
  justify-content: flex-start;
}

.uniface-pagination-panel.right {
  justify-content: flex-end;
}

.page-options {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.pagination {
  flex: 0 0 auto;
}

.pagination-info {
  font-size: 14px;
  color: #666;
}

/* 移动响应式 */
@media (max-width: 767px) {
  .uniface-pagination-panel {
    flex-direction: column;
    gap: 12px;
  }
  
  .page-options,
  .pagination-info {
    font-size: 12px;
  }
}
```

## 可访问性

- 全面支持键盘导航
- 为所有交互元素提供 ARIA 标签
- 页面更改的屏幕阅读器通知
- 高对比度模式兼容性
- 控件之间的焦点管理

## 相关组件

- [分页](../pagination/README.md) - 核心分页组件
- [选项单选](../options-select/README.md) - 行数选择器
- [数据表格](../data-table/README.md) - 带分页的数据表格
- [按钮](../button/README.md) - 用于自定义分页操作