刘磊
2025-04-19 2f18780a16a68f7fc67dd3bca61b8d0aed7c8e1a
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<script>
    import Vue from 'vue'
    export default {
        created() {
            //plus.navigator.closeSplashscreen();
        },
        onLaunch: function() {
            // plus.screen.lockOrientation('landscape');
            // plus.screen.lockOrientation('portrait');
            uni.getSystemInfo({
                success: function(e) {
                    Vue.prototype.statusBar = e.statusBarHeight;
                    let height = 45;
                    if (e.platform == 'android')
                        height = 50;
                    Vue.prototype.CustomBar = e.statusBarHeight + height;
                }
            })
            // #ifdef APP-PLUS 
            //        console.log(plus.push.getClientInfo().clientid);
            //     const _self = this;
            //     const _handlePush = function(message) {
            //     };
            // plus.push.addEventListener('click', function(message) {
            //     //plus.nativeUI.toast('push click');
            //     // uni.navigateTo({
            //     //     url: "/pages/index/main"
            //     // })
            // });
            // plus.push.addEventListener('receive', function(message) {
            //     //plus.push.createMessage("您有新的消息");  
            //     //plus.nativeUI.alert(message.content);
            //     // uni.navigateTo({ 
            //     //     url: "/pages/index/main"
            //     // })
            // });
            var requestIP = this.$AjaxRequest.RequestUrl;
            // 获取本地应用资源版本号  
            plus.runtime.getProperty(plus.runtime.appid, function(inf) {
                //console.log("当前应用版本:" + inf.version + "---" + plus.runtime.version);
                var server = requestIP + "Dt_appVersionRecord/CheckVersion"; //检查更新地址
                var req = { //升级检测数据
                    MainData: {
                        "appid": plus.runtime.appid,
                        "version": inf.version, //plus.runtime.version,
                        "Extra": 'APP',
                        'VerificationCode': 'App',
                        'UUID': 'App'
                    }
                };
                //console.log(req);
                uni.request({
                    method: 'POST',
                    url: server,
                    data: req,
                    dataType: 'json',
                    header: {
                        'Content-Type': 'application/json; charset=utf-8',
                        'Authorization': 'Bearer '
                    },
                    success: (res) => {
                        if (res.statusCode == 200 && res.data.data.status && !res.data.data.latestVersion) {
                            var urls = res.data.data.url;
                            var downLoad = requestIP + "Dt_appVersionRecord/DownLoadWgt?filePath=" + urls;
                            uni.showModal({ //提醒用户更新
                                title: "更新提示",
                                content: "检测新版本,是否更新?",
                                showCancel: true,
                                success: (res) => {
                                    if (res.confirm) {
                                        var wgtWaiting = null;
                                        wgtWaiting = plus.nativeUI.showWaiting("开始下载");
                                        var down = plus.downloader.createDownload(downLoad, {}, function(download, status) {
                                            plus.nativeUI.closeWaiting();
                                            if (status == 200) {
                                                //console.log(down.filename);
                                                installApk(down.filename); // 更新应用资源  
                                            } else {
                                                plus.downloader.clear();
                                            }
                                        });
                                        down.start();
                                        down.addEventListener("statechanged", function(download, status) {
                                            switch (download.state) {
                                                case 2:
                                                    wgtWaiting.setTitle("已连接到服务器");
                                                    break;
                                                case 3:
                                                    var percent = download.downloadedSize / download.totalSize * 100;
                                                    wgtWaiting.setTitle("已下载 " + parseInt(percent) + "%");
                                                    break;
                                                case 4:
                                                    wgtWaiting.setTitle("下载完成");
                                                    break;
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                })
                // 更新应用资源  
                var installApk = function(path) {
                    plus.runtime.install(path, {}, function() {
                        plus.nativeUI.closeWaiting();
                        //console.log("安装文件成功!");
                        plus.runtime.restart();
                    }, function(e) {
                        plus.nativeUI.closeWaiting();
                        //console.log(JSON.stringify(e));
                        uni.showToast({
                            title: '安装失败',
                            mask: false,
                            icon: 'none',
                            duration: 2500
                        });
                    });
                }
            });
 
            //#endif
        }
    };
</script>
 
<style lang="scss">
    @import "uview-ui/index.scss";
    @import "common/demo.scss";
/* #ifdef H5 */
    @media screen and (min-width: 768px) {
        body{
            overflow-y: scroll;
        }
    }
 
     /* 顶栏通栏样式 */
    /* .uni-top-window {
        left: 0;
        right: 0;
    } */
 
    uni-page-body {
        background-color: #F5F5F5 !important;
        min-height: 100% !important;
        height: auto !important;
    }
 
    .uni-top-window uni-tabbar .uni-tabbar {
        background-color: #fff !important;
    }
 
    .uni-app--showleftwindow .hideOnPc {
        display: none !important;
    }
    /* #endif */
    body {
        background: #FFFFFF !important;
    }
</style>