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
| <template>
| <div class="UpdateBox">
| <div class="title">设备版本信息</div>
| <div class="version">当前版本: V1.2.1</div>
| <div class="newVersion">检测到有最新版本: V2.1.1</div>
| <div class="button" @click="updateVersion" v-if="loadingStatus == 0">
| 更新
| </div>
| <div class="button loading" v-if="loadingStatus == 1">更新中</div>
| <div class="button loading" v-if="loadingStatus == 2">已是最新版本</div>
| <div class="close iconfont" @click="close"></div>
| </div>
| </template>
|
| <script>
| import { updateVersion, checkVersion } from "@/api/device";
|
| export default {
| props: {
| device: {},
| },
| data() {
| return {
| loadingStatus: 0,
| timer: null,
| };
| },
| methods: {
| close() {
| this.$emit("close");
| },
| async updateVersion() {
| this.loadingStatus = 1;
| await updateVersion();
| this.check();
| },
| async check() {
| const res = await checkVersion();
| if (res.data.hasNewVersion) {
| this.timer = setTimeout(() => {
| this.check();
| }, 1000);
|
| if (!res.data.hasNewVersion) {
| this.timer = null;
| this.loadingStatus = 2;
| }
| }
| },
| },
| };
| </script>
|
| <style lang="scss" scoped>
| .UpdateBox {
| position: relative;
| box-sizing: border-box;
| position: fixed;
| top: 230px;
| left: 50%;
| margin-left: -260px;
| width: 520px;
| height: 230px;
| padding: 20px;
| font-size: 14px;
| background: #ffffff;
| box-shadow: 0px 2px 16px rgba(0, 43, 106, 0.25);
| z-index: 2;
|
| .title {
| padding-left: 10px;
| margin-bottom: 30px;
| height: 20px;
| line-height: 20px;
| font-size: 16px;
| font-weight: 700;
| border-left: 4px solid #0065ff;
| }
|
| .version {
| margin-bottom: 10px;
| font-weight: 700;
| }
|
| .button {
| position: absolute;
| right: 20px;
| bottom: 30px;
| width: 140px;
| height: 40px;
| text-align: center;
| line-height: 40px;
| color: #fff;
| background: #0065ff;
| }
|
| .loading {
| color: #045500;
| background: #40b63a;
| }
|
| .close {
| position: absolute;
| top: 10px;
| right: 10px;
| font-size: 12px;
| color: 187, 187, 187;
| cursor: pointer;
| }
| }
| </style>
|
|