Steps.tsx 3.3 KB
Newer Older
R
Rongfeng Fu 已提交
1
import { intl } from '@/utils/intl';
R
Rongfeng Fu 已提交
2 3 4
import { useModel } from 'umi';
import { Space } from 'antd';
import { ClockCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
R
Rongfeng Fu 已提交
5 6 7 8 9 10
import { getLocale } from 'umi';
import EnStyles from './indexEn.less';
import ZhStyles from './indexZh.less';

const locale = getLocale();
const styles = locale === 'zh-CN' ? ZhStyles : EnStyles;
R
Rongfeng Fu 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import { useEffect, useState } from 'react';

export default function Steps() {
  const { currentStep } = useModel('global');
  const [showBorder, setShowBorder] = useState(false);

  const getIcon = (key: number) => {
    return currentStep > key ? (
      <CheckCircleOutlined className={styles.stepIcon} />
    ) : (
      <ClockCircleOutlined
        className={`${styles.stepIcon} ${styles.stepWaitIcon} ${
          currentStep === key ? styles.stepCurrentIcon : ''
        }`}
      />
    );
  };

  const getStepsItems = () => {
    return [
R
Rongfeng Fu 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
      {
        title: intl.formatMessage({
          id: 'OBD.pages.components.Steps.DeploymentConfiguration',
          defaultMessage: '部署配置',
        }),
        key: 1,
        icon: getIcon(1),
      },
      {
        title: intl.formatMessage({
          id: 'OBD.pages.components.Steps.NodeConfiguration',
          defaultMessage: '节点配置',
        }),
        key: 2,
        icon: getIcon(2),
      },
      {
        title: intl.formatMessage({
          id: 'OBD.pages.components.Steps.ClusterConfiguration',
          defaultMessage: '集群配置',
        }),
        key: 3,
        icon: getIcon(3),
      },
      {
        title: intl.formatMessage({
          id: 'OBD.pages.components.Steps.PreCheck',
          defaultMessage: '预检查',
        }),
        key: 4,
        icon: getIcon(4),
      },
      {
        title: intl.formatMessage({
          id: 'OBD.pages.components.Steps.Deployment',
          defaultMessage: '部署',
        }),
        key: 5,
        icon: getIcon(5),
      },
R
Rongfeng Fu 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    ];
  };

  const showStepsKeys = [1, 2, 3, 4, 5];

  const handleScroll = () => {
    if (document.documentElement.scrollTop > 0) {
      setShowBorder(true);
    } else {
      setShowBorder(false);
    }
  };

  useEffect(() => {
    document.addEventListener('scroll', handleScroll);
  }, []);

  return (
    <div
      className={styles.stepsContainer}
      style={{ borderBottom: `${showBorder ? '1px solid #dde4ed' : '0px'}` }}
    >
      {showStepsKeys.includes(currentStep) ? (
        <div style={{ height: 120 }}>
          <div className={styles.stepsContent}>
            <div className={styles.stepsBackground}>
              <div
                className={styles.stepsBackgroundProgress}
                style={{ width: `${(currentStep - 1) * 25}%` }}
              ></div>
            </div>
R
Rongfeng Fu 已提交
102
            <Space size={locale === 'zh-CN' ? 100 : 0}>
R
Rongfeng Fu 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
              {getStepsItems().map((item) => (
                <span className={styles.stepItem} key={item.key}>
                  {item.icon}
                  <span
                    className={`${styles.stepTitle} ${
                      currentStep === item.key ? styles.stepCurrentTitle : ''
                    } ${currentStep > item.key ? styles.stepAlreadyTitle : ''}`}
                  >
                    {item.title}
                  </span>
                </span>
              ))}
            </Space>
          </div>
        </div>
      ) : null}
    </div>
  );
}