PageHeader.tsx 1.91 KB
import { useState } from 'react';
import { App } from 'antd';
import { DownloadOutlined } from '@ant-design/icons';
import { UButton } from '@uj/ui';
import { store } from '@/api';

const DEFAULT_TEMPLATE = '【优加】门店上架模版-V1.0.1.xlsx';

export function PageHeader() {
  const { message } = App.useApp();
  const [downloading, setDownloading] = useState(false);

  const handleDownload = async () => {
    if (downloading) return;
    setDownloading(true);
    try {
      await store.downloadImportTemplate(DEFAULT_TEMPLATE);
      message.success('模板下载成功');
    } catch (e) {
      message.error((e as Error).message ?? '模板下载失败');
    } finally {
      setDownloading(false);
    }
  };

  const actions = [
    {
      key: 'download',
      label: '下载模板',
      icon: <DownloadOutlined />,
      loading: downloading,
      onClick: handleDownload,
    },
  ];

  return (
    <div
      style={{
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'flex-start',
        marginBottom: 20,
      }}
    >
      <div>
        <h1
          style={{
            fontSize: 20,
            fontWeight: 600,
            margin: 0,
            color: '#1A202C',
          }}
        >
          导入门店信息
        </h1>
        <p
          style={{
            fontSize: 13,
            color: '#6B7280',
            margin: '8px 0 0',
            lineHeight: 1.6,
          }}
        >
          按《{DEFAULT_TEMPLATE}》导入单个门店的商务政策(一行 = 一个产品分类),
          校验通过并提交审批,审批通过后门店方可对外展示。
        </p>
      </div>
      <div style={{ display: 'flex', gap: 12 }}>
        {actions.map((a) => (
          <UButton key={a.key} icon={a.icon ?? undefined} loading={a.loading} onClick={a.onClick}>
            {a.label}
          </UButton>
        ))}
      </div>
    </div>
  );
}