cuiqian2004
8 天以前 30311cd24ee3b1567ffafac002494bb67feda657
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
<template>
    <view class="pages-my-version-update">
        <view class="group">
            <view class="item">
                <view>自动更新</view>
                <view class="right"></view>
                <switch :checked="autoUpdate" @change="switchChangeAutoUpdate" />
            </view>
 
        </view>
        <view class="tip">
            开启后,设备将在2:00-6:00自动更新软件版本
        </view>
        <view class="group" v-if="newPack.size > 0">
            <view class="item big-text ">
                可更新版本{{newPack.version}}
            </view>
            <view class="item gray-text">
                {{newVersionSize}}
            </view>
            <view class="item">
                有更新的版本{{newPack.version}}
            </view>
            <view class="item">
                当前版本为{{appVersion}}
            </view>
        </view>
        <view class="no-version gray-text" v-else>
            <uni-icons type="upload-filled" size="150" color="#888"></uni-icons>
            当前为最新版本{{appVersion}}
        </view>
 
        <view class="button-group" v-if="newPack.size > 0">
            <a-button type="primary" class="button" @click="clickNowUpdate">现在更新</a-button>
        </view>
    </view>
</template>
<script>
    import {
        session,
        showToast,
        showModal
    } from "@/comm/utils.js"
    import {
        Button
    } from 'antd-mobile-vue-next'
    export default {
        name: "PagesMyVersionUpdate",
        components: {
            'a-button': Button
        },
        data() {
            return {
                autoUpdate:false,
                appVersion: "1.0.0",
                newPack:{}
                // newPack: {
                //     version: "1.0.0",
                //     size: 200 * 1024 * 1024,
                // }
            }
        },
        onLoad() {
            this.loadData()
 
        },
        computed: {
            newVersionSize() {
                const packSize = this.newPack?.size || 0
                let size = 0
                if (packSize < 1024) {
                    size = Math.round(packSize * 100)
                    return `${size/100} KB`
                } else if (packSize < 1024 * 1024) {
                    size = Math.round(packSize * 100 / 1024)
                    return `${size/100} MB`
                } else {
                    size = Math.round(packSize * 100 / (1024 * 1024 * 1024))
                    return `${size/100} GB`
                }
            }
 
        },
        methods: {
            setData(obj) {
                let that = this;
                let keys = [];
                let val, data;
 
                Object.keys(obj).forEach(function(key) {
                    keys = key.split(".");
                    val = obj[key];
                    data = that.$data;
                    keys.forEach(function(key2, index) {
                        if (index + 1 == keys.length) {
                            that.$set(data, key2, val);
                        } else {
                            if (!data[key2]) {
                                that.$set(data, key2, {});
                            }
                        }
                        data = data[key2];
                    });
                });
            },
            loadData() {
                
                    this.autoUpdate = session.getValue("auto_update") ? true :false
                const _this = this
                // #ifdef APP-PLUS
                plus.runtime.getProperty(plus.runtime.appid, (info) => {
                    // console.log(info);
                    _this.setData({
                        appVersion: info.version
                    })
                });
                //#endif
            },
 
 
            switchChangeAutoUpdate(e) {
                this.autoUpdate = e.detail.value
                session.setValue("auto_update", this.autoUpdate ? 1 :0)
            },
 
            clickNowUpdate() {
            
            },
 
        }
    }
</script>
 
<style lang="scss">
    .pages-my-version-update {
        display: flex;
        width: 750rpx;
        height: 100vh;
        flex-direction: column;
 
        .group {
            width: calc(100% - 40rpx);
            border: 2rpx solid #ccc;
            background-color: #fff;
            border-radius: 20rpx;
            margin: 20rpx;
            padding: 0 10rpx;
            display: flex;
            flex-direction: column;
 
            .item {
                width: 100%;
                padding: 20rpx 10rpx;
                display: flex;
                flex-direction: row;
                align-items: center;
 
                .right {
                    flex: 1;
                    text-align: right;
                    color: #888;
                }
            }
 
 
        }
        .tip{
            color: #888;
            padding: 10rpx;
            margin-left: 50rpx;
        }
        .gray-text {
            color: #888;
        }
 
        .big-text {
            font-size: 40rpx;
        }
        .no-version{
            margin: auto;
            display: flex;
            flex-direction: column;
        }
 
        .button-group {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            font-size: 30rpx !important;
 
            .am-button {
                border-radius: 30px;
            }
 
        }
 
        .button {
            margin: auto;
            margin-top: 20rpx;
            border-radius: 4rpx;
            width: 500rpx;
        }
 
 
    }
</style>