app uni-app登录系统自动更新代码

1.html代码

<uni-popup ref="versionUpdate" :mask-click="false" type="center">
            <view class="version-content">
                <view class="version-content-title">
                    版本更新提示
                </view>
                <view class="version-content-text">
                    <view class="version-content-text-edition">
                        发现新版本{{versionName}}
                    </view>
                    <view class="version-content-text-tips">
                        优化 | 修复部分已知问题,优化功能体验
                    </view>
                </view>
                <view class="version-content-button">
                    <view class="version-content-button-cancel" @click="cancelVersionUpdate">
                        暂不更新
                    </view>
                    <view class="version-content-button-confirm" @click="confirmVersionUpdate">
                        立即更新
                    </view>
                </view>
            </view>
        </uni-popup>

2.data定义

data() {
            return {
                privacyShow: false,
                account: '',
                password: '’',
                isRememberAccount: false, // 是否记住用户名密码
                device: {}, // 设备信息
                jsonData: {}, // 入库数据
                appVersion: '', // app版本号
                // 可更新APP版本号
                versionName: '',
                // 版本更新下载地址:
                downloadUrl: ''
            };
        },

3.调用方法

this.chkVersion()

4.方法

chkVersion() {
                // const server = "http://116.52.158.139:9998";//服务器
                // const server = "http://192.168.16.147:8080";//本地服务器
                const server = "http://116.52.158.139:9997"; //本地调试
                // const server = "http://192.168.16.166:8085"; //配合xlj调试
                var checkVersionUrl = server + '/api/anon/checkVersion'; //检查版本更新地址
                // 检测更新
                let url = `${checkVersionUrl}?appid=${plus.runtime.appid}&version=${plus.runtime.version}`
                let that = this
                uni.request({
                    url: url,
                    method: 'GET',
                    success: (res) => {
                        if (res.data.code == '200') {
                            var updateFlag = res.data.data.updateFlag;
                            var appVersion = res.data.data.appVersion;
                            that.versionName = appVersion.versionName
                            that.downloadUrl = appVersion.downloadUrl
                            if (updateFlag == '1'&& that.$updateStatus === '0') {
                                that.$refs.versionUpdate.open('center')
                            } 
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: '数据异常'
                            })
                        }
                    },
                    fail: (err) => {
                        uni.showToast({
                            icon: 'none',
                            title: '连接失败'
                        })
                    }
                });
            },

5.//关闭版本更新弹窗
            cancelVersionUpdate() {
                Vue.prototype.$updateStatus = '1'
                this.$refs.versionUpdate.close()
            },
6.  // 更新版本
            confirmVersionUpdate() {
                this.$refs.versionUpdate.close()
                uni.showLoading({
                    title: '正在下载...'
                });
                // 应用内下载app
                uni.downloadFile({
                    url: 'http://116.52.158.139:9997' +
                        this.downloadUrl,
                    success: (res) => {
                        uni.hideLoading();
                        if (res.statusCode === 200) {
                            // 调用第三方程序打开指定的临时文件
                            plus.runtime.openFile(res
                                .tempFilePath, {},
                                function() {
                                    uni.showToast({
                                        title: '安装失败',
                                        duration: 2000
                                    });
                                });
                        }
                    }
                });
            },

  • 11
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值