@aks-dev/easyui 1.0.149 → 1.0.151

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.
@@ -2,7 +2,7 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-04-19 10:23:01
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2022-11-18 19:09:00
5
+ * @LastEditTime: 2023-03-10 14:05:17
6
6
  * @FilePath: /@aks-dev/easyui/jsbridge/RNEasyui.ts
7
7
  */
8
8
 
@@ -36,3 +36,7 @@ export const getNavigationBarHeight = () => {
36
36
  export const gotoDesktop = () => {
37
37
  if (Platform.OS == 'android') RNEasyui?.gotoDesktop();
38
38
  }
39
+
40
+
41
+
42
+
@@ -100,6 +100,7 @@ export default React.forwardRef<AlertViewOptions.RefAttributes, {}>((_, ref) =>
100
100
  <TouchableOpacity
101
101
  style={[styles.cancel, { marginRight: state.confirmText ? px2dp(15) : 0 }, state.cancelContainerStyle]}
102
102
  activeOpacity={0.8}
103
+ disabled={state.cancelDisabled}
103
104
  onPress={() => {
104
105
  hide()
105
106
  cancelCallbackRef.current && cancelCallbackRef.current()
@@ -2,8 +2,8 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-04-22 17:30:32
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2022-09-09 10:53:51
6
- * @FilePath: /@aks-dev/easyui/lib/Hud/AlertView/index.ts
5
+ * @LastEditTime: 2023-03-10 12:21:30
6
+ * @FilePath: /@aks-dev/easyui/lib/Hud/AlertView/index.d.ts
7
7
  */
8
8
  import * as React from 'react'
9
9
 
@@ -19,6 +19,7 @@ export declare type AlertViewOptions = {
19
19
  cancelContainerStyle: StyleProp<ViewStyle>;
20
20
  cancelTextStyle: StyleProp<TextStyle>;
21
21
  cancel: () => void;
22
+ cancelDisabled:boolean;
22
23
  confirmText: string;
23
24
  confirmContainerStyle: StyleProp<ViewStyle>;
24
25
  confirmTextStyle: StyleProp<TextStyle>;
package/lib/Hud/Hud.tsx CHANGED
@@ -2,8 +2,8 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-04-24 14:10:04
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2022-09-09 09:55:01
6
- * @FilePath: /cmwy-device-app/node_modules/@aks-dev/easyui/lib/Hud/Hud.tsx
5
+ * @LastEditTime: 2023-03-23 11:13:55
6
+ * @FilePath: /aks-fire-app/node_modules/@aks-dev/easyui/lib/Hud/Hud.tsx
7
7
  */
8
8
  import * as React from 'react'
9
9
  // import { StyleSheet } from 'react-native'
@@ -31,6 +31,9 @@ import {
31
31
  import { showPopoverView, hidePopoverView, popoverViewRef, PopoverView } from './PopoverView/PopoverView'
32
32
 
33
33
 
34
+ import {
35
+ showScanner, hideScanner, scannerRef, Scanner
36
+ } from './Scanner/Scanner'
34
37
 
35
38
 
36
39
 
@@ -48,6 +51,7 @@ export const Hud: React.FC<{}> = () => React.cloneElement(
48
51
  <AlertBottomView key="hud-3-0" ref={alertBottomViewRef} />,
49
52
  <AlertSheetView key="hud-3-1" ref={alertSheetViewRef} />,
50
53
  <PopoverView key="hud-4" ref={popoverViewRef} />,
54
+ <Scanner key="hud-5" ref={scannerRef} />,
51
55
  ]
52
56
  )
53
57
 
@@ -58,6 +62,6 @@ export {
58
62
  showLoading, hideLoading,
59
63
  showAlertBottomModal,
60
64
  showAlertSheetModal,
61
- showPopoverView, hidePopoverView
62
-
65
+ showPopoverView, hidePopoverView,
66
+ showScanner,hideScanner,
63
67
  }
@@ -0,0 +1,256 @@
1
+ /*
2
+ * @Author: shiguo
3
+ * @Date: 2022-04-24 14:27:02
4
+ * @LastEditors: shiguo
5
+ * @LastEditTime: 2023-03-23 12:37:10
6
+ * @FilePath: /@aks-dev/easyui/lib/Hud/Scanner/Scanner.tsx
7
+ */
8
+ import React, { useImperativeHandle, useState } from 'react';
9
+ import {
10
+ Animated, BackHandler, Easing, Image, StyleProp, StyleSheet, Text, TouchableOpacity, View, ViewStyle
11
+ } from 'react-native';
12
+ import { RNCamera } from 'react-native-camera';
13
+ import { PERMISSIONS, requestMultiple } from 'react-native-permissions';
14
+ import { navigationBarHeight, px2dp, statusBarHeight } from '../../../screen/px2dp';
15
+ import { px2sp } from '../../../screen/px2sp';
16
+ import * as utils from '../../../utils/lazy';
17
+ import { showToast } from '../Toast/Toast';
18
+ import { ScannerOptions } from './index';
19
+
20
+
21
+
22
+
23
+
24
+
25
+ // enum SCANNER_TYPE {
26
+ // DENIED = -1,//没有开始权限
27
+ // START = 0,//没有扫描结果,继续扫描
28
+ // SUCCESS = 1,//已有扫描结果,停止扫描
29
+ // }
30
+
31
+ export const Scanner = React.forwardRef<ScannerOptions.RefAttributes, {}>((_, ref) => {
32
+ const [show, setShow] = useState(false);
33
+ const [torchOn, setTorchOn] = React.useState(false)
34
+ const moveAnim = React.useRef(new Animated.Value(0)).current
35
+ const [pointStyle, setPointStyle] = React.useState<StyleProp<ViewStyle>>()
36
+ const cameraRef = React.useRef<RNCamera>()
37
+ const _cbRef = React.useRef<ScannerOptions.CallBack>()
38
+ const _scanerResultRef = React.useRef<any>()
39
+ React.useEffect(() => {
40
+ const onBackPress = () => {
41
+ if (show) {
42
+ _hideScanner()
43
+ }
44
+ return true
45
+ }
46
+ BackHandler.addEventListener('hardwareBackPress', onBackPress);
47
+ return () => BackHandler.removeEventListener('hardwareBackPress', onBackPress);
48
+ }, [show])
49
+
50
+
51
+
52
+
53
+ useImperativeHandle<unknown, ScannerOptions.RefAttributes>(ref, () => ({
54
+ showScanner: _showScanner,
55
+ hideScanner: _hideScanner
56
+ }), [show])
57
+
58
+
59
+
60
+ const _showScanner = async (cb: ScannerOptions.CallBack) => {
61
+ let res = await requestMultiple([PERMISSIONS.IOS.CAMERA, PERMISSIONS.ANDROID.CAMERA])
62
+ if (res[PERMISSIONS.ANDROID.CAMERA] == "granted" || res[PERMISSIONS.IOS.CAMERA] == "granted") {
63
+ _scanerResultRef.current = undefined;
64
+ setShow(true);
65
+ setPointStyle({})
66
+ await utils.sleep()
67
+ animationStart()
68
+ _cbRef.current = cb;
69
+ } else {
70
+ _hideScanner()
71
+ showToast('您未开启相机权限,暂不能使用此功能')
72
+ }
73
+
74
+
75
+ }
76
+
77
+ const _hideScanner = async () => {
78
+ animationStop()
79
+ await utils.sleep()
80
+ setShow(false);
81
+ }
82
+
83
+
84
+
85
+ const animation = Animated.loop(Animated.sequence([
86
+ Animated.timing(
87
+ moveAnim,
88
+ {
89
+ toValue: px2dp(222),
90
+ duration: 3000,
91
+ easing: Easing.linear,
92
+ useNativeDriver: true,
93
+ }
94
+ ),
95
+ Animated.timing(
96
+ moveAnim,
97
+ {
98
+ toValue: 0,
99
+ duration: 3000,
100
+ easing: Easing.linear,
101
+ useNativeDriver: true,
102
+ }
103
+ )
104
+ ]))
105
+
106
+
107
+
108
+ const animationStart = async () => {
109
+
110
+ cameraRef.current?.resumePreview()
111
+ animation.start(({ finished }) => {
112
+ // console.log('animationStart finished', finished)
113
+ if (finished) {
114
+ animation.reset()
115
+ animation.start()
116
+ }
117
+ })
118
+ }
119
+ const animationStop = (result?: any) => {
120
+ cameraRef.current?.pausePreview()
121
+ animation.stop()
122
+ }
123
+
124
+
125
+ // const getPointFromBounds = (bounds) => {
126
+ // let x = 0
127
+ // let y = 0
128
+
129
+ // if (Platform.OS == 'android') {
130
+ // bounds.origin.forEach(i => {
131
+ // x = Math.max(x, parseFloat(i.x))
132
+ // y = Math.max(y, parseFloat(i.y))
133
+ // })
134
+
135
+ // y = y * DeviceHeight / bounds.width
136
+ // x = x * DeviceWidth / bounds.height
137
+ // }
138
+
139
+ // if(Platform.OS == 'ios'){
140
+ // x=parseFloat(bounds.origin.x)
141
+ // y=parseFloat(bounds.origin.y)
142
+ // }
143
+
144
+ // return { x, y }
145
+ // }
146
+
147
+
148
+ const onBarCodeRead = (e) => {
149
+ // console.log('ss onBarCodeRead: ', JSON.stringify(e))
150
+ if (e?.data?.length > 0 && _scanerResultRef.current == undefined) {
151
+ _scanerResultRef.current = e?.data
152
+ _cbRef.current(e?.data)
153
+ _hideScanner()
154
+ }
155
+ }
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+ if (!show) return null;
164
+ return (
165
+ <TouchableOpacity disabled style={styles.container}>
166
+
167
+ <RNCamera
168
+ ref={cameraRef}
169
+ captureAudio={false}
170
+ autoFocus={RNCamera.Constants.AutoFocus.on}/*自动对焦*/
171
+ style={styles.camera}
172
+ type={RNCamera.Constants.Type.back}/*切换前后摄像头 front前back后*/
173
+ flashMode={torchOn ? RNCamera.Constants.FlashMode.torch : RNCamera.Constants.FlashMode.off}/*相机闪光模式*/
174
+ onBarCodeRead={onBarCodeRead}
175
+
176
+
177
+ >
178
+ {/* 导航栏 */}
179
+ <View style={{ display: 'flex', justifyContent: "center", alignItems: "center", height: navigationBarHeight, marginTop: statusBarHeight, position: 'relative' }}>
180
+ <TouchableOpacity onPress={() => _hideScanner()} style={{ height: navigationBarHeight, width: px2dp(50), paddingLeft: px2dp(15), position: 'absolute', left: 0, display: 'flex', justifyContent: 'center' }} >
181
+ <Image source={require('./icon_back_white.png')} style={{ width: px2dp(20), height: px2dp(20) }} resizeMode='contain' />
182
+ </TouchableOpacity>
183
+ <Text style={{ fontSize: px2sp(16), color: 'white', fontWeight: 'bold' }}>扫一扫</Text>
184
+ </View>
185
+
186
+ {/* 动画框 */}
187
+ <View style={styles.scanContainer}>
188
+ <View style={styles.rectangle}>
189
+ <View style={styles.rectangleLeft} />
190
+ <View style={styles.cameraBackground}>
191
+ <Animated.View style={[styles.scanLine, { transform: [{ translateY: moveAnim }] }]} />
192
+ <View style={styles.reactLineTopLeftX} />
193
+ <View style={styles.reactLineTopLeftY} />
194
+ <View style={styles.reactLineTopRightX} />
195
+ <View style={styles.reactLineTopRightY} />
196
+ <View style={styles.reactLineBottomLeftX} />
197
+ <View style={styles.reactLineBottomLeftY} />
198
+ <View style={styles.reactLineBottomRightX} />
199
+ <View style={styles.reactLineBottomRightY} />
200
+ </View>
201
+ <View style={styles.rectangleRight} />
202
+ </View>
203
+
204
+ <TouchableOpacity onPress={() => {
205
+ setTorchOn(!torchOn)
206
+ }}>
207
+ <Image
208
+ source={torchOn ? require('./flashlight-blue.png') : require('./flashlight-white.png')}
209
+ style={styles.flashlight} />
210
+ </TouchableOpacity>
211
+ <Text style={styles.rectangleText}>将二维码/条码放入框内,即可自动扫描</Text>
212
+ </View>
213
+ <View style={pointStyle} />
214
+ </RNCamera>
215
+
216
+ </TouchableOpacity>
217
+ )
218
+ })
219
+
220
+
221
+
222
+ const transparent = '#00000000'
223
+ const lineColor = '#6ab3ff'
224
+ const scanW = 225
225
+ const scanCornerLineLength = 15;
226
+ const scanCornerLineHeight = 3
227
+ const styles = StyleSheet.create({
228
+ container: {
229
+ ...StyleSheet.absoluteFillObject,
230
+ },
231
+ camera: { display: 'flex', flex: 1, flexDirection: 'column', backgroundColor: "red" },
232
+ cameraBackground: { width: px2dp(scanW), height: px2dp(scanW), backgroundColor: transparent },
233
+ scanContainer: { display: 'flex', flex: 1, justifyContent: 'center', alignItems: 'center' },
234
+ rectangle: { flexDirection: 'row', overflow: 'hidden', },
235
+ rectangleLeft: { backgroundColor: transparent, height: px2dp(scanW), width: px2dp(scanW) },
236
+ rectangleRight: { backgroundColor: transparent, height: px2dp(scanW), width: px2dp(scanW) },
237
+ rectangleText: { color: '#fff', lineHeight: px2dp(15), },
238
+ scanLine: { width: px2dp(scanW), height: px2dp(scanCornerLineHeight), borderRadius: px2dp(25), backgroundColor: lineColor, },
239
+ reactLineTopLeftX: { position: 'absolute', top: 0, left: 0, width: px2dp(scanCornerLineLength), height: px2dp(scanCornerLineHeight), backgroundColor: lineColor },
240
+ reactLineTopLeftY: { position: 'absolute', top: 0, left: 0, width: px2dp(scanCornerLineHeight), height: px2dp(scanCornerLineLength), backgroundColor: lineColor },
241
+ reactLineTopRightX: { position: 'absolute', top: 0, right: 0, width: px2dp(scanCornerLineLength), height: px2dp(scanCornerLineHeight), backgroundColor: lineColor },
242
+ reactLineTopRightY: { position: 'absolute', top: 0, right: 0, width: px2dp(scanCornerLineHeight), height: px2dp(scanCornerLineLength), backgroundColor: lineColor },
243
+ reactLineBottomLeftX: { position: 'absolute', bottom: 0, left: 0, width: px2dp(scanCornerLineLength), height: px2dp(scanCornerLineHeight), backgroundColor: lineColor },
244
+ reactLineBottomLeftY: { position: 'absolute', bottom: 0, left: 0, width: px2dp(scanCornerLineHeight), height: px2dp(scanCornerLineLength), backgroundColor: lineColor },
245
+ reactLineBottomRightX: { position: 'absolute', bottom: 0, right: 0, width: px2dp(scanCornerLineLength), height: px2dp(scanCornerLineHeight), backgroundColor: lineColor },
246
+ reactLineBottomRightY: { position: 'absolute', bottom: 0, right: 0, width: px2dp(scanCornerLineHeight), height: px2dp(scanCornerLineLength), backgroundColor: lineColor },
247
+ flashlight: { width: px2dp(30), height: px2dp(30), resizeMode: 'contain', marginTop: px2dp(50), marginBottom: px2dp(15), marginHorizontal: px2dp(15) },
248
+ grantedText: { lineHeight: px2dp(30), color: lineColor, fontWeight: 'bold' }
249
+ })
250
+
251
+
252
+
253
+
254
+ export const scannerRef = React.createRef<ScannerOptions.RefAttributes>();
255
+ export const showScanner = (cb: ScannerOptions.CallBack) => scannerRef.current?.showScanner(cb)
256
+ export const hideScanner = () => scannerRef.current?.hideScanner()
@@ -0,0 +1,42 @@
1
+
2
+ /*
3
+ * @Author: shiguo
4
+ * @Date: 2022-04-24 14:27:02
5
+ * @LastEditors: shiguo
6
+ * @LastEditTime: 2023-03-23 12:36:02
7
+ * @FilePath: /@aks-dev/easyui/lib/Hud/Scanner/index.d.ts
8
+ */
9
+ import * as React from 'react'
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ declare namespace ScannerOptions {
21
+
22
+ type CallBack = (e: string) => void;
23
+
24
+
25
+ type RefAttributes = {
26
+ showScanner: (cb: CallBack) => void;
27
+ hideScanner: () => void;
28
+ }
29
+ }
30
+
31
+
32
+
33
+ export declare const showScanner: (cb: ScannerOptions.CallBack) => void;
34
+
35
+
36
+ export declare const hideScanner: () => void;
37
+
38
+
39
+ export declare const scannerRef: React.RefObject<ScannerOptions.RefAttributes>;
40
+
41
+ export declare const Scanner: React.ForwardRefExoticComponent<React.PropsWithoutRef<{}> & React.RefAttributes<ScannerOptions.RefAttributes>>
42
+
package/lib/Hud/index.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-04-24 14:14:42
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2022-09-09 09:55:43
6
- * @FilePath: /cmwy-device-app/node_modules/@aks-dev/easyui/lib/Hud/index.ts
5
+ * @LastEditTime: 2023-03-23 11:05:22
6
+ * @FilePath: /aks-fire-app/node_modules/@aks-dev/easyui/lib/Hud/index.ts
7
7
  */
8
8
 
9
9
 
@@ -16,4 +16,5 @@ export * from './Toast'
16
16
  export * from './AlertBottomView'
17
17
  export * from './AlertSheetView'
18
18
  export * from './PopoverView'
19
+ export * from './Scanner'
19
20
  export declare const Hud: React.FC<{}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aks-dev/easyui",
3
- "version": "1.0.149",
3
+ "version": "1.0.151",
4
4
  "description": "工具箱",
5
5
  "main": "./src/index.ts",
6
6
  "typings": "./src/index.d.ts",
@@ -39,7 +39,9 @@
39
39
  "@aks-dev/react-native-syan-image-picker": "*",
40
40
  "react": "*",
41
41
  "react-native": "*",
42
- "react-native-webview": "*"
42
+ "react-native-webview": "*",
43
+ "react-native-permissions": "*",
44
+ "react-native-camera": "*"
43
45
  },
44
46
  "dependencies": {
45
47
  "echarts": "^5.3.2",
package/src/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-04-26 11:44:22
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2022-12-21 18:15:26
5
+ * @LastEditTime: 2023-03-23 12:33:55
6
6
  * @FilePath: /@aks-dev/easyui/src/index.d.ts
7
7
  */
8
8
 
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @Author: shiguo
4
4
  * @Date: 2022-04-13 12:47:34
5
5
  * @LastEditors: shiguo
6
- * @LastEditTime: 2022-12-21 18:15:37
6
+ * @LastEditTime: 2023-03-23 12:34:09
7
7
  * @FilePath: /@aks-dev/easyui/src/index.ts
8
8
  */
9
9
 
@@ -21,7 +21,8 @@ export {
21
21
  showAlertModal,
22
22
  showAlertBottomModal,
23
23
  showAlertSheetModal,
24
- showPopoverView, hidePopoverView
24
+ showPopoverView, hidePopoverView,
25
+ showScanner,hideScanner
25
26
  } from '../lib/Hud/Hud'
26
27
 
27
28
  export * from '../lib/Modal/Modal'
package/utils/lazy.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: shiguo
3
3
  * @Date: 2022-04-27 18:17:54
4
4
  * @LastEditors: shiguo
5
- * @LastEditTime: 2023-02-28 12:07:28
5
+ * @LastEditTime: 2023-03-10 14:04:08
6
6
  * @FilePath: /@aks-dev/easyui/utils/lazy.ts
7
7
  */
8
8
  import type { SyncLoopCallBack } from '.'
@@ -334,3 +334,5 @@ export const getUuid = () => {
334
334
  var uuid = s.join("");
335
335
  return uuid
336
336
  }
337
+
338
+