123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /**
- * @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)<currTimeStamp){
- this.getVersion();
- }
- },
- fail:()=>{
- // 获取缓存失败(第一次进入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;
- }
|