antdesign: 利用Modal封装个拦截登录弹框

效果:

 

背景:项目是通过antdesignpro搭建的

在request.js里面加入如下代码

import { Modal } from 'antd';
const { warning } = Modal;
const ShowDialog = () => {
  warning({
    title: '提示',
    centered: true,
    width: 624,
    className: 'modal',
    content: (
      <div
        style={{
          display: 'flex',
          flexDirection: 'column',
          alignItems: 'center',
        }}
      >
        <img
          style={{
            width: '80px',
            height: '80px',
            marginBottom: '32px',
          }}
          src={require('@/assets/login/warn.png')}
          alt=""
        />
        <h3
          tyle={{
            color: '#15132b',
            fontWeight: '600',
            fontSize: '18px',
            fontFamily: 'PingFangSC-Semibold, PingFang SC',
          }}
        >
          账号登录失效
        </h3>
        <span>账号登录失效,即将会登出系统,请重新登录</span>
      </div>
    ),
    cancelText: '',
    closable: false,
    keyboard: false,
    okButtonProps: {
      href: loginPath,
      type: 'primary',
    },
    okText: '立即登录',
    onOk() {
      show = false;// 一个用来判断showModal有没有调用的变量,调用了置为true,不再弹出弹框
    },
  });
};

 modal样式类:

.modal {
  .ant-btn {
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    // box-shadow: 1px 1px 6px 0px #e5e5ee;
  }
  .ant-modal-content {
    border-radius: 12px;
  }
  .ant-modal-header {
    border-bottom: 0;
    border-radius: 12px;
    .ant-modal-title {
      color: #252525;
      font-size: 18px;
      font-family: PingFangSC-Medium, PingFang SC;
    }
  }
  .ant-modal-body {
    padding-top: 20px;
    color: rgba(21, 19, 43, 0.65);
    img {
      width: 80px;
      height: 80px;
      margin-bottom: 32px;
    }
    h3 {
      color: #15132b;
      font-weight: 600;
      font-size: 18px;
      font-family: PingFangSC-Semibold, PingFang SC;
    }
    .ant-modal-confirm-body .ant-modal-confirm-content {
      margin-left: 0;
    }
    .ant-modal-confirm-body > .anticon {
      display: none;
    }
    .ant-modal-confirm-btns {
      float: none;
      text-align: center;
    }
  }
  .ant-modal-footer {
    display: flex;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 32px;
    border-top: 0;
  }
}

使用方式:

umirequest的response拦截器,里面调用方法,配合<code>show</code>变量

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值