@cloudbase/framework-plugin-low-code 0.7.10-beta.3 → 0.7.10

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.
Files changed (33) hide show
  1. package/lib/builder/core/generate.d.ts.map +1 -1
  2. package/lib/builder/core/generate.js +6 -8
  3. package/lib/builder/core/index.d.ts.map +1 -1
  4. package/lib/builder/service/builder/webpack.d.ts +1 -1
  5. package/lib/builder/service/builder/webpack.d.ts.map +1 -1
  6. package/lib/builder/service/builder/webpack.js +17 -28
  7. package/lib/index.d.ts.map +1 -1
  8. package/lib/index.js +25 -73
  9. package/lib/weapps-core/utils/style.js +8 -0
  10. package/package.json +1 -1
  11. package/template/html/index.html.ejs +426 -426
  12. package/template/mp/app/weapps-api.js +27 -95
  13. package/template/mp/app.js +60 -76
  14. package/template/mp/common/util.js +3 -312
  15. package/template/mp/datasources/index.js +16 -5
  16. package/template/mp/package.json +2 -2
  17. package/template/package.json +2 -2
  18. package/template/src/app/global-api.js +41 -154
  19. package/template/src/datasources/index.js.tpl +14 -2
  20. package/template/src/handlers/FieldMiddleware/renderer.jsx +26 -86
  21. package/template/src/handlers/actionHandler/utils.js +11 -32
  22. package/template/src/handlers/lifecycle.js +10 -21
  23. package/template/src/handlers/render.jsx +6 -17
  24. package/template/src/handlers/utils/common.js +26 -42
  25. package/template/src/handlers/utils/widgets.js +9 -38
  26. package/template/src/index.jsx +9 -8
  27. package/template/src/pages/app.tpl +3 -1
  28. package/template/src/pages/composite.tpl +1 -1
  29. package/template/src/utils/formatEnum.js +1 -1
  30. package/template/src/utils/index.js +1 -15
  31. package/template/src/utils/ScanCodeComponent.js +0 -345
  32. package/template/src/utils/date.js +0 -324
  33. package/template/src/utils/scan-code-action.js +0 -27
@@ -1,345 +0,0 @@
1
- import React, { useRef, useEffect, useImperativeHandle, useState, useCallback, useMemo } from 'react';
2
- import ReactDOM from 'react-dom';
3
-
4
- import { BrowserMultiFormatReader, NotFoundException, BarcodeFormat, DecodeHintType } from '@zxing/library';
5
- import { app } from '../app/global-api';
6
-
7
-
8
- export const FORMAT = {
9
- 0: { scanType: 'AZTEC', wxtype: null },
10
- 1: { scanType: 'CODABAR', wxtype: 'barCode' },
11
- 2: { scanType: 'CODE_39', wxtype: 'barCode' },
12
- 3: { scanType: 'CODE_93', wxtype: 'barCode' },
13
- 4: { scanType: 'CODE_128', wxtype: 'barCode' },
14
- 5: { scanType: 'DATA_MATRIX', wxtype: 'qrCode' },
15
- 6: { scanType: 'EAN_8', wxtype: 'barCode' },
16
- 7: { scanType: 'EAN_13', wxtype: 'barCode' },
17
- 8: { scanType: 'ITF', wxtype: 'barCode' },
18
- 9: { scanType: 'MAXICODE', wxtype: null },
19
- 10: { scanType: 'PDF_417', wxtype: 'qrCode' },
20
- 11: { scanType: 'QR_CODE', wxtype: 'qrCode' },
21
- 12: { scanType: 'RSS_14', wxtype: 'barCode' },
22
- 13: { scanType: 'RSS_EXPANDED', wxtype: 'barCode' },
23
- 14: { scanType: 'UPC_A', wxtype: 'barCode' },
24
- 15: { scanType: 'UPC_E', wxtype: 'barCode' },
25
- 16: { scanType: 'UPC_EAN_EXTENSION', wxtype: 'barCode' },
26
- };
27
-
28
- const hints = new Map();
29
- const formats = [
30
- BarcodeFormat.QR_CODE,
31
- BarcodeFormat.UPC_A,
32
- BarcodeFormat.UPC_E,
33
- BarcodeFormat.EAN_8,
34
- BarcodeFormat.EAN_13,
35
- BarcodeFormat.CODE_39,
36
- BarcodeFormat.CODE_93,
37
- BarcodeFormat.CODE_128,
38
- BarcodeFormat.DATA_MATRIX,
39
- BarcodeFormat.PDF_417,
40
- ];
41
- hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);
42
-
43
- const Codescanner = React.forwardRef(({ events = {}, closeScanCode, scanType, onInit }, fref) => {
44
- const ref = useRef();
45
- const {
46
- fail = () => {},
47
- success = () => {},
48
- complete = () => {},
49
- } = events;
50
-
51
- const inited = useRef(false);
52
- const codeReader = new BrowserMultiFormatReader(hints);
53
- const start = async () => {
54
- setTimeout(() => {
55
- // try harder after 5 sceonds
56
- hints.set(DecodeHintType.TRY_HARDER, true);
57
- codeReader.timeBetweenDecodingAttempts = 1500;
58
- codeReader.hints = hints;
59
- }, 5000);
60
- const devices = await codeReader.listVideoInputDevices();
61
-
62
- if (devices.length) {
63
- try {
64
- await codeReader.decodeFromConstraints(
65
- { video: { facingMode: 'environment' } },
66
- ref.current,
67
- (result, err) => {
68
- if (!inited.current) {
69
- inited.current = true;
70
- onInit();
71
- }
72
- if (result) {
73
- if (scanType.includes(FORMAT[result.format].wxtype)) {
74
- success(wechatLikeResult(result));
75
- complete();
76
- closeScanCode();
77
- }
78
- }
79
-
80
- if (err && !err instanceof NotFoundException) {
81
- fail(err);
82
- complete();
83
- }
84
- },
85
- );
86
- } catch (err) {
87
- fail(err);
88
- complete();
89
- }
90
- } else {
91
- fail(new Error('No camera detect'));
92
- complete();
93
- }
94
- };
95
-
96
- const stop = () => {
97
- codeReader.reset();
98
- };
99
-
100
- useImperativeHandle(fref, () => ({
101
- start,
102
- stop,
103
- }));
104
-
105
- useEffect(() => {
106
- start().catch(fail);
107
- return () => {
108
- stop();
109
- };
110
- }, []);
111
- return (
112
- <>
113
- <video
114
- autoPlay
115
- ref={ref}
116
- id="weapp-scancode-video"
117
- ></video>
118
- </>
119
- );
120
- });
121
-
122
-
123
- function fileToImage(file) {
124
- return new Promise((resolve, reject) => {
125
- const reader = new FileReader();
126
- reader.readAsDataURL(file);
127
- reader.onload = async (ev) => {
128
- const img = new Image();
129
- img.src = ev.target.result;
130
- resolve(img);
131
- };
132
- reader.onerror = reject;
133
- });
134
- }
135
-
136
- const SCAN_CODE_STATE = 'scan-code-modal';
137
- export default function ScanCode({ root, options }) {
138
- const {
139
- onlyFromCamera,
140
- scanType,
141
- success: successCallback,
142
- fail,
143
- complete,
144
- enableDefaultBehavior,
145
- } = options;
146
- useEffect(() => {
147
- // 覆盖一次返回按键为关闭
148
- if (history.state?.SCANCODE !== SCAN_CODE_STATE) {
149
- history.pushState({ SCANCODE: SCAN_CODE_STATE }, null);
150
- }
151
- const onPopState = () => {
152
- closeScanCode();
153
- };
154
- window.addEventListener('popstate', onPopState);
155
- return () => {
156
- if (history.state?.SCANCODE === SCAN_CODE_STATE) {
157
- history.back();
158
- }
159
- window.removeEventListener('popstate', onPopState);
160
- };
161
- }, [closeScanCode]);
162
- const ref = useRef();
163
- const closeScanCode = () => {
164
- ref.current?.stop?.();
165
- ReactDOM.render(null, root);
166
- };
167
- const success = useCallback((res) => {
168
- const { result } = res;
169
- if (enableDefaultBehavior) {
170
- if (/^https?:\/\//.test(result)) {
171
- window.open(result);
172
- } else {
173
- app.showModal({
174
- title: '扫描到以下内容',
175
- content: result,
176
- showCancel: false,
177
- confirmColor: '#006eff',
178
- });
179
- }
180
- }
181
- successCallback(res);
182
- });
183
- const [isCameraInit, setIscameraInit] = useState(false);
184
- const onInitCamera = () => {
185
- setIscameraInit(true);
186
- };
187
- const [modalErrMessage, setModalErrMessage] = useState('');
188
- const handleModalClick = () => {
189
- setModalErrMessage('');
190
- };
191
- const fileChanged = async (ev) => {
192
- const { files } = ev.target;
193
- if (files.length <= 0) return;
194
- const file = files[0];
195
- const img = await fileToImage(file);
196
- hints.set(DecodeHintType.TRY_HARDER, true);
197
- const codeReader = new BrowserMultiFormatReader(hints);
198
- try {
199
- const result = await codeReader.decodeFromImage(img);
200
- success(wechatLikeResult(result));
201
- closeScanCode();
202
- } catch (err) {
203
- onScanFail(err);
204
- }
205
- };
206
- const scanTypeText = useMemo(() => scanType.map((type) => {
207
- switch (type) {
208
- case 'qrCode':
209
- return '二维码';
210
- case 'barCode':
211
- return '条码';
212
- default:
213
- return type;
214
- }
215
- }).join(' / '), [scanType]);
216
- const onScanFail = (err) => {
217
- if (err instanceof NotFoundException) {
218
- setModalErrMessage(`未发现${scanTypeText}`);
219
- setIscameraInit(false);
220
- } else if (err.message === 'Permission denied') {
221
- setModalErrMessage('请打开相机权限以获取扫码功能');
222
- } else if (err.message === 'No camera detect') {
223
- setModalErrMessage('未能检测到相机设备');
224
- } else {
225
- setModalErrMessage(err.message);
226
- }
227
- setIscameraInit(false);
228
- fail(err);
229
- };
230
- if (modalErrMessage) {
231
- return <div className="weapp-scancode-modal" onClick={handleModalClick}>
232
- <div className="weapp-scancode-modal-main">
233
- <div className="weapp-scancode-scan-wrapper">
234
- <p className="weapp-scancode-scan-not-found">{modalErrMessage}</p>
235
- <p>点击重新扫码</p>
236
- </div>
237
- <CloseButton onClick={closeScanCode} />
238
- </div>
239
- </div>;
240
- }
241
- return (
242
- <div className="weapp-scancode-modal">
243
- <div className="weapp-scancode-modal-main">
244
- <Codescanner
245
- events={{ fail: onScanFail, success, complete }}
246
- ref={ref}
247
- closeScanCode={closeScanCode}
248
- scanType={scanType}
249
- onInit={(onInitCamera)}
250
- />
251
-
252
- {isCameraInit && <><CloseButton onClick={closeScanCode} />
253
- <div className="weapp-scancode-scan-wrapper">
254
- <div className="weapp-scancode-scan-square">
255
- <div className="weapp-scancode-scan-bar"></div>
256
- </div>
257
- <p className="weapp-scancode-scan-tip">{scanTypeText}</p>
258
- </div>
259
- </>
260
- }
261
- {!onlyFromCamera && isCameraInit && <div
262
- className="weapp-scancode-img-selector"
263
- >
264
- <input onChange={fileChanged} type="file" id="weapp-scancode-img-picker-input" accept="image/*" style={{ display: 'none' }} />
265
- <label
266
- htmlFor="weapp-scancode-img-picker-input"
267
- className="weapp-scancode-img-picker"
268
- >
269
- <span>
270
- <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg">
271
- <title>icon/album</title>
272
- <g id="icon/album" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
273
- <rect id="矩形" x="0" y="0" width="24" height="24"></rect>
274
- <path d="M21,4 C21.5522847,4 22,4.44771525 22,5 L22,19 C22,19.5522847 21.5522847,20 21,20 L3,20 C2.44771525,20 2,19.5522847 2,19 L2,5 C2,4.44771525 2.44771525,4 3,4 L21,4 Z M20.5,5.5 L3.5,5.5 L3.5,13.932 L8.34720227,9.89314397 C8.69729746,9.60139798 9.19512095,9.58601647 9.56028418,9.84165631 L9.65637439,9.91809179 L14.036,13.86 L16.8907001,11.8207928 C17.2650251,11.5533999 17.7734822,11.5758744 18.1227552,11.8752513 L18.1227552,11.8752513 L20.5,13.913 L20.5,5.5 Z" id="形状结合" fill="#FFFFFF" fillRule="nonzero"></path>
275
- </g>
276
- </svg>
277
- </span>
278
- </label>
279
- </div>}
280
- </div>
281
- </div>
282
- );
283
- }
284
-
285
- function CloseButton({ onClick }) {
286
- return (
287
- <a
288
- className="weapp-scancode-close-button"
289
- aria-label="close modal"
290
- onClick={onClick}
291
- >
292
- <svg width="12px" height="12px" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
293
- <path fillRule="evenodd" clipRule="evenodd" d="M12.5348 2.04999L7.9998 6.58499L3.4638 2.04999L2.0498 3.46499L6.5858 8.00099L2.0498 12.536L3.4638 13.95L7.9998 9.41499L12.5348 13.95L13.9498 12.536L9.4138 8.00099L13.9498 3.46499L12.5348 2.04999Z" fill="currentColor"/>
294
- </svg>
295
- </a>
296
- );
297
- }
298
-
299
- function wechatLikeResult(zxingResult) {
300
- const wechatResult = {
301
- result: zxingResult.text || zxingResult.result,
302
- scanType: FORMAT[zxingResult.format].wxtype,
303
- };
304
- return wechatResult;
305
- }
306
-
307
- // https://github.com/AlloyTeam/AlloyImage/blob/master/src/module/filter/toGray.js
308
- function toGray(imgData) {
309
- const { data } = imgData;
310
-
311
- for (let i = 0, n = data.length;i < n;i += 4) {
312
- const gray = parseInt((0.299 * data[i] + 0.578 * data[i + 1] + 0.114 * data[i + 2]), 10);
313
- // eslint-disable-next-line no-multi-assign
314
- data[i + 2] = data[i + 1] = data[i] = gray;
315
- }
316
-
317
- imgData.data.set(data);
318
-
319
- return imgData;
320
- }
321
-
322
- // https://github.com/AlloyTeam/AlloyImage/blob/master/src/module/filter/sharp.js
323
- function sharp(imgData, arg = []) {
324
- const lamta = arg[0] || 0.6;
325
- const { data } = imgData;
326
- const { width } = imgData;
327
-
328
- for (let i = 0, n = data.length;i < n;i += 4) {
329
- const ii = i / 4;
330
- const row = parseInt(ii / width, 10);
331
- const col = ii % width;
332
- if (row === 0 || col === 0) continue;
333
-
334
- const A = ((row - 1) * width + (col - 1)) * 4;
335
- const B = ((row - 1) * width + col) * 4;
336
- const E = (ii - 1) * 4;
337
-
338
- for (let j = 0;j < 3;j ++) {
339
- const delta = data[i + j] - (data[B + j] + data[E + j] + data[A + j]) / 3;
340
- data[i + j] += delta * lamta;
341
- }
342
- }
343
-
344
- return imgData;
345
- }
@@ -1,324 +0,0 @@
1
- // 日期转换
2
- class CustomDate {
3
- constructor() {
4
- this.i18n = {
5
- dayNames: [
6
- 'Sun',
7
- 'Mon',
8
- 'Tue',
9
- 'Wed',
10
- 'Thu',
11
- 'Fri',
12
- 'Sat',
13
- 'Sunday',
14
- 'Monday',
15
- 'Tuesday',
16
- 'Wednesday',
17
- 'Thursday',
18
- 'Friday',
19
- 'Saturday',
20
- ],
21
- monthNames: [
22
- 'Jan',
23
- 'Feb',
24
- 'Mar',
25
- 'Apr',
26
- 'May',
27
- 'Jun',
28
- 'Jul',
29
- 'Aug',
30
- 'Sep',
31
- 'Oct',
32
- 'Nov',
33
- 'Dec',
34
- 'January',
35
- 'February',
36
- 'March',
37
- 'April',
38
- 'May',
39
- 'June',
40
- 'July',
41
- 'August',
42
- 'September',
43
- 'October',
44
- 'November',
45
- 'December',
46
- ],
47
- timeNames: ['a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM'],
48
- };
49
- this.masks = {
50
- default: 'ddd mmm dd yyyy HH:MM:ss',
51
- shortDate: 'm/d/yy',
52
- paddedShortDate: 'mm/dd/yyyy',
53
- mediumDate: 'mmm d, yyyy',
54
- longDate: 'mmmm d, yyyy',
55
- fullDate: 'dddd, mmmm d, yyyy',
56
- shortTime: 'h:MM TT',
57
- mediumTime: 'h:MM:ss TT',
58
- longTime: 'h:MM:ss TT Z',
59
- isoDate: 'yyyy-mm-dd',
60
- isoTime: 'HH:MM:ss',
61
- isoDateTime: "yyyy-mm-dd'T'HH:MM:sso",
62
- isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'",
63
- expiresHeaderFormat: 'ddd, dd mmm yyyy HH:MM:ss Z',
64
- };
65
- this.token = /d{1,4}|D{3,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|W{1,2}|[LlopSZN]|"[^"]*"|'[^']*'/g;
66
- this.timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g;
67
- this.timezoneClip = /[^-+\dA-Z]/g;
68
- }
69
-
70
- /*
71
- *
72
- | Name | Mask | Example |
73
- | ----------------- | ------------------------------ | ------------------------ |
74
- | `default` | `ddd mmm dd yyyy HH:MM:ss` | Sat Jun 09 2007 17:46:21 |
75
- | `shortDate` | `m/d/yy` | 6/9/07 |
76
- | `paddedShortDate` | `mm/dd/yyyy` | 06/09/2007 |
77
- | `mediumDate` | `mmm d, yyyy` | Jun 9, 2007 |
78
- | `longDate` | `mmmm d, yyyy` | June 9, 2007 |
79
- | `fullDate` | `dddd, mmmm d, yyyy` | Saturday, June 9, 2007 |
80
- | `shortTime` | `h:MM TT` | 5:46 PM |
81
- | `mediumTime` | `h:MM:ss TT` | 5:46:21 PM |
82
- | `longTime` | `h:MM:ss TT Z` | 5:46:21 PM EST |
83
- | `isoDate` | `yyyy-mm-dd` | 2007-06-09 |
84
- | `isoTime` | `HH:MM:ss` | 17:46:21 |
85
- | `isoDateTime` | `yyyy-mm-dd'T'HH:MM:sso` | 2007-06-09T17:46:21+0700 |
86
- | `isoUtcDateTime` | `UTC:yyyy-mm-dd'T'HH:MM:ss'Z'` | 2007-06-09T22:46:21Z |
87
- *
88
- */
89
- format(date, mask, utc, gmt) {
90
- let newMask = mask;
91
- let newDate = date;
92
- let newUtc = utc;
93
- let newGmt = gmt;
94
- if (
95
- arguments.length === 1 &&
96
- this._kindOf(newDate) === 'string' &&
97
- !/\d/.test(newDate)
98
- ) {
99
- newDate = undefined;
100
- }
101
- newDate = newDate || newDate === 0 ? newDate : new Date();
102
- if (!(newDate instanceof Date)) newDate = new Date(newDate);
103
- if (isNaN(newDate)) throw TypeError('Invalid date');
104
- newMask = String(this.masks[newMask] || newMask || this.masks['default']);
105
- const maskSlice = newMask.slice(0, 4);
106
- if (maskSlice === 'UTC:' || maskSlice === 'GMT:') {
107
- newMask = newMask.slice(4);
108
- newUtc = true;
109
- if (maskSlice === 'GMT:') newGmt = true;
110
- }
111
- const _ = newUtc ? 'getUTC' : 'get';
112
- const _d = newDate[`${_}Date`]();
113
- const D = newDate[`${_}Day`]();
114
- const _m = newDate[`${_}Month`]();
115
- const y = newDate[`${_}FullYear`]();
116
- const _H = newDate[`${_}Hours`]();
117
- const _M = newDate[`${_}Minutes`]();
118
- const _s = newDate[`${_}Seconds`]();
119
- const _L = newDate[`${_}Milliseconds`]();
120
- const _o = newUtc ? 0 : newDate.getTimezoneOffset();
121
- const _W = this._getWeek(newDate);
122
- const _N = this._getDayOfWeek(newDate);
123
- // eslint-disable-next-line @typescript-eslint/no-this-alias
124
- const self = this;
125
- // @ts-ignore
126
- // @ts-ignore
127
- const flags = {
128
- d: () => _d,
129
- dd: () => self._pad(_d),
130
- ddd: () => self.i18n.dayNames[D],
131
- DDD: () =>
132
- self._getDayName({
133
- y,
134
- m: _m,
135
- d: _d,
136
- _,
137
- dayName: self.i18n.dayNames[D],
138
- short: true,
139
- }),
140
- dddd: () => self.i18n.dayNames[D + 7],
141
- DDDD: () =>
142
- self._getDayName({
143
- y: y,
144
- m: _m,
145
- d: _d,
146
- _: _,
147
- dayName: self.i18n.dayNames[D + 7],
148
- }),
149
- m: () => _m + 1,
150
- mm: () => self._pad(_m + 1),
151
- mmm: () => self.i18n.monthNames[_m],
152
- mmmm: () => self.i18n.monthNames[_m + 12],
153
- yy: () => String(y).slice(2),
154
- yyyy: () => self._pad(y, 4),
155
- h: () => _H % 12 || 12,
156
- hh: () => self._pad(_H % 12 || 12),
157
- H: () => _H,
158
- HH: () => self._pad(_H),
159
- M: () => _M,
160
- MM: () => self._pad(_M),
161
- s: () => _s,
162
- ss: () => self._pad(_s),
163
- l: () => self._pad(_L, 3),
164
- L: () => self._pad(Math.floor(_L / 10)),
165
- t: () => (_H < 12 ? self.i18n.timeNames[0] : self.i18n.timeNames[1]),
166
- tt: () => (_H < 12 ? self.i18n.timeNames[2] : self.i18n.timeNames[3]),
167
- T: () => (_H < 12 ? self.i18n.timeNames[4] : self.i18n.timeNames[5]),
168
- TT: () => (_H < 12 ? self.i18n.timeNames[6] : self.i18n.timeNames[7]),
169
- // eslint-disable-next-line no-nested-ternary
170
- Z: () =>
171
- newGmt
172
- ? 'GMT'
173
- : newUtc
174
- ? 'UTC'
175
- : (String(newDate).match(self.timezone) || [''])
176
- .pop()
177
- .replace(self.timezoneClip, '')
178
- .replace(/GMT\+0000/g, 'UTC'),
179
- o: () =>
180
- (_o > 0 ? '-' : '+') +
181
- self._pad(Math.floor(Math.abs(_o) / 60) * 100 + (Math.abs(_o) % 60), 4),
182
- p: () =>
183
- `${
184
- (_o > 0 ? '-' : '+') + self._pad(Math.floor(Math.abs(_o) / 60), 2)
185
- }:${self._pad(Math.floor(Math.abs(_o) % 60), 2)}`,
186
- // @ts-ignore
187
- S: () =>
188
- ['th', 'st', 'nd', 'rd'][
189
- _d % 10 > 3 ? 0 : (((_d % 100) - (_d % 10) != 10) * _d) % 10
190
- ],
191
- W: () => _W,
192
- WW: () => self._pad(_W),
193
- N: () => _N,
194
- };
195
- return mask.replace(this.token, (match) => {
196
- if (match in flags) {
197
- return flags[match]();
198
- }
199
- return match.slice(1, match.length - 1);
200
- });
201
- }
202
-
203
- _pad(val, len) {
204
- let newVal = String(val);
205
- const newLen = len || 2;
206
- while (newVal.length < newLen) {
207
- newVal = `0${newVal}`;
208
- }
209
- return newVal;
210
- }
211
-
212
- _getDayName(_ref) {
213
- const { y, m, d, _, dayName } = _ref;
214
- const _ref$short = _ref['short'];
215
- const _short = _ref$short === void 0 ? false : _ref$short;
216
- const today = new Date();
217
- const yesterday = new Date();
218
- yesterday.setDate(yesterday[`${_}Date`]() - 1);
219
- const tomorrow = new Date();
220
- tomorrow.setDate(tomorrow[`${_}Date`]() + 1);
221
- const today_d = function today_d() {
222
- return today[`${_}Date`]();
223
- };
224
- const today_m = function today_m() {
225
- return today[`${_}Month`]();
226
- };
227
- const today_y = function today_y() {
228
- return today[`${_}FullYear`]();
229
- };
230
- const yesterday_d = function yesterday_d() {
231
- return yesterday[`${_}Date`]();
232
- };
233
- const yesterday_m = function yesterday_m() {
234
- return yesterday[`${_}Month`]();
235
- };
236
- const yesterday_y = function yesterday_y() {
237
- return yesterday[`${_}FullYear`]();
238
- };
239
- const tomorrow_d = function tomorrow_d() {
240
- return tomorrow[`${_}Date`]();
241
- };
242
- const tomorrow_m = function tomorrow_m() {
243
- return tomorrow[`${_}Month`]();
244
- };
245
- const tomorrow_y = function tomorrow_y() {
246
- return tomorrow[`${_}FullYear`]();
247
- };
248
- if (today_y() === y && today_m() === m && today_d() === d) {
249
- return _short ? 'Tdy' : 'Today';
250
- }
251
- if (yesterday_y() === y && yesterday_m() === m && yesterday_d() === d) {
252
- return _short ? 'Ysd' : 'Yesterday';
253
- }
254
- if (tomorrow_y() === y && tomorrow_m() === m && tomorrow_d() === d) {
255
- return _short ? 'Tmw' : 'Tomorrow';
256
- }
257
- return dayName;
258
- }
259
-
260
- _getWeek(date) {
261
- const targetThursday = new Date(
262
- date.getFullYear(),
263
- date.getMonth(),
264
- date.getDate()
265
- );
266
- targetThursday.setDate(
267
- targetThursday.getDate() - ((targetThursday.getDay() + 6) % 7) + 3
268
- );
269
- const firstThursday = new Date(targetThursday.getFullYear(), 0, 4);
270
- firstThursday.setDate(
271
- firstThursday.getDate() - ((firstThursday.getDay() + 6) % 7) + 3
272
- );
273
- const ds =
274
- targetThursday.getTimezoneOffset() - firstThursday.getTimezoneOffset();
275
- targetThursday.setHours(targetThursday.getHours() - ds);
276
- const weekDiff = (targetThursday - firstThursday) / (864e5 * 7);
277
- return 1 + Math.floor(weekDiff);
278
- }
279
-
280
- _getDayOfWeek(date) {
281
- let dow = date.getDay();
282
- if (dow === 0) {
283
- dow = 7;
284
- }
285
- return dow;
286
- }
287
-
288
- _kindOf(val) {
289
- if (val === null) {
290
- return 'null';
291
- }
292
- if (val === undefined) {
293
- return 'undefined';
294
- }
295
- if (this._typeof(val) !== 'object') {
296
- return this._typeof(val);
297
- }
298
- if (Array.isArray(val)) {
299
- return 'array';
300
- }
301
- return {}.toString.call(val).slice(8, -1).toLowerCase();
302
- }
303
-
304
- _typeof(obj) {
305
- if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
306
- this._typeof = function _typeof(obj) {
307
- return typeof obj;
308
- };
309
- } else {
310
- this._typeof = function _typeof(obj) {
311
- return obj &&
312
- typeof Symbol === 'function' &&
313
- obj.constructor === Symbol &&
314
- obj !== Symbol.prototype
315
- ? 'symbol'
316
- : typeof obj;
317
- };
318
- }
319
- return this._typeof(obj);
320
- }
321
- }
322
-
323
- const dataInstance = new CustomDate();
324
- export const formatDate = new CustomDate().format.bind(dataInstance);
@@ -1,27 +0,0 @@
1
- import React from "react";
2
- import { Suspense } from "react";
3
- import ReactDOM from 'react-dom';
4
-
5
- const ScanCode = React.lazy(() => import('./ScanCodeComponent'));
6
- const WEAPP_SCAN_CODE_ELEMENT_ID = 'weapp-scan-code-modal-root';
7
- export function scanCodeApi(opts) {
8
- const options = {
9
- onlyFromCamera: false,
10
- scanType: ['barCode', 'qrCode'],
11
- success: () => {},
12
- fail: () => {},
13
- complete: () => {},
14
- enableDefaultBehavior: true,
15
- ...opts,
16
- };
17
- if (typeof options.scanType === 'string') {
18
- options.scanType = [options.scanType];
19
- }
20
- let root = document.getElementById(WEAPP_SCAN_CODE_ELEMENT_ID);
21
- if (!root) {
22
- root = document.createElement('div');
23
- root.id = WEAPP_SCAN_CODE_ELEMENT_ID;
24
- }
25
- document.body.appendChild(root);
26
- ReactDOM.render(<Suspense fallback={<></>}><ScanCode root={root} options={options} /></Suspense>, root);
27
- }