|
@@ -6,6 +6,7 @@
|
|
|
import Vue from "vue";
|
|
import Vue from "vue";
|
|
|
import appUpdate from "common/util/appUpdate.js";
|
|
import appUpdate from "common/util/appUpdate.js";
|
|
|
import configService from "@/common/service/config.service.js";
|
|
import configService from "@/common/service/config.service.js";
|
|
|
|
|
+import api from "@/api/api";
|
|
|
export default {
|
|
export default {
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
@@ -13,25 +14,12 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
onLaunch: function () {
|
|
onLaunch: function () {
|
|
|
|
|
+ //app在线版本更新
|
|
|
|
|
+ this.checkVersion()
|
|
|
|
|
+ // this.getVersionFn()
|
|
|
//消息推送
|
|
//消息推送
|
|
|
- uni.getPushClientId({
|
|
|
|
|
- //获取客户端推送标识
|
|
|
|
|
- success: (res) => {
|
|
|
|
|
- console.log(res.cid, 'cid---');
|
|
|
|
|
- uni.setStorageSync('push_cid', res.cid); // 存储CID供后续使用
|
|
|
|
|
- },
|
|
|
|
|
- fail(err) {
|
|
|
|
|
- console.log(err)
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // uni.onPushMessage((res) => {
|
|
|
|
|
- // //客户端监听推送消息
|
|
|
|
|
- // console.log("收到推送消息:", res) //监听推送消息
|
|
|
|
|
- // if (res.data) {
|
|
|
|
|
- // uni.createPushMessage(res.data) //收到消息推送,创建系统状态栏及锁屏通 知
|
|
|
|
|
- // }
|
|
|
|
|
- // })
|
|
|
|
|
|
|
+ this.getPushClientID()
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const savedIP = uni.getStorageSync("selectedIP");
|
|
const savedIP = uni.getStorageSync("selectedIP");
|
|
|
if (configService.apiUrl !== "") {
|
|
if (configService.apiUrl !== "") {
|
|
@@ -303,13 +291,157 @@ export default {
|
|
|
},
|
|
},
|
|
|
onShow: function () {
|
|
onShow: function () {
|
|
|
console.log("App Show");
|
|
console.log("App Show");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
onHide: function () {
|
|
onHide: function () {
|
|
|
console.log("App Hide");
|
|
console.log("App Hide");
|
|
|
clearInterval(this.$store.state.timer); // 假设定时器存储在 Vuex 的状态管理中
|
|
clearInterval(this.$store.state.timer); // 假设定时器存储在 Vuex 的状态管理中
|
|
|
},
|
|
},
|
|
|
- methods: {}
|
|
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ //消息推送
|
|
|
|
|
+ getPushClientID() {
|
|
|
|
|
+ uni.getPushClientId({
|
|
|
|
|
+ //获取客户端推送标识
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ console.log(res.cid, 'cid---');
|
|
|
|
|
+ uni.setStorageSync('push_cid', res.cid); // 存储CID供后续使用
|
|
|
|
|
+ },
|
|
|
|
|
+ fail(err) {
|
|
|
|
|
+ console.log(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ // 检测版本
|
|
|
|
|
+ checkVersion() {
|
|
|
|
|
+ plus.runtime.getProperty(plus.runtime.appid, (appInfo) => {
|
|
|
|
|
+ // 获取版本号
|
|
|
|
|
+ const currentVersion = appInfo.version
|
|
|
|
|
+ // 这是用来看看版本是多少的
|
|
|
|
|
+ console.log(currentVersion, '版本号');
|
|
|
|
|
+ this.getVersionFn(currentVersion)
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ getVersionFn(currentVersion) {
|
|
|
|
|
+ let that = this
|
|
|
|
|
+ new Promise((resolve, reject) => {
|
|
|
|
|
+ api
|
|
|
|
|
+ .getAppLast({})
|
|
|
|
|
+ .then((response) => {
|
|
|
|
|
+ if (response.statusCode == 200) {
|
|
|
|
|
+ console.log(response, '响应数据')
|
|
|
|
|
+ const updateUrl = `${configService.apiUrlP}:9999${response.data.downloadUrl}`; // 下载地址
|
|
|
|
|
+ let indexF = response.data.filename.lastIndexOf('-')
|
|
|
|
|
+ let indexL = response.data.filename.lastIndexOf('.')
|
|
|
|
|
+ const latestVersion = response.data.filename.substring(indexF + 1, indexL)// 版本号
|
|
|
|
|
+ console.log(updateUrl, '下载地址')
|
|
|
|
|
+ console.log(latestVersion, '版本号')
|
|
|
|
|
+ // 比较版本号,判断是否有新版本
|
|
|
|
|
+ if (that.compareVersion(currentVersion, latestVersion) < 0) {
|
|
|
|
|
+ // 提示用户更新
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '更新提示',
|
|
|
|
|
+ content: '检测到新版本,是否立即更新?',
|
|
|
|
|
+ success: (modalRes) => {
|
|
|
|
|
+ if (modalRes.confirm) {
|
|
|
|
|
+ // 用户确认更新,下载新版本
|
|
|
|
|
+ that.downloadAndInstall(updateUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('当前已是最新版本');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reject(response);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((error) => {
|
|
|
|
|
+ console.log("catch===>response", response);
|
|
|
|
|
+ reject(error);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 比较版本号
|
|
|
|
|
+ compareVersion(v1, v2) {
|
|
|
|
|
+ const version1 = v1.split('.').map(Number);
|
|
|
|
|
+ const version2 = v2.split('.').map(Number);
|
|
|
|
|
+
|
|
|
|
|
+ for (let i = 0; i < version1.length; i++) {
|
|
|
|
|
+ if (version1[i] < version2[i]) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ } else if (version1[i] > version2[i]) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 下载并安装新版本
|
|
|
|
|
+ downloadAndInstall(url) {
|
|
|
|
|
+ let dtask = plus.downloader.createDownload(url, {
|
|
|
|
|
+ filename: '_downloads/temporary.apk' //利用保存路径,实现下载文件的重命名
|
|
|
|
|
+ },
|
|
|
|
|
+ function (d, status) {
|
|
|
|
|
+ // 下载完成
|
|
|
|
|
+ if (status == 200) {
|
|
|
|
|
+ plus.runtime.install(plus.io.convertLocalFileSystemURL(
|
|
|
|
|
+ d.filename), {}, {}, function (error) {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '安装失败',
|
|
|
|
|
+ duration: 1500
|
|
|
|
|
+ });
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '更新失败',
|
|
|
|
|
+ duration: 1500
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ try {
|
|
|
|
|
+ console.log('开始下载');
|
|
|
|
|
+ dtask.start(); // 开启下载的任务
|
|
|
|
|
+ let prg = 0;
|
|
|
|
|
+ let showLoading = plus.nativeUI.showWaiting(
|
|
|
|
|
+ "正在下载"); //创建一个showWaiting对象
|
|
|
|
|
+ dtask.addEventListener('statechanged', function (
|
|
|
|
|
+ task,
|
|
|
|
|
+ status
|
|
|
|
|
+ ) {
|
|
|
|
|
+ // 给下载任务设置一个监听 并根据状态 做操作
|
|
|
|
|
+ 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();
|
|
|
|
|
+ //下载完成
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ plus.nativeUI.closeWaiting();
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '更新失败',
|
|
|
|
|
+ mask: false,
|
|
|
|
|
+ duration: 1500
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|