動態獲取和域名更新
阿新 • • 發佈:2020-12-16
技術標籤:javascript
// 取得版本號 plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) { that.ver = wgtinfo.version // console.log(that.ver, '當前版本號'); }); that.http.get('http://wdt.cn-sh2.ufileos.com/n/paage.json').then(res => { uni.request({ url: res.data.url + "/api/portal/index/version", //請求更新地址 success: res => { // return var data = res.data.data; // console.log(data) // console.log(data.version) // console.log(that.ver == data.version) // console.log(that.ver) if (that.ver != data.version) { that.wgtUrl = data.android; //儲存下載地址 that.wgtipurl = data.ios; // console.log(that.wgtUrl) uni.showModal({ title: '發現新版本', content: '確認下載更新', success: function(e) { if (e.confirm) { if (plus.os.name.toLowerCase() == 'ios') { // 跳轉到下載頁面 plus.runtime.openURL(data.ios) } else { console.log(that.wgtUrl) var dtask = plus.downloader.createDownload( that.wgtUrl, {}, function(d, status) { console.log(status, 333333333333333333333) uni.showToast({ title: '下載完成', mask: false, duration: 1500 }); }); try { dtask.start(); // 開啟下載的任務 var prg = 0; var showLoading = plus.nativeUI.showWaiting("正在下載"); //建立一個showWaiting物件 dtask.addEventListener('statechanged', function( task, status ) { console.log(task) // 給下載任務設定一個監聽 並根據狀態 做操作 switch (task.state) { case 1: showLoading.setTitle("正在下載"); break; case 2: showLoading.setTitle("已連線到伺服器"); break; case 3: prg = parseInt( (parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * 100 ); showLoading.setTitle(" 正在下載" + prg + "% "); break; case 4: plus.nativeUI.closeWaiting(); //下載完成 plus.runtime.install(plus.io.convertLocalFileSystemURL(task.filename), //安裝APP { force: true }, function() { uni.showToast({ title: '安裝成功', icon: 'none', mask: false, duration: 1500 }) plus.runtime.restart(); }, function() { uni.showToast({ title: '安裝失敗', icon: 'none', mask: false, duration: 1500 }) }); break; } }); } catch (err) { plus.nativeUI.closeWaiting(); uni.showToast({ title: '更新失敗', mask: false, icon: 'none', duration: 1500 }); } } } else { //取消 } } }); } else { // uni.showModal({ // title: '提示', // content: '已是最新版本', // showCancel: false // }); } }, }) })