@pisell/utils 3.0.4 → 3.0.6
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/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
- package/es/arrayUtils.d.ts +76 -1
- package/es/arrayUtils.js +103 -24
- package/es/common/stateHelper.d.ts +22 -0
- package/es/common/stateHelper.js +23 -0
- package/es/common/types.d.ts +31 -0
- package/es/componentStorage.d.ts +38 -0
- package/es/componentStorage.js +106 -0
- package/es/constants/index.js +7 -9
- package/es/date.d.ts +6 -3
- package/es/date.js +36 -53
- package/es/document.d.ts +6 -3
- package/es/document.js +43 -67
- package/es/escPosPrinter/EscPosPrinter.js +353 -490
- package/es/escPosPrinter/index.d.ts +9 -9
- package/es/escPosPrinter/index.js +37 -52
- package/es/format.d.ts +29 -0
- package/es/format.js +90 -112
- package/es/image.d.ts +13 -10
- package/es/image.js +48 -60
- package/es/index.d.ts +39 -18
- package/es/index.js +40 -29
- package/es/jsBridge/index.d.ts +14 -106
- package/es/jsBridge/index.js +57 -40
- package/es/jsBridge/regDeviceApi.js +87 -126
- package/es/jsBridge/types.d.ts +129 -0
- package/es/locales.d.ts +11 -11
- package/es/locales.js +79 -69
- package/es/log.d.ts +11 -6
- package/es/log.js +37 -59
- package/es/miniRedux.d.ts +20 -13
- package/es/miniRedux.js +42 -71
- package/es/number-input/hooks/useNumberInputState.d.ts +29 -0
- package/es/number-input/hooks/useNumberInputState.js +72 -0
- package/es/number-input/types.d.ts +96 -0
- package/es/number-input/utils/formatter.d.ts +56 -0
- package/es/number-input/utils/formatter.js +56 -0
- package/es/number-input/utils/validation.d.ts +32 -0
- package/es/number-input/utils/validation.js +52 -0
- package/es/otherUtils.d.ts +12 -9
- package/es/otherUtils.js +71 -120
- package/es/platform.d.ts +12 -9
- package/es/platform.js +61 -85
- package/es/select/hooks/useDebouncedSearch.d.ts +23 -0
- package/es/select/hooks/useDebouncedSearch.js +41 -0
- package/es/select/hooks/useSelectState.d.ts +19 -0
- package/es/select/hooks/useSelectState.js +60 -0
- package/es/select/index.d.ts +7 -0
- package/es/select/types.d.ts +256 -0
- package/es/select/utils/filterOptions.d.ts +23 -0
- package/es/select/utils/filterOptions.js +29 -0
- package/es/select/utils/helpers.d.ts +43 -0
- package/es/select/utils/helpers.js +51 -0
- package/es/select/utils/index.d.ts +4 -0
- package/es/select/utils/sortOptions.d.ts +13 -0
- package/es/select/utils/sortOptions.js +20 -0
- package/es/select/utils/tagAggregation.d.ts +25 -0
- package/es/select/utils/tagAggregation.js +35 -0
- package/es/text-input/hooks/useTextInputState.d.ts +28 -0
- package/es/text-input/hooks/useTextInputState.js +70 -0
- package/es/text-input/types.d.ts +56 -0
- package/es/text-input/utils/validation.d.ts +28 -0
- package/es/text-input/utils/validation.js +51 -0
- package/es/typeUtils.d.ts +11 -8
- package/es/typeUtils.js +61 -84
- package/es/walletValidity.d.ts +57 -0
- package/es/walletValidity.js +404 -460
- package/es/weighing.d.ts +65 -0
- package/es/weighing.js +96 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
- package/lib/_virtual/_rolldown/runtime.js +23 -0
- package/lib/arrayUtils.d.ts +76 -1
- package/lib/arrayUtils.js +102 -37
- package/lib/common/stateHelper.d.ts +22 -0
- package/lib/common/stateHelper.js +23 -0
- package/lib/common/types.d.ts +31 -0
- package/lib/componentStorage.d.ts +38 -0
- package/lib/componentStorage.js +114 -0
- package/lib/constants/index.js +7 -36
- package/lib/date.d.ts +6 -3
- package/lib/date.js +43 -65
- package/lib/document.d.ts +6 -3
- package/lib/document.js +46 -62
- package/lib/escPosPrinter/EscPosPrinter.js +327 -403
- package/lib/escPosPrinter/index.d.ts +9 -9
- package/lib/escPosPrinter/index.js +38 -84
- package/lib/format.d.ts +29 -0
- package/lib/format.js +91 -93
- package/lib/image.d.ts +13 -10
- package/lib/image.js +48 -74
- package/lib/index.d.ts +39 -18
- package/lib/index.js +137 -68
- package/lib/jsBridge/index.d.ts +14 -106
- package/lib/jsBridge/index.js +60 -60
- package/lib/jsBridge/regDeviceApi.js +86 -133
- package/lib/jsBridge/types.d.ts +129 -0
- package/lib/locales.d.ts +11 -11
- package/lib/locales.js +79 -63
- package/lib/log.d.ts +11 -6
- package/lib/log.js +37 -61
- package/lib/miniRedux.d.ts +20 -13
- package/lib/miniRedux.js +43 -91
- package/lib/number-input/hooks/useNumberInputState.d.ts +29 -0
- package/lib/number-input/hooks/useNumberInputState.js +73 -0
- package/lib/number-input/types.d.ts +96 -0
- package/lib/number-input/utils/formatter.d.ts +56 -0
- package/lib/number-input/utils/formatter.js +58 -0
- package/lib/number-input/utils/validation.d.ts +32 -0
- package/lib/number-input/utils/validation.js +52 -0
- package/lib/otherUtils.d.ts +12 -9
- package/lib/otherUtils.js +86 -91
- package/lib/platform.d.ts +12 -9
- package/lib/platform.js +68 -123
- package/lib/select/hooks/useDebouncedSearch.d.ts +23 -0
- package/lib/select/hooks/useDebouncedSearch.js +42 -0
- package/lib/select/hooks/useSelectState.d.ts +19 -0
- package/lib/select/hooks/useSelectState.js +62 -0
- package/lib/select/index.d.ts +7 -0
- package/lib/select/types.d.ts +256 -0
- package/lib/select/utils/filterOptions.d.ts +23 -0
- package/lib/select/utils/filterOptions.js +30 -0
- package/lib/select/utils/helpers.d.ts +43 -0
- package/lib/select/utils/helpers.js +55 -0
- package/lib/select/utils/index.d.ts +4 -0
- package/lib/select/utils/sortOptions.d.ts +13 -0
- package/lib/select/utils/sortOptions.js +20 -0
- package/lib/select/utils/tagAggregation.d.ts +25 -0
- package/lib/select/utils/tagAggregation.js +35 -0
- package/lib/text-input/hooks/useTextInputState.d.ts +28 -0
- package/lib/text-input/hooks/useTextInputState.js +71 -0
- package/lib/text-input/types.d.ts +56 -0
- package/lib/text-input/utils/validation.d.ts +28 -0
- package/lib/text-input/utils/validation.js +51 -0
- package/lib/typeUtils.d.ts +11 -8
- package/lib/typeUtils.js +68 -73
- package/lib/walletValidity.d.ts +57 -0
- package/lib/walletValidity.js +420 -323
- package/lib/weighing.d.ts +65 -0
- package/lib/weighing.js +114 -0
- package/package.json +1 -1
- package/es/constants/index.d.ts +0 -7
- package/es/firebase/config/index.d.ts +0 -13
- package/es/firebase/config/index.js +0 -54
- package/es/firebase/index.d.ts +0 -28
- package/es/firebase/index.js +0 -232
- package/lib/constants/index.d.ts +0 -7
- package/lib/firebase/config/index.d.ts +0 -13
- package/lib/firebase/config/index.js +0 -79
- package/lib/firebase/index.d.ts +0 -28
- package/lib/firebase/index.js +0 -180
package/es/index.js
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
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
|
-
|
|
1
|
+
import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
|
|
2
|
+
import { changeArray, createArray, detectIncognito, generateUniqueIdByObj, getItemByArray, getUniqueId } from "./otherUtils.js";
|
|
3
|
+
import { isArr, isBoolean, isFunction, isJson, isNumber, isPlainObject, isString, isUndefined } from "./typeUtils.js";
|
|
4
|
+
import { clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getRecordBoardColumnSettingFromLocal, getStorageKeySuffix, saveColumnSettingToLocal, saveColumnVisibilityToLocal } from "./componentStorage.js";
|
|
5
|
+
import { copyToClipboard, setTheme } from "./document.js";
|
|
6
|
+
import { excelDateToJSDate, formatDate, jsDateToExcelDate } from "./date.js";
|
|
7
|
+
import { checkEnv, isAndroid, isIOS, isIos, isIpad, isMobile, isSafari, isWx, isWxApp } from "./platform.js";
|
|
8
|
+
import { sendWarningLog } from "./log.js";
|
|
9
|
+
import { formatAmount, formatAmountWithOptions } from "./format.js";
|
|
10
|
+
import EscPosPrinter, { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, columnWidthWithAlignment } from "./escPosPrinter/EscPosPrinter.js";
|
|
11
|
+
import { preparing } from "./escPosPrinter/index.js";
|
|
12
|
+
import { miniRedux } from "./miniRedux.js";
|
|
13
|
+
import { dataManager, webPayment, webPrint } from "./jsBridge/index.js";
|
|
14
|
+
import { image } from "./image.js";
|
|
15
|
+
import { locales } from "./locales.js";
|
|
16
|
+
import { getByPath, groupBy, uniqueByKey } from "./arrayUtils.js";
|
|
17
|
+
import { getScheduleSummary, getWalletValidityRange } from "./walletValidity.js";
|
|
18
|
+
import { INVALID_SCALE_READING_STATUSES, MAX_RETAIL_SCALE_WEIGHT_KG, STANDARD_WEIGHT_UNIT, STANDARD_WEIGHT_UNIT_SYMBOL, UNIT_PRICE_PRECISION, WEIGHT_PRECISION, WEIGHT_UNIT_GRAMS, WEIGHT_UNIT_NAMES, WEIGHT_UNIT_SYMBOLS, formatUnitPriceValue, formatWeightValue, getUsableScaleWeight, getWeightUnitGrams, getWeightUnitPriceConversionFactor, getWeightUnitSymbol, isInvalidScaleReadingStatus, isSupportedWeightUnit, normalizeWeightUnit, resolveWeighingSnapshot } from "./weighing.js";
|
|
19
|
+
import { getDisplayState } from "./common/stateHelper.js";
|
|
20
|
+
import { validateValue as validateValue$1 } from "./text-input/utils/validation.js";
|
|
21
|
+
import { useTextInputState } from "./text-input/hooks/useTextInputState.js";
|
|
22
|
+
import { validateValue } from "./number-input/utils/validation.js";
|
|
23
|
+
import { useNumberInputState } from "./number-input/hooks/useNumberInputState.js";
|
|
24
|
+
import { addThousandsSeparator, formatNumber, formatPrecision } from "./number-input/utils/formatter.js";
|
|
25
|
+
import { useMultipleSelectState, useSelectState } from "./select/hooks/useSelectState.js";
|
|
26
|
+
import { useDebouncedSearch } from "./select/hooks/useDebouncedSearch.js";
|
|
27
|
+
import { calculateTagDisplay } from "./select/utils/tagAggregation.js";
|
|
28
|
+
import { defaultFilterOption, filterOptions } from "./select/utils/filterOptions.js";
|
|
29
|
+
import { sortOptions } from "./select/utils/sortOptions.js";
|
|
30
|
+
import { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple } from "./select/utils/helpers.js";
|
|
31
|
+
//#region src/index.ts
|
|
32
|
+
const setPisellUtilsConfig = (config) => {
|
|
33
|
+
globalThis.pisellUtilsConfig = _objectSpread2(_objectSpread2({}, globalThis.pisellUtilsConfig || {}), config || {});
|
|
34
|
+
console.log("PisellUtilsConfig_set>>>>", config, globalThis);
|
|
26
35
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
36
|
+
const getPisellUtilsConfig = () => {
|
|
37
|
+
console.log("PisellUtilsConfig_get>>>>", globalThis);
|
|
38
|
+
return globalThis.pisellUtilsConfig || {};
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, EscPosPrinter, INVALID_SCALE_READING_STATUSES, MAX_RETAIL_SCALE_WEIGHT_KG, STANDARD_WEIGHT_UNIT, STANDARD_WEIGHT_UNIT_SYMBOL, UNIT_PRICE_PRECISION, WEIGHT_PRECISION, WEIGHT_UNIT_GRAMS, WEIGHT_UNIT_NAMES, WEIGHT_UNIT_SYMBOLS, addThousandsSeparator, calculateTagDisplay, changeArray, checkEnv, clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, columnWidthWithAlignment, copyToClipboard, createArray, dataManager, defaultFilterOption, detectIncognito, excelDateToJSDate, filterOptions, findOptionByValue, findOptionsByValues, formatAmount, formatAmountWithOptions, formatDate, formatNumber, formatPrecision, formatUnitPriceValue, formatWeightValue, generateId, generateUniqueIdByObj, getByPath, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getDisplayState, getItemByArray, getPisellUtilsConfig, getRecordBoardColumnSettingFromLocal, getScheduleSummary, getStorageKeySuffix, getUniqueId, getUsableScaleWeight, getWalletValidityRange, getWeightUnitGrams, getWeightUnitPriceConversionFactor, getWeightUnitSymbol, groupBy, image, isAndroid, isArr, isBoolean, isFunction, isIOS, isInvalidScaleReadingStatus, isIos, isIpad, isJson, isMobile, isNumber, isOptionSelected, isOptionSelectedInMultiple, isPlainObject, isSafari, isString, isSupportedWeightUnit, isUndefined, isWx, isWxApp, jsDateToExcelDate, locales, miniRedux, normalizeWeightUnit, preparing, resolveWeighingSnapshot, saveColumnSettingToLocal, saveColumnVisibilityToLocal, sendWarningLog, setPisellUtilsConfig, setTheme, sortOptions, uniqueByKey, useDebouncedSearch, useMultipleSelectState, useNumberInputState, useSelectState, useTextInputState, validateValue as validateNumberValue, validateValue$1 as validateTextValue, webPayment, webPrint };
|
package/es/jsBridge/index.d.ts
CHANGED
|
@@ -1,118 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
zh_HK: number;
|
|
5
|
-
};
|
|
6
|
-
declare type LanguageString = {
|
|
7
|
-
en: string;
|
|
8
|
-
zh_CN: string;
|
|
9
|
-
zh_HK: string;
|
|
10
|
-
} | string;
|
|
11
|
-
/**
|
|
12
|
-
* 打印小票
|
|
13
|
-
*/
|
|
14
|
-
declare type WebPrint0 = {
|
|
15
|
-
/**
|
|
16
|
-
* 打印类型
|
|
17
|
-
* 0: 小票
|
|
18
|
-
* 1:ITS备货单/划菜单
|
|
19
|
-
* 2:手环
|
|
20
|
-
*/
|
|
21
|
-
type: "0";
|
|
22
|
-
data: {
|
|
23
|
-
/** 订单ID */
|
|
24
|
-
order_id: string;
|
|
25
|
-
};
|
|
26
|
-
/** 打印语言对应的数量 */
|
|
27
|
-
language: LanguageNumber;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* 打印ITS备货单/划菜单
|
|
31
|
-
*/
|
|
32
|
-
declare type WebPrint1 = {
|
|
33
|
-
/**
|
|
34
|
-
* 打印类型
|
|
35
|
-
* 0: 小票
|
|
36
|
-
* 1:ITS备货单/划菜单
|
|
37
|
-
* 2:手环
|
|
38
|
-
*/
|
|
39
|
-
type: "1";
|
|
40
|
-
data: {
|
|
41
|
-
/** 0:备货 1:划单 */
|
|
42
|
-
mode: "0" | "1";
|
|
43
|
-
resource: LanguageString;
|
|
44
|
-
/** 订单备注 */
|
|
45
|
-
order_note: string;
|
|
46
|
-
/** 订单时间或商品下单时间 */
|
|
47
|
-
time: string;
|
|
48
|
-
/** 订单编号 */
|
|
49
|
-
order_number?: string;
|
|
50
|
-
/** 商品 */
|
|
51
|
-
products: {
|
|
52
|
-
/** 商品名称 */
|
|
53
|
-
product_title: LanguageString;
|
|
54
|
-
/** 商品规格 */
|
|
55
|
-
product_option_string: LanguageString;
|
|
56
|
-
/** 商品备注 */
|
|
57
|
-
product_note: string;
|
|
58
|
-
/** 商品数量 */
|
|
59
|
-
product_quantity: number;
|
|
60
|
-
/** 加菜标识 待定 */
|
|
61
|
-
is_append?: boolean;
|
|
62
|
-
/** 退菜标识 待定 */
|
|
63
|
-
is_removed?: boolean;
|
|
64
|
-
}[];
|
|
65
|
-
};
|
|
66
|
-
/** 打印语言对应的数量 */
|
|
67
|
-
language: LanguageNumber;
|
|
68
|
-
};
|
|
69
|
-
declare type WebPrint2 = {
|
|
70
|
-
/**
|
|
71
|
-
* 打印类型
|
|
72
|
-
* 0: 小票
|
|
73
|
-
* 1:ITS备货单/划菜单
|
|
74
|
-
* 2:手环
|
|
75
|
-
*/
|
|
76
|
-
type: "2";
|
|
77
|
-
data: {
|
|
78
|
-
/** 0: 普通票 1:成人票 2:免费成人票 */
|
|
79
|
-
type: "0" | "1" | "2";
|
|
80
|
-
/** 发行编码 */
|
|
81
|
-
encoded: string;
|
|
82
|
-
/** 编码 */
|
|
83
|
-
code: string;
|
|
84
|
-
/** 到期时间 */
|
|
85
|
-
expire_date: string;
|
|
86
|
-
areas: {
|
|
87
|
-
/** 区域名字 */
|
|
88
|
-
area_name: string;
|
|
89
|
-
/** 区域代码 */
|
|
90
|
-
area_code: string;
|
|
91
|
-
/** 可用次数 */
|
|
92
|
-
limit_num: number;
|
|
93
|
-
/** 已用次数 */
|
|
94
|
-
used_num: number;
|
|
95
|
-
}[];
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2;
|
|
1
|
+
import { DataManagerParams, WebPaymentParams, WebPrintParams } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/jsBridge/index.d.ts
|
|
99
4
|
/**
|
|
100
5
|
* webView页面中调用打印机打印
|
|
101
6
|
* 此api暂时只支持native app平台下ios手机
|
|
102
7
|
* @param params
|
|
103
8
|
* @param callback
|
|
104
9
|
*/
|
|
105
|
-
|
|
106
|
-
declare type DataManagerParams = {
|
|
107
|
-
module: "set" | "get";
|
|
108
|
-
key: string;
|
|
109
|
-
data?: any;
|
|
110
|
-
};
|
|
10
|
+
declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
111
11
|
/**
|
|
112
12
|
* webView页面中调用APP内的数据
|
|
113
13
|
* 此api暂时只支持native app平台下ios手机
|
|
114
14
|
* @param params
|
|
115
15
|
* @param callback
|
|
116
16
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
17
|
+
declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
18
|
+
/**
|
|
19
|
+
* webView页面中调用APP内的支付
|
|
20
|
+
* 此api暂时只支持native app平台下ios
|
|
21
|
+
* @param params
|
|
22
|
+
* @param callback
|
|
23
|
+
*/
|
|
24
|
+
declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { dataManager, webPayment, webPrint };
|
package/es/jsBridge/index.js
CHANGED
|
@@ -1,44 +1,61 @@
|
|
|
1
|
-
import regDeviceApi from "./regDeviceApi";
|
|
2
|
-
|
|
1
|
+
import regDeviceApi from "./regDeviceApi.js";
|
|
2
|
+
//#region src/jsBridge/index.ts
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
* webView页面中调用打印机打印
|
|
5
|
+
* 此api暂时只支持native app平台下ios手机
|
|
6
|
+
* @param params
|
|
7
|
+
* @param callback
|
|
8
|
+
*/
|
|
9
|
+
function webPrint(params, callback, onError) {
|
|
10
|
+
regDeviceApi().then((jsBridge) => {
|
|
11
|
+
jsBridge.callDeviceApi({
|
|
12
|
+
apiName: "webPrint",
|
|
13
|
+
params,
|
|
14
|
+
callback: (...arg) => {
|
|
15
|
+
callback && callback(...arg);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}).catch((err) => {
|
|
19
|
+
onError === null || onError === void 0 || onError(err);
|
|
20
|
+
console.error("webPrint", err);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
11
23
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
* webView页面中调用APP内的数据
|
|
25
|
+
* 此api暂时只支持native app平台下ios手机
|
|
26
|
+
* @param params
|
|
27
|
+
* @param callback
|
|
28
|
+
*/
|
|
29
|
+
function dataManager(params, callback, onError) {
|
|
30
|
+
regDeviceApi().then((jsBridge) => {
|
|
31
|
+
jsBridge.callDeviceApi({
|
|
32
|
+
apiName: "dataManager",
|
|
33
|
+
params,
|
|
34
|
+
callback: (...arg) => {
|
|
35
|
+
callback && callback(...arg);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}).catch(onError);
|
|
27
39
|
}
|
|
28
40
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
* webView页面中调用APP内的支付
|
|
42
|
+
* 此api暂时只支持native app平台下ios
|
|
43
|
+
* @param params
|
|
44
|
+
* @param callback
|
|
45
|
+
*/
|
|
46
|
+
function webPayment(params, callback, onError) {
|
|
47
|
+
regDeviceApi().then((jsBridge) => {
|
|
48
|
+
jsBridge.callDeviceApi({
|
|
49
|
+
apiName: "webPayment",
|
|
50
|
+
params,
|
|
51
|
+
callback: (...arg) => {
|
|
52
|
+
callback && callback(...arg);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}).catch((err) => {
|
|
56
|
+
onError === null || onError === void 0 || onError(err);
|
|
57
|
+
console.error("webPayment", err);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { dataManager, webPayment, webPrint };
|
|
@@ -1,133 +1,94 @@
|
|
|
1
|
-
import { isAndroid, isIos } from "../platform";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { isAndroid, isIos } from "../platform.js";
|
|
2
|
+
//#region src/jsBridge/regDeviceApi.js
|
|
3
|
+
let androidRegStatus = false;
|
|
4
|
+
let iosRegStatus = false;
|
|
5
|
+
let androidBridge;
|
|
6
|
+
let iosBridge;
|
|
7
|
+
let composedBridge;
|
|
7
8
|
function regIosJsBridge(callback) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
if (window.WebViewJavascriptBridge) {
|
|
10
|
+
callback(window.WebViewJavascriptBridge);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (window.WVJBCallbacks) {
|
|
14
|
+
window.WVJBCallbacks.push(callback);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
window.WVJBCallbacks = [callback];
|
|
18
|
+
const WVJBIframe = document.createElement("iframe");
|
|
19
|
+
WVJBIframe.style.display = "none";
|
|
20
|
+
WVJBIframe.src = "https://__bridge_loaded__";
|
|
21
|
+
document.documentElement && document.documentElement.appendChild(WVJBIframe);
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
try {
|
|
24
|
+
document.documentElement && document.documentElement.removeChild(WVJBIframe);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.log(e);
|
|
27
|
+
}
|
|
28
|
+
}, 0);
|
|
28
29
|
}
|
|
29
30
|
function regAndroidJsBridge(extraInit) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
extraInit(bridge);
|
|
45
|
-
}, false);
|
|
31
|
+
if (window._jsBridge) {
|
|
32
|
+
extraInit(window._jsBridge);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
document.addEventListener("WebViewJavascriptBridgeReady", (event) => {
|
|
36
|
+
const { bridge } = event;
|
|
37
|
+
window._jsBridge = bridge;
|
|
38
|
+
if (!bridge) return;
|
|
39
|
+
bridge.init((message, responseCallback) => {
|
|
40
|
+
if (responseCallback) responseCallback("init responseCallback");
|
|
41
|
+
});
|
|
42
|
+
extraInit(bridge);
|
|
43
|
+
}, false);
|
|
46
44
|
}
|
|
47
|
-
|
|
48
45
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
* 通用jsBridge
|
|
47
|
+
* @param deviceType
|
|
48
|
+
*/
|
|
52
49
|
function getComposedBridge(deviceType) {
|
|
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
|
-
inCb.apply(void 0, [result].concat(args));
|
|
79
|
-
};
|
|
80
|
-
if (deviceType === 'iphone') {
|
|
81
|
-
iosBridge.callHandler(apiName, params, callback, function (e) {
|
|
82
|
-
console.log(e, '--- 调用ios api报错:', apiName);
|
|
83
|
-
if (onError) {
|
|
84
|
-
onError(e);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
} else if (deviceType === 'android') {
|
|
88
|
-
var res = androidBridge.callHandler(apiName, JSON.stringify(params));
|
|
89
|
-
callback(res);
|
|
90
|
-
} else {
|
|
91
|
-
console.log('--- 没获取到js bridge ---');
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
// 被设备调用的方法
|
|
95
|
-
calledByDevice: function calledByDevice(_ref2) {
|
|
96
|
-
var apiName = _ref2.apiName,
|
|
97
|
-
callback = _ref2.callback;
|
|
98
|
-
if (deviceType === 'iphone') {
|
|
99
|
-
iosBridge.registerHandler(apiName, callback);
|
|
100
|
-
} else if (deviceType === 'android') {
|
|
101
|
-
androidBridge.registerHandler(apiName, callback);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
return composedBridge;
|
|
50
|
+
if (composedBridge) return composedBridge;
|
|
51
|
+
composedBridge = {
|
|
52
|
+
callDeviceApi: ({ apiName, callback: inCb, params = {}, onError }) => {
|
|
53
|
+
const callback = (res, ...args) => {
|
|
54
|
+
let result = res;
|
|
55
|
+
try {
|
|
56
|
+
result = JSON.parse(res);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.log(`error ${apiName}`, error);
|
|
59
|
+
}
|
|
60
|
+
inCb(result, ...args);
|
|
61
|
+
};
|
|
62
|
+
if (deviceType === "iphone") iosBridge.callHandler(apiName, params, callback, (e) => {
|
|
63
|
+
console.log(e, "--- 调用ios api报错:", apiName);
|
|
64
|
+
if (onError) onError(e);
|
|
65
|
+
});
|
|
66
|
+
else if (deviceType === "android") callback(androidBridge.callHandler(apiName, JSON.stringify(params)));
|
|
67
|
+
else console.log("--- 没获取到js bridge ---");
|
|
68
|
+
},
|
|
69
|
+
calledByDevice: ({ apiName, callback }) => {
|
|
70
|
+
if (deviceType === "iphone") iosBridge.registerHandler(apiName, callback);
|
|
71
|
+
else if (deviceType === "android") androidBridge.registerHandler(apiName, callback);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return composedBridge;
|
|
106
75
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
} else if (isAndroid() && androidRegStatus) {
|
|
127
|
-
var _realBridge = getComposedBridge('android');
|
|
128
|
-
resolve(_realBridge);
|
|
129
|
-
} else {
|
|
130
|
-
reject();
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
76
|
+
function regDeviceApi() {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
if (isIos() && !iosRegStatus) regIosJsBridge((bridge) => {
|
|
79
|
+
iosRegStatus = true;
|
|
80
|
+
iosBridge = bridge;
|
|
81
|
+
resolve(getComposedBridge("iphone"));
|
|
82
|
+
});
|
|
83
|
+
else if (isIos() && iosRegStatus) resolve(getComposedBridge("iphone"));
|
|
84
|
+
else if (isAndroid() && !androidRegStatus) regAndroidJsBridge((bridge) => {
|
|
85
|
+
androidBridge = bridge;
|
|
86
|
+
androidRegStatus = true;
|
|
87
|
+
resolve(getComposedBridge("android"));
|
|
88
|
+
});
|
|
89
|
+
else if (isAndroid() && androidRegStatus) resolve(getComposedBridge("android"));
|
|
90
|
+
else reject();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { regDeviceApi as default };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//#region src/jsBridge/types.d.ts
|
|
2
|
+
type LanguageNumber = {
|
|
3
|
+
en: number;
|
|
4
|
+
zh_CN: number;
|
|
5
|
+
zh_HK: number;
|
|
6
|
+
};
|
|
7
|
+
type LanguageString = {
|
|
8
|
+
en: string;
|
|
9
|
+
zh_CN: string;
|
|
10
|
+
zh_HK: string;
|
|
11
|
+
} | string;
|
|
12
|
+
/**
|
|
13
|
+
* 打印小票
|
|
14
|
+
*/
|
|
15
|
+
type WebPrint0 = {
|
|
16
|
+
/**
|
|
17
|
+
* 打印类型
|
|
18
|
+
* 0: 小票
|
|
19
|
+
* 1:ITS备货单/划菜单
|
|
20
|
+
* 2:手环
|
|
21
|
+
*/
|
|
22
|
+
type: '0';
|
|
23
|
+
data: {
|
|
24
|
+
/** 订单ID */order_id: string;
|
|
25
|
+
}; /** 打印语言对应的数量 */
|
|
26
|
+
language: LanguageNumber;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 打印ITS备货单/划菜单
|
|
30
|
+
*/
|
|
31
|
+
type WebPrint1 = {
|
|
32
|
+
/**
|
|
33
|
+
* 打印类型
|
|
34
|
+
* 0: 小票
|
|
35
|
+
* 1:ITS备货单/划菜单
|
|
36
|
+
* 2:手环
|
|
37
|
+
*/
|
|
38
|
+
type: '1';
|
|
39
|
+
data: {
|
|
40
|
+
/** 0:备货 1:划单 */mode: '0' | '1';
|
|
41
|
+
resource: LanguageString; /** 订单备注 */
|
|
42
|
+
order_note: string; /** 订单时间或商品下单时间 */
|
|
43
|
+
time: string; /** 订单编号 */
|
|
44
|
+
order_number?: string; /** 商品 */
|
|
45
|
+
products: {
|
|
46
|
+
/** 商品名称 */product_title: LanguageString; /** 商品规格 */
|
|
47
|
+
product_option_string: LanguageString; /** 商品备注 */
|
|
48
|
+
product_note: string; /** 商品数量 */
|
|
49
|
+
product_quantity: number; /** 加菜标识 待定 */
|
|
50
|
+
is_append?: boolean; /** 退菜标识 待定 */
|
|
51
|
+
is_removed?: boolean;
|
|
52
|
+
}[];
|
|
53
|
+
}; /** 打印语言对应的数量 */
|
|
54
|
+
language: LanguageNumber;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 打印手环
|
|
58
|
+
*/
|
|
59
|
+
type WebPrint2 = {
|
|
60
|
+
/**
|
|
61
|
+
* 打印类型
|
|
62
|
+
* 0: 小票
|
|
63
|
+
* 1:ITS备货单/划菜单
|
|
64
|
+
* 2:手环
|
|
65
|
+
*/
|
|
66
|
+
type: '2';
|
|
67
|
+
data: {
|
|
68
|
+
/** 0: 普通票 1:成人票 2:免费成人票 */type: '0' | '1' | '2'; /** 发行编码 */
|
|
69
|
+
encoded: string; /** 编码 */
|
|
70
|
+
code: string; /** 到期时间 */
|
|
71
|
+
expire_date: string;
|
|
72
|
+
areas: {
|
|
73
|
+
/** 区域名字 */area_name: string; /** 区域代码 */
|
|
74
|
+
area_code: string; /** 可用次数 */
|
|
75
|
+
limit_num: number; /** 已用次数 */
|
|
76
|
+
used_num: number;
|
|
77
|
+
}[];
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* 打印充值卡
|
|
82
|
+
*/
|
|
83
|
+
type WebPrint4 = {
|
|
84
|
+
type: '4';
|
|
85
|
+
data: {
|
|
86
|
+
order_id: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* 打印订单中所有
|
|
91
|
+
*/
|
|
92
|
+
type WebPrint99 = {
|
|
93
|
+
type: '99';
|
|
94
|
+
data: {
|
|
95
|
+
order_id: string;
|
|
96
|
+
machine_code_print_info: {
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
}[];
|
|
99
|
+
small_ticket_data: {
|
|
100
|
+
[key: string]: any;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 打印
|
|
106
|
+
*/
|
|
107
|
+
type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2 | WebPrint4 | WebPrint99;
|
|
108
|
+
/**
|
|
109
|
+
* 数据管理
|
|
110
|
+
*/
|
|
111
|
+
type DataManagerParams = {
|
|
112
|
+
module: 'set' | 'get';
|
|
113
|
+
key: string;
|
|
114
|
+
data?: any;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* 支付
|
|
118
|
+
*/
|
|
119
|
+
type WebPaymentParams = {
|
|
120
|
+
module: 'payment' | 'refund' | string;
|
|
121
|
+
key: 'mx51' | string;
|
|
122
|
+
data?: {
|
|
123
|
+
order_id: string | number;
|
|
124
|
+
amount: string | number;
|
|
125
|
+
surcharge?: string | number;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { DataManagerParams, WebPaymentParams, WebPrintParams };
|