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
| <template>
| <view>
| {{data}}
| <div>
| {{wgtVer}}
| </div>
| <div>
| {{version}}
| </div>
| <div>{{isandroid}}</div>
| <div>{{success}}</div>
| </view>
| </template>
|
| <script>
| export default {
| data() {
| return {
| wgtVer:'',
| version:'',
| data:null,
| isandroid:'',
| success:''
| }
| },
| onLoad() {
| this.plusReady();
| this.isandroid1();
| },
| methods: {
| // 获取当前版本号
| plusReady() {
| var that = this;
| // 获取本地应用资源版本号
| plus.runtime.getProperty(plus.runtime.appid, function(inf) {
| that.data = inf
| console.log(inf,'inf')
| that.wgtVer = inf.version; //获取当前版本号
| that.version = plus.runtime.version;
|
| });
|
| },
| // 检查是否安卓
| isandroid1() {
| var that1 = this;
| uni.getSystemInfo({
| success: res => {
| console.log(res)
| that1.isandroid=res
| if (res.platform == "android") {
| that1.AndroidCheckUpdate();
| }
| }
| })
| },
| // 自动更新
| AndroidCheckUpdate() {
| var that2 = this;
| that2.success=22
| uni.request({
| url: helper.webUrl + 'index.php/App/getAndroidVersion', //获取最新版本号
| method: 'GET',
| data: {},
| success: res => {
| if (res.data.version != that2.version) {
| if (plus.networkinfo.getCurrentType() != 3) {
| uni.showToast({
| title: '有新的版本发布,检测到您目前非Wifi连接,为节约您的流量,程序已停止自动更新,将在您连接WIFI之后重新检测更新。',
| mask: false,
| duration: 5000,
| icon: "none"
| });
| return;
| }
| uni.showToast({
| title: '有新的版本发布,检测到您目前为Wifi连接,程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
| mask: false,
| duration: 5000,
| icon: "none"
| });
| //res.data.androidurl 是apk的下载链接
| var dtask = plus.downloader.createDownload(res.data.androidurl, {}, function(d,
| status) {
| // 下载完成
| if (status == 200) {
| plus.runtime.install(plus.io.convertLocalFileSystemURL(d
| .filename), {}, {}, function(error) {
| uni.showToast({
| title: '安装失败',
| mask: false,
| duration: 1500
| });
| })
| } else {
| uni.showToast({
| title: '更新失败',
| mask: false,
| duration: 1500
| });
| }
| });
| dtask.start();
| }
| }
| });
| }
| },
| }
| </script>
|
| <style lang="scss">
|
| </style>
|
|