我真的不想秃头呀 2023-06-06 15:52 采纳率: 88.9%
浏览 55
已结题

antd,tabs组件下方数据不显示?

  • react中,使用antd的Tabs标签页组件,tabs中的代码在页面不显示
  • tabkey === 0或1时,后面的组件都没有显示。

img

const { TabPane } = Tabs;
const antIcon = <LoadingOutlined style={{ fontSize: 24 }} spin />;

const storeType = {
  0: 'B2B 批发店铺',
  1: 'B2C 零售店铺',
};

export default function StoreSelect() {
  const navigate = useNavigate();
  const { t } = useTranslation();
  const [tabkey, setTabKey] = useState(0);
  const [storeList, setStoreList] = useState([]);
  const activeList = storeList.filter((a) => a.status == 0);
  const DeactivateList = storeList.filter((a) => a.status == 1);

  useEffect(() => {
    fetchGetShopList().then((res) => {
      setStoreList(res);
    });
  }, [tabkey]);

  const onBack = () => {
    navigate('/');
  };

  const handleSetTab = (e, newValue) => {
    console.log('handleSetTab', e);
    setValue(newValue);
  };

  const handleTab = (item) => {
    setTabKey(+item);
  };

  const tabItems = [
    {
      key: '0',
      label:'活跃',
    },
    {
      key: '1',
      label:'停用',
    },
  ];

  return (
    <>
      {!storeList && (
        <Progress
          strokeColor={{ '0%': '#108ee9', '100%': '#87d068' }}
          className={styles.pros}
        />
      )}
      <Row className={styles.root}>
        <Col span={10} className={styles.container}>
          <div className={styles.paper}>
            <div className={styles.logo}>
              <img src={logo} width={200} height={42} alt="" />
            </div>
            <div className={styles.header}>
              <Typography.Title level={3} style={{ fontWeight: 500 }}>
                <Button
                  shape="circle"
                  type="text"
                  className={styles.iconButton}
                  icon={<ArrowLeftOutlined />}
                  onClick={onBack}
                />
                {t('store.title')}
              </Typography.Title>
              <Button
                size="large"
                type="primary"
                onClick={() => navigate('/create-store-type')}
              >
                {t('store.shop')}
              </Button>
            </div>
            {storeList.length < 1 ? (
              <Alert
                type="info"
                message="您暂无店铺"
                description="如需,请点击创建其他店铺"
                showIcon
                style={{
                  marginTop: '20px',
                  height: '150px',
                  padding: '30px 0 0 20px',
                }}
              />
            ) : (
              <Tabs
                activeKey={'' + tabkey}
                items={tabItems}
                onTabClick={(e) => handleTab(e)}
                size="large"
              >
                {tabkey === 0 && (
                  <div>
                    {storeList === null ? (
                      <div className={styles.loading}>
                        <Spin indicator={antIcon} />
                      </div>
                    ) : storeList ? (
                      <>
                        <List>
                          {activeList.map((item) => {
                            const p: any = {};
                            if (item.status == 0 && item.shopDomain) {
                              p.href =
                                'http://' +
                                item.shopDomain +
                                '/admin/auth/login';
                            }

                            <List.Item key={item.sid} className={styles.item}>
                              <div className={styles.title}>
                                <div
                                  style={{
                                    fontSize: 23,
                                    color: '#757575',
                                    marginRight: 25,
                                  }}
                                >
                                  <BankOutlined />
                                </div>
                                <div className={styles.listBody}>
                                  <Card
                                    title={
                                      <Typography.Title
                                        level={4}
                                        style={{ fontWeight: 500 }}
                                      >
                                        {item?.name}
                                      </Typography.Title>
                                    }
                                  >
                                    <div className={styles.sub}>
                                      {item?.shopType == 1 && (
                                        <Chip
                                          label={t('erp.administrator')}
                                          size="small"
                                          variant="outlined"
                                          className={styles.chip}
                                        />
                                      )}
                                      {storeType[item?.shopType]}
                                    </div>
                                    <div style={{ color: '#008060' }}>
                                      {item?.shopDomain}
                                    </div>
                                  </Card>
                                </div>
                              </div>
                              <Button>
                                <span
                                  style={{
                                    fontSize: '14px',
                                    margin: '0 10px 0 0',
                                  }}
                                >
                                  {item.status == 1
                                    ? t('erp.under-review')
                                    : ''}
                                </span>
                                {item.status == 1 ? <></> : <RightOutlined />}
                              </Button>
                            </List.Item>
                          })}
                        </List>
                      </>
                    ) : (
                      <Alert type="error" showIcon description={t('erp.tip2')}>
                        {/* {t('erp.tip2')} */}
                      </Alert>
                    )}
                  </div>
                )}
                {tabkey === 1 && (
                  <div>
                    {storeList === null ? (
                      <div className={styles.loading}>
                        <Spin indicator={antIcon} />
                      </div>
                    ) : storeList ? (
                      <>
                        <List>
                          {DeactivateList.map((item) => {
                            const p: any = {};
                            if (item.status == 0 && item.shopDomain) {
                              p.href = 'http://' + item.shopDomain;
                            }

                            <List.Item key={item.sid} className={styles.item}>
                              <div className={styles.title}>
                                <div
                                  style={{
                                    fontSize: 23,
                                    color: '#757575',
                                    marginRight: 25,
                                  }}
                                >
                                  <BankOutlined />
                                </div>
                                <div className={styles.listBody}>
                                  <Card
                                    title={
                                      <Typography.Title
                                        level={4}
                                        style={{ fontWeight: 500 }}
                                      >
                                        {item?.contacts}
                                      </Typography.Title>
                                    }
                                  >
                                    <div className={styles.sub}>
                                      {item?.shopType == 1 && (
                                        <Chip
                                          label={t('erp.administrator')}
                                          size="small"
                                          variant="outlined"
                                          className={styles.chip}
                                        />
                                      )}
                                      {storeType[item?.shopType]}
                                    </div>
                                    <div style={{ color: '#008060' }}>
                                      {item?.shopDomain}
                                    </div>
                                  </Card>
                                </div>
                              </div>
                              <Button>
                                <span
                                  style={{
                                    fontSize: '14px',
                                    margin: '0 10px 0 0',
                                  }}
                                >
                                  {item.status == 0
                                    ? t('erp.under-review')
                                    : ''}
                                </span>
                                {item.status == 0 ? <></> : <RightOutlined />}
                              </Button>
                            </List.Item>
                          })}
                        </List>
                      </>
                    ) : (
                      <Alert
                        type="error"
                        showIcon
                        description={t('erp.tip2')}
                      ></Alert>
                    )}
                  </div>
                )}
                {/* </> */}
              </Tabs>
            )}
          </div>
        </Col>
        <Col span={14} className="bg-image" />
      </Row>
    </>
  );
}



  • 写回答

4条回答 默认 最新

  • CSDN专家-showbo 2023-06-06 15:59
    关注

    Tabs中的内嵌子组件无法显示,放到外部来

                  <Tabs
                    activeKey={'' + tabkey}
                    items={tabItems}
                    onTabClick={(e) => handleTab(e)}
                    size="large"></Tabs>//把最后的结束标签放到这里
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 6月16日
  • 已采纳回答 6月8日
  • 创建了问题 6月6日

悬赏问题

  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题
  • ¥15 pic16F877a单片机的外部触发中断程序仿真失效
  • ¥15 Matlab插值拟合差分微分规划图论
  • ¥15 keil5 target not created
  • ¥15 C/C++数据与算法请教
  • ¥15 怎么找志同道合的伙伴
  • ¥20 如何让程序ab.eXe自已删除干净硬盘里的本文件自己的ab.eXe文件
  • ¥50 爬虫预算充足,跪巨佬
  • ¥15 滑块验证码拖动问题悬赏