hy-app 0.7.1 → 0.7.3

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
@@ -89,6 +89,6 @@ const modalProps = {
89
89
  type: String,
90
90
  default: 'left'
91
91
  }
92
- } as const
92
+ }
93
93
 
94
94
  export default modalProps
@@ -1,16 +1,52 @@
1
- import type { ExtractPropTypes } from 'vue'
2
- // import modalProps from './props'
3
-
4
- // export interface HyModalProps extends ExtractPropTypes<typeof modalProps> {}
5
-
6
- export interface IModalEmits {
7
- /** 点击确认按钮时触发 */
8
- (e: 'confirm'): void
9
- /** 点击取消按钮时触发 */
10
- (e: 'cancel'): void
11
- /** 点击遮罩关闭时触发 */
12
- (e: 'close'): void
13
- /** 更新值触发 */
14
- (e: 'update:modelValue', show: boolean): void
15
- (e: 'update:loading', show: boolean): void
16
- }
1
+ export interface HyModalProps {
2
+ /** 是否显示模态框 */
3
+ modelValue: boolean
4
+ /** 标题内容 */
5
+ title?: string
6
+ /** 模态框内容 */
7
+ content?: string
8
+ /** 确认按钮的文字 */
9
+ confirmText?: string
10
+ /** 取消按钮的文字 */
11
+ cancelText?: string
12
+ /** 是否显示确认按钮 */
13
+ showConfirmButton?: boolean
14
+ /** 是否显示取消按钮 */
15
+ showCancelButton?: boolean
16
+ /** 确认按钮的颜色 */
17
+ confirmColor?: string
18
+ /** 取消按钮的颜色 */
19
+ cancelColor?: string
20
+ /** 对调确认和取消的位置 */
21
+ buttonReverse?: boolean
22
+ /** 是否开启缩放模式 */
23
+ zoom?: boolean
24
+ /** 弹窗的圆角 */
25
+ round?: string | number
26
+ /** 点击确认按钮自动关闭 */
27
+ autoClose?: boolean
28
+ /** 加载按钮 */
29
+ loading?: boolean
30
+ /** 是否允许点击遮罩关闭Modal */
31
+ closeOnClickOverlay?: boolean
32
+ /** 往上偏移的值 */
33
+ negativeTop?: number
34
+ /** modal宽度 */
35
+ width?: string | number
36
+ /** 确认按钮的样式 */
37
+ confirmButtonShape?: 'circle' | 'square'
38
+ /** 文案对齐方式 */
39
+ contentTextAlign?: 'left' | 'center' | 'right'
40
+ }
41
+
42
+ export interface IModalEmits {
43
+ /** 点击确认按钮时触发 */
44
+ (e: 'confirm'): void
45
+ /** 点击取消按钮时触发 */
46
+ (e: 'cancel'): void
47
+ /** 点击遮罩关闭时触发 */
48
+ (e: 'close'): void
49
+ /** 更新值触发 */
50
+ (e: 'update:modelValue', show: boolean): void
51
+ (e: 'update:loading', show: boolean): void
52
+ }
@@ -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"
@@ -175,7 +175,6 @@ const format = (value: number | string): number => {
175
175
  // 对比最大最小值,取在min和max之间的值
176
176
  value = Math.max(Math.min(props.max, value), props.min)
177
177
  // 如果设定了最大的小数位数,使用toFixed去进行格式化
178
- console.log(value, 111)
179
178
  if (props.decimalLength !== null) {
180
179
  value = parseFloat(value.toFixed(props.decimalLength))
181
180
  }
@@ -197,7 +196,6 @@ watch(
197
196
  if (newValue !== currentValue.value) {
198
197
  currentValue.value = format(props.modelValue)
199
198
  }
200
- console.log(currentValue.value)
201
199
  },
202
200
  { immediate: true }
203
201
  )
@@ -1,102 +1,286 @@
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
+ * @param serverVersion 服务端版本
111
+ * @param localVersion 本地版本
112
+ * @returns
113
+ * 1: 服务端版本更高
114
+ * 0: 版本相同
115
+ * -1: 本地版本更高
116
+ */
117
+ compareVersion(serverVersion: string, localVersion: string) {
118
+ if (!serverVersion || !localVersion) return 0
119
+ const v1 = serverVersion.split('.').map(Number)
120
+ const v2 = localVersion.split('.').map(Number)
121
+ const length = Math.max(v1.length, v2.length)
122
+
123
+ for (let i = 0; i < length; i++) {
124
+ const n1 = v1[i] || 0
125
+ const n2 = v2[i] || 0
126
+
127
+ if (n1 > n2) {
128
+ return 1
129
+ }
130
+
131
+ if (n1 < n2) {
132
+ return -1
133
+ }
134
+ }
135
+
136
+ return 0
137
+ },
138
+
139
+ /**
140
+ * 下载更新包
141
+ */
142
+ downloadApp(
143
+ downloadUrl: string,
144
+ callbacks?: {
145
+ onProgress?: (progress: OnProgressDownloadResult) => void
146
+ onSuccess?: () => void
147
+ onFail?: (error: string) => void
148
+ }
149
+ ) {
150
+ const { onProgress, onSuccess, onFail } = callbacks || {}
151
+
152
+ if (!downloadUrl) {
153
+ const msg = '下载地址不能为空'
154
+
155
+ uni.showToast({
156
+ title: msg,
157
+ icon: 'none'
158
+ })
159
+
160
+ onFail?.(msg)
161
+
162
+ return
163
+ }
164
+
165
+ const downloadTask = uni.downloadFile({
166
+ url: downloadUrl,
167
+
168
+ success: (res) => {
169
+ if (res.statusCode !== 200) {
170
+ const msg = '下载失败'
171
+
172
+ uni.showToast({
173
+ title: msg,
174
+ icon: 'none'
175
+ })
176
+
177
+ onFail?.(msg)
178
+
179
+ return
180
+ }
181
+
182
+ this.installPackage(res.tempFilePath, downloadUrl, onSuccess, onFail)
183
+ },
184
+
185
+ fail: (err) => {
186
+ console.error('下载失败', err)
187
+
188
+ const msg = '下载失败'
189
+
190
+ uni.showToast({
191
+ title: msg,
192
+ icon: 'none'
193
+ })
194
+
195
+ onFail?.(msg)
196
+ }
197
+ })
198
+
199
+ downloadTask.onProgressUpdate((res) => {
200
+ onProgress?.(res)
201
+ })
202
+ },
203
+
204
+ /**
205
+ * 安装更新包
206
+ */
207
+ installPackage(
208
+ filePath: string,
209
+ downloadUrl: string,
210
+ onSuccess?: () => void,
211
+ onFail?: (error: string) => void
212
+ ) {
213
+ const isWgt = downloadUrl.toLowerCase().endsWith('.wgt')
214
+
215
+ const isApk = downloadUrl.toLowerCase().endsWith('.apk')
216
+
217
+ // WGT热更新
218
+ if (isWgt) {
219
+ plus.runtime.install(
220
+ filePath,
221
+ {
222
+ force: false
223
+ },
224
+ () => {
225
+ uni.showToast({
226
+ title: '更新成功'
227
+ })
228
+
229
+ onSuccess?.()
230
+
231
+ setTimeout(() => {
232
+ plus.runtime.restart()
233
+ }, 1000)
234
+ },
235
+ (err) => {
236
+ console.error('安装失败', err)
237
+
238
+ const msg = `安装失败:${err.message}`
239
+
240
+ uni.showToast({
241
+ title: msg,
242
+ icon: 'none'
243
+ })
244
+
245
+ onFail?.(msg)
246
+ }
247
+ )
248
+
249
+ return
250
+ }
251
+
252
+ // APK整包更新
253
+ if (isApk) {
254
+ plus.runtime.openFile(
255
+ filePath,
256
+ {},
257
+ () => {
258
+ onSuccess?.()
259
+ },
260
+ (err) => {
261
+ console.error('APK安装失败', err)
262
+
263
+ const msg = 'APK安装失败'
264
+
265
+ uni.showToast({
266
+ title: msg,
267
+ icon: 'none'
268
+ })
269
+
270
+ onFail?.(msg)
271
+ }
272
+ )
273
+
274
+ return
275
+ }
276
+
277
+ const msg = '未知安装包格式'
278
+
279
+ uni.showToast({
280
+ title: msg,
281
+ icon: 'none'
282
+ })
283
+
284
+ onFail?.(msg)
285
+ }
286
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hy-app",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "📱一个基于vue3+ts构建的uni-app组件库,拥有八十多个精美组件,适配多端,支持自定义主题",
5
5
  "main": "./index.ts",
6
6
  "private": false,