chenhaozhe
2025-08-06 00a363f1ef1e2ded9f7a8e933cd89d863458a3b4
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<template>
<view class="mains">
    <view class="hl" v-if="showTc">
        <view class="mask"></view>
        <view class="main">
            <view class="vers">版本号:{{vers}}</view>
            <view class="download">{{fieldTwo}}</view>
            <view class="download_btn" v-if="!waitLine" @tap="upOn">立即升级</view>
            <view class="download_line" v-if="waitLine">
                <progress :percent="loadPercent" stroke-width="20" active="true" active-mode="forwards" activeColor="#4587ff" backgroundColor="#a5c8ff"/>
                <view style="height: 30px;width: 100%; font-size: 26rpx;font-weight: bold; text-align: center;margin-top: -20px;color: #FFFFFF;">下载中,请稍后...</view>
            </view>
        </view>
    </view>
</view>
 
</template>
<script>
import { getUserInfo,getToken } from '@/utils/auth';
export default {
  data() {
    return {
        serverUrl: uni.getStorageSync('serverUrl')||'http://47.96.97.237/API',
        showTc:false,
        // 版本更新
        loadPercent:0,
        waitLine: false,
        timer:'',
        fieldTwo:'',
        vers:'',
    };
  },
  props: {
 
  },
  created() {
    // #ifdef APP-PLUS
    if(uni.getSystemInfoSync().platform !=='ios'){
        this.update();
    }else if(uni.getSystemInfoSync().platform =='ios'){
        uni.showToast({
            title:'请使用安卓手机,以免发生兼容性问题',
            icon:'none'
        })
    }
    //#endif
  },
  methods: {
    update() {
        var _this = this;
        uni.request({
            url:_this.serverUrl + '/LMES/AppUpdate',
            data: { type:'' },
            success: result => {
                console.log(1111111,result)
                // "DowloadPath": 整包更新下载地址,
                // "HotDowloadPath": 最新热更新下载地址,
                // "VersionNumber": "最新整包版本",
                // "HotVersionNumber": "最新版本",
                // "Content": ""
                if (result.data.count == 1) {
                    var datas = result.data.data[0]
                    uni.setStorageSync('remarkURL',datas.DowloadPath)
                    plus.runtime.getProperty(plus.runtime.appid, function(inf) {
                        console.log(inf)
                        _this.vers = datas.HotVersionNumber
                        uni.setStorageSync('vers','V' + inf.version)
                        console.log(datas.HotVersionNumber,inf.versionCode,datas.HotVersionNumber > inf.versionCode)
                        if(datas.HotVersionNumber > inf.versionCode){
                            var configType = datas.VersionNumber
                            _this.fieldTwo = datas.Content
                            if(configType > inf.versionCode ){
                                _this.showTc = true
                                console.log(configType,_this.showTc,_this.fieldTwo)
                            }else{
                                uni.showLoading({
                                    title:'发现新资源,正在下载中...',
                                    mask:true,
                                })
                                uni.downloadFile({
                                    url: datas.HotDowloadPath,
                                    success: (downloadResult) => {
                                        if (downloadResult.statusCode === 200) {
                                            uni.hideLoading()
                                            plus.runtime.install(downloadResult.tempFilePath, {
                                                force: false
                                            }, function() {
                                                console.log('install success...');
                                                plus.runtime.restart();
                                            }, function(e) {
                                                console.error('install fail...');
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            },
        })
    },
    upOn(){
        this.doUpData();
        this.loadPercent = 0
    },
    doUpData() {
        this.waitLine = true
        uni.hideTabBar()
        this.timer = setInterval(() => {
            if(this.loadPercent<98){
                this.loadPercent = this.loadPercent + 1
            }
        }, 400);
        uni.downloadFile({//执行下载
            url: uni.getStorageSync('remarkURL'), //下载地址
            success: downloadResult => {//下载成功
                this.loadPercent = 100
                this.waitLine = false
                this.showTc = false
                uni.showTabBar()
                if (downloadResult.statusCode == 200) {
                    uni.showModal({
                        title: '',
                        content: '下载成功,确定现在重启吗?',
                        confirmText: '确定',
                        cancelText: '取消',
                        confirmColor: '#4587ff',
                        success: function(res) {
                            this.waitLine = false
                            if (res.confirm == true) {
                                plus.runtime.install(//安装
                                    downloadResult.tempFilePath, {
                                        force: true
                                    },
                                    function(res) {
                                        utils.showToast('更新成功,重启中...');
                                        plus.runtime.restart();
                                    }
                                );
                            }else{
                                uni.showModal({
                                    content:'更新失败',
                                    confirmText:'确认',
                                    cancelText:'取消',
                                })
                            }
                        }
                    });
                }else{
                    this.waitLine = false
                    uni.showModal({
                        content: '请重新下载更新',
                        confirmText:'确认',
                        cancelText:'取消',
                    })
                }
            },
            fail: downloadResult => {//下载失败
                this.waitLine = false
                uni.showModal({
                    content:'请重新下载更新',
                    confirmText:'确认',
                    cancelText: '取消',
                })
            }
        });
    },
  }
};
</script>
<style scoped lang="scss">
.hl{
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    .mask{
        position: absolute;
        width: 100vw;
        height: 100vh;
        background: rgba(#000, .3);
    }
    .main{
        width: 550rpx;
        height: 730rpx;
        position: absolute;
        top: 20vh;
        left: 100rpx;
        background-image: url('/static/images/newVer.png');
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
        .vers{
            margin: 180rpx 0 0 50rpx;
            color: #fff;
            font-size: 38rpx;
            font-weight: bold;
        }
        .download{
            width: 480rpx;
            margin: 0 auto;
            margin-top: 150rpx;
            font-size: 30rpx;
            color: #333;
        }
        .download_btn{
            width: 420rpx;
            height: 68rpx;
            line-height: 68rpx;
            position: absolute;
            left: 80rpx;
            bottom: 40rpx;
            border-radius: 40rpx;
            background-color: #4587ff;
            text-align: center;
            color: #fff;
            font-size: 32rpx;
            box-shadow: 0 2rpx 2rpx 1rpx #1a3562;
        }
        .download_line{
            width: 80%;
            position: absolute;
            bottom: 20rpx;
            left: 10%;
        }
    }
}
</style>