#
whycq
2023-02-07 8852ab9972da035e8afdba2d1a003983c35619e5
#
1个文件已修改
90 ■■■■■ 已修改文件
App.vue 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
App.vue
@@ -3,6 +3,7 @@
    export default {
        globalData: {
            baseHttp:'',
            baseUrll: '',
        },
        onLaunch: function() {
            Vue.prototype.ColorList = [{
@@ -87,11 +88,100 @@
            // #ifdef APP-PLUS
            plus.navigator.setFullscreen(true)
            // #endif
            // 获取版本
            this.getVersion();
            this.baseUrll = uni.getStorageSync("baseUrl")
            console.log('App Show')
        },
        onHide: function() {
            console.log('App Hide')
        },
        methods: {
            //检测当前平台,如果是安卓则启动安卓更新
            getVersion() {
                let that = this;
                uni.getSystemInfo({
                    success: (res) => {
                        console.log(res.platform);
                        if (res.platform == "android") {
                            that.AndroidCheckUpdate();
                        }
                    }
                })
            },
            // 获取当前版本号
            AndroidCheckUpdate() {
                let that = this;
                plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
                    that.version = wgtinfo.version //客户端版本号
                    console.log('当前app版本信息:' + that.version);
                })
                that.getUpdateVersion()
            },
            getUpdateVersion() {
                let that = this;
                uni.request({
                    url: that.baseUrll + "/mobile/appUpdate/queryUpdate",
                    // data: {combParam: 'asd'},
                    method:'GET',
                    success(res) {
                        console.log(res);
                    }
                })
                return
                that.$req.get(that.baseUrll + "/appUpdate/queryUpdate", {}, {}).then(function(res) {
                    console.log('res.data:' + JSON.stringify(res.data))
                    console.log("现在的版本" + that.version + "数据库版本" + res.data.data.version + "进入查找app版本");
                    if (res.data.data.version > that.version) {
                        // 这里下载apkurl从/appUpdate/queryUpdate接口请求返回数据中获取
                        that.downloadUrl = BaseUrl + '/' + res.data.data.androidUrl
                        // 是否强制更新(0 否;1 是)
                        that.isForceUpdate = res.data.data.isForceUpdate
                        uni.showModal({
                            // 更新提醒
                            title: '发现新版本,是否更新',
                            content: '此版本号:' + that.version + '\xa0\xa0\xa0' + '待更新版本号:' + res.data.data
                                .version,
                            success: res => {
                                if (res.confirm) {
                                    that.downWgt(); //下载文件
                                    // that.showdownLine = true;
                                    // plus.runtime.openURL(androidUrl)
                                } else if (res.cancel) {
                                    console.log('that.isForceUpdate:' + that.isForceUpdate);
                                    // 不更新强制退出app
                                    if (that.isForceUpdate == 1) {
                                        console.log('that.isForceUpdate1:' + that.isForceUpdate);
                                        uni.showModal({
                                            // 更新提醒
                                            title: '发现新版本,是否更新',
                                            content: '此版本为强制更新版本如不升级将退出APP',
                                            success: res => {
                                                if (res.confirm) {
                                                    console.log('不更新强制退出app');
                                                    plus.runtime.quit();
                                                } else if (res.cancel) {
                                                    that.AndroidCheckUpdate();
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                        });
                        //dtask.start();
                    }
                }).catch(error => {
                    uni.showToast({
                        title: '调用请求失败',
                        mask: false,
                        duration: 5000,
                        icon: "none"
                    });
                });
                complete: () => {}
            },
        }
    }
</script>