Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e02ce7

Browse files
Merge pull request#2042 from iamfaran/fix/scanner
[Fix]: Scanner duplicate code, and open URL on success
2 parentsae4a1a2 +022cd51 commit6e02ce7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎client/packages/lowcoder/src/comps/comps/buttonComp/scannerComp.tsx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import React, {
3030
useState,
3131
useContext,
3232
}from"react";
33-
import{arrayStringExposingStateControl}from"comps/controls/codeStateControl";
33+
import{arrayStringExposingStateControl,stringExposingStateControl}from"comps/controls/codeStateControl";
3434
import{BoolControl}from"comps/controls/boolControl";
3535
import{RefControl}from"comps/controls/refControl";
3636
import{EditorContext}from"comps/editorState";
@@ -120,6 +120,7 @@ const BarcodeScannerComponent = React.lazy(
120120
constScannerTmpComp=(function(){
121121
constchildrenMap={
122122
data:arrayStringExposingStateControl("data"),
123+
value:stringExposingStateControl("value"),
123124
text:withDefault(StringControl,trans("scanner.text")),
124125
continuous:BoolControl,
125126
uniqueData:withDefault(BoolControl,true),
@@ -150,17 +151,27 @@ const ScannerTmpComp = (function () {
150151
},[success,showModal]);
151152

152153
constcontinuousValue=useRef<string[]>([]);
154+
constseenSetRef=useRef<Set<string>>(newSet());
153155

154156
consthandleUpdate=(err:any,result:any)=>{
155157
if(result){
156158
if(props.continuous){
157-
continuousValue.current=[...continuousValue.current,result.text];
159+
constscannedText:string=result.text;
160+
if(props.uniqueData&&seenSetRef.current.has(scannedText)){
161+
return;
162+
}
163+
continuousValue.current=[...continuousValue.current,scannedText];
164+
if(props.uniqueData){
165+
seenSetRef.current.add(scannedText);
166+
}
158167
constval=props.uniqueData
159168
?[...newSet(continuousValue.current)]
160169
:continuousValue.current;
170+
props.value.onChange(scannedText);
161171
props.data.onChange(val);
162172
props.onEvent("success");
163173
}else{
174+
props.value.onChange(result.text);
164175
props.data.onChange([result.text]);
165176
setShowModal(false);
166177
setSuccess(true);
@@ -205,6 +216,7 @@ const ScannerTmpComp = (function () {
205216
props.onEvent("click");
206217
setShowModal(true);
207218
continuousValue.current=[];
219+
seenSetRef.current=newSet();
208220
}}
209221
>
210222
<span>{props.text}</span>
@@ -317,6 +329,7 @@ const ScannerTmpComp = (function () {
317329

318330
exportconstScannerComp=withExposingConfigs(ScannerTmpComp,[
319331
newNameConfig("data",trans("data")),
332+
newNameConfig("value",trans("value")),
320333
newNameConfig("text",trans("button.textDesc")),
321334
...CommonNameConfig,
322335
]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp