/** * @Descripttion: app检查更新 * @Version: 1.0.0 * @Author: lgen */ import config from '@/lgen-config.js' import appDialog from './dialog' const { timer=24 }=config.upgrade; class CheckUpate{ // 判断时间戳检测是否更新 judgeTimeStamp(){ uni.getStorage({ key:'appUpdateTime', success:(res)=>{ const timeLength=1000*60*60*timer; const currTimeStamp=new Date().getTime(); if((res.data+timeLength){ // 获取缓存失败(第一次进入APP)检测更新 this.getVersion(); } }) } // 获取当前版本信息 getVersion(){ plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{ CheckUpate.getUrl(wgtinfo.versionCode).then(res=>{ /* res.status 是否有新版本,0无,1有 res.path 新版 apk 地址 */ if(res.status===1){ const path=res.path || ''; appDialog.show(path) } }) this.storageTimeStamp() }); } // 缓存检测更新的时间戳 storageTimeStamp(){ const currTimeStamp=new Date().getTime(); uni.setStorage({ key:'appUpdateTime', data:currTimeStamp }) } } // type检测类型:0自动检测,1用户主动检测 export default function(fn,type=0){ const cu=new CheckUpate() if(type==1){ cu.getVersion(); }else{ cu.judgeTimeStamp(); } CheckUpate.getUrl=fn; }