@pisell/utils 1.0.20 → 1.0.22

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/format.js CHANGED
@@ -35,6 +35,11 @@ export var formatAmount = function formatAmount() {
35
35
  // 添加小数点
36
36
  if (precision > 0) {
37
37
  formattedAmount += '.' + decimalPart;
38
+
39
+ // 如果小数位是 .00的话 抹去
40
+ if (formattedAmount.indexOf('.00') !== -1) {
41
+ formattedAmount = formattedAmount.substring(0, formattedAmount.length - 3);
42
+ }
38
43
  }
39
44
 
40
45
  // 添加负号
package/es/image.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare const image: {
2
+ ali: (url: string, w: number) => string;
3
+ getImageSize: (url: string) => {
4
+ width: number;
5
+ height: number;
6
+ ratio: number;
7
+ success: boolean;
8
+ widthRatio: number;
9
+ originRatio: number;
10
+ };
11
+ };
package/es/image.js ADDED
@@ -0,0 +1,63 @@
1
+ var ali = function ali(url, w) {
2
+ if (!url || /^\s+$/.test(url)) {
3
+ return '';
4
+ }
5
+ // 如果图片链接中已经包含了过滤参数,则直接跳过
6
+ if (/x-oss-process=/.test(url)) {
7
+ return url;
8
+ }
9
+ var dpr = 2;
10
+ w = w || 750;
11
+ if (url.indexOf('?') > -1) {
12
+ url += '&';
13
+ } else {
14
+ url += '?';
15
+ }
16
+ url += 'x-oss-process=image/resize,w_' + parseInt(w * dpr + '') + ',image/format,webp/interlace,1,image/quality,Q_60/sharpen,90';
17
+ return url;
18
+ };
19
+
20
+ /**
21
+ * @Title: 获取图片尺寸
22
+ * @Describe: 通过 __ 进行分割
23
+ * @Author: Wzw
24
+ * @param {string} url
25
+ */
26
+
27
+ var getImageSize = function getImageSize(url) {
28
+ var size = {
29
+ width: 375,
30
+ height: 375,
31
+ ratio: 1,
32
+ widthRatio: 1,
33
+ success: false,
34
+ originRatio: 1
35
+ };
36
+ if (typeof url !== 'string') return size;
37
+ // https://file.mypisel.dev/boxlocal/image/9c4e5a0afdbefadc78e3eab27c9ca3202021_07_23_16_05_00_916_02868331878656287__2160_976__.jpeg
38
+ // 根据 __ 分割url
39
+ try {
40
+ var arr = url.split('__');
41
+ // 根据规则, 第二个下标为图片的宽高
42
+ if (arr[1]) {
43
+ // 分割宽高, 第一个值是宽 第二个值是高
44
+ var sizeArr = arr[1].split('_');
45
+ // 如果没取到则默认为375
46
+ var _width = Number(sizeArr[0]) || 375;
47
+ var _height = Number(sizeArr[1]) || 375;
48
+ size.width = _width;
49
+ size.height = _height;
50
+ size.success = true;
51
+ size.ratio = Number(_height / _width);
52
+ size.widthRatio = Number((_width / _height).toFixed(2));
53
+ size.originRatio = Number(_height / _width);
54
+ }
55
+ return size;
56
+ } catch (err) {
57
+ return size;
58
+ }
59
+ };
60
+ export var image = {
61
+ ali: ali,
62
+ getImageSize: getImageSize
63
+ };
package/es/index.d.ts CHANGED
@@ -6,3 +6,7 @@ export * from "./platform";
6
6
  export * from "./log";
7
7
  export * from "./format";
8
8
  export * from "./escPosPrinter";
9
+ export * from './miniRedux';
10
+ export * from "./jsBridge";
11
+ export * from "./image";
12
+ export * from "./locales";
package/es/index.js CHANGED
@@ -6,4 +6,8 @@ export * from "./platform";
6
6
  export * from "./log";
7
7
  export * from "./format";
8
8
  export * from "./escPosPrinter";
9
+ export * from "./miniRedux";
10
+ export * from "./jsBridge";
11
+ export * from "./image";
12
+ export * from "./locales";
9
13
  // export { default as firebase } from './firebase';
@@ -0,0 +1,106 @@
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
+ 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;
99
+ /**
100
+ * webView页面中调用打印机打印
101
+ * 此api暂时只支持native app平台下ios手机
102
+ * @param params
103
+ * @param callback
104
+ */
105
+ export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void): void;
106
+ export {};
@@ -0,0 +1,18 @@
1
+ import regDeviceApi from "./regDeviceApi";
2
+ /**
3
+ * webView页面中调用打印机打印
4
+ * 此api暂时只支持native app平台下ios手机
5
+ * @param params
6
+ * @param callback
7
+ */
8
+ export function webPrint(params, _callback) {
9
+ regDeviceApi().then(function (jsBridge) {
10
+ jsBridge.callDeviceApi({
11
+ apiName: "webPrint",
12
+ params: params,
13
+ callback: function callback() {
14
+ _callback && _callback.apply(void 0, arguments);
15
+ }
16
+ });
17
+ });
18
+ }
@@ -0,0 +1,15 @@
1
+ type ComposedJSBridge = {
2
+ // eslint-disable-next-line camelcase
3
+ callDeviceApi: (a: {
4
+ apiName: string;
5
+ callback: Functon;
6
+ onError?: (e: any) => void;
7
+ params?: any;
8
+ key_events?: string[];
9
+ }) => void;
10
+ calledByDevice: (a: { apiName: string; callback: Functon }) => void;
11
+ };
12
+
13
+ const regDeviceApi: () => Promise<ComposedJSBridge>;
14
+
15
+ export default regDeviceApi;
@@ -0,0 +1,137 @@
1
+ import { isAndroid, isIos } from "../platform";
2
+ var androidRegStatus = false;
3
+ var iosRegStatus = false;
4
+ var androidBridge;
5
+ var iosBridge;
6
+ var composedBridge;
7
+ function regIosJsBridge(callback) {
8
+ if (window.WebViewJavascriptBridge) {
9
+ callback(window.WebViewJavascriptBridge);
10
+ return;
11
+ }
12
+ if (window.WVJBCallbacks) {
13
+ window.WVJBCallbacks.push(callback);
14
+ return;
15
+ }
16
+ window.WVJBCallbacks = [callback];
17
+ var WVJBIframe = document.createElement('iframe');
18
+ WVJBIframe.style.display = 'none';
19
+ WVJBIframe.src = 'https://__bridge_loaded__';
20
+ document.documentElement && document.documentElement.appendChild(WVJBIframe);
21
+ setTimeout(function () {
22
+ try {
23
+ document.documentElement && document.documentElement.removeChild(WVJBIframe);
24
+ } catch (e) {
25
+ console.log(e);
26
+ }
27
+ }, 0);
28
+ }
29
+ function regAndroidJsBridge(extraInit) {
30
+ if (window._jsBridge) {
31
+ extraInit(window._jsBridge);
32
+ return;
33
+ }
34
+ document.addEventListener('WebViewJavascriptBridgeReady', function (event) {
35
+ var bridge = event.bridge;
36
+ window._jsBridge = bridge;
37
+ if (!bridge) return;
38
+ // 这段代码不能删除
39
+ bridge.init(function (message, responseCallback) {
40
+ if (responseCallback) {
41
+ responseCallback('init responseCallback');
42
+ }
43
+ });
44
+ extraInit(bridge);
45
+ }, false);
46
+ }
47
+
48
+ /**
49
+ * 通用jsBridge
50
+ * @param deviceType
51
+ */
52
+ function getComposedBridge(deviceType) {
53
+ if (composedBridge) {
54
+ return composedBridge;
55
+ }
56
+ composedBridge = {
57
+ // 主动调用设备的方法
58
+ callDeviceApi: function callDeviceApi(_ref) {
59
+ var apiName = _ref.apiName,
60
+ inCb = _ref.callback,
61
+ _ref$params = _ref.params,
62
+ params = _ref$params === void 0 ? {} : _ref$params,
63
+ onError = _ref.onError;
64
+ var callback = function callback(res) {
65
+ var result = res;
66
+ try {
67
+ result = JSON.parse(res);
68
+ } catch (error) {
69
+ console.log("error ".concat(apiName), error);
70
+ }
71
+ if (result.code || result.code === 0) {
72
+ // 强转字符串,兼容安卓的number
73
+ result.code = "".concat(result.code);
74
+ }
75
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
76
+ args[_key - 1] = arguments[_key];
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
+ androidBridge.callHandler(apiName, params, callback, function (e) {
89
+ console.log(e, '--- 调用android api报错:', apiName);
90
+ if (onError) {
91
+ onError(e);
92
+ }
93
+ });
94
+ } else {
95
+ console.log('--- 没获取到js bridge ---');
96
+ }
97
+ },
98
+ // 被设备调用的方法
99
+ calledByDevice: function calledByDevice(_ref2) {
100
+ var apiName = _ref2.apiName,
101
+ callback = _ref2.callback;
102
+ if (deviceType === 'iphone') {
103
+ iosBridge.registerHandler(apiName, callback);
104
+ } else if (deviceType === 'android') {
105
+ androidBridge.registerHandler(apiName, callback);
106
+ }
107
+ }
108
+ };
109
+ return composedBridge;
110
+ }
111
+ export default function regDeviceApi() {
112
+ return new Promise(function (resolve, reject) {
113
+ if (isIos() && !iosRegStatus) {
114
+ regIosJsBridge(function (bridge) {
115
+ iosRegStatus = true;
116
+ iosBridge = bridge;
117
+ var realBridge = getComposedBridge('iphone');
118
+ resolve(realBridge);
119
+ });
120
+ } else if (isIos() && iosRegStatus) {
121
+ var realBridge = getComposedBridge('iphone');
122
+ resolve(realBridge);
123
+ } else if (isAndroid() && !androidRegStatus) {
124
+ regAndroidJsBridge(function (bridge) {
125
+ androidBridge = bridge;
126
+ androidRegStatus = true;
127
+ var realBridge = getComposedBridge('android');
128
+ resolve(realBridge);
129
+ });
130
+ } else if (isAndroid() && androidRegStatus) {
131
+ var _realBridge = getComposedBridge('android');
132
+ resolve(_realBridge);
133
+ } else {
134
+ reject();
135
+ }
136
+ });
137
+ }
@@ -0,0 +1,13 @@
1
+ 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
+ };
13
+ export default locales;
package/es/locales.js ADDED
@@ -0,0 +1,75 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ // 所有多语言储存
8
+ var localeMaps = {
9
+ en: {},
10
+ 'zh-CN': {},
11
+ 'zh-HK': {}
12
+ };
13
+
14
+ // 当前语言
15
+ var locale = 'en';
16
+
17
+ // 当前语言对应的多语言
18
+ var localeMap = {};
19
+
20
+ // 语言格式化
21
+ var formatLocale = function formatLocale(_locale) {
22
+ var obj = {
23
+ 'en': 'en',
24
+ 'zh-CN': 'zh-CN',
25
+ 'zh-HK': 'zh-HK',
26
+ 'zh-TW': 'zh-HK',
27
+ 'en-US': 'en'
28
+ };
29
+ return obj[_locale] || 'en';
30
+ };
31
+
32
+ /**
33
+ * @title: 初始化多语言
34
+ * @description:
35
+ * @param {any} _localeMaps
36
+ * @param {string} _locale
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ * @Date: 2024-01-17 21:38
40
+ */
41
+ var init = function init(_localeMaps, _locale) {
42
+ // 设置语言
43
+ locale = formatLocale(_locale);
44
+ var allLocales = {};
45
+ for (var key in localeMaps) {
46
+ allLocales[key] = _objectSpread(_objectSpread({}, localeMaps[key]), _localeMaps[key]);
47
+ }
48
+
49
+ // 更新语言
50
+ localeMaps = allLocales;
51
+
52
+ // 更新当前语言对应的多语言
53
+ localeMap = localeMaps[locale];
54
+ };
55
+
56
+ /**
57
+ * @title: 获取语言
58
+ * @description:
59
+ * @param {string} id
60
+ * @return {*}
61
+ * @Author: zhiwei.Wang
62
+ * @Date: 2024-01-17 21:39
63
+ */
64
+ var getText = function getText(id) {
65
+ return localeMap[id] || id;
66
+ };
67
+ var locales = {
68
+ init: init,
69
+ getText: getText,
70
+ locale: locale,
71
+ localeMap: localeMap,
72
+ localeMaps: localeMaps,
73
+ formatLocale: formatLocale
74
+ };
75
+ export default locales;
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ interface MiniReduxProps<State, Namespace> {
3
+ namespace?: Namespace;
4
+ state?: State;
5
+ reducers?: any;
6
+ effects?: any;
7
+ }
8
+ export declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({ namespace, state, reducers, effects, }: MiniReduxProps<State, Namespace>) => {
9
+ Context: React.Context<{ [K in Namespace]: State; } & {
10
+ dispatch: (params: {
11
+ type: string;
12
+ payload: any;
13
+ }) => void;
14
+ }>;
15
+ Provider: (ComponentUi: any) => (props: any) => JSX.Element;
16
+ };
17
+ export {};
@@ -0,0 +1,70 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
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
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import React, { createContext, useCallback, useReducer } from "react";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ export var miniRedux = function miniRedux(_ref2) {
16
+ var _ref2$namespace = _ref2.namespace,
17
+ namespace = _ref2$namespace === void 0 ? "state" : _ref2$namespace,
18
+ state = _ref2.state,
19
+ _ref2$reducers = _ref2.reducers,
20
+ reducers = _ref2$reducers === void 0 ? {} : _ref2$reducers,
21
+ _ref2$effects = _ref2.effects,
22
+ effects = _ref2$effects === void 0 ? {} : _ref2$effects;
23
+ var Context = /*#__PURE__*/createContext({});
24
+ var Provider = function Provider(ComponentUi) {
25
+ var Components = function Components(props) {
26
+ var _objectSpread2, _ref5;
27
+ var _useReducer = useReducer(function (state, _ref3) {
28
+ var type = _ref3.type,
29
+ payload = _ref3.payload;
30
+ if (reducers[type]) {
31
+ return reducers[type](state, payload) || state;
32
+ } else {
33
+ return state;
34
+ }
35
+ }, state),
36
+ _useReducer2 = _slicedToArray(_useReducer, 2),
37
+ providerState = _useReducer2[0],
38
+ dispatch = _useReducer2[1];
39
+ var _dispatch = useCallback(function (_ref4) {
40
+ var type = _ref4.type,
41
+ payload = _ref4.payload;
42
+ if (effects[type]) {
43
+ effects[type].call(null, payload, dispatch);
44
+ } else if (reducers[type]) {
45
+ dispatch({
46
+ type: type,
47
+ payload: payload
48
+ });
49
+ }
50
+ }, []);
51
+ var _props = _objectSpread(_objectSpread({}, props), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, namespace, providerState), _defineProperty(_objectSpread2, "dispatch", _dispatch), _objectSpread2));
52
+ var _ref = null;
53
+ if (_props.forwardedRef) {
54
+ _ref = _props.forwardedRef;
55
+ delete _props.forwardedRef;
56
+ }
57
+ return /*#__PURE__*/_jsx(Context.Provider, {
58
+ value: (_ref5 = {}, _defineProperty(_ref5, namespace, providerState), _defineProperty(_ref5, "dispatch", _dispatch), _ref5),
59
+ children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
60
+ ref: _ref
61
+ }))
62
+ });
63
+ };
64
+ return Components;
65
+ };
66
+ return {
67
+ Context: Context,
68
+ Provider: Provider
69
+ };
70
+ };
@@ -6,3 +6,25 @@
6
6
  * @return {*}
7
7
  */
8
8
  export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
+ /**
10
+ * @title: 对数组进行增|删
11
+ * @description: 用于多选选中和取消选中的处理
12
+ * @param {any} list
13
+ * @param {any} item
14
+ * @param {string} key
15
+ * @return {*}
16
+ * @Author: zhiwei.Wang
17
+ * @Date: 2023-12-19 16:44
18
+ */
19
+ export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
20
+ /**
21
+ * @title: 判断某个字段是否在列表内
22
+ * @description:
23
+ * @param {*} T
24
+ * @param {boolean} param2
25
+ * @return {*}
26
+ * @Author: zhiwei.Wang
27
+ * @Date: 2023-12-19 16:54
28
+ */
29
+ export declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
30
+ export declare const createArray: (length: number, returnItem: any) => any;
package/es/otherUtils.js CHANGED
@@ -9,4 +9,69 @@ export var getUniqueId = function getUniqueId() {
9
9
  var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
10
10
  var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
11
11
  return prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength);
12
+ };
13
+
14
+ /**
15
+ * @title: 对数组进行增|删
16
+ * @description: 用于多选选中和取消选中的处理
17
+ * @param {any} list
18
+ * @param {any} item
19
+ * @param {string} key
20
+ * @return {*}
21
+ * @Author: zhiwei.Wang
22
+ * @Date: 2023-12-19 16:44
23
+ */
24
+ export var changeArray = function changeArray() {
25
+ var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
26
+ var item = arguments.length > 1 ? arguments[1] : undefined;
27
+ var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'this';
28
+ var _list = JSON.parse(JSON.stringify(list));
29
+ var isSome = false;
30
+ if (key === 'this') {
31
+ isSome = _list.includes(item);
32
+ } else {
33
+ //@ts-ignore
34
+ isSome = _list.some(function (d) {
35
+ return d[key] === item[key];
36
+ });
37
+ }
38
+ if (isSome) {
39
+ _list = _list.filter(function (d) {
40
+ if (key === 'this') {
41
+ return d !== item;
42
+ }
43
+
44
+ //@ts-ignore
45
+ return d[key] !== item[key];
46
+ });
47
+ } else {
48
+ _list.push(item);
49
+ }
50
+ return _list;
51
+ };
52
+
53
+ /**
54
+ * @title: 判断某个字段是否在列表内
55
+ * @description:
56
+ * @param {*} T
57
+ * @param {boolean} param2
58
+ * @return {*}
59
+ * @Author: zhiwei.Wang
60
+ * @Date: 2023-12-19 16:54
61
+ */
62
+ export var getItemByArray = function getItemByArray() {
63
+ var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
64
+ var item = arguments.length > 1 ? arguments[1] : undefined;
65
+ var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'this';
66
+ if (key === 'this') {
67
+ return list.includes(item);
68
+ }
69
+
70
+ //@ts-ignore
71
+ return list.some(function (d) {
72
+ return d[key] === item[key];
73
+ });
74
+ };
75
+ export var createArray = function createArray(length, returnItem) {
76
+ return Array.from(new Array(length)).map(returnItem);
12
77
  };
package/lib/format.js CHANGED
@@ -36,6 +36,9 @@ var formatAmount = (amount = 0, precision = 2, symbol = "") => {
36
36
  let formattedAmount = symbol + integerPart.toString();
37
37
  if (precision > 0) {
38
38
  formattedAmount += "." + decimalPart;
39
+ if (formattedAmount.indexOf(".00") !== -1) {
40
+ formattedAmount = formattedAmount.substring(0, formattedAmount.length - 3);
41
+ }
39
42
  }
40
43
  if (roundedAmount < 0) {
41
44
  formattedAmount = "-" + formattedAmount;