Skip to content

Commit bd115c6

Browse files
committed
refactor(ui): 重构debugger组件使用统一的TipsComponent
1 parent 3932b83 commit bd115c6

File tree

4 files changed

+201
-122
lines changed

4 files changed

+201
-122
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class DebuggerComponent implements LanguageUpdateable {
3434
private currentLanguage: Language | undefined;
3535
private currentConfig: DebuggerConfig | undefined;
3636
private componentElement: HTMLElement | null = null;
37+
private tipsInstances: { [key: string]: TipsComponent } = {}; // 存储tips实例的映射表
3738

3839
constructor() {
3940
this.componentId = 'debugger-component';
@@ -96,6 +97,11 @@ export class DebuggerComponent implements LanguageUpdateable {
9697
const tempContainer = document.createElement('div');
9798
tempContainer.innerHTML = createDebuggerTemplate(language, debuggerInformation);
9899
this.componentElement = tempContainer.firstElementChild as HTMLElement;
100+
101+
// 渲染所有的tips组件
102+
if (this.componentElement) {
103+
this.renderTipsComponents(language, debuggerInformation.id);
104+
}
99105

100106
// 绑定事件处理
101107
bindDebuggerEvents(
@@ -114,6 +120,53 @@ export class DebuggerComponent implements LanguageUpdateable {
114120

115121
return this.componentElement;
116122
}
123+
124+
/**
125+
* 渲染所有tips组件
126+
* @param language 语言配置
127+
* @param debuggerId 断点ID
128+
*/
129+
private renderTipsComponents(language: Language, debuggerId: string): void {
130+
if (!this.componentElement) return;
131+
132+
// 为每个提示容器渲染TipsComponent
133+
const tipsConfig = [
134+
{ containerId: `${debuggerId}-enable-tip-container`, tipText: language.debugger_config.enableTips },
135+
{ containerId: `${debuggerId}-url-pattern-tip-container`, tipText: language.debugger_config.urlPatternTips },
136+
{ containerId: `${debuggerId}-url-pattern-text-tip-container`, tipText: language.debugger_config.urlPatternTextTips },
137+
{ containerId: `${debuggerId}-url-pattern-test-tip-container`, tipText: language.debugger_config.urlPatternTestTips },
138+
{ containerId: `${debuggerId}-enable-request-debugger-tip-container`, tipText: language.debugger_config.enableRequestDebuggerTips },
139+
{ containerId: `${debuggerId}-enable-response-debugger-tip-container`, tipText: language.debugger_config.enableResponseDebuggerTips },
140+
{ containerId: `${debuggerId}-callback-function-param-name-tip-container`, tipText: language.debugger_config.callbackFunctionParamNameTips },
141+
{ containerId: `${debuggerId}-comment-tip-container`, tipText: language.debugger_config.commentTips }
142+
];
143+
144+
// 清理旧的tips实例
145+
for (const key in this.tipsInstances) {
146+
if (this.tipsInstances[key]) {
147+
this.tipsInstances[key].destroy();
148+
}
149+
}
150+
this.tipsInstances = {};
151+
152+
for (const config of tipsConfig) {
153+
const container = this.componentElement.querySelector(`#${config.containerId}`);
154+
if (container) {
155+
// 先清空容器内容
156+
container.innerHTML = '';
157+
158+
// 创建新的TipsComponent实例
159+
const tipComponent = new TipsComponent();
160+
const tipElement = tipComponent.render(config.tipText);
161+
162+
// 保存tips实例以便后续管理
163+
this.tipsInstances[config.containerId] = tipComponent;
164+
165+
// 将tip元素添加到容器中
166+
container.appendChild(tipElement);
167+
}
168+
}
169+
}
117170

118171
/**
119172
* 实现LanguageUpdateable接口
@@ -131,6 +184,9 @@ export class DebuggerComponent implements LanguageUpdateable {
131184
return;
132185
}
133186

187+
// 更新语言时重新渲染所有tips组件
188+
this.renderTipsComponents(language, this.currentConfig.id);
189+
134190
updateDebuggerLanguage(
135191
this.componentElement,
136192
language,
@@ -171,6 +227,14 @@ export class DebuggerComponent implements LanguageUpdateable {
171227
if (this.tipsComponent) {
172228
this.tipsComponent.destroy();
173229
}
230+
231+
// 销毁所有tips实例
232+
for (const key in this.tipsInstances) {
233+
if (this.tipsInstances[key]) {
234+
this.tipsInstances[key].destroy();
235+
}
236+
}
237+
this.tipsInstances = {};
174238

175239
// 移除DOM元素
176240
if (this.componentElement) {

src/config/ui/component/debugger/language-update.ts

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,14 @@ export function updateDebuggerLanguage(
6868
// 强制更新每一行的标签文本
6969
updateRowLabel(rows[0], language.debugger_config.enable);
7070
updateRowLabel(rows[1], language.debugger_config.urlPattern);
71-
updateRowLabel(rows[2], language.debugger_config.urlPattern);
71+
updateRowLabel(rows[2], language.debugger_config.urlPatternKeyword);
7272
updateRowLabel(rows[3], language.debugger_config.urlPatternTest);
7373
updateRowLabel(rows[4], language.debugger_config.enableRequestDebugger);
7474
updateRowLabel(rows[5], language.debugger_config.enableResponseDebugger);
7575
updateRowLabel(rows[6], language.debugger_config.callbackFunctionParamName);
7676
updateRowLabel(rows[7], language.debugger_config.comment);
7777

78-
// 更新提示信息
79-
updateRowTooltip(rows[0], language.debugger_config.enableTips);
80-
updateRowTooltip(rows[1], language.debugger_config.urlPatternTips);
81-
updateRowTooltip(rows[2], language.debugger_config.urlPatternTextTips);
82-
updateRowTooltip(rows[3], language.debugger_config.urlPatternTestTips);
83-
updateRowTooltip(rows[4], language.debugger_config.enableRequestDebuggerTips);
84-
updateRowTooltip(rows[5], language.debugger_config.enableResponseDebuggerTips);
85-
updateRowTooltip(rows[6], language.debugger_config.callbackFunctionParamNameTips);
86-
updateRowTooltip(rows[7], language.debugger_config.commentTips);
78+
// 不再需要直接更新提示信息,因为TipsComponent会处理这部分
8779
}
8880

8981
// 更新子组件的语言
@@ -112,9 +104,7 @@ export function updateDebuggerLanguage(
112104
if (textareaComponent) {
113105
textareaComponent.updateLanguage(language);
114106
}
115-
if (tipsComponent) {
116-
tipsComponent.updateLanguage(language);
117-
}
107+
// tipsComponent由DebuggerComponent中的renderTipsComponents方法更新,无需在此处理
118108

119109
// 直接更新所有输入框的placeholder
120110
updateAllInputPlaceholders(componentElement, language, currentConfig, inputComponent);
@@ -138,28 +128,13 @@ export function updateDebuggerLanguage(
138128
function updateRowLabel(row: Element | null, text: string): void {
139129
if (!row) return;
140130

141-
// 获取右侧单元格中的span标签
142-
const label = row.querySelector('td[align="right"] span:last-child');
131+
// 获取右侧单元格中的标签文本元素
132+
const label = row.querySelector('td[align="right"] .label-text');
143133
if (label) {
144134
label.textContent = text;
145135
}
146136
}
147137

148-
/**
149-
* 更新行中的提示信息
150-
* @param row 表格行
151-
* @param tooltipText 提示文本
152-
*/
153-
function updateRowTooltip(row: Element | null, tooltipText: string): void {
154-
if (!row) return;
155-
156-
// 获取提示元素
157-
const tooltip = row.querySelector('.js-script-hook-tooltip');
158-
if (tooltip) {
159-
tooltip.textContent = tooltipText;
160-
}
161-
}
162-
163138
/**
164139
* 强制更新所有文本标签
165140
* 使用多种选择器查找所有可能的标签元素,确保语言切换时全部更新
@@ -169,8 +144,8 @@ function updateRowTooltip(row: Element | null, tooltipText: string): void {
169144
function forceUpdateAllTextLabels(componentElement: HTMLElement, language: Language): void {
170145
if (!componentElement) return;
171146

172-
// 1. 获取所有字段标签并根据内容标识它们
173-
const allLabelSpans = componentElement.querySelectorAll('td[align="right"] span');
147+
// 获取所有字段标签并根据内容标识它们
148+
const allLabelSpans = componentElement.querySelectorAll('td[align="right"] .label-text');
174149

175150
allLabelSpans.forEach(span => {
176151
const text = span.textContent?.trim() || '';
@@ -198,45 +173,6 @@ function forceUpdateAllTextLabels(componentElement: HTMLElement, language: Langu
198173
span.textContent = language.debugger_config.urlPatternTest;
199174
}
200175
});
201-
202-
// 2. 对于嵌套在表格行中的标签,使用行索引方法再次更新
203-
const rows = componentElement.querySelectorAll('.debugger-component-table tr');
204-
if (rows && rows.length > 0) {
205-
// 对关键行强制更新
206-
if (rows[4]) {
207-
updateRowLabel(rows[4], language.debugger_config.enableRequestDebugger);
208-
}
209-
if (rows[5]) {
210-
updateRowLabel(rows[5], language.debugger_config.enableResponseDebugger);
211-
}
212-
if (rows[6]) {
213-
updateRowLabel(rows[6], language.debugger_config.callbackFunctionParamName);
214-
}
215-
if (rows[7]) {
216-
updateRowLabel(rows[7], language.debugger_config.comment);
217-
}
218-
}
219-
220-
// 3. 检查是否有特定ID的字段可以直接更新
221-
const requestLabel = componentElement.querySelector('#request-debugger-label');
222-
if (requestLabel) {
223-
requestLabel.textContent = language.debugger_config.enableRequestDebugger;
224-
}
225-
226-
const responseLabel = componentElement.querySelector('#response-debugger-label');
227-
if (responseLabel) {
228-
responseLabel.textContent = language.debugger_config.enableResponseDebugger;
229-
}
230-
231-
const callbackLabel = componentElement.querySelector('#callback-function-label');
232-
if (callbackLabel) {
233-
callbackLabel.textContent = language.debugger_config.callbackFunctionParamName;
234-
}
235-
236-
const commentLabel = componentElement.querySelector('#comment-label');
237-
if (commentLabel) {
238-
commentLabel.textContent = language.debugger_config.comment;
239-
}
240176
}
241177

242178
/**

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

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export const debuggerStyles = `
5959
}
6060
6161
.debugger-component-table tr {
62-
height: 38px;
62+
min-height: 38px;
63+
height: auto;
6364
vertical-align: middle;
6465
}
6566
@@ -69,10 +70,10 @@ export const debuggerStyles = `
6970
}
7071
7172
.debugger-component-table td[align="right"] {
72-
width: 200px;
73+
width: 300px;
7374
text-align: right;
7475
padding-right: 15px;
75-
white-space: nowrap;
76+
white-space: normal;
7677
}
7778
7879
.debugger-component-table td[align="left"] {
@@ -99,4 +100,106 @@ export const debuggerStyles = `
99100
line-height: 28px;
100101
padding: 0 10px;
101102
}
103+
104+
/* Tips和标签布局容器 */
105+
.tips-label-container {
106+
display: inline-flex;
107+
align-items: center;
108+
justify-content: flex-end;
109+
width: 100%;
110+
min-height: 26px;
111+
gap: 4px;
112+
}
113+
114+
/* Tips容器样式 */
115+
.tip-container {
116+
display: inline-block;
117+
flex-shrink: 0;
118+
margin-right: 0;
119+
width: 16px;
120+
height: 16px;
121+
}
122+
123+
/* 标签文本样式 */
124+
.label-text {
125+
display: inline-block;
126+
vertical-align: middle;
127+
word-break: break-word;
128+
line-height: 1.3;
129+
padding-top: 1px;
130+
}
131+
132+
/* 原生问号样式覆盖,避免与tips冲突 */
133+
.breakpoint-question-mark {
134+
display: none !important;
135+
}
136+
137+
/* 隐藏ServerGo界面的原生问号标记 */
138+
.breakpoint-configuration .questionmark {
139+
display: none !important;
140+
}
141+
142+
/* 隐藏任何出现在我们组件外围的问号 */
143+
.js-script-hook-debugger-list > div > .questionmark,
144+
.breakpoint-configuration > .questionmark,
145+
#js-script-hook-debugger-list ~ .questionmark,
146+
.debugger-component-fieldset ~ .questionmark {
147+
display: none !important;
148+
}
149+
150+
/* 隐藏任何问号字符 */
151+
.js-script-hook-debugger-list .questionmark,
152+
#js-script-hook-debugger-list .questionmark {
153+
display: none !important;
154+
}
155+
156+
/* 可能的通用类,隐藏所有原生问号 */
157+
.js-script-hook-modal .questionmark,
158+
.js-script-hook-modal-content .questionmark {
159+
display: none !important;
160+
}
161+
162+
/* 增强问号隐藏规则 */
163+
.js-script-hook-modal *[class*="uestion"],
164+
.breakpoint-configuration *[class*="uestion"] {
165+
display: none !important;
166+
}
167+
168+
/* 针对箭头指向的问号 */
169+
.breakpoint-configuration > * > .questionmark {
170+
display: none !important;
171+
}
172+
173+
/* 修复ServerGo断点配置界面的布局问题 */
174+
.breakpoint-configuration {
175+
/* 确保内容不超出容器 */
176+
max-width: 100%;
177+
}
178+
179+
/* 调整实际界面中的问号与标签对齐 */
180+
.breakpoint-configuration td:first-child {
181+
width: 10px !important;
182+
padding-right: 4px !important;
183+
white-space: nowrap;
184+
}
185+
186+
/* 使标签靠近问号 */
187+
.breakpoint-configuration td[align="right"],
188+
.breakpoint-configuration td:nth-child(2) {
189+
text-align: left !important;
190+
padding-left: 5px !important;
191+
width: auto !important;
192+
}
193+
194+
/* 直接针对红框中的JSONP回调函数布局问题 */
195+
.breakpoint-configuration tr:nth-child(6) td,
196+
.breakpoint-configuration tr:nth-child(6) td * {
197+
vertical-align: top !important;
198+
display: inline-block;
199+
}
200+
201+
/* 强制所有标签左对齐 */
202+
.breakpoint-configuration table tr td {
203+
text-align: left !important;
204+
}
102205
`;

0 commit comments

Comments
 (0)