wanshenmean
2025-04-08 ef0a08b828d021bdc7978406e72bbde000097f5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script>
    import http from "@/common/http.interceptor.js"
    export default {
        data: function() {
            return {
                curVersion: "",
                curVersionCode: ""
            }
        },
        onLaunch: function() {
            // console.log('App Launch')
            this.checkVeision();
        },
        onShow: function() {
            console.log('App Show')
        },
        onHide: function() {
            console.log('App Hide')
        },
        methods: {
            checkVeision() {
                // 获取manifest.json 的信息 版本信息
                plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
                    this.curVersion = wgtinfo.version; //应用版本名称
                    this.curVersionCode = wgtinfo.versionCode; //应用版本号
                });
                this.$u.get('/biz/test/GetRelease', null).then(res => {
                    // 当前版本code
                    let curVersionCode = parseInt(this.curVersionCode);
                    // 新版本code
                    let newVersionCode = res.data;
                    console.log("curVersionCode:", curVersionCode);
                    console.log("newVersionCode:", newVersionCode);
                    // 有新版本
                    if (newVersionCode > curVersionCode) {
                        console.log("有新版本")
                        // 检测新版本提示
                        uni.showModal({
                            title: '版本检查',
                            content: '检测到新版本,是否下载安装包?',
                            confirmText: '下载',
                            success: res => {
                                // 安装包下载地址
                                if (res.confirm) {
                                    const url = http.baseUrl + "/biz/test/FileDownload"
                                    uni.showLoading({
                                        title: '安装包下载中'
                                    });
                                    // 新建下载任务
                                    let dtask = plus.downloader.createDownload(url, {}, (d,
                                    status) => {
                                        if (status == 200) {
                                            uni.hideLoading();
                                            uni.showModal({
                                                title: '提示',
                                                content: '安装包下载成功,是否确认安装?',
                                                success: res => {
                                                    if (res.confirm) {
                                                        plus.runtime.install(
                                                            plus.io
                                                            .convertLocalFileSystemURL(
                                                                d.filename
                                                                ), {},
                                                            success => {
                                                                uni.showToast({
                                                                    title: '安装成功',
                                                                    mask: false,
                                                                    duration: 1500
                                                                });
                                                            },
                                                            error => {
                                                                uni.showToast({
                                                                    title: '安装失败',
                                                                    mask: false,
                                                                    duration: 1500
                                                                });
                                                            }
                                                        );
                                                    }
                                                }
                                            });
                                        } else {
                                            uni.hideLoading();
                                            uni.showToast({
                                                title: '安装包下载失败',
                                                mask: false,
                                                duration: 1500
                                            });
                                        }
                                    });
                                    // 开始下载
                                    dtask.start();
                                }
                            }
                        });
                    }
                    else{
                        this.$t.message.toast("暂无更新")
                    }
                })
            }
        }
    }
</script>
 
<style lang="scss">
    @import './tuniao-ui/index.scss';
    @import './tuniao-ui/iconfont.css';
    @import "uview-ui/index.scss";
    /*每个页面公共css */
</style>