uni-oaview 1.1.7 → 1.1.9

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/dist/index.d.ts CHANGED
@@ -7,12 +7,24 @@ import { App } from 'vue';
7
7
  declare function sendLaunchAppParamsLog(params: any): void;
8
8
 
9
9
  /**
10
- * 防抖函数
11
- * @param callback
12
- * @param time
10
+ * 获取当前app版本
13
11
  * @returns
14
12
  */
15
- declare function createDebounceFn(callback: (...params: any[]) => void, time: number): (...params: any[]) => void;
13
+ declare function getAppVersion(): string;
14
+ /**
15
+ * 比较两个版本号
16
+ * @param versionA
17
+ * @param versionB
18
+ * @returns
19
+ */
20
+ declare function compareVersions(versionA: string, versionB: string): number;
21
+ /**
22
+ * 判断当前版本是否高于或等于传入版本
23
+ * @param version
24
+ * @returns
25
+ */
26
+ declare function isCurrentVersionHigher(appVersion: string, warningText?: string): boolean;
27
+
16
28
  /**
17
29
  * 展示消息提醒,或者是确认弹窗等
18
30
  * @param title
@@ -44,6 +56,14 @@ declare const Message: {
44
56
  confirm(content: string, title?: string, confirmText?: string, cancelText?: string): Promise<unknown>;
45
57
  };
46
58
 
59
+ /**
60
+ * 防抖函数
61
+ * @param callback
62
+ * @param time
63
+ * @returns
64
+ */
65
+ declare function createDebounceFn(callback: (...params: any[]) => void, time: number): (...params: any[]) => void;
66
+
47
67
  declare const _default: {
48
68
  install: (app: App<Element>) => void;
49
69
  };
@@ -56,4 +76,4 @@ declare const _default: {
56
76
  */
57
77
  declare function getDataByApp(eventName: string, params: Record<string, any>, immediate?: boolean): Promise<any>;
58
78
 
59
- export { Message, createDebounceFn, _default as default, getDataByApp, sendLaunchAppParamsLog };
79
+ export { Message, compareVersions, createDebounceFn, _default as default, getAppVersion, getDataByApp, isCurrentVersionHigher, sendLaunchAppParamsLog };
package/dist/index.esm.js CHANGED
@@ -40,24 +40,6 @@ var OPEN_TOAST = "".concat(prefix, "open-toast");
40
40
  */
41
41
  var OPEN_CONFIRM_BOX = "".concat(prefix, "open-confirm-box");
42
42
 
43
- /**
44
- * 防抖函数
45
- * @param callback
46
- * @param time
47
- * @returns
48
- */
49
- function createDebounceFn(callback, time) {
50
- var timer = null;
51
- return function () {
52
- for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
53
- params[_key] = arguments[_key];
54
- }
55
- clearTimeout(timer);
56
- timer = setTimeout(function () {
57
- callback.apply(void 0, params);
58
- }, time);
59
- };
60
- }
61
43
  /**
62
44
  * 展示消息提醒,或者是确认弹窗等
63
45
  * @param title
@@ -126,6 +108,78 @@ var Message = {
126
108
  }
127
109
  };
128
110
 
111
+ /**
112
+ * 获取当前app版本
113
+ * @returns
114
+ */
115
+ function getAppVersion() {
116
+ var systemInfo = uni.getSystemInfoSync();
117
+ return systemInfo.hostVersion;
118
+ }
119
+ function isValidVersion(version) {
120
+ // 检查版本号是否只包含数字和点,并且至少有一个点
121
+ return /^(\d+\.)*\d+$/.test(version);
122
+ }
123
+ /**
124
+ * 比较两个版本号
125
+ * @param versionA
126
+ * @param versionB
127
+ * @returns
128
+ */
129
+ function compareVersions(versionA, versionB) {
130
+ if (!isValidVersion(versionA) || !isValidVersion(versionB)) {
131
+ console.log('【error】:无效的版本格式,请提供格式为"x.y.z"的版本号');
132
+ return -2;
133
+ }
134
+ var partsA = versionA.split('.').map(Number);
135
+ var partsB = versionB.split('.').map(Number);
136
+ var maxLength = Math.max(partsA.length, partsB.length);
137
+ for (var i = 0; i < maxLength; i++) {
138
+ var numA = partsA[i] || 0;
139
+ var numB = partsB[i] || 0;
140
+ if (numA > numB) {
141
+ return 1; // versionA > versionB
142
+ } else if (numA < numB) {
143
+ return -1; // versionA < versionB
144
+ }
145
+ }
146
+
147
+ return 0; // versionA == versionB
148
+ }
149
+ /**
150
+ * 判断当前版本是否高于或等于传入版本
151
+ * @param version
152
+ * @returns
153
+ */
154
+ function isCurrentVersionHigher(appVersion, warningText) {
155
+ var currentVersion = getAppVersion();
156
+ var result = compareVersions(appVersion, currentVersion);
157
+ if (result < 0) {
158
+ Message.warning('版本更新', warningText || '您的App版本过低,请升级App后体验小程序新功能。');
159
+ return false;
160
+ }
161
+ return true;
162
+ }
163
+
164
+ /**
165
+ * 防抖函数
166
+ * @param callback
167
+ * @param time
168
+ * @returns
169
+ */
170
+ function createDebounceFn(callback, time) {
171
+ var timer = null;
172
+ return function () {
173
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
174
+ params[_key] = arguments[_key];
175
+ }
176
+ clearTimeout(timer);
177
+ timer = setTimeout(function () {
178
+ callback.apply(void 0, params);
179
+ }, time);
180
+ };
181
+ }
182
+
129
183
  var install = function install(app) {
130
184
  app.mixin({
131
185
  onLaunch: function onLaunch(params) {
@@ -166,4 +220,4 @@ function getDataByApp(eventName, params) {
166
220
  });
167
221
  }
168
222
 
169
- export { Message, createDebounceFn, index as default, getDataByApp, sendLaunchAppParamsLog };
223
+ export { Message, compareVersions, createDebounceFn, index as default, getAppVersion, getDataByApp, isCurrentVersionHigher, sendLaunchAppParamsLog };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-oaview",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "uniapp小程序组件库",
5
5
  "main": "dist/index.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -0,0 +1,56 @@
1
+ import { Message } from './message';
2
+
3
+ /**
4
+ * 获取当前app版本
5
+ * @returns
6
+ */
7
+ export function getAppVersion() {
8
+ const systemInfo = uni.getSystemInfoSync() as any;
9
+ return systemInfo.hostVersion as string;
10
+ }
11
+
12
+ function isValidVersion(version: string): boolean {
13
+ // 检查版本号是否只包含数字和点,并且至少有一个点
14
+ return /^(\d+\.)*\d+$/.test(version);
15
+ }
16
+
17
+ /**
18
+ * 比较两个版本号
19
+ * @param versionA
20
+ * @param versionB
21
+ * @returns
22
+ */
23
+ export function compareVersions(versionA: string, versionB: string): number {
24
+ if (!isValidVersion(versionA) || !isValidVersion(versionB)) {
25
+ console.log('【error】:无效的版本格式,请提供格式为"x.y.z"的版本号');
26
+ return -2;
27
+ }
28
+ const partsA = versionA.split('.').map(Number);
29
+ const partsB = versionB.split('.').map(Number);
30
+ const maxLength = Math.max(partsA.length, partsB.length);
31
+ for (let i = 0; i < maxLength; i++) {
32
+ const numA = partsA[i] || 0;
33
+ const numB = partsB[i] || 0;
34
+ if (numA > numB) {
35
+ return 1; // versionA > versionB
36
+ } else if (numA < numB) {
37
+ return -1; // versionA < versionB
38
+ }
39
+ }
40
+ return 0; // versionA == versionB
41
+ }
42
+
43
+ /**
44
+ * 判断当前版本是否高于或等于传入版本
45
+ * @param version
46
+ * @returns
47
+ */
48
+ export function isCurrentVersionHigher(appVersion: string, warningText?: string): boolean {
49
+ const currentVersion = getAppVersion();
50
+ const result = compareVersions(appVersion, currentVersion);
51
+ if (result < 0) {
52
+ Message.warning('版本更新', warningText || '您的App版本过低,请升级App后体验小程序新功能。');
53
+ return false;
54
+ }
55
+ return true;
56
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 防抖函数
3
+ * @param callback
4
+ * @param time
5
+ * @returns
6
+ */
7
+ export function createDebounceFn(callback: (...params: any[]) => void, time: number) {
8
+ let timer: any = null;
9
+ return (...params: any[]) => {
10
+ clearTimeout(timer);
11
+ timer = setTimeout(() => {
12
+ callback(...params);
13
+ }, time);
14
+ };
15
+ }
@@ -1,85 +1,4 @@
1
1
  export * from './send-log';
2
- import { OPEN_CONFIRM_BOX, OPEN_TOAST } from '../../constants';
3
- /**
4
- * 防抖函数
5
- * @param callback
6
- * @param time
7
- * @returns
8
- */
9
- export function createDebounceFn(callback: (...params: any[]) => void, time: number) {
10
- let timer: any = null;
11
- return (...params: any[]) => {
12
- clearTimeout(timer);
13
- timer = setTimeout(() => {
14
- callback(...params);
15
- }, time);
16
- };
17
- }
18
-
19
- /**
20
- * 展示消息提醒,或者是确认弹窗等
21
- * @param title
22
- * @param duration
23
- */
24
- export const Message = {
25
- /**
26
- * 成功弹出框提醒
27
- * @param title 标题
28
- * @param content 内容
29
- * @param confirmText 确认按钮文本
30
- */
31
- success(title: string, content: string, confirmText?: string) {
32
- return new Promise((res) => {
33
- uni.$emit(OPEN_TOAST, {
34
- type: 'success',
35
- title,
36
- content,
37
- confirmText,
38
- callback: res,
39
- });
40
- });
41
- },
42
- /**
43
- * 警告弹框提醒
44
- * @param title 警告标题
45
- * @param content 警告内容
46
- * @param confirmText 警告按钮文本
47
- */
48
- warning(title: string, content: string, confirmText?: string) {
49
- return new Promise((res) => {
50
- uni.$emit(OPEN_TOAST, {
51
- type: 'warning',
52
- title,
53
- content,
54
- confirmText,
55
- callback: res,
56
- });
57
- });
58
- },
59
- /**
60
- * 确认弹窗
61
- * @param content 确认内容
62
- * @param title 标题
63
- * @param confirmText 确定按钮文本
64
- * @param cancelText 取消按钮文本
65
- * @returns
66
- */
67
- confirm(content: string, title?: string, confirmText?: string, cancelText?: string) {
68
- return new Promise((res, rej) => {
69
- const callback = (type: 'confirm' | 'cancel') => {
70
- if (type === 'confirm') {
71
- res('');
72
- } else {
73
- rej();
74
- }
75
- };
76
- uni.$emit(OPEN_CONFIRM_BOX, {
77
- title,
78
- content,
79
- confirmText,
80
- cancelText,
81
- callback,
82
- });
83
- });
84
- },
85
- };
2
+ export * from './app-version';
3
+ export * from './message';
4
+ export * from './core';
@@ -0,0 +1,69 @@
1
+ import { OPEN_CONFIRM_BOX, OPEN_TOAST } from '../../constants';
2
+
3
+ /**
4
+ * 展示消息提醒,或者是确认弹窗等
5
+ * @param title
6
+ * @param duration
7
+ */
8
+ export const Message = {
9
+ /**
10
+ * 成功弹出框提醒
11
+ * @param title 标题
12
+ * @param content 内容
13
+ * @param confirmText 确认按钮文本
14
+ */
15
+ success(title: string, content: string, confirmText?: string) {
16
+ return new Promise((res) => {
17
+ uni.$emit(OPEN_TOAST, {
18
+ type: 'success',
19
+ title,
20
+ content,
21
+ confirmText,
22
+ callback: res,
23
+ });
24
+ });
25
+ },
26
+ /**
27
+ * 警告弹框提醒
28
+ * @param title 警告标题
29
+ * @param content 警告内容
30
+ * @param confirmText 警告按钮文本
31
+ */
32
+ warning(title: string, content: string, confirmText?: string) {
33
+ return new Promise((res) => {
34
+ uni.$emit(OPEN_TOAST, {
35
+ type: 'warning',
36
+ title,
37
+ content,
38
+ confirmText,
39
+ callback: res,
40
+ });
41
+ });
42
+ },
43
+ /**
44
+ * 确认弹窗
45
+ * @param content 确认内容
46
+ * @param title 标题
47
+ * @param confirmText 确定按钮文本
48
+ * @param cancelText 取消按钮文本
49
+ * @returns
50
+ */
51
+ confirm(content: string, title?: string, confirmText?: string, cancelText?: string) {
52
+ return new Promise((res, rej) => {
53
+ const callback = (type: 'confirm' | 'cancel') => {
54
+ if (type === 'confirm') {
55
+ res('');
56
+ } else {
57
+ rej();
58
+ }
59
+ };
60
+ uni.$emit(OPEN_CONFIRM_BOX, {
61
+ title,
62
+ content,
63
+ confirmText,
64
+ cancelText,
65
+ callback,
66
+ });
67
+ });
68
+ },
69
+ };