Skip to content

Commit 57c3b8b

Browse files
committed
:bugfix: :绑定事件时,如果开启扩展参数,添加后的函数对扩展参数处理有问题,导致JS面板报错
1 parent 13ef4b3 commit 57c3b8b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/plugin/plugin-event-bind-dialog/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import './index.less';
99
const defaultParams = '{\n \t "testKey":123 \n}';
1010
// 模板变量占位
1111
const tempPlaceHolder = '${extParams}';
12+
const tempPlaceHolderReg = /\$\{extParams\}/g;
13+
1214
const defaultEditorOption = {
1315
style: { width: '100%', height: '319px' },
1416
readOnly: false,
@@ -179,7 +181,7 @@ export default class EventBindDialog extends Component<PluginProps> {
179181

180182
onSearchEvent = () => {};
181183

182-
onChange = (checked) => {
184+
onChange = (checked: boolean) => {
183185
this.setState({
184186
useParams: checked,
185187
});
@@ -196,22 +198,23 @@ export default class EventBindDialog extends Component<PluginProps> {
196198
}
197199
};
198200

199-
pickupFunctionName = (codeStr) => {
201+
pickupFunctionName = (codeStr: string) => {
200202
return codeStr.substr(0, codeStr.indexOf('('));
201203
};
202204

203-
removeSpace = (str) => {
205+
removeSpace = (str: string) => {
204206
return str.replace(/\s*/g, '');
205207
};
206208

207-
formatTemplate = (template, eventName, useParams) => {
209+
formatTemplate = (template: string, eventName: string, useParams: boolean) => {
208210
let formatTemp;
209211
if (template) {
210212
const functionName = this.pickupFunctionName(template);
211213

212214
formatTemp = template.replace(new RegExp('^s*' + functionName), eventName);
213215
if (useParams) {
214-
formatTemp = formatTemp.replace(/tempPlaceHolder/g, 'extParams');
216+
formatTemp = formatTemp.replace(tempPlaceHolderReg, 'extParams');
217+
215218
} else {
216219
const leftIndex = formatTemp.indexOf('(');
217220
const rightIndex = formatTemp.indexOf(')');
@@ -240,7 +243,7 @@ export default class EventBindDialog extends Component<PluginProps> {
240243
return formatTemp;
241244
};
242245

243-
formatEventName = (eventName) => {
246+
formatEventName = (eventName: string) => {
244247
const newEventNameArr = eventName.split('');
245248
const index = eventName.indexOf('.');
246249
if (index >= 0) {
@@ -283,7 +286,7 @@ export default class EventBindDialog extends Component<PluginProps> {
283286
this.closeDialog();
284287
};
285288

286-
onChangeEditor = (paramStr) => {
289+
onChangeEditor = (paramStr: string) => {
287290
this.setState({
288291
paramStr,
289292
});
@@ -370,7 +373,7 @@ export default class EventBindDialog extends Component<PluginProps> {
370373
value={paramStr}
371374
{...defaultEditorOption}
372375
{...{ language: 'json' }}
373-
onChange={(newCode) => this.onChangeEditor(newCode)}
376+
onChange={(newCode: string) => this.onChangeEditor(newCode)}
374377
/>
375378
{!useParams && <div className="mask" />}
376379
</div>

0 commit comments

Comments
 (0)