@pisell/utils 1.0.53 → 1.0.55
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/constants/index.d.ts +7 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/jsBridge/index.d.ts +22 -0
- package/es/jsBridge/types.d.ts +149 -0
- package/es/locales.d.ts +12 -0
- package/es/miniRedux.js +7 -2
- package/es/walletValidity.js +499 -0
- package/lib/constants/index.d.ts +7 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/jsBridge/index.d.ts +22 -0
- package/lib/jsBridge/types.d.ts +149 -0
- package/lib/locales.d.ts +12 -0
- package/lib/miniRedux.js +5 -7
- package/lib/walletValidity.js +349 -0
- package/package.json +1 -1
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./jsBridge";
|
|
|
17
17
|
export * from "./image";
|
|
18
18
|
export * from "./locales";
|
|
19
19
|
export * from "./arrayUtils";
|
|
20
|
+
export * from "./walletValidity";
|
|
20
21
|
// export { default as firebase } from './firebase';
|
|
21
22
|
|
|
22
23
|
export var setPisellUtilsConfig = function setPisellUtilsConfig(config) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WebPrintParams, DataManagerParams, WebPaymentParams } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* webView页面中调用打印机打印
|
|
4
|
+
* 此api暂时只支持native app平台下ios手机
|
|
5
|
+
* @param params
|
|
6
|
+
* @param callback
|
|
7
|
+
*/
|
|
8
|
+
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
9
|
+
/**
|
|
10
|
+
* webView页面中调用APP内的数据
|
|
11
|
+
* 此api暂时只支持native app平台下ios手机
|
|
12
|
+
* @param params
|
|
13
|
+
* @param callback
|
|
14
|
+
*/
|
|
15
|
+
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
16
|
+
/**
|
|
17
|
+
* webView页面中调用APP内的支付
|
|
18
|
+
* 此api暂时只支持native app平台下ios
|
|
19
|
+
* @param params
|
|
20
|
+
* @param callback
|
|
21
|
+
*/
|
|
22
|
+
export declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
declare type LanguageNumber = {
|
|
2
|
+
en: number;
|
|
3
|
+
zh_CN: number;
|
|
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
|
+
export 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
|
+
export 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
|
+
/**
|
|
70
|
+
* 打印手环
|
|
71
|
+
*/
|
|
72
|
+
export declare type WebPrint2 = {
|
|
73
|
+
/**
|
|
74
|
+
* 打印类型
|
|
75
|
+
* 0: 小票
|
|
76
|
+
* 1:ITS备货单/划菜单
|
|
77
|
+
* 2:手环
|
|
78
|
+
*/
|
|
79
|
+
type: '2';
|
|
80
|
+
data: {
|
|
81
|
+
/** 0: 普通票 1:成人票 2:免费成人票 */
|
|
82
|
+
type: '0' | '1' | '2';
|
|
83
|
+
/** 发行编码 */
|
|
84
|
+
encoded: string;
|
|
85
|
+
/** 编码 */
|
|
86
|
+
code: string;
|
|
87
|
+
/** 到期时间 */
|
|
88
|
+
expire_date: string;
|
|
89
|
+
areas: {
|
|
90
|
+
/** 区域名字 */
|
|
91
|
+
area_name: string;
|
|
92
|
+
/** 区域代码 */
|
|
93
|
+
area_code: string;
|
|
94
|
+
/** 可用次数 */
|
|
95
|
+
limit_num: number;
|
|
96
|
+
/** 已用次数 */
|
|
97
|
+
used_num: number;
|
|
98
|
+
}[];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* 打印充值卡
|
|
103
|
+
*/
|
|
104
|
+
export declare type WebPrint4 = {
|
|
105
|
+
type: '4';
|
|
106
|
+
data: {
|
|
107
|
+
order_id: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* 打印订单中所有
|
|
112
|
+
*/
|
|
113
|
+
export declare type WebPrint99 = {
|
|
114
|
+
type: '99';
|
|
115
|
+
data: {
|
|
116
|
+
order_id: string;
|
|
117
|
+
machine_code_print_info: {
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
}[];
|
|
120
|
+
small_ticket_data: {
|
|
121
|
+
[key: string]: any;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* 打印
|
|
127
|
+
*/
|
|
128
|
+
export declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2 | WebPrint4 | WebPrint99;
|
|
129
|
+
/**
|
|
130
|
+
* 数据管理
|
|
131
|
+
*/
|
|
132
|
+
export declare type DataManagerParams = {
|
|
133
|
+
module: 'set' | 'get';
|
|
134
|
+
key: string;
|
|
135
|
+
data?: any;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* 支付
|
|
139
|
+
*/
|
|
140
|
+
export declare type WebPaymentParams = {
|
|
141
|
+
module: 'payment' | 'refund' | string;
|
|
142
|
+
key: 'mx51' | string;
|
|
143
|
+
data?: {
|
|
144
|
+
order_id: string | number;
|
|
145
|
+
amount: string | number;
|
|
146
|
+
surcharge?: string | number;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
export {};
|
package/es/locales.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const locales: {
|
|
2
|
+
init: (_localeMaps: any, _locale: string) => void;
|
|
3
|
+
getText: (id: string) => any;
|
|
4
|
+
locale: string;
|
|
5
|
+
localeMap: any;
|
|
6
|
+
localeMaps: {
|
|
7
|
+
en: {};
|
|
8
|
+
'zh-CN': {};
|
|
9
|
+
'zh-HK': {};
|
|
10
|
+
};
|
|
11
|
+
formatLocale: (_locale: string) => string;
|
|
12
|
+
};
|
package/es/miniRedux.js
CHANGED
|
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import React, { createContext, useCallback, useReducer, forwardRef, useRef } from 'react';
|
|
13
|
+
import React, { createContext, useCallback, useMemo, useReducer, forwardRef, useRef } from 'react';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
export var miniRedux = function miniRedux(_ref2) {
|
|
16
16
|
var _ref2$namespace = _ref2.namespace,
|
|
@@ -49,6 +49,11 @@ export var miniRedux = function miniRedux(_ref2) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
}, []);
|
|
52
|
+
|
|
53
|
+
// 缓存Context value,避免不必要的重新渲染
|
|
54
|
+
var contextValue = useMemo(function () {
|
|
55
|
+
return _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch);
|
|
56
|
+
}, [providerState, _dispatch]);
|
|
52
57
|
var _props = _objectSpread(_objectSpread({}, props), {}, _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch));
|
|
53
58
|
var _ref = null;
|
|
54
59
|
if (_props.forwardedRef) {
|
|
@@ -56,7 +61,7 @@ export var miniRedux = function miniRedux(_ref2) {
|
|
|
56
61
|
delete _props.forwardedRef;
|
|
57
62
|
}
|
|
58
63
|
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
59
|
-
value:
|
|
64
|
+
value: contextValue,
|
|
60
65
|
children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
|
|
61
66
|
ref: ref
|
|
62
67
|
}))
|
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
// 文案配置类型定义
|
|
4
|
+
|
|
5
|
+
// 常量定义
|
|
6
|
+
var CONSTANTS = {
|
|
7
|
+
ALL_DAY_START: '00:00',
|
|
8
|
+
ALL_DAY_END: '23:59',
|
|
9
|
+
DEFAULT_FUTURE_YEARS: 10,
|
|
10
|
+
SECONDS_SUFFIX: ':59'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// 日程项接口定义
|
|
14
|
+
|
|
15
|
+
// 多语言文案配置
|
|
16
|
+
var textConfig = {
|
|
17
|
+
'zh-HK': {
|
|
18
|
+
weekdays: ['日', '一', '二', '三', '四', '五', '六'],
|
|
19
|
+
separator: '、',
|
|
20
|
+
timeSeparator: '–',
|
|
21
|
+
rangeSeparator: ' 至 ',
|
|
22
|
+
periodSeparator: ';',
|
|
23
|
+
timeSlotSeparator: ',',
|
|
24
|
+
every: '每',
|
|
25
|
+
day: '天',
|
|
26
|
+
week: '周',
|
|
27
|
+
month: '月',
|
|
28
|
+
year: '年',
|
|
29
|
+
available: '可用',
|
|
30
|
+
unlimited: '无限期',
|
|
31
|
+
multipleRules: '多規則,點詳情',
|
|
32
|
+
multipleSlots: ',多時段',
|
|
33
|
+
until: '至',
|
|
34
|
+
daily: '每天',
|
|
35
|
+
days: '天',
|
|
36
|
+
weeks: '周',
|
|
37
|
+
everyPrefix: '每',
|
|
38
|
+
weekPrefix: '周',
|
|
39
|
+
dateFormat: 'YYYY-MM-DD',
|
|
40
|
+
dateTimeFormat: 'YYYY-MM-DD HH:mm',
|
|
41
|
+
longTermValidFrom: '自',
|
|
42
|
+
noExpiry: '起長期有效',
|
|
43
|
+
on: ''
|
|
44
|
+
},
|
|
45
|
+
'zh-CN': {
|
|
46
|
+
weekdays: ['日', '一', '二', '三', '四', '五', '六'],
|
|
47
|
+
separator: '、',
|
|
48
|
+
timeSeparator: '–',
|
|
49
|
+
rangeSeparator: ' 至 ',
|
|
50
|
+
periodSeparator: ';',
|
|
51
|
+
timeSlotSeparator: ',',
|
|
52
|
+
every: '每',
|
|
53
|
+
day: '天',
|
|
54
|
+
week: '周',
|
|
55
|
+
month: '月',
|
|
56
|
+
year: '年',
|
|
57
|
+
available: '可用',
|
|
58
|
+
unlimited: '无限期',
|
|
59
|
+
multipleRules: '多规则,点详情',
|
|
60
|
+
multipleSlots: ',多时段',
|
|
61
|
+
until: '至',
|
|
62
|
+
daily: '每天',
|
|
63
|
+
days: '天',
|
|
64
|
+
weeks: '周',
|
|
65
|
+
everyPrefix: '每',
|
|
66
|
+
weekPrefix: '周',
|
|
67
|
+
dateFormat: 'YYYY-MM-DD',
|
|
68
|
+
dateTimeFormat: 'YYYY-MM-DD HH:mm',
|
|
69
|
+
longTermValidFrom: '自',
|
|
70
|
+
noExpiry: '起长期有效',
|
|
71
|
+
on: ''
|
|
72
|
+
},
|
|
73
|
+
'en': {
|
|
74
|
+
weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
75
|
+
separator: ', ',
|
|
76
|
+
timeSeparator: '–',
|
|
77
|
+
rangeSeparator: ' - ',
|
|
78
|
+
periodSeparator: '; ',
|
|
79
|
+
timeSlotSeparator: ', ',
|
|
80
|
+
every: 'every ',
|
|
81
|
+
day: 'day',
|
|
82
|
+
week: 'week',
|
|
83
|
+
month: 'month',
|
|
84
|
+
year: 'year',
|
|
85
|
+
available: 'available',
|
|
86
|
+
unlimited: 'unlimited',
|
|
87
|
+
multipleRules: 'Multiple rules, see details',
|
|
88
|
+
multipleSlots: ', multiple slots',
|
|
89
|
+
until: 'Until ',
|
|
90
|
+
daily: 'daily',
|
|
91
|
+
days: 'days',
|
|
92
|
+
weeks: 'weeks',
|
|
93
|
+
everyPrefix: 'every ',
|
|
94
|
+
weekPrefix: '',
|
|
95
|
+
dateFormat: 'DD MMM YYYY',
|
|
96
|
+
dateTimeFormat: 'DD MMM YYYY h:mm A',
|
|
97
|
+
longTermValidFrom: 'from ',
|
|
98
|
+
noExpiry: ', no expiry',
|
|
99
|
+
on: 'on '
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 获取星期几的表示
|
|
105
|
+
* @param dayNumbers 星期几的数字数组 (0-6, 0代表周日)
|
|
106
|
+
* @param locale 语言设置
|
|
107
|
+
* @param separator 分隔符,可选,默认使用locale配置的分隔符
|
|
108
|
+
* @returns 格式化的星期几文案
|
|
109
|
+
*/
|
|
110
|
+
function getWeekdayText(dayNumbers, locale, separator) {
|
|
111
|
+
var config = textConfig[locale];
|
|
112
|
+
return dayNumbers.map(function (day) {
|
|
113
|
+
return config.weekdays[day];
|
|
114
|
+
}).join(separator || config.separator);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 获取指定语言的文案配置
|
|
119
|
+
* @param locale 语言设置
|
|
120
|
+
* @param key 配置项key
|
|
121
|
+
* @returns 对应语言的文案
|
|
122
|
+
*/
|
|
123
|
+
function getText(locale, key) {
|
|
124
|
+
return textConfig[locale][key];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 获取指定语言的配置对象(缓存优化)
|
|
129
|
+
* @param locale 语言设置
|
|
130
|
+
* @returns 对应语言的完整配置对象
|
|
131
|
+
*/
|
|
132
|
+
function getConfig(locale) {
|
|
133
|
+
return textConfig[locale];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 获取每日频率文案
|
|
138
|
+
* @param frequency 频率数字
|
|
139
|
+
* @param locale 语言设置
|
|
140
|
+
* @returns 格式化的每日频率文案
|
|
141
|
+
*/
|
|
142
|
+
function getDailyFrequencyText(frequency, locale) {
|
|
143
|
+
if (frequency === 1) {
|
|
144
|
+
return getText(locale, 'daily');
|
|
145
|
+
}
|
|
146
|
+
var config = textConfig[locale];
|
|
147
|
+
if (locale === 'en') {
|
|
148
|
+
return "".concat(config.everyPrefix).concat(frequency, " ").concat(config.days);
|
|
149
|
+
} else {
|
|
150
|
+
return "".concat(config.everyPrefix).concat(frequency).concat(config.days);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 获取每周频率前缀文案
|
|
156
|
+
* @param frequency 频率数字
|
|
157
|
+
* @param locale 语言设置
|
|
158
|
+
* @returns 格式化的每周频率前缀文案
|
|
159
|
+
*/
|
|
160
|
+
function getWeeklyFrequencyPrefix(frequency, locale) {
|
|
161
|
+
if (frequency === 1) {
|
|
162
|
+
return '';
|
|
163
|
+
}
|
|
164
|
+
var config = textConfig[locale];
|
|
165
|
+
if (locale === 'en') {
|
|
166
|
+
return "".concat(config.everyPrefix).concat(frequency, " ").concat(config.weeks, ", ");
|
|
167
|
+
} else {
|
|
168
|
+
return "".concat(config.everyPrefix).concat(frequency).concat(config.weeks, " ");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 格式化日期时间函数
|
|
174
|
+
* @param dateTime 日期时间字符串
|
|
175
|
+
* @param isAll 是否为全天
|
|
176
|
+
* @param locale 语言设置
|
|
177
|
+
* @returns 格式化后的日期时间字符串
|
|
178
|
+
*/
|
|
179
|
+
function formatDateTime(dateTime) {
|
|
180
|
+
var isAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
181
|
+
var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'zh-CN';
|
|
182
|
+
var date = dayjs(dateTime);
|
|
183
|
+
var config = getConfig(locale);
|
|
184
|
+
if (isAll) {
|
|
185
|
+
// 全天情况下的日期格式
|
|
186
|
+
return date.format(config.dateFormat);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 非全天情况下的日期时间格式
|
|
190
|
+
return date.format(config.dateTimeFormat);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 判断是否为全天日程
|
|
195
|
+
* @param startTime 开始时间 (HH:mm格式)
|
|
196
|
+
* @param endTime 结束时间 (HH:mm格式)
|
|
197
|
+
* @returns 是否为全天日程
|
|
198
|
+
*/
|
|
199
|
+
function isAllDaySchedule(startTime, endTime) {
|
|
200
|
+
return startTime === CONSTANTS.ALL_DAY_START && endTime === CONSTANTS.ALL_DAY_END;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 生成日期范围文案
|
|
205
|
+
* @param startDate 开始日期
|
|
206
|
+
* @param endDate 结束日期
|
|
207
|
+
* @param isStarted 是否已开始
|
|
208
|
+
* @param locale 语言设置
|
|
209
|
+
* @param isAllDay 是否为全天
|
|
210
|
+
* @returns 格式化的日期范围文案
|
|
211
|
+
*/
|
|
212
|
+
function formatDateRange(startDate, endDate, isStarted, locale) {
|
|
213
|
+
var isAllDay = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
214
|
+
var config = getConfig(locale);
|
|
215
|
+
if (isStarted) {
|
|
216
|
+
var endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
217
|
+
return "".concat(config.until).concat(endDateStr);
|
|
218
|
+
} else {
|
|
219
|
+
var startDateStr = formatDateTime(startDate, isAllDay, locale);
|
|
220
|
+
var _endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
221
|
+
return "".concat(startDateStr).concat(config.rangeSeparator).concat(_endDateStr);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 获取schedule摘要信息
|
|
227
|
+
* @param scheduleList 日程列表
|
|
228
|
+
* @param locale 语言设置
|
|
229
|
+
* @returns 摘要文本
|
|
230
|
+
*/
|
|
231
|
+
export function getScheduleSummary(scheduleList) {
|
|
232
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'zh-CN';
|
|
233
|
+
try {
|
|
234
|
+
// 输入验证
|
|
235
|
+
if (!scheduleList || !Array.isArray(scheduleList)) {
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 如果是多个日程,直接返回多规则提示
|
|
240
|
+
if (scheduleList.length > 1) {
|
|
241
|
+
return getText(locale, 'multipleRules');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 如果没有日程,返回空字符串
|
|
245
|
+
if (scheduleList.length === 0) {
|
|
246
|
+
return '';
|
|
247
|
+
}
|
|
248
|
+
var schedule = scheduleList[0];
|
|
249
|
+
if (!schedule) {
|
|
250
|
+
return '';
|
|
251
|
+
}
|
|
252
|
+
var now = dayjs();
|
|
253
|
+
|
|
254
|
+
// 获取日程开始时间
|
|
255
|
+
var startTime = null;
|
|
256
|
+
if (schedule.start_time) {
|
|
257
|
+
startTime = dayjs(schedule.start_time);
|
|
258
|
+
} else if (schedule.designation && schedule.designation.length > 0) {
|
|
259
|
+
// designation类型,取第一个日期作为开始时间
|
|
260
|
+
var firstDesignation = schedule.designation[0];
|
|
261
|
+
if (firstDesignation && firstDesignation.start_date && firstDesignation.start_time) {
|
|
262
|
+
startTime = dayjs("".concat(firstDesignation.start_date, " ").concat(firstDesignation.start_time));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 判断开始时间是否在当前时间之后
|
|
267
|
+
var isStarted = startTime ? isTimeStarted(now, startTime) : false;
|
|
268
|
+
|
|
269
|
+
// 根据不同类型和状态返回摘要
|
|
270
|
+
return generateSummaryText(schedule, isStarted, locale);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.warn('Error in getScheduleSummary:', error);
|
|
273
|
+
return '';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 判断开始时间是否在当前时间之后
|
|
279
|
+
* @param now 当前时间
|
|
280
|
+
* @param startTime 开始时间
|
|
281
|
+
* @returns 是否已开始
|
|
282
|
+
*/
|
|
283
|
+
function isTimeStarted(now, startTime) {
|
|
284
|
+
return startTime.isBefore(now);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 生成摘要文本
|
|
289
|
+
* @param schedule 日程对象
|
|
290
|
+
* @param isStarted 是否已开始
|
|
291
|
+
* @param locale 语言设置
|
|
292
|
+
* @returns 生成的摘要文本
|
|
293
|
+
*/
|
|
294
|
+
function generateSummaryText(schedule, isStarted, locale) {
|
|
295
|
+
// 1. 多天多段 (designation类型且有多个日期段)
|
|
296
|
+
if (schedule.type === 'designation' && schedule.designation && schedule.designation.length > 1) {
|
|
297
|
+
return getText(locale, 'multipleRules');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 2. 单日多段 (time-slots类型)
|
|
301
|
+
if (schedule.type === 'time-slots') {
|
|
302
|
+
var endDate = getScheduleEndDate(schedule);
|
|
303
|
+
if (!endDate) return '';
|
|
304
|
+
var endDateStr = formatDateTime(endDate, true, locale);
|
|
305
|
+
var prefix = '';
|
|
306
|
+
var suffix = getText(locale, 'multipleSlots');
|
|
307
|
+
return "".concat(prefix).concat(endDateStr).concat(suffix);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// 3. 循环日程
|
|
311
|
+
if (schedule.repeat_type !== 'none' && schedule.repeat_rule) {
|
|
312
|
+
return generateRecurringSummary(schedule, isStarted, locale);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 4. 单个日程(包括designation类型的单个日期段)
|
|
316
|
+
return generateSingleScheduleSummary(schedule, isStarted, locale);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 生成循环日程摘要
|
|
321
|
+
* @param schedule 日程对象
|
|
322
|
+
* @param isStarted 是否已开始
|
|
323
|
+
* @param locale 语言设置
|
|
324
|
+
* @returns 循环日程摘要文本
|
|
325
|
+
*/
|
|
326
|
+
function generateRecurringSummary(schedule, isStarted, locale) {
|
|
327
|
+
var repeat_type = schedule.repeat_type,
|
|
328
|
+
repeat_rule = schedule.repeat_rule;
|
|
329
|
+
if (!repeat_rule) return '';
|
|
330
|
+
var frequency = repeat_rule.frequency,
|
|
331
|
+
frequency_date = repeat_rule.frequency_date,
|
|
332
|
+
end = repeat_rule.end;
|
|
333
|
+
|
|
334
|
+
// 特殊处理:当 end.type === 'never' 时的格式
|
|
335
|
+
if (end.type === 'never') {
|
|
336
|
+
return generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeat_type, frequency, frequency_date);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 原有逻辑:有结束时间的循环日程
|
|
340
|
+
var endDate = getScheduleEndDate(schedule);
|
|
341
|
+
if (!endDate) return '';
|
|
342
|
+
var endDateStr = formatDateTime(endDate, true, locale);
|
|
343
|
+
|
|
344
|
+
// 按天循环
|
|
345
|
+
if (repeat_type === 'daily') {
|
|
346
|
+
var frequencyText = getDailyFrequencyText(frequency, locale);
|
|
347
|
+
var dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
348
|
+
return "".concat(dateRange, "\uFF0C").concat(frequencyText);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 按周循环
|
|
352
|
+
if (repeat_type === 'weekly') {
|
|
353
|
+
var weekdaysText = getWeekdayText(frequency_date, locale, '/');
|
|
354
|
+
var frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
355
|
+
var config = getConfig(locale);
|
|
356
|
+
var _dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
357
|
+
return "".concat(_dateRange, "\uFF0C").concat(frequencyPrefix).concat(config.weekPrefix).concat(weekdaysText);
|
|
358
|
+
}
|
|
359
|
+
return '';
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* 生成永不结束的循环日程摘要
|
|
364
|
+
* @param schedule 日程对象
|
|
365
|
+
* @param isStarted 是否已开始
|
|
366
|
+
* @param locale 语言设置
|
|
367
|
+
* @param repeatType 循环类型
|
|
368
|
+
* @param frequency 频率
|
|
369
|
+
* @param frequencyDate 频率日期数组(用于周循环)
|
|
370
|
+
* @returns 永不结束的循环日程摘要文本
|
|
371
|
+
*/
|
|
372
|
+
function generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeatType, frequency, frequencyDate) {
|
|
373
|
+
var config = getConfig(locale);
|
|
374
|
+
|
|
375
|
+
// 按天循环
|
|
376
|
+
if (repeatType === 'daily') {
|
|
377
|
+
if (frequency === 1) {
|
|
378
|
+
// 频率=1:中文"自 YYYY-MM-DD 起长期有效",英文"Valid from DD MMM YYYY, no expiry"
|
|
379
|
+
if (schedule.start_time) {
|
|
380
|
+
var startDateStr = formatDateTime(schedule.start_time, true, locale);
|
|
381
|
+
return "".concat(config.longTermValidFrom).concat(startDateStr).concat(config.noExpiry);
|
|
382
|
+
}
|
|
383
|
+
return '';
|
|
384
|
+
} else {
|
|
385
|
+
// 频率>1:中文"每2天可用",英文"Every 2 days"
|
|
386
|
+
var frequencyText = getDailyFrequencyText(frequency, locale);
|
|
387
|
+
if (locale === 'en') {
|
|
388
|
+
return "".concat(frequencyText);
|
|
389
|
+
} else {
|
|
390
|
+
return "".concat(frequencyText).concat(config.available);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// 按周循环
|
|
396
|
+
if (repeatType === 'weekly') {
|
|
397
|
+
var weekdaysText = getWeekdayText(frequencyDate, locale, locale === 'en' ? ' & ' : '/');
|
|
398
|
+
if (frequency === 1) {
|
|
399
|
+
// 频率=1:中文"每周三/五可用",英文"on Wed & Fri"
|
|
400
|
+
if (locale === 'en') {
|
|
401
|
+
return "".concat(config.on).concat(weekdaysText);
|
|
402
|
+
} else {
|
|
403
|
+
return "".concat(config.everyPrefix).concat(config.weekPrefix).concat(weekdaysText).concat(config.available);
|
|
404
|
+
}
|
|
405
|
+
} else {
|
|
406
|
+
// 频率>1:中文"每2周 周三/五",英文"Every 2 weeks, on Wed & Fri"
|
|
407
|
+
var frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
408
|
+
if (locale === 'en') {
|
|
409
|
+
return "".concat(frequencyPrefix).concat(config.on).concat(weekdaysText);
|
|
410
|
+
} else {
|
|
411
|
+
return "".concat(frequencyPrefix).concat(config.weekPrefix).concat(weekdaysText);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return '';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* 生成单个日程摘要
|
|
420
|
+
* @param schedule 日程对象
|
|
421
|
+
* @param isStarted 是否已开始
|
|
422
|
+
* @param locale 语言设置
|
|
423
|
+
* @returns 单个日程摘要文本
|
|
424
|
+
*/
|
|
425
|
+
function generateSingleScheduleSummary(schedule, isStarted, locale) {
|
|
426
|
+
var isAllDay = schedule.is_all === 1;
|
|
427
|
+
|
|
428
|
+
// 处理designation类型的单个日期段
|
|
429
|
+
if (schedule.type === 'designation' && schedule.designation && schedule.designation.length === 1) {
|
|
430
|
+
var designation = schedule.designation[0];
|
|
431
|
+
var startDate = designation.start_date;
|
|
432
|
+
var endDate = designation.end_date;
|
|
433
|
+
var startTime = designation.start_time;
|
|
434
|
+
var endTime = designation.end_time;
|
|
435
|
+
|
|
436
|
+
// 判断是否为全天
|
|
437
|
+
var isDesignationAllDay = isAllDaySchedule(startTime, endTime);
|
|
438
|
+
if (isDesignationAllDay || isAllDay) {
|
|
439
|
+
// 全天日程
|
|
440
|
+
return formatDateRange(startDate, endDate, isStarted, locale, true);
|
|
441
|
+
} else {
|
|
442
|
+
// 非全天日程
|
|
443
|
+
var startDateTime = "".concat(startDate, " ").concat(startTime).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
444
|
+
var endDateTime = "".concat(endDate, " ").concat(endTime).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
445
|
+
return formatDateRange(startDateTime, endDateTime, isStarted, locale, false);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// 标准日程处理
|
|
450
|
+
if (isAllDay) {
|
|
451
|
+
// 全天日程
|
|
452
|
+
var _endDate = getScheduleEndDate(schedule);
|
|
453
|
+
if (!_endDate) return '';
|
|
454
|
+
return formatDateRange(schedule.start_time, _endDate, isStarted, locale, true);
|
|
455
|
+
} else {
|
|
456
|
+
// 非全天日程
|
|
457
|
+
return formatDateRange(schedule.start_time, schedule.end_time, isStarted, locale, false);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 获取日程结束日期
|
|
463
|
+
* @param schedule 日程对象
|
|
464
|
+
* @returns 结束日期字符串,如果无法确定则返回null
|
|
465
|
+
*/
|
|
466
|
+
function getScheduleEndDate(schedule) {
|
|
467
|
+
try {
|
|
468
|
+
// 循环日程
|
|
469
|
+
if (schedule.repeat_rule) {
|
|
470
|
+
if (schedule.repeat_rule.end.type === 'never') {
|
|
471
|
+
// 无限期的情况,返回一个合理的未来日期作为显示
|
|
472
|
+
var futureDate = dayjs().add(CONSTANTS.DEFAULT_FUTURE_YEARS, 'year');
|
|
473
|
+
return "".concat(futureDate.format('YYYY-MM-DD'), " ").concat(CONSTANTS.ALL_DAY_END).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
474
|
+
} else if (schedule.repeat_rule.end.end_date) {
|
|
475
|
+
return "".concat(schedule.repeat_rule.end.end_date, " ").concat(CONSTANTS.ALL_DAY_END).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// designation类型
|
|
480
|
+
if (schedule.designation && schedule.designation.length > 0) {
|
|
481
|
+
var lastDesignation = schedule.designation[schedule.designation.length - 1];
|
|
482
|
+
return "".concat(lastDesignation.end_date, " ").concat(lastDesignation.end_time).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// 标准日程
|
|
486
|
+
if (schedule.end_time) {
|
|
487
|
+
return schedule.end_time;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// time-slots类型
|
|
491
|
+
if (schedule.start_time) {
|
|
492
|
+
return schedule.start_time;
|
|
493
|
+
}
|
|
494
|
+
return null;
|
|
495
|
+
} catch (error) {
|
|
496
|
+
console.warn('Error in getScheduleEndDate:', error);
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __reExport(src_exports, require("./jsBridge"), module.exports);
|
|
|
37
37
|
__reExport(src_exports, require("./image"), module.exports);
|
|
38
38
|
__reExport(src_exports, require("./locales"), module.exports);
|
|
39
39
|
__reExport(src_exports, require("./arrayUtils"), module.exports);
|
|
40
|
+
__reExport(src_exports, require("./walletValidity"), module.exports);
|
|
40
41
|
var setPisellUtilsConfig = (config) => {
|
|
41
42
|
globalThis.pisellUtilsConfig = {
|
|
42
43
|
...globalThis.pisellUtilsConfig || {},
|
|
@@ -64,5 +65,6 @@ var getPisellUtilsConfig = () => {
|
|
|
64
65
|
...require("./jsBridge"),
|
|
65
66
|
...require("./image"),
|
|
66
67
|
...require("./locales"),
|
|
67
|
-
...require("./arrayUtils")
|
|
68
|
+
...require("./arrayUtils"),
|
|
69
|
+
...require("./walletValidity")
|
|
68
70
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WebPrintParams, DataManagerParams, WebPaymentParams } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* webView页面中调用打印机打印
|
|
4
|
+
* 此api暂时只支持native app平台下ios手机
|
|
5
|
+
* @param params
|
|
6
|
+
* @param callback
|
|
7
|
+
*/
|
|
8
|
+
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
9
|
+
/**
|
|
10
|
+
* webView页面中调用APP内的数据
|
|
11
|
+
* 此api暂时只支持native app平台下ios手机
|
|
12
|
+
* @param params
|
|
13
|
+
* @param callback
|
|
14
|
+
*/
|
|
15
|
+
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
16
|
+
/**
|
|
17
|
+
* webView页面中调用APP内的支付
|
|
18
|
+
* 此api暂时只支持native app平台下ios
|
|
19
|
+
* @param params
|
|
20
|
+
* @param callback
|
|
21
|
+
*/
|
|
22
|
+
export declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
declare type LanguageNumber = {
|
|
2
|
+
en: number;
|
|
3
|
+
zh_CN: number;
|
|
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
|
+
export 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
|
+
export 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
|
+
/**
|
|
70
|
+
* 打印手环
|
|
71
|
+
*/
|
|
72
|
+
export declare type WebPrint2 = {
|
|
73
|
+
/**
|
|
74
|
+
* 打印类型
|
|
75
|
+
* 0: 小票
|
|
76
|
+
* 1:ITS备货单/划菜单
|
|
77
|
+
* 2:手环
|
|
78
|
+
*/
|
|
79
|
+
type: '2';
|
|
80
|
+
data: {
|
|
81
|
+
/** 0: 普通票 1:成人票 2:免费成人票 */
|
|
82
|
+
type: '0' | '1' | '2';
|
|
83
|
+
/** 发行编码 */
|
|
84
|
+
encoded: string;
|
|
85
|
+
/** 编码 */
|
|
86
|
+
code: string;
|
|
87
|
+
/** 到期时间 */
|
|
88
|
+
expire_date: string;
|
|
89
|
+
areas: {
|
|
90
|
+
/** 区域名字 */
|
|
91
|
+
area_name: string;
|
|
92
|
+
/** 区域代码 */
|
|
93
|
+
area_code: string;
|
|
94
|
+
/** 可用次数 */
|
|
95
|
+
limit_num: number;
|
|
96
|
+
/** 已用次数 */
|
|
97
|
+
used_num: number;
|
|
98
|
+
}[];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* 打印充值卡
|
|
103
|
+
*/
|
|
104
|
+
export declare type WebPrint4 = {
|
|
105
|
+
type: '4';
|
|
106
|
+
data: {
|
|
107
|
+
order_id: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* 打印订单中所有
|
|
112
|
+
*/
|
|
113
|
+
export declare type WebPrint99 = {
|
|
114
|
+
type: '99';
|
|
115
|
+
data: {
|
|
116
|
+
order_id: string;
|
|
117
|
+
machine_code_print_info: {
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
}[];
|
|
120
|
+
small_ticket_data: {
|
|
121
|
+
[key: string]: any;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* 打印
|
|
127
|
+
*/
|
|
128
|
+
export declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2 | WebPrint4 | WebPrint99;
|
|
129
|
+
/**
|
|
130
|
+
* 数据管理
|
|
131
|
+
*/
|
|
132
|
+
export declare type DataManagerParams = {
|
|
133
|
+
module: 'set' | 'get';
|
|
134
|
+
key: string;
|
|
135
|
+
data?: any;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* 支付
|
|
139
|
+
*/
|
|
140
|
+
export declare type WebPaymentParams = {
|
|
141
|
+
module: 'payment' | 'refund' | string;
|
|
142
|
+
key: 'mx51' | string;
|
|
143
|
+
data?: {
|
|
144
|
+
order_id: string | number;
|
|
145
|
+
amount: string | number;
|
|
146
|
+
surcharge?: string | number;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
export {};
|
package/lib/locales.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const locales: {
|
|
2
|
+
init: (_localeMaps: any, _locale: string) => void;
|
|
3
|
+
getText: (id: string) => any;
|
|
4
|
+
locale: string;
|
|
5
|
+
localeMap: any;
|
|
6
|
+
localeMaps: {
|
|
7
|
+
en: {};
|
|
8
|
+
'zh-CN': {};
|
|
9
|
+
'zh-HK': {};
|
|
10
|
+
};
|
|
11
|
+
formatLocale: (_locale: string) => string;
|
|
12
|
+
};
|
package/lib/miniRedux.js
CHANGED
|
@@ -61,6 +61,10 @@ var miniRedux = ({
|
|
|
61
61
|
dispatch({ type, payload });
|
|
62
62
|
}
|
|
63
63
|
}, []);
|
|
64
|
+
const contextValue = (0, import_react.useMemo)(() => ({
|
|
65
|
+
[namespace]: providerState,
|
|
66
|
+
dispatch: _dispatch
|
|
67
|
+
}), [providerState, _dispatch]);
|
|
64
68
|
let _props = {
|
|
65
69
|
...props,
|
|
66
70
|
[namespace]: providerState,
|
|
@@ -71,13 +75,7 @@ var miniRedux = ({
|
|
|
71
75
|
_ref = _props.forwardedRef;
|
|
72
76
|
delete _props.forwardedRef;
|
|
73
77
|
}
|
|
74
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
75
|
-
Context.Provider,
|
|
76
|
-
{
|
|
77
|
-
value: { [namespace]: providerState, dispatch: _dispatch }
|
|
78
|
-
},
|
|
79
|
-
/* @__PURE__ */ import_react.default.createElement(ComponentUi, { ..._props, ref })
|
|
80
|
-
);
|
|
78
|
+
return /* @__PURE__ */ import_react.default.createElement(Context.Provider, { value: contextValue }, /* @__PURE__ */ import_react.default.createElement(ComponentUi, { ..._props, ref }));
|
|
81
79
|
});
|
|
82
80
|
return Components;
|
|
83
81
|
};
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/walletValidity.ts
|
|
30
|
+
var walletValidity_exports = {};
|
|
31
|
+
__export(walletValidity_exports, {
|
|
32
|
+
getScheduleSummary: () => getScheduleSummary
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(walletValidity_exports);
|
|
35
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
36
|
+
var CONSTANTS = {
|
|
37
|
+
ALL_DAY_START: "00:00",
|
|
38
|
+
ALL_DAY_END: "23:59",
|
|
39
|
+
DEFAULT_FUTURE_YEARS: 10,
|
|
40
|
+
SECONDS_SUFFIX: ":59"
|
|
41
|
+
};
|
|
42
|
+
var textConfig = {
|
|
43
|
+
"zh-HK": {
|
|
44
|
+
weekdays: ["日", "一", "二", "三", "四", "五", "六"],
|
|
45
|
+
separator: "、",
|
|
46
|
+
timeSeparator: "–",
|
|
47
|
+
rangeSeparator: " 至 ",
|
|
48
|
+
periodSeparator: ";",
|
|
49
|
+
timeSlotSeparator: ",",
|
|
50
|
+
every: "每",
|
|
51
|
+
day: "天",
|
|
52
|
+
week: "周",
|
|
53
|
+
month: "月",
|
|
54
|
+
year: "年",
|
|
55
|
+
available: "可用",
|
|
56
|
+
unlimited: "无限期",
|
|
57
|
+
multipleRules: "多規則,點詳情",
|
|
58
|
+
multipleSlots: ",多時段",
|
|
59
|
+
until: "至",
|
|
60
|
+
daily: "每天",
|
|
61
|
+
days: "天",
|
|
62
|
+
weeks: "周",
|
|
63
|
+
everyPrefix: "每",
|
|
64
|
+
weekPrefix: "周",
|
|
65
|
+
dateFormat: "YYYY-MM-DD",
|
|
66
|
+
dateTimeFormat: "YYYY-MM-DD HH:mm",
|
|
67
|
+
longTermValidFrom: "自",
|
|
68
|
+
noExpiry: "起長期有效",
|
|
69
|
+
on: ""
|
|
70
|
+
},
|
|
71
|
+
"zh-CN": {
|
|
72
|
+
weekdays: ["日", "一", "二", "三", "四", "五", "六"],
|
|
73
|
+
separator: "、",
|
|
74
|
+
timeSeparator: "–",
|
|
75
|
+
rangeSeparator: " 至 ",
|
|
76
|
+
periodSeparator: ";",
|
|
77
|
+
timeSlotSeparator: ",",
|
|
78
|
+
every: "每",
|
|
79
|
+
day: "天",
|
|
80
|
+
week: "周",
|
|
81
|
+
month: "月",
|
|
82
|
+
year: "年",
|
|
83
|
+
available: "可用",
|
|
84
|
+
unlimited: "无限期",
|
|
85
|
+
multipleRules: "多规则,点详情",
|
|
86
|
+
multipleSlots: ",多时段",
|
|
87
|
+
until: "至",
|
|
88
|
+
daily: "每天",
|
|
89
|
+
days: "天",
|
|
90
|
+
weeks: "周",
|
|
91
|
+
everyPrefix: "每",
|
|
92
|
+
weekPrefix: "周",
|
|
93
|
+
dateFormat: "YYYY-MM-DD",
|
|
94
|
+
dateTimeFormat: "YYYY-MM-DD HH:mm",
|
|
95
|
+
longTermValidFrom: "自",
|
|
96
|
+
noExpiry: "起长期有效",
|
|
97
|
+
on: ""
|
|
98
|
+
},
|
|
99
|
+
"en": {
|
|
100
|
+
weekdays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
101
|
+
separator: ", ",
|
|
102
|
+
timeSeparator: "–",
|
|
103
|
+
rangeSeparator: " - ",
|
|
104
|
+
periodSeparator: "; ",
|
|
105
|
+
timeSlotSeparator: ", ",
|
|
106
|
+
every: "every ",
|
|
107
|
+
day: "day",
|
|
108
|
+
week: "week",
|
|
109
|
+
month: "month",
|
|
110
|
+
year: "year",
|
|
111
|
+
available: "available",
|
|
112
|
+
unlimited: "unlimited",
|
|
113
|
+
multipleRules: "Multiple rules, see details",
|
|
114
|
+
multipleSlots: ", multiple slots",
|
|
115
|
+
until: "Until ",
|
|
116
|
+
daily: "daily",
|
|
117
|
+
days: "days",
|
|
118
|
+
weeks: "weeks",
|
|
119
|
+
everyPrefix: "every ",
|
|
120
|
+
weekPrefix: "",
|
|
121
|
+
dateFormat: "DD MMM YYYY",
|
|
122
|
+
dateTimeFormat: "DD MMM YYYY h:mm A",
|
|
123
|
+
longTermValidFrom: "from ",
|
|
124
|
+
noExpiry: ", no expiry",
|
|
125
|
+
on: "on "
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function getWeekdayText(dayNumbers, locale, separator) {
|
|
129
|
+
const config = textConfig[locale];
|
|
130
|
+
return dayNumbers.map((day) => config.weekdays[day]).join(separator || config.separator);
|
|
131
|
+
}
|
|
132
|
+
function getText(locale, key) {
|
|
133
|
+
return textConfig[locale][key];
|
|
134
|
+
}
|
|
135
|
+
function getConfig(locale) {
|
|
136
|
+
return textConfig[locale];
|
|
137
|
+
}
|
|
138
|
+
function getDailyFrequencyText(frequency, locale) {
|
|
139
|
+
if (frequency === 1) {
|
|
140
|
+
return getText(locale, "daily");
|
|
141
|
+
}
|
|
142
|
+
const config = textConfig[locale];
|
|
143
|
+
if (locale === "en") {
|
|
144
|
+
return `${config.everyPrefix}${frequency} ${config.days}`;
|
|
145
|
+
} else {
|
|
146
|
+
return `${config.everyPrefix}${frequency}${config.days}`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function getWeeklyFrequencyPrefix(frequency, locale) {
|
|
150
|
+
if (frequency === 1) {
|
|
151
|
+
return "";
|
|
152
|
+
}
|
|
153
|
+
const config = textConfig[locale];
|
|
154
|
+
if (locale === "en") {
|
|
155
|
+
return `${config.everyPrefix}${frequency} ${config.weeks}, `;
|
|
156
|
+
} else {
|
|
157
|
+
return `${config.everyPrefix}${frequency}${config.weeks} `;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function formatDateTime(dateTime, isAll = false, locale = "zh-CN") {
|
|
161
|
+
const date = (0, import_dayjs.default)(dateTime);
|
|
162
|
+
const config = getConfig(locale);
|
|
163
|
+
if (isAll) {
|
|
164
|
+
return date.format(config.dateFormat);
|
|
165
|
+
}
|
|
166
|
+
return date.format(config.dateTimeFormat);
|
|
167
|
+
}
|
|
168
|
+
function isAllDaySchedule(startTime, endTime) {
|
|
169
|
+
return startTime === CONSTANTS.ALL_DAY_START && endTime === CONSTANTS.ALL_DAY_END;
|
|
170
|
+
}
|
|
171
|
+
function formatDateRange(startDate, endDate, isStarted, locale, isAllDay = false) {
|
|
172
|
+
const config = getConfig(locale);
|
|
173
|
+
if (isStarted) {
|
|
174
|
+
const endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
175
|
+
return `${config.until}${endDateStr}`;
|
|
176
|
+
} else {
|
|
177
|
+
const startDateStr = formatDateTime(startDate, isAllDay, locale);
|
|
178
|
+
const endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
179
|
+
return `${startDateStr}${config.rangeSeparator}${endDateStr}`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function getScheduleSummary(scheduleList, locale = "zh-CN") {
|
|
183
|
+
try {
|
|
184
|
+
if (!scheduleList || !Array.isArray(scheduleList)) {
|
|
185
|
+
return "";
|
|
186
|
+
}
|
|
187
|
+
if (scheduleList.length > 1) {
|
|
188
|
+
return getText(locale, "multipleRules");
|
|
189
|
+
}
|
|
190
|
+
if (scheduleList.length === 0) {
|
|
191
|
+
return "";
|
|
192
|
+
}
|
|
193
|
+
const schedule = scheduleList[0];
|
|
194
|
+
if (!schedule) {
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
const now = (0, import_dayjs.default)();
|
|
198
|
+
let startTime = null;
|
|
199
|
+
if (schedule.start_time) {
|
|
200
|
+
startTime = (0, import_dayjs.default)(schedule.start_time);
|
|
201
|
+
} else if (schedule.designation && schedule.designation.length > 0) {
|
|
202
|
+
const firstDesignation = schedule.designation[0];
|
|
203
|
+
if (firstDesignation && firstDesignation.start_date && firstDesignation.start_time) {
|
|
204
|
+
startTime = (0, import_dayjs.default)(`${firstDesignation.start_date} ${firstDesignation.start_time}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const isStarted = startTime ? isTimeStarted(now, startTime) : false;
|
|
208
|
+
return generateSummaryText(schedule, isStarted, locale);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.warn("Error in getScheduleSummary:", error);
|
|
211
|
+
return "";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function isTimeStarted(now, startTime) {
|
|
215
|
+
return startTime.isBefore(now);
|
|
216
|
+
}
|
|
217
|
+
function generateSummaryText(schedule, isStarted, locale) {
|
|
218
|
+
if (schedule.type === "designation" && schedule.designation && schedule.designation.length > 1) {
|
|
219
|
+
return getText(locale, "multipleRules");
|
|
220
|
+
}
|
|
221
|
+
if (schedule.type === "time-slots") {
|
|
222
|
+
const endDate = getScheduleEndDate(schedule);
|
|
223
|
+
if (!endDate) return "";
|
|
224
|
+
const endDateStr = formatDateTime(endDate, true, locale);
|
|
225
|
+
const prefix = "";
|
|
226
|
+
const suffix = getText(locale, "multipleSlots");
|
|
227
|
+
return `${prefix}${endDateStr}${suffix}`;
|
|
228
|
+
}
|
|
229
|
+
if (schedule.repeat_type !== "none" && schedule.repeat_rule) {
|
|
230
|
+
return generateRecurringSummary(schedule, isStarted, locale);
|
|
231
|
+
}
|
|
232
|
+
return generateSingleScheduleSummary(schedule, isStarted, locale);
|
|
233
|
+
}
|
|
234
|
+
function generateRecurringSummary(schedule, isStarted, locale) {
|
|
235
|
+
const { repeat_type, repeat_rule } = schedule;
|
|
236
|
+
if (!repeat_rule) return "";
|
|
237
|
+
const { frequency, frequency_date, end } = repeat_rule;
|
|
238
|
+
if (end.type === "never") {
|
|
239
|
+
return generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeat_type, frequency, frequency_date);
|
|
240
|
+
}
|
|
241
|
+
const endDate = getScheduleEndDate(schedule);
|
|
242
|
+
if (!endDate) return "";
|
|
243
|
+
const endDateStr = formatDateTime(endDate, true, locale);
|
|
244
|
+
if (repeat_type === "daily") {
|
|
245
|
+
const frequencyText = getDailyFrequencyText(frequency, locale);
|
|
246
|
+
const dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
247
|
+
return `${dateRange},${frequencyText}`;
|
|
248
|
+
}
|
|
249
|
+
if (repeat_type === "weekly") {
|
|
250
|
+
const weekdaysText = getWeekdayText(frequency_date, locale, "/");
|
|
251
|
+
const frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
252
|
+
const config = getConfig(locale);
|
|
253
|
+
const dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
254
|
+
return `${dateRange},${frequencyPrefix}${config.weekPrefix}${weekdaysText}`;
|
|
255
|
+
}
|
|
256
|
+
return "";
|
|
257
|
+
}
|
|
258
|
+
function generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeatType, frequency, frequencyDate) {
|
|
259
|
+
const config = getConfig(locale);
|
|
260
|
+
if (repeatType === "daily") {
|
|
261
|
+
if (frequency === 1) {
|
|
262
|
+
if (schedule.start_time) {
|
|
263
|
+
const startDateStr = formatDateTime(schedule.start_time, true, locale);
|
|
264
|
+
return `${config.longTermValidFrom}${startDateStr}${config.noExpiry}`;
|
|
265
|
+
}
|
|
266
|
+
return "";
|
|
267
|
+
} else {
|
|
268
|
+
const frequencyText = getDailyFrequencyText(frequency, locale);
|
|
269
|
+
if (locale === "en") {
|
|
270
|
+
return `${frequencyText}`;
|
|
271
|
+
} else {
|
|
272
|
+
return `${frequencyText}${config.available}`;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (repeatType === "weekly") {
|
|
277
|
+
const weekdaysText = getWeekdayText(frequencyDate, locale, locale === "en" ? " & " : "/");
|
|
278
|
+
if (frequency === 1) {
|
|
279
|
+
if (locale === "en") {
|
|
280
|
+
return `${config.on}${weekdaysText}`;
|
|
281
|
+
} else {
|
|
282
|
+
return `${config.everyPrefix}${config.weekPrefix}${weekdaysText}${config.available}`;
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
const frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
286
|
+
if (locale === "en") {
|
|
287
|
+
return `${frequencyPrefix}${config.on}${weekdaysText}`;
|
|
288
|
+
} else {
|
|
289
|
+
return `${frequencyPrefix}${config.weekPrefix}${weekdaysText}`;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return "";
|
|
294
|
+
}
|
|
295
|
+
function generateSingleScheduleSummary(schedule, isStarted, locale) {
|
|
296
|
+
const isAllDay = schedule.is_all === 1;
|
|
297
|
+
if (schedule.type === "designation" && schedule.designation && schedule.designation.length === 1) {
|
|
298
|
+
const designation = schedule.designation[0];
|
|
299
|
+
const startDate = designation.start_date;
|
|
300
|
+
const endDate = designation.end_date;
|
|
301
|
+
const startTime = designation.start_time;
|
|
302
|
+
const endTime = designation.end_time;
|
|
303
|
+
const isDesignationAllDay = isAllDaySchedule(startTime, endTime);
|
|
304
|
+
if (isDesignationAllDay || isAllDay) {
|
|
305
|
+
return formatDateRange(startDate, endDate, isStarted, locale, true);
|
|
306
|
+
} else {
|
|
307
|
+
const startDateTime = `${startDate} ${startTime}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
308
|
+
const endDateTime = `${endDate} ${endTime}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
309
|
+
return formatDateRange(startDateTime, endDateTime, isStarted, locale, false);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (isAllDay) {
|
|
313
|
+
const endDate = getScheduleEndDate(schedule);
|
|
314
|
+
if (!endDate) return "";
|
|
315
|
+
return formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
316
|
+
} else {
|
|
317
|
+
return formatDateRange(schedule.start_time, schedule.end_time, isStarted, locale, false);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function getScheduleEndDate(schedule) {
|
|
321
|
+
try {
|
|
322
|
+
if (schedule.repeat_rule) {
|
|
323
|
+
if (schedule.repeat_rule.end.type === "never") {
|
|
324
|
+
const futureDate = (0, import_dayjs.default)().add(CONSTANTS.DEFAULT_FUTURE_YEARS, "year");
|
|
325
|
+
return `${futureDate.format("YYYY-MM-DD")} ${CONSTANTS.ALL_DAY_END}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
326
|
+
} else if (schedule.repeat_rule.end.end_date) {
|
|
327
|
+
return `${schedule.repeat_rule.end.end_date} ${CONSTANTS.ALL_DAY_END}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (schedule.designation && schedule.designation.length > 0) {
|
|
331
|
+
const lastDesignation = schedule.designation[schedule.designation.length - 1];
|
|
332
|
+
return `${lastDesignation.end_date} ${lastDesignation.end_time}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
333
|
+
}
|
|
334
|
+
if (schedule.end_time) {
|
|
335
|
+
return schedule.end_time;
|
|
336
|
+
}
|
|
337
|
+
if (schedule.start_time) {
|
|
338
|
+
return schedule.start_time;
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
console.warn("Error in getScheduleEndDate:", error);
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
347
|
+
0 && (module.exports = {
|
|
348
|
+
getScheduleSummary
|
|
349
|
+
});
|