hy-app 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/attributes.json +1 -1
- package/components/hy-list/hy-list.vue +346 -228
- package/components/hy-list/index.scss +0 -1
- package/components/hy-list/props.ts +69 -69
- package/components/hy-number-step/hy-number-step.vue +1 -1
- package/libs/common/versionControl.ts +285 -102
- package/package.json +1 -1
- package/web-types.json +1 -1
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import type { PropType } from 'vue'
|
|
2
|
-
|
|
3
|
-
const listProps = {
|
|
4
|
-
/** 数据列表 */
|
|
5
|
-
list: {
|
|
6
|
-
type: Array,
|
|
7
|
-
default: () => []
|
|
8
|
-
},
|
|
9
|
-
/** 容器高度,必须给个高度,否则加载全部数据 */
|
|
10
|
-
containerHeight: {
|
|
11
|
-
type: String,
|
|
12
|
-
default: '100%'
|
|
13
|
-
},
|
|
14
|
-
/** 子容器的高度,必须和内容一致,否则计算有问题 */
|
|
15
|
-
itemHeight: {
|
|
16
|
-
type: [String, Number],
|
|
17
|
-
default: '40px'
|
|
18
|
-
},
|
|
19
|
-
/** 子容器的底部,会计算到容器内 */
|
|
20
|
-
marginBottom: {
|
|
21
|
-
type: [String, Number],
|
|
22
|
-
default: 0
|
|
23
|
-
},
|
|
24
|
-
/** 子容器的内边距 */
|
|
25
|
-
padding: {
|
|
26
|
-
type: [String, Number],
|
|
27
|
-
default: 10
|
|
28
|
-
},
|
|
29
|
-
/** 子容器的圆角,单位px */
|
|
30
|
-
borderRadius: {
|
|
31
|
-
type: [String, Number],
|
|
32
|
-
default: '3px'
|
|
33
|
-
},
|
|
34
|
-
/** 容器背景色 */
|
|
35
|
-
background: {
|
|
36
|
-
type: String,
|
|
37
|
-
default: 'transparent'
|
|
38
|
-
},
|
|
39
|
-
/** 是否显示边框 */
|
|
40
|
-
border: {
|
|
41
|
-
type: Boolean,
|
|
42
|
-
default: false
|
|
43
|
-
},
|
|
44
|
-
/** 展示几列 */
|
|
45
|
-
line: {
|
|
46
|
-
type: Number,
|
|
47
|
-
default: 1
|
|
48
|
-
},
|
|
49
|
-
/** 每一项的唯一标识key */
|
|
50
|
-
keyField: {
|
|
51
|
-
type: String,
|
|
52
|
-
default: 'id'
|
|
53
|
-
},
|
|
54
|
-
/**
|
|
55
|
-
* 加载状态
|
|
56
|
-
* @values loadMore,loading,noMore
|
|
57
|
-
* */
|
|
58
|
-
load: {
|
|
59
|
-
type: String,
|
|
60
|
-
default: 'loadMore'
|
|
61
|
-
},
|
|
62
|
-
/** 显示底部加载状态 */
|
|
63
|
-
showDivider: {
|
|
64
|
-
type: Boolean,
|
|
65
|
-
default: true
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default listProps
|
|
1
|
+
import type { PropType } from 'vue'
|
|
2
|
+
|
|
3
|
+
const listProps = {
|
|
4
|
+
/** 数据列表 */
|
|
5
|
+
list: {
|
|
6
|
+
type: Array,
|
|
7
|
+
default: () => []
|
|
8
|
+
},
|
|
9
|
+
/** 容器高度,必须给个高度,否则加载全部数据 */
|
|
10
|
+
containerHeight: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: '100%'
|
|
13
|
+
},
|
|
14
|
+
/** 子容器的高度,必须和内容一致,否则计算有问题 */
|
|
15
|
+
itemHeight: {
|
|
16
|
+
type: [String, Number],
|
|
17
|
+
default: '40px'
|
|
18
|
+
},
|
|
19
|
+
/** 子容器的底部,会计算到容器内 */
|
|
20
|
+
marginBottom: {
|
|
21
|
+
type: [String, Number],
|
|
22
|
+
default: 0
|
|
23
|
+
},
|
|
24
|
+
/** 子容器的内边距 */
|
|
25
|
+
padding: {
|
|
26
|
+
type: [String, Number],
|
|
27
|
+
default: 10
|
|
28
|
+
},
|
|
29
|
+
/** 子容器的圆角,单位px */
|
|
30
|
+
borderRadius: {
|
|
31
|
+
type: [String, Number],
|
|
32
|
+
default: '3px'
|
|
33
|
+
},
|
|
34
|
+
/** 容器背景色 */
|
|
35
|
+
background: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: 'transparent'
|
|
38
|
+
},
|
|
39
|
+
/** 是否显示边框 */
|
|
40
|
+
border: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false
|
|
43
|
+
},
|
|
44
|
+
/** 展示几列 */
|
|
45
|
+
line: {
|
|
46
|
+
type: Number,
|
|
47
|
+
default: 1
|
|
48
|
+
},
|
|
49
|
+
/** 每一项的唯一标识key */
|
|
50
|
+
keyField: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: 'id'
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* 加载状态
|
|
56
|
+
* @values loadMore,loading,noMore
|
|
57
|
+
* */
|
|
58
|
+
load: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: 'loadMore'
|
|
61
|
+
},
|
|
62
|
+
/** 显示底部加载状态 */
|
|
63
|
+
showDivider: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default listProps
|
|
@@ -1,102 +1,285 @@
|
|
|
1
|
-
export
|
|
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
|
-
const
|
|
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
|
-
}
|
|
1
|
+
export interface UpdateVersionOptions {
|
|
2
|
+
/** 最新版本号 */
|
|
3
|
+
version: string
|
|
4
|
+
/** 更新内容 */
|
|
5
|
+
description: string
|
|
6
|
+
/** 下载地址 */
|
|
7
|
+
url: string
|
|
8
|
+
/** 是否强制更新 */
|
|
9
|
+
force?: boolean
|
|
10
|
+
/** iOS AppStore地址 */
|
|
11
|
+
iosStoreUrl?: string
|
|
12
|
+
/** 下载进度 */
|
|
13
|
+
onProgress?: (progress: OnProgressDownloadResult) => void
|
|
14
|
+
/** 更新前回调 */
|
|
15
|
+
beforeUpdate?: (version: string) => boolean | void
|
|
16
|
+
/** 更新成功 */
|
|
17
|
+
onSuccess?: () => void
|
|
18
|
+
/** 更新失败 */
|
|
19
|
+
onFail?: (error: string) => void
|
|
20
|
+
/** 点击确认回调 */
|
|
21
|
+
onConfirm?: () => void
|
|
22
|
+
/** 点击取消回调 */
|
|
23
|
+
onCancel?: () => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const appInit = {
|
|
27
|
+
/**
|
|
28
|
+
* 检查更新
|
|
29
|
+
*/
|
|
30
|
+
updateVersion(options: UpdateVersionOptions) {
|
|
31
|
+
const {
|
|
32
|
+
version,
|
|
33
|
+
description,
|
|
34
|
+
url,
|
|
35
|
+
force = false,
|
|
36
|
+
iosStoreUrl,
|
|
37
|
+
onProgress,
|
|
38
|
+
beforeUpdate,
|
|
39
|
+
onSuccess,
|
|
40
|
+
onFail,
|
|
41
|
+
onConfirm,
|
|
42
|
+
onCancel
|
|
43
|
+
} = options
|
|
44
|
+
|
|
45
|
+
if (!version) {
|
|
46
|
+
console.error('version不能为空')
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
|
51
|
+
const localVersion = widgetInfo.version
|
|
52
|
+
const compareResult = this.compareVersion(version, localVersion)
|
|
53
|
+
if (compareResult !== 1) {
|
|
54
|
+
return uni.showToast({ title: '已是最新版本', icon: 'none' })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof beforeUpdate === 'function') {
|
|
58
|
+
const result = beforeUpdate(version)
|
|
59
|
+
|
|
60
|
+
if (result === false) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
uni.showModal({
|
|
66
|
+
title: `发现新版本 V${version}`,
|
|
67
|
+
content: description,
|
|
68
|
+
showCancel: !force,
|
|
69
|
+
confirmText: '立即更新',
|
|
70
|
+
success: (res) => {
|
|
71
|
+
if (!res.confirm) {
|
|
72
|
+
if (typeof onCancel === 'function') {
|
|
73
|
+
onCancel()
|
|
74
|
+
}
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (typeof onConfirm === 'function') {
|
|
79
|
+
onConfirm()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const platform = uni.getSystemInfoSync().platform
|
|
83
|
+
|
|
84
|
+
// iOS
|
|
85
|
+
if (platform === 'ios') {
|
|
86
|
+
if (iosStoreUrl) {
|
|
87
|
+
plus.runtime.openURL(iosStoreUrl)
|
|
88
|
+
} else {
|
|
89
|
+
uni.showToast({
|
|
90
|
+
title: '请配置AppStore地址',
|
|
91
|
+
icon: 'none'
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Android
|
|
98
|
+
this.downloadApp(url, {
|
|
99
|
+
onProgress,
|
|
100
|
+
onSuccess,
|
|
101
|
+
onFail
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 比较版本号
|
|
110
|
+
* 1:服务器版本大
|
|
111
|
+
* 0:相等
|
|
112
|
+
* -1:本地版本大
|
|
113
|
+
* @param serverVersion 最新版本
|
|
114
|
+
* @param localVersion 本地版本
|
|
115
|
+
*/
|
|
116
|
+
compareVersion(serverVersion: string, localVersion: string) {
|
|
117
|
+
if (!serverVersion || !localVersion) return 0
|
|
118
|
+
const v1 = serverVersion.split('.').map(Number)
|
|
119
|
+
const v2 = localVersion.split('.').map(Number)
|
|
120
|
+
const length = Math.max(v1.length, v2.length)
|
|
121
|
+
|
|
122
|
+
for (let i = 0; i < length; i++) {
|
|
123
|
+
const n1 = v1[i] || 0
|
|
124
|
+
const n2 = v2[i] || 0
|
|
125
|
+
|
|
126
|
+
if (n1 > n2) {
|
|
127
|
+
return 1
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (n1 < n2) {
|
|
131
|
+
return -1
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return 0
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 下载更新包
|
|
140
|
+
*/
|
|
141
|
+
downloadApp(
|
|
142
|
+
downloadUrl: string,
|
|
143
|
+
callbacks?: {
|
|
144
|
+
onProgress?: (progress: OnProgressDownloadResult) => void
|
|
145
|
+
onSuccess?: () => void
|
|
146
|
+
onFail?: (error: string) => void
|
|
147
|
+
}
|
|
148
|
+
) {
|
|
149
|
+
const { onProgress, onSuccess, onFail } = callbacks || {}
|
|
150
|
+
|
|
151
|
+
if (!downloadUrl) {
|
|
152
|
+
const msg = '下载地址不能为空'
|
|
153
|
+
|
|
154
|
+
uni.showToast({
|
|
155
|
+
title: msg,
|
|
156
|
+
icon: 'none'
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
onFail?.(msg)
|
|
160
|
+
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const downloadTask = uni.downloadFile({
|
|
165
|
+
url: downloadUrl,
|
|
166
|
+
|
|
167
|
+
success: (res) => {
|
|
168
|
+
if (res.statusCode !== 200) {
|
|
169
|
+
const msg = '下载失败'
|
|
170
|
+
|
|
171
|
+
uni.showToast({
|
|
172
|
+
title: msg,
|
|
173
|
+
icon: 'none'
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
onFail?.(msg)
|
|
177
|
+
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.installPackage(res.tempFilePath, downloadUrl, onSuccess, onFail)
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
fail: (err) => {
|
|
185
|
+
console.error('下载失败', err)
|
|
186
|
+
|
|
187
|
+
const msg = '下载失败'
|
|
188
|
+
|
|
189
|
+
uni.showToast({
|
|
190
|
+
title: msg,
|
|
191
|
+
icon: 'none'
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
onFail?.(msg)
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
downloadTask.onProgressUpdate((res) => {
|
|
199
|
+
onProgress?.(res)
|
|
200
|
+
})
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 安装更新包
|
|
205
|
+
*/
|
|
206
|
+
installPackage(
|
|
207
|
+
filePath: string,
|
|
208
|
+
downloadUrl: string,
|
|
209
|
+
onSuccess?: () => void,
|
|
210
|
+
onFail?: (error: string) => void
|
|
211
|
+
) {
|
|
212
|
+
const isWgt = downloadUrl.toLowerCase().endsWith('.wgt')
|
|
213
|
+
|
|
214
|
+
const isApk = downloadUrl.toLowerCase().endsWith('.apk')
|
|
215
|
+
|
|
216
|
+
// WGT热更新
|
|
217
|
+
if (isWgt) {
|
|
218
|
+
plus.runtime.install(
|
|
219
|
+
filePath,
|
|
220
|
+
{
|
|
221
|
+
force: false
|
|
222
|
+
},
|
|
223
|
+
() => {
|
|
224
|
+
uni.showToast({
|
|
225
|
+
title: '更新成功'
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
onSuccess?.()
|
|
229
|
+
|
|
230
|
+
setTimeout(() => {
|
|
231
|
+
plus.runtime.restart()
|
|
232
|
+
}, 1000)
|
|
233
|
+
},
|
|
234
|
+
(err) => {
|
|
235
|
+
console.error('安装失败', err)
|
|
236
|
+
|
|
237
|
+
const msg = `安装失败:${err.message}`
|
|
238
|
+
|
|
239
|
+
uni.showToast({
|
|
240
|
+
title: msg,
|
|
241
|
+
icon: 'none'
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
onFail?.(msg)
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// APK整包更新
|
|
252
|
+
if (isApk) {
|
|
253
|
+
plus.runtime.openFile(
|
|
254
|
+
filePath,
|
|
255
|
+
{},
|
|
256
|
+
() => {
|
|
257
|
+
onSuccess?.()
|
|
258
|
+
},
|
|
259
|
+
(err) => {
|
|
260
|
+
console.error('APK安装失败', err)
|
|
261
|
+
|
|
262
|
+
const msg = 'APK安装失败'
|
|
263
|
+
|
|
264
|
+
uni.showToast({
|
|
265
|
+
title: msg,
|
|
266
|
+
icon: 'none'
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
onFail?.(msg)
|
|
270
|
+
}
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const msg = '未知安装包格式'
|
|
277
|
+
|
|
278
|
+
uni.showToast({
|
|
279
|
+
title: msg,
|
|
280
|
+
icon: 'none'
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
onFail?.(msg)
|
|
284
|
+
}
|
|
285
|
+
}
|