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.
@@ -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
@@ -92,7 +92,7 @@
92
92
  v-if="showPlus && $slots.plus"
93
93
  @touchend.stop="onClearTimeout"
94
94
  >
95
- <slot name="plus" />
95
+ <slot name="plus" :disabled="isDisabled('plus')" />
96
96
  </view>
97
97
  <view
98
98
  v-else-if="showPlus"
@@ -1,102 +1,285 @@
1
- export const appInit = {
2
- data() {
3
- return {
4
- version: ""
5
- }
6
- },
7
- /**
8
- * app更新下载版本
9
- * @param version 最新版本号
10
- * @param description 版本描述
11
- * @param url 最新版本下载链接
12
- * @returns
13
- * */
14
- updateVersion(content):void {
15
- const { version, description, url } = content
16
- plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
17
- this.version = widgetInfo.version as string
18
- let _this = this
19
-
20
- // 1代表app新包版本号大于本地版本号
21
- if (this.compareVersion(version, this.version) === 1) {
22
- uni.showModal({
23
- title: `发现新版本V${version}`,
24
- content: `更新内容:${description}`,
25
- success: function (res1) {
26
- if (res1.confirm) {
27
- _this.downloadApp(url)
28
- }
29
- }
30
- });
31
- }
32
- });
33
- },
34
- /**
35
- * 进行版本更新检查操作
36
- * */
37
- compareVersion(version1: string, version2: string) {
38
- const newVersion1 = `${version1}`.split('.').length < 3 ? `${version1}`.concat('.0') : `${version1}`;
39
- const newVersion2 = `${version2}`.split('.').length < 3 ? `${version2}`.concat('.0') : `${version2}`;
40
-
41
- return this.isUpdateVersion(newVersion1 ,newVersion2);
42
- },
43
- /**
44
- * 计算版本号大小,转化大小
45
- * */
46
- toNum(a: number | string){
47
- const c = a.toString().split('.');
48
- const num_place = ["", "0", "00", "000", "0000"],
49
- r = num_place.reverse();
50
- for (let i = 0; i < c.length; i++){
51
- const len=c[i].length;
52
- c[i]=r[len]+c[i];
53
- }
54
- return c.join('');
55
- },
56
- /**
57
- * 检测版本号是否需要更新
58
- * */
59
- isUpdateVersion(a: number | string, b: number | string) {
60
- const numA = this.toNum(a);
61
- const numB = this.toNum(b);
62
- return numA > numB ? 1 : numA < numB ? -1 : 0;
63
- },
64
- /**
65
- * 下载新的app版本
66
- * */
67
- downloadApp(downloadUrl: string) {
68
- uni.showLoading({
69
- title: '更新中……'
70
- })
71
- uni.downloadFile({
72
- // 存放最新安装包的地址
73
- url: downloadUrl,
74
- success: (downloadResult) => {
75
- uni.hideLoading();
76
- if (downloadResult.statusCode === 200) {
77
- plus.runtime.install(downloadResult.tempFilePath,{
78
- force: false
79
- }, function() {
80
- plus.runtime.restart();
81
- }, function(e) {
82
- uni.showToast({
83
- title: "安装失败",
84
- icon: "none"
85
- })
86
- });
87
- } else {
88
- uni.showToast({
89
- title: "更新失败",
90
- icon: "none"
91
- })
92
- }
93
- },
94
- fail: (err) => {
95
- uni.showToast({
96
- title: "下载失败",
97
- icon: "none"
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hy-app",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "📱一个基于vue3+ts构建的uni-app组件库,拥有八十多个精美组件,适配多端,支持自定义主题",
5
5
  "main": "./index.ts",
6
6
  "private": false,