| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import { getApkVersion } from '@/api/auth'
- import { IMGHOST } from '@/config'
- export default {
- data() {
- return {
- version:0
- };
- },
- onLoad(){
- // #ifdef APP-PLUS
- plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
- this.version = wgtinfo.versionCode
- });
- uni.getSystemInfo({
- success:(res) => {
- //检测当前平台,如果是安卓则启动安卓更新
- if(res.platform=="android"){
- this.androidCheckUpdate()
- }
- }
- })
- // #endif
- },
- methods: {
- androidCheckUpdate(){
- let that = this
- getApkVersion().then(res=>{
- console.log(res)
- if(res.code == 1){
- let version = res.data.version
- let mustUpdate = res.data.mustUpdate
- let singer = mustUpdate == 1 ? true : false
- if(version <= that.version){
- return false
- }
- if(plus.networkinfo.getCurrentType()!=3){
- uni.showModal({
- title: '提示',
- content: '有新的版本可以更新',
- cancelText: "取消",
- confirmText: "使用流量更新",
- showCancel: false,
- success: (res) => {
- if(res.confirm) {
- that.install(version)
- }
- }
- })
- }else{
- uni.showModal({
- title: '提示',
- content: '有新的版本可以更新',
- cancelText: "取消",
- confirmText: "确认",
- showCancel: false,
- success: (res) => {
- if(res.confirm) {
- that.install(version)
- }
- }
- })
- }
- }
- })
- },
- install(version){
- uni.showToast({ title: '后台下载中...', mask: false, duration: 1200,icon:"none"})
- console.log(IMGHOST+'/apk/hd/pad'+version+'.apk')
- var dtask = plus.downloader.createDownload( IMGHOST+'/apk/hd/pad'+version+'.apk', {}, function ( d, status ) {
- // 下载完成
- if ( status == 200 ) {
- plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){
- uni.showToast({ title: '安装失败', mask: false, duration: 1500,icon:"none" })
- })
- } else {
- uni.showToast({ title: '安装失败', mask: false, duration: 1500,icon:"none" })
- }
- })
- dtask.start()
- }
- }
- }
|