vite-uni-dev-tool 1.1.0 → 1.2.0
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/README.md +8 -0
- package/dist/const.cjs +1 -1
- package/dist/const.d.ts +1 -0
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +1 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -2
- package/dist/i18n/locales/en.cjs +1 -1
- package/dist/i18n/locales/en.d.ts +5 -0
- package/dist/i18n/locales/en.d.ts.map +1 -1
- package/dist/i18n/locales/en.js +1 -1
- package/dist/i18n/locales/zh-Hans.cjs +1 -1
- package/dist/i18n/locales/zh-Hans.d.ts +5 -0
- package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
- package/dist/i18n/locales/zh-Hans.js +1 -1
- package/dist/modules/devIntercept/index.cjs +9 -9
- package/dist/modules/devIntercept/index.d.ts +1 -1
- package/dist/modules/devIntercept/index.d.ts.map +1 -1
- package/dist/modules/devIntercept/index.js +9 -9
- package/dist/modules/devStore/index.cjs +1 -1
- package/dist/modules/devStore/index.d.ts.map +1 -1
- package/dist/modules/devStore/index.js +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -1
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
- package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -1
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
- package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
- package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -1
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
- package/dist/type.d.ts +3 -0
- package/dist/type.d.ts.map +1 -1
- package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -199
- package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -730
- package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -167
- package/dist/v3/DevTool/components/CaptureScreen/index.vue +109 -109
- package/dist/v3/DevTool/components/ConsoleList/ConsoleItem.vue +230 -225
- package/dist/v3/DevTool/components/ConsoleList/RunJSInput.vue +247 -247
- package/dist/v3/DevTool/components/ConsoleList/index.vue +171 -171
- package/dist/v3/DevTool/components/ConsoleList/staticTips.ts +1145 -1145
- package/dist/v3/DevTool/components/DevToolTitle/index.vue +24 -24
- package/dist/v3/DevTool/components/DevToolWindow/DevToolOverlay.vue +197 -197
- package/dist/v3/DevTool/components/DevToolWindow/hooks/dataUtils.ts +48 -48
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolData.ts +387 -387
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolHandlers.ts +629 -629
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolOverlay.ts +201 -197
- package/dist/v3/DevTool/components/ElEvent/ElEventItem.vue +105 -105
- package/dist/v3/DevTool/components/ElEvent/index.vue +106 -106
- package/dist/v3/DevTool/components/Instance/components/InstanceTreeNode.vue +265 -265
- package/dist/v3/DevTool/components/Instance/flatten.ts +226 -226
- package/dist/v3/DevTool/components/Instance/index.vue +94 -94
- package/dist/v3/DevTool/components/Instance/registry.ts +49 -49
- package/dist/v3/DevTool/components/Instance/transformTree.ts +375 -375
- package/dist/v3/DevTool/components/Instance/transformTreeCtx.ts +268 -268
- package/dist/v3/DevTool/components/Instance/typing.d.ts +43 -43
- package/dist/v3/DevTool/components/InstanceDetail/index.vue +485 -485
- package/dist/v3/DevTool/components/JsonDetail/index.vue +70 -70
- package/dist/v3/DevTool/components/NFCList/NFCItem.vue +112 -112
- package/dist/v3/DevTool/components/NFCList/NFCTool.vue +454 -454
- package/dist/v3/DevTool/components/NFCList/const.ts +56 -56
- package/dist/v3/DevTool/components/NFCList/index.vue +94 -94
- package/dist/v3/DevTool/components/NetworkList/InterceptConfig.vue +624 -624
- package/dist/v3/DevTool/components/NetworkList/InterceptItem.vue +140 -140
- package/dist/v3/DevTool/components/NetworkList/NetworkDetail.vue +287 -287
- package/dist/v3/DevTool/components/NetworkList/NetworkIntercept.vue +88 -88
- package/dist/v3/DevTool/components/NetworkList/NetworkItem.vue +163 -163
- package/dist/v3/DevTool/components/NetworkList/NetworkSend.vue +589 -589
- package/dist/v3/DevTool/components/NetworkList/const.ts +4 -4
- package/dist/v3/DevTool/components/NetworkList/hooks/useNetworkForm.ts +86 -86
- package/dist/v3/DevTool/components/NetworkList/index.vue +160 -160
- package/dist/v3/DevTool/components/NetworkList/utils.ts +101 -101
- package/dist/v3/DevTool/components/Performance/index.vue +498 -498
- package/dist/v3/DevTool/components/Performance/modules/PerformanceMetrics.vue +153 -153
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceChart.ts +460 -460
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceData.ts +258 -258
- package/dist/v3/DevTool/components/PiniaList/index.vue +93 -93
- package/dist/v3/DevTool/components/RunJS/index.vue +148 -148
- package/dist/v3/DevTool/components/ScanCodeList/ScanCodeItem.vue +97 -97
- package/dist/v3/DevTool/components/ScanCodeList/index.vue +100 -100
- package/dist/v3/DevTool/components/SettingButton/index.vue +45 -45
- package/dist/v3/DevTool/components/SettingList/index.vue +218 -218
- package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -304
- package/dist/v3/DevTool/components/SettingList/modules/SettingDevTool.vue +212 -212
- package/dist/v3/DevTool/components/SettingList/modules/SettingInfo.vue +157 -157
- package/dist/v3/DevTool/components/SettingList/modules/SettingLanguage.vue +74 -74
- package/dist/v3/DevTool/components/SettingList/modules/SettingLog.vue +230 -230
- package/dist/v3/DevTool/components/SettingList/typing.d.ts +2 -2
- package/dist/v3/DevTool/components/SourceCode/Line.vue +127 -127
- package/dist/v3/DevTool/components/SourceCode/parseCode.ts +609 -609
- package/dist/v3/DevTool/components/StorageList/index.vue +174 -174
- package/dist/v3/DevTool/components/TransferList/TransferDetail.vue +268 -268
- package/dist/v3/DevTool/components/VuexList/index.vue +84 -84
- package/dist/v3/DevTool/index.vue +1 -0
- package/dist/v3/components/AppTransition/index.vue +176 -176
- package/dist/v3/components/AutoSizer/index.vue +192 -192
- package/dist/v3/components/AutoSizer/index1.vue +184 -184
- package/dist/v3/components/AutoSizer/utils.ts +49 -49
- package/dist/v3/components/Barrage/BarrageItem.vue +137 -137
- package/dist/v3/components/Barrage/index.vue +202 -202
- package/dist/v3/components/CircularButton/index.vue +84 -84
- package/dist/v3/components/CustomSwiper/CustomSwiperItem.vue +49 -49
- package/dist/v3/components/CustomSwiper/index.vue +104 -104
- package/dist/v3/components/DevErrorBoundary/index.vue +380 -0
- package/dist/v3/components/Empty/index.vue +29 -29
- package/dist/v3/components/FilterSelect/index.vue +179 -179
- package/dist/v3/components/JsonPretty/components/Brackets/index.vue +27 -27
- package/dist/v3/components/JsonPretty/components/Carets/index.vue +59 -59
- package/dist/v3/components/JsonPretty/components/CheckController/index.vue +136 -136
- package/dist/v3/components/JsonPretty/components/TreeNode/index.vue +387 -387
- package/dist/v3/components/JsonPretty/hooks/useClipboard.ts +21 -21
- package/dist/v3/components/JsonPretty/hooks/useError.ts +21 -21
- package/dist/v3/components/JsonPretty/type.ts +127 -127
- package/dist/v3/components/JsonPretty/utils/index.ts +169 -169
- package/dist/v3/components/MovableContainer/index.vue +8 -4
- package/dist/v3/components/Pick/index.vue +322 -322
- package/dist/v3/components/Tag/index.vue +113 -113
- package/dist/v3/components/VirtualList/AutoSize.vue +40 -40
- package/dist/v3/components/VirtualList/index.vue +416 -416
- package/dist/v3/hooks/useBluetooth/index.ts +561 -561
- package/dist/v3/hooks/useContainerStyle.ts +153 -153
- package/dist/v3/hooks/useNFC/index.ts +107 -107
- package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
- package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
- package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
- package/dist/v3/hooks/useNFC/utils.ts +754 -754
- package/dist/v3/hooks/useRequest/index.ts +586 -586
- package/dist/v3/hooks/useRequest/utils.ts +267 -267
- package/dist/v3/hooks/useScanCode/index.ts +206 -206
- package/dist/v3/hooks/useWebsocket/index.ts +253 -253
- package/dist/v3/styles/theme.ts +12 -12
- package/package.json +9 -1
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
import { onHide, onShow, onUnload } from '@dcloudio/uni-app';
|
|
2
|
-
import { ref, watch } from 'vue';
|
|
3
|
-
import type { Ref } from 'vue';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* android PDA
|
|
7
|
-
*
|
|
8
|
-
* h5 扫码枪
|
|
9
|
-
*
|
|
10
|
-
* @export
|
|
11
|
-
* @param {(code: string) => void} callback
|
|
12
|
-
* @param {{
|
|
13
|
-
* disabled?: Ref<boolean>;
|
|
14
|
-
* broadcastAction?: string;
|
|
15
|
-
* broadcastStringDataLabel?: string;
|
|
16
|
-
* scanDelay?: number;
|
|
17
|
-
* onScanEnd: (code: string) => void;
|
|
18
|
-
* }} [options]
|
|
19
|
-
*/
|
|
20
|
-
export default function useScanCode(
|
|
21
|
-
callback: (code: string) => void,
|
|
22
|
-
options?: {
|
|
23
|
-
/** 禁用扫描 */
|
|
24
|
-
disabled?: Ref<boolean>;
|
|
25
|
-
/** 广播动作 */
|
|
26
|
-
broadcastAction?: string;
|
|
27
|
-
/** 广播标签 */
|
|
28
|
-
broadcastStringDataLabel?: string;
|
|
29
|
-
/**
|
|
30
|
-
* 扫描延迟 单位 ms
|
|
31
|
-
* 默认 150
|
|
32
|
-
*/
|
|
33
|
-
scanDelay?: number;
|
|
34
|
-
/**
|
|
35
|
-
* 扫描结束
|
|
36
|
-
* @param {string} code
|
|
37
|
-
*/
|
|
38
|
-
onScanEnd?: (code: string) => void;
|
|
39
|
-
},
|
|
40
|
-
) {
|
|
41
|
-
let main: any;
|
|
42
|
-
const show = ref(true);
|
|
43
|
-
|
|
44
|
-
let lastTime: number | null = null;
|
|
45
|
-
let nextTime: number | null = null;
|
|
46
|
-
let lastCode: string | null = null;
|
|
47
|
-
let nextCode: string | null = null;
|
|
48
|
-
|
|
49
|
-
let code = '';
|
|
50
|
-
|
|
51
|
-
let _codeQueryTag = false;
|
|
52
|
-
|
|
53
|
-
let receiver: PlusAndroidInstanceObject;
|
|
54
|
-
|
|
55
|
-
let filter: {
|
|
56
|
-
addAction: (arg0: string) => void;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// #ifdef APP-PLUS
|
|
60
|
-
|
|
61
|
-
function startScan() {
|
|
62
|
-
main.registerReceiver(receiver, filter);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function stopScan() {
|
|
66
|
-
main.unregisterReceiver(receiver);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function queryCode(code: string) {
|
|
70
|
-
if (_codeQueryTag) return false;
|
|
71
|
-
|
|
72
|
-
_codeQueryTag = true;
|
|
73
|
-
|
|
74
|
-
setTimeout(function () {
|
|
75
|
-
_codeQueryTag = false;
|
|
76
|
-
}, options?.scanDelay || 150);
|
|
77
|
-
|
|
78
|
-
if (show.value) {
|
|
79
|
-
callback?.(code);
|
|
80
|
-
options?.onScanEnd?.(code);
|
|
81
|
-
// 单独使用该 hooks 时,删除收集
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
uni?.__dev_tool_scan_code_collection__?.(code, 'broadcast');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function initScan() {
|
|
88
|
-
if (!options?.broadcastAction || !options.broadcastStringDataLabel) {
|
|
89
|
-
throw new Error(
|
|
90
|
-
'PAD 扫描必须传入 broadcastAction, broadcastStringDataLabel',
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
main = plus.android.runtimeMainActivity(); //获取activity
|
|
95
|
-
|
|
96
|
-
const IntentFilter: any = plus.android.importClass(
|
|
97
|
-
'android.content.IntentFilter',
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
filter = new IntentFilter();
|
|
101
|
-
|
|
102
|
-
filter.addAction(options?.broadcastAction); // 换你的广播动作
|
|
103
|
-
|
|
104
|
-
receiver = plus.android.implements(
|
|
105
|
-
'io.dcloud.feature.internal.reflect.BroadcastReceiver',
|
|
106
|
-
{
|
|
107
|
-
onReceive: function (_context: any, intent: any) {
|
|
108
|
-
plus.android.importClass(intent);
|
|
109
|
-
const code = intent.getStringExtra(options?.broadcastStringDataLabel); // 换你的广播标签
|
|
110
|
-
queryCode(code);
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
onShow(() => {
|
|
117
|
-
initScan();
|
|
118
|
-
startScan();
|
|
119
|
-
show.value = !options?.disabled?.value;
|
|
120
|
-
});
|
|
121
|
-
onHide(() => {
|
|
122
|
-
show.value = false;
|
|
123
|
-
stopScan();
|
|
124
|
-
});
|
|
125
|
-
onUnload(() => {
|
|
126
|
-
show.value = false;
|
|
127
|
-
stopScan();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
watch(
|
|
131
|
-
() => [options?.disabled?.value],
|
|
132
|
-
() => {
|
|
133
|
-
show.value = !options?.disabled?.value;
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
// #endif
|
|
138
|
-
|
|
139
|
-
// #ifdef H5
|
|
140
|
-
|
|
141
|
-
function queryCodeH5(e: KeyboardEvent) {
|
|
142
|
-
if (_codeQueryTag) return;
|
|
143
|
-
|
|
144
|
-
if (e.key === 'Enter') {
|
|
145
|
-
e.preventDefault();
|
|
146
|
-
}
|
|
147
|
-
if (e.key === 'CapsLock') {
|
|
148
|
-
e.preventDefault();
|
|
149
|
-
}
|
|
150
|
-
nextCode = e.key;
|
|
151
|
-
|
|
152
|
-
nextTime = Date.now();
|
|
153
|
-
|
|
154
|
-
if (lastCode !== null && lastTime !== null && nextTime - lastTime <= 40) {
|
|
155
|
-
code += lastCode;
|
|
156
|
-
} else if (
|
|
157
|
-
lastCode !== null &&
|
|
158
|
-
lastTime !== null &&
|
|
159
|
-
nextTime - lastTime > 100
|
|
160
|
-
) {
|
|
161
|
-
code = '';
|
|
162
|
-
}
|
|
163
|
-
lastCode = nextCode;
|
|
164
|
-
lastTime = nextTime;
|
|
165
|
-
|
|
166
|
-
if (e.key === 'Enter' && code.length > 0) {
|
|
167
|
-
_codeQueryTag = true;
|
|
168
|
-
setTimeout(function () {
|
|
169
|
-
_codeQueryTag = false;
|
|
170
|
-
}, options?.scanDelay || 150);
|
|
171
|
-
callback?.(code);
|
|
172
|
-
options?.onScanEnd?.(code);
|
|
173
|
-
// 单独使用该 hooks 时,删除收集
|
|
174
|
-
// @ts-ignore
|
|
175
|
-
uni?.__dev_tool_scan_code_collection__?.(code, 'keypress');
|
|
176
|
-
code = '';
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
onShow(() => {
|
|
181
|
-
show.value = true;
|
|
182
|
-
});
|
|
183
|
-
onHide(() => {
|
|
184
|
-
window.removeEventListener('keypress', queryCodeH5);
|
|
185
|
-
});
|
|
186
|
-
onUnload(() => {
|
|
187
|
-
window.removeEventListener('keypress', queryCodeH5);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
watch(
|
|
191
|
-
() => [options?.disabled?.value, show.value],
|
|
192
|
-
() => {
|
|
193
|
-
if (!options?.disabled?.value && show.value) {
|
|
194
|
-
window.removeEventListener('keypress', queryCodeH5);
|
|
195
|
-
window.addEventListener('keypress', queryCodeH5);
|
|
196
|
-
} else {
|
|
197
|
-
window.removeEventListener('keypress', queryCodeH5);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
immediate: true,
|
|
202
|
-
},
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
// #endif
|
|
206
|
-
}
|
|
1
|
+
import { onHide, onShow, onUnload } from '@dcloudio/uni-app';
|
|
2
|
+
import { ref, watch } from 'vue';
|
|
3
|
+
import type { Ref } from 'vue';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* android PDA
|
|
7
|
+
*
|
|
8
|
+
* h5 扫码枪
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @param {(code: string) => void} callback
|
|
12
|
+
* @param {{
|
|
13
|
+
* disabled?: Ref<boolean>;
|
|
14
|
+
* broadcastAction?: string;
|
|
15
|
+
* broadcastStringDataLabel?: string;
|
|
16
|
+
* scanDelay?: number;
|
|
17
|
+
* onScanEnd: (code: string) => void;
|
|
18
|
+
* }} [options]
|
|
19
|
+
*/
|
|
20
|
+
export default function useScanCode(
|
|
21
|
+
callback: (code: string) => void,
|
|
22
|
+
options?: {
|
|
23
|
+
/** 禁用扫描 */
|
|
24
|
+
disabled?: Ref<boolean>;
|
|
25
|
+
/** 广播动作 */
|
|
26
|
+
broadcastAction?: string;
|
|
27
|
+
/** 广播标签 */
|
|
28
|
+
broadcastStringDataLabel?: string;
|
|
29
|
+
/**
|
|
30
|
+
* 扫描延迟 单位 ms
|
|
31
|
+
* 默认 150
|
|
32
|
+
*/
|
|
33
|
+
scanDelay?: number;
|
|
34
|
+
/**
|
|
35
|
+
* 扫描结束
|
|
36
|
+
* @param {string} code
|
|
37
|
+
*/
|
|
38
|
+
onScanEnd?: (code: string) => void;
|
|
39
|
+
},
|
|
40
|
+
) {
|
|
41
|
+
let main: any;
|
|
42
|
+
const show = ref(true);
|
|
43
|
+
|
|
44
|
+
let lastTime: number | null = null;
|
|
45
|
+
let nextTime: number | null = null;
|
|
46
|
+
let lastCode: string | null = null;
|
|
47
|
+
let nextCode: string | null = null;
|
|
48
|
+
|
|
49
|
+
let code = '';
|
|
50
|
+
|
|
51
|
+
let _codeQueryTag = false;
|
|
52
|
+
|
|
53
|
+
let receiver: PlusAndroidInstanceObject;
|
|
54
|
+
|
|
55
|
+
let filter: {
|
|
56
|
+
addAction: (arg0: string) => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// #ifdef APP-PLUS
|
|
60
|
+
|
|
61
|
+
function startScan() {
|
|
62
|
+
main.registerReceiver(receiver, filter);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function stopScan() {
|
|
66
|
+
main.unregisterReceiver(receiver);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function queryCode(code: string) {
|
|
70
|
+
if (_codeQueryTag) return false;
|
|
71
|
+
|
|
72
|
+
_codeQueryTag = true;
|
|
73
|
+
|
|
74
|
+
setTimeout(function () {
|
|
75
|
+
_codeQueryTag = false;
|
|
76
|
+
}, options?.scanDelay || 150);
|
|
77
|
+
|
|
78
|
+
if (show.value) {
|
|
79
|
+
callback?.(code);
|
|
80
|
+
options?.onScanEnd?.(code);
|
|
81
|
+
// 单独使用该 hooks 时,删除收集
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
uni?.__dev_tool_scan_code_collection__?.(code, 'broadcast');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function initScan() {
|
|
88
|
+
if (!options?.broadcastAction || !options.broadcastStringDataLabel) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
'PAD 扫描必须传入 broadcastAction, broadcastStringDataLabel',
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main = plus.android.runtimeMainActivity(); //获取activity
|
|
95
|
+
|
|
96
|
+
const IntentFilter: any = plus.android.importClass(
|
|
97
|
+
'android.content.IntentFilter',
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
filter = new IntentFilter();
|
|
101
|
+
|
|
102
|
+
filter.addAction(options?.broadcastAction); // 换你的广播动作
|
|
103
|
+
|
|
104
|
+
receiver = plus.android.implements(
|
|
105
|
+
'io.dcloud.feature.internal.reflect.BroadcastReceiver',
|
|
106
|
+
{
|
|
107
|
+
onReceive: function (_context: any, intent: any) {
|
|
108
|
+
plus.android.importClass(intent);
|
|
109
|
+
const code = intent.getStringExtra(options?.broadcastStringDataLabel); // 换你的广播标签
|
|
110
|
+
queryCode(code);
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
onShow(() => {
|
|
117
|
+
initScan();
|
|
118
|
+
startScan();
|
|
119
|
+
show.value = !options?.disabled?.value;
|
|
120
|
+
});
|
|
121
|
+
onHide(() => {
|
|
122
|
+
show.value = false;
|
|
123
|
+
stopScan();
|
|
124
|
+
});
|
|
125
|
+
onUnload(() => {
|
|
126
|
+
show.value = false;
|
|
127
|
+
stopScan();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
watch(
|
|
131
|
+
() => [options?.disabled?.value],
|
|
132
|
+
() => {
|
|
133
|
+
show.value = !options?.disabled?.value;
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// #endif
|
|
138
|
+
|
|
139
|
+
// #ifdef H5
|
|
140
|
+
|
|
141
|
+
function queryCodeH5(e: KeyboardEvent) {
|
|
142
|
+
if (_codeQueryTag) return;
|
|
143
|
+
|
|
144
|
+
if (e.key === 'Enter') {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
}
|
|
147
|
+
if (e.key === 'CapsLock') {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
}
|
|
150
|
+
nextCode = e.key;
|
|
151
|
+
|
|
152
|
+
nextTime = Date.now();
|
|
153
|
+
|
|
154
|
+
if (lastCode !== null && lastTime !== null && nextTime - lastTime <= 40) {
|
|
155
|
+
code += lastCode;
|
|
156
|
+
} else if (
|
|
157
|
+
lastCode !== null &&
|
|
158
|
+
lastTime !== null &&
|
|
159
|
+
nextTime - lastTime > 100
|
|
160
|
+
) {
|
|
161
|
+
code = '';
|
|
162
|
+
}
|
|
163
|
+
lastCode = nextCode;
|
|
164
|
+
lastTime = nextTime;
|
|
165
|
+
|
|
166
|
+
if (e.key === 'Enter' && code.length > 0) {
|
|
167
|
+
_codeQueryTag = true;
|
|
168
|
+
setTimeout(function () {
|
|
169
|
+
_codeQueryTag = false;
|
|
170
|
+
}, options?.scanDelay || 150);
|
|
171
|
+
callback?.(code);
|
|
172
|
+
options?.onScanEnd?.(code);
|
|
173
|
+
// 单独使用该 hooks 时,删除收集
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
uni?.__dev_tool_scan_code_collection__?.(code, 'keypress');
|
|
176
|
+
code = '';
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
onShow(() => {
|
|
181
|
+
show.value = true;
|
|
182
|
+
});
|
|
183
|
+
onHide(() => {
|
|
184
|
+
window.removeEventListener('keypress', queryCodeH5);
|
|
185
|
+
});
|
|
186
|
+
onUnload(() => {
|
|
187
|
+
window.removeEventListener('keypress', queryCodeH5);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
watch(
|
|
191
|
+
() => [options?.disabled?.value, show.value],
|
|
192
|
+
() => {
|
|
193
|
+
if (!options?.disabled?.value && show.value) {
|
|
194
|
+
window.removeEventListener('keypress', queryCodeH5);
|
|
195
|
+
window.addEventListener('keypress', queryCodeH5);
|
|
196
|
+
} else {
|
|
197
|
+
window.removeEventListener('keypress', queryCodeH5);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
immediate: true,
|
|
202
|
+
},
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// #endif
|
|
206
|
+
}
|