react+ant 实现版本号对比+弹框提醒更新

首先引入相关组件

import { message,notification } from 'antd';

版本号对比+提醒

//版本对比,更新提醒
  getLocalVersion=()=>{
    const localVersion=infoLocal.version;
    const latestVersion=sysVersion;
    console.log(localVersion,latestVersion)
    if (localVersion && latestVersion) {
      let arr1=localVersion.split('.').map(function(item){
        return parseInt(item)
      });
      let arr2=latestVersion.split('.').map(function(item){
        return parseInt(item)
      });
      console.log(arr1,arr2);
      let min=Math.min(arr1.length,arr2.length)
      let pos=0,diff=0
      while(pos<min){
        diff=arr1[pos]-arr2[pos]
        if(diff!=0){
          console.log(diff)
          break;
        }
        pos++
      }
      console.log(diff)
      if(diff<0){
        console.log('系统版本:'+latestVersion+'有更新,高于本地版本:'+localVersion);
        // message.warning('系统版本:'+sysVersion+' 有更新 , 高于本地版本:'+localVersion+' , 将于6秒后自动刷新更新系统',+6,onclose=function() {
          //   location.reload;
        // });
        const key = `open${Date.now()}`;
        const btn = (
          <Button type="primary" size="small" onClick={() => location.reload()}>
            现在更新
          </Button>
        );
        notification.open({
          message: '版本更新提醒',
          description:
            '当前系统版本:'+latestVersion+' 有更新 ! 关闭弹框稍后再次提醒!',
          btn,
          key,
          onClose: function() {
            notification.close(key)
          },
        });
      }else{
        console.log('服务器版本:'+latestVersion+'等于本地版本:'+localVersion)
      }
    } else{
      return false;
    }
  }

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值