index.tsx 3.53 KB
import { INVOICE_COLUMNS, InvoiceItem } from '@/pages/Invoice/constant';
import { postServiceInvoiceQueryInvoice } from '@/services';
import { getUserInfo } from '@/utils/user';
import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
import {
  ActionType,
  PageContainer,
  ProTable,
} from '@ant-design/pro-components';
import { history } from '@umijs/max';
import { Avatar, Button, Dropdown, Tag } from 'antd';
import { useRef } from 'react';

const userInfo = getUserInfo();
const InvoicePage = () => {
  const actionRef = useRef<ActionType>();
  return (
    <>
      <PageContainer
        header={{
          title: '发票管理',
          extra: [
            <Avatar key="0" style={{ verticalAlign: 'middle' }} size="large">
              {userInfo?.username}
            </Avatar>,
            <Tag key="nickName">{userInfo?.nickName}</Tag>,
            <Dropdown
              key="dropdown"
              trigger={['click']}
              menu={{
                items: [
                  {
                    label: '退出登录',
                    key: '1',
                    onClick: () => {
                      localStorage.removeItem('token');
                      history.push('/login');
                    },
                  },
                  // {
                  //   label: '修改密码',
                  //   key: '2',
                  // },
                ],
              }}
            >
              <Button key="4" style={{ padding: '0 8px' }}>
                <EllipsisOutlined />
              </Button>
            </Dropdown>,
          ],
        }}
      >
        <ProTable<InvoiceItem>
          scroll={{ x: true }}
          columns={INVOICE_COLUMNS}
          actionRef={actionRef}
          cardBordered
          request={async (params) => {
            const res = await postServiceInvoiceQueryInvoice({
              data: { ...params },
            });
            if (res) {
              return {
                data: res?.data?.data || [],
                total: res?.data?.total || 0,
              };
            }
          }}
          columnsState={{
            persistenceKey: 'pro-table-singe-demos',
            persistenceType: 'localStorage',
            defaultValue: {
              option: { fixed: 'right', disable: true },
            },
            onChange(value) {
              console.log('value: ', value);
            },
          }}
          rowKey="id"
          search={{
            labelWidth: 'auto',
          }}
          options={{
            setting: {
              listsHeight: 400,
            },
          }}
          form={{
            // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
            syncToUrl: (values, type) => {
              if (type === 'get') {
                return {
                  ...values,
                  created_at: [values.startTime, values.endTime],
                };
              }
              return values;
            },
          }}
          pagination={{
            pageSize: 5,
            onChange: (page) => console.log(page),
          }}
          dateFormatter="string"
          headerTitle="发票列表"
          toolBarRender={() => [
            <Button
              key="button"
              icon={<PlusOutlined />}
              onClick={() => {
                actionRef.current?.reload();
              }}
              type="primary"
            >
              新建
            </Button>,
          ]}
        />
      </PageContainer>
    </>
  );
};

export default InvoicePage;