Skip to content

Commit 85e7fe4

Browse files
author
githubnull
committed
feat: HTTP方法颜色语义化显示,点击扫描URL跳转HTTP信息页
1 parent 3c65223 commit 85e7fe4

2 files changed

Lines changed: 66 additions & 4 deletions

File tree

src/frontEnd/src/utils/requestFormatter.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,33 @@ export function highlightHttpRequest(lines: string[], searchKeyword?: string, op
9999
const url = parts.slice(1, -1).join(' ') || ''
100100
const version = parts[parts.length - 1] || ''
101101

102-
highlightedLine = `<span style="background-color:#8b5cf6 !important; color:#ffffff !important; font-weight:bold !important; padding:2px 6px !important; border-radius:4px !important; font-size:12px !important; display:inline-block !important; margin-right:8px !important; border:1px solid #7c3aed !important;">${escapeHtml(method)}</span>` +
103-
`<span style="color:#34d399 !important; text-decoration:underline !important; font-weight:600 !important;">${escapeHtml(url)}</span>` +
104-
` <span style="color:#06b6d4 !important; font-weight:600 !important;">${escapeHtml(version)}</span>`
102+
// 根据HTTP方法的安全性/危险程度标记颜色
103+
// GET/HEAD/OPTIONS: 绿色(只读,安全)
104+
// POST/PUT/PATCH: 橙色(写入,有影响)
105+
// DELETE: 红色(危险,删除数据)
106+
let methodColor = '#10b981' // 默认绿色(安全)
107+
let methodBgColor = '#10b981'
108+
let methodBorderColor = '#059669'
109+
110+
const upperMethod = method.toUpperCase()
111+
if (['POST', 'PUT', 'PATCH'].includes(upperMethod)) {
112+
// 写入方法 - 橙色
113+
methodBgColor = '#f59e0b'
114+
methodBorderColor = '#d97706'
115+
} else if (upperMethod === 'DELETE') {
116+
// 删除方法 - 红色
117+
methodBgColor = '#ef4444'
118+
methodBorderColor = '#dc2626'
119+
} else {
120+
// GET/HEAD/OPTIONS等只读方法 - 绿色
121+
methodBgColor = '#10b981'
122+
methodBorderColor = '#059669'
123+
}
124+
125+
// 请求方法、PATH、版本字体大小一致,都使用 inherit 继承父元素的22px
126+
highlightedLine = `<span style="background-color:${methodBgColor} !important; color:#ffffff !important; font-weight:bold !important; padding:4px 10px !important; border-radius:6px !important; font-size:inherit !important; display:inline-block !important; margin-right:10px !important; border:1px solid ${methodBorderColor} !important; vertical-align:middle !important;">${escapeHtml(method)}</span>` +
127+
`<span style="color:#34d399 !important; text-decoration:underline !important; font-weight:600 !important; font-size:inherit !important;">${escapeHtml(url)}</span>` +
128+
` <span style="color:#06b6d4 !important; font-weight:600 !important; font-size:inherit !important;">${escapeHtml(version)}</span>`
105129
}
106130
} else if (!isBody) {
107131
// 2. HTTP头高亮

src/frontEnd/src/views/TaskList/index.vue

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@
8585
</Column>
8686
<Column field="scanUrl" header="扫描URL" :style="{ minWidth: '250px', maxWidth: '600px' }" sortable>
8787
<template #body="{ data }">
88-
<div class="url-cell" :title="data.scanUrl">
88+
<div
89+
class="url-cell clickable-url"
90+
:title="'点击查看HTTP请求信息'"
91+
@click="goToTaskHttpInfo(data)"
92+
>
8993
{{ data.scanUrl }}
9094
</div>
9195
</template>
@@ -98,6 +102,9 @@
98102
:value="data.injected ? '存在注入' : '无注入'"
99103
:severity="data.injected ? 'danger' : 'success'"
100104
:icon="data.injected ? 'pi pi-exclamation-triangle' : 'pi pi-check-circle'"
105+
:class="{ 'clickable-tag': data.injected }"
106+
@click="data.injected && goToTaskResults(data)"
107+
v-tooltip.top="data.injected ? '点击查看扫描结果' : ''"
101108
/>
102109
<Tag v-else value="未知" severity="secondary" icon="pi pi-question-circle" />
103110
</template>
@@ -428,6 +435,16 @@ function goToTaskLogs(task: any) {
428435
router.push({ path: `/tasks/${task.taskid}`, query: { tab: '4' } })
429436
}
430437
438+
function goToTaskResults(task: any) {
439+
// 跳转到任务详情页的扫描结果标签页(value="3")
440+
router.push({ path: `/tasks/${task.taskid}`, query: { tab: '3' } })
441+
}
442+
443+
function goToTaskHttpInfo(task: any) {
444+
// 跳转到任务详情页的HTTP请求信息标签页(value="1")
445+
router.push({ path: `/tasks/${task.taskid}`, query: { tab: '1' } })
446+
}
447+
431448
async function stopTask(taskId: string) {
432449
await taskStore.stopTask(taskId)
433450
}
@@ -745,6 +762,27 @@ function confirmDeleteAll() {
745762
}
746763
}
747764
765+
// 可点击URL样式
766+
.clickable-url {
767+
cursor: pointer;
768+
color: #6366f1;
769+
text-decoration: none;
770+
transition: all 0.2s ease;
771+
772+
&:hover {
773+
color: #4f46e5;
774+
background: rgba(99, 102, 241, 0.1);
775+
text-decoration: underline;
776+
transform: translateY(-1px);
777+
box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
778+
border-radius: 4px;
779+
}
780+
781+
&:active {
782+
transform: translateY(0);
783+
}
784+
}
785+
748786
.clickable-id {
749787
cursor: pointer;
750788
padding: 4px 8px;

0 commit comments

Comments
 (0)