Skip to content

Commit 14ff9c0

Browse files
committed
完全修复JSONP回调函数参数名输入框默认值问题:1. 修改DebuggerConfig类型定义;2. 增强输入组件处理;3. 调整参数顺序
1 parent ad6cda4 commit 14ff9c0

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

src/config/ui/component/basic/input/input-component.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class InputComponent implements LanguageUpdateable {
4949
* @param onChange 值变化回调
5050
* @returns HTMLElement
5151
*/
52-
render(id: string, placeholder?: string, value?: string, label?: string, onChange?: (value: string) => void): HTMLElement {
52+
render(id: string, value?: string, placeholder?: string, label?: string, onChange?: (value: string) => void): HTMLElement {
5353
this.currentPlaceholder = placeholder;
5454
this.currentLabel = label;
5555

@@ -78,15 +78,31 @@ export class InputComponent implements LanguageUpdateable {
7878
// 为输入框设置特殊类名,用于识别真正为空的输入框
7979
input.classList.add('js-script-hook-empty-input');
8080

81+
// 先设置placeholder, 这样可以在后续逻辑中进行比较
8182
if (placeholder) {
8283
input.placeholder = placeholder;
8384
}
8485

85-
// 只有当value是有效值时,才设置value并移除空输入框标记
86-
if (value !== undefined && value !== null && value !== '') {
87-
input.value = value;
88-
input.classList.remove('js-script-hook-empty-input');
89-
}
86+
// 当焦点进入时,清除可能被错误填充的placeholder文本
87+
input.addEventListener('focus', function() {
88+
// 如果输入框的值与placeholder相同,或者被标记为空,则清空值
89+
const currentPlaceholder = this.placeholder || '';
90+
if ((this.value === currentPlaceholder && this.value !== '') ||
91+
(this.classList.contains('js-script-hook-empty-input') && this.value !== '')) {
92+
// 清空并保持聚焦
93+
this.value = '';
94+
inputLogger.debug(`焦点事件: 清空了输入框 ${id} 的值,可能是placeholder错误设置为了值`);
95+
}
96+
});
97+
98+
// 当失去焦点时的处理
99+
input.addEventListener('blur', function() {
100+
// 如果输入框为空,确保添加空输入框标记
101+
if (this.value === '') {
102+
this.classList.add('js-script-hook-empty-input');
103+
inputLogger.debug(`失焦事件: 输入框 ${id} 为空,添加空输入标记`);
104+
}
105+
});
90106

91107
// 添加事件处理
92108
if (onChange) {
@@ -104,14 +120,14 @@ export class InputComponent implements LanguageUpdateable {
104120
});
105121
}
106122

107-
// 当焦点进入时,清除可能被错误填充的placeholder文本
108-
input.addEventListener('focus', function() {
109-
// 如果输入框标记为空但有显示的值,说明可能是placeholder被错误地作为值
110-
if (this.classList.contains('js-script-hook-empty-input') && this.value !== '') {
111-
// 清空并聚焦
112-
this.value = '';
113-
}
114-
});
123+
// 只有当value是有效值时,才设置value并移除空输入框标记
124+
if (value !== undefined && value !== null && value !== '') {
125+
input.value = value;
126+
input.classList.remove('js-script-hook-empty-input');
127+
inputLogger.debug(`设置输入框 ${id} 的值为: ${value}`);
128+
} else {
129+
inputLogger.debug(`输入框 ${id} 没有设置初始值,保持为空`);
130+
}
115131

116132
this.containerElement.appendChild(input);
117133

src/config/ui/component/debugger/events.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,17 @@ export function bindDebuggerEvents(
204204
// 为callback函数名绑定事件
205205
const callbackFunctionParamNameContainer = element.querySelector(`#${debuggerInformation.id}-callback-function-param-name-container`);
206206
if (callbackFunctionParamNameContainer) {
207+
// 添加调试输出
208+
console.log(`[DEBUG] callbackFunctionName value: ${debuggerInformation.callbackFunctionName}, type: ${typeof debuggerInformation.callbackFunctionName}`);
209+
210+
// 确保空字符串和null都作为有效的空值传递给render
211+
const value = debuggerInformation.callbackFunctionName === null || debuggerInformation.callbackFunctionName === '' ?
212+
null : debuggerInformation.callbackFunctionName;
213+
207214
callbackFunctionParamNameContainer.appendChild(
208215
inputComponent.render(
209216
`${debuggerInformation.id}-callback-function-param-name-text`,
210-
debuggerInformation.callbackFunctionName,
217+
value,
211218
language.debugger_config.callbackFunctionParamNamePlaceholder,
212219
undefined,
213220
(value: string) => {

src/config/ui/component/debugger/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export interface DebuggerConfig {
2020
enableRequestDebugger: boolean;
2121
enableResponseDebugger: boolean;
2222
comment: string;
23-
callbackFunctionName: string;
23+
callbackFunctionName: string | null;
2424
}

src/config/ui/component/global-options/global-options-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ export class GlobalOptionsComponent implements LanguageUpdateable {
182182

183183
const prefixInput = this.inputComponent.render(
184184
'js-script-hook-global-config-prefix',
185-
language.global_settings.flagPrefixPlaceholder,
186185
oldConfig.prefix,
186+
language.global_settings.flagPrefixPlaceholder,
187187
undefined,
188188
(value: string) => {
189189
handlePrefixInput(value, oldConfig);

0 commit comments

Comments
 (0)