import React, { useState } from 'react' import { Table, TableColumnOptions, Link } from 'react-icecream' import originalRecords, { Record } from './shared-records' const columnIdx: TableColumnOptions = { title: '索引', width: '40px', render: (_, __, idx) => idx + 1, fixed: 'left' } const columnName: TableColumnOptions = { title: '空间名称', width: '150px', accessor: 'name', render: name => name, fixed: 'left' } const columnType: TableColumnOptions = { title: '空间类型', accessor: 'type' } const columnRegion: TableColumnOptions = { title: '存储区域', accessor: 'region' } const columnAccess: TableColumnOptions = { title: '空间权限', accessor: 'access' } const columnOperator: TableColumnOptions = { title: '操作', width: '210px', fixed: 'right', render() { return ( 概览 文件 设置 域名 ) } } export default function Demo() { const { records, loading, currentPage, pageSize, total, setPageInfo } = useData() return (
fixColumn={{ contentWidth: 'max-content' }} columns={[columnIdx, columnName, columnType, columnRegion, columnAccess, columnOperator]} records={records} loading={loading} pagination={{ currentPage, pageSize, total, onChange: setPageInfo }} />
) } function useData() { const [{ currentPage, pageSize }, setPageInfo] = useState({ pageSize: 10, currentPage: 0 }) const [loading, setLoading] = useState(false) async function handleSetPageInfo(nextCurrentPage: number, nextPageSize: number) { setLoading(true) await new Promise(r => setTimeout(r, 1000)) setLoading(false) setPageInfo({ pageSize: nextPageSize, currentPage: nextCurrentPage }) } return { records: originalRecords.slice(currentPage * pageSize, (currentPage + 1) * pageSize), currentPage, pageSize, setPageInfo: handleSetPageInfo, total: originalRecords.length, loading } }