| | |
| | | onLaunch: function() { |
| | | this.initJPush() |
| | | this.checkAndStartLocationPolling() |
| | | this.checkAppUpdate() |
| | | }, |
| | | onShow: function() { |
| | | console.log('App Show') |
| | |
| | | uni.getLocation({ |
| | | type: 'gcj02', |
| | | success: (res) => { |
| | | console.log(res) |
| | | this.$u.api.updateLocation({ |
| | | latitude: res.latitude, |
| | | longitude: res.longitude |
| | | }) |
| | | } |
| | | }) |
| | | }, |
| | | |
| | | compareVersion(localVersion, serverVersion) { |
| | | const v1 = localVersion.split('.') |
| | | const v2 = serverVersion.split('.') |
| | | for (let i = 0; i < Math.max(v1.length, v2.length); i++) { |
| | | const n1 = parseInt(v1[i] || 0) |
| | | const n2 = parseInt(v2[i] || 0) |
| | | if (n1 < n2) return -1 |
| | | if (n1 > n2) return 1 |
| | | } |
| | | return 0 |
| | | }, |
| | | |
| | | checkAppUpdate() { |
| | | this.$u.api.getApiVersion({ type: 0 }).then(res => { |
| | | if (res.code === 200 && res.data) { |
| | | const localVersionCode = plus.runtime.versionCode |
| | | const serverVersionCode = res.data.versionCode |
| | | if (serverVersionCode && localVersionCode < serverVersionCode) { |
| | | const isForce = res.data.isForce === 1 |
| | | uni.showModal({ |
| | | title: '发现新版本', |
| | | content: res.data.versionInfo || '有新版本可用,是否立即更新?', |
| | | showCancel: !isForce, |
| | | cancelText: isForce ? '' : '暂不更新', |
| | | confirmText: '立即更新', |
| | | success: (modalRes) => { |
| | | if (modalRes.confirm) { |
| | | if (res.data.fileUrl) { |
| | | plus.runtime.openURL(res.data.fileUrl) |
| | | } |
| | | } |
| | | if (isForce && modalRes.cancel) { |
| | | this.checkAppUpdate() |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | } |