下面示例给出一个单页 HTML 管理界面,基于 Vue 3 + Element Plus,通过嵌套可展开的表格来管理 Fingerprint、Rule 和 Condition,支持增删改。所有代码放在同一个文件里,且使用 CDN 引入,无需额外构建工具。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Fingerprint 管理界面</title>
<!-- 引入 Element Plus 样式 -->
<link
rel="stylesheet"
href="https://unpkg.com/element-plus/dist/index.css"
/>
<style>
body {
padding: 20px;
}
.tag-input {
display: flex;
flex-wrap: wrap;
border: 1px solid #dcdfe6;
padding: 5px;
border-radius: 4px;
}
.tag-input input {
border: none;
outline: none;
flex: 1;
min-width: 50px;
}
.tag-input .el-tag {
margin-right: 4px;
margin-bottom: 4px;
}
</style>
</head>
<body>
<div id="app">
<el-card>
<div slot="header" class="clearfix">
<span style="line-height: 36px;">Fingerprint 管理</span>
<el-button style="float: right" type="primary" @click="openFpDialog()">新增 Fingerprint</el-button>
</div>
<el-table
:data="fingerprints"
style="width: 100%"
row-key="name"
>
<!-- 可展开行 -->
<el-table-column type="expand">
<template #default="{ row }">
<!-- Rules 表格 -->
<el-card shadow="never" style="margin-bottom: 10px;">
<div slot="header" class="clearfix">
<span>Rules of {{ row.name }}</span>
<el-button
style="float: right"
type="text" icon="el-icon-plus"
@click="openRuleDialog(row)"
>
新增 Rule
</el-button>
</div>
<el-table
:data="row.rules"
row-key="__rid__"
size="small"
style="width: 100%"
>
<el-table-column type="expand">
<template #default="{ row: rule }">
<!-- Conditions 表格 -->
<el-card shadow="never">
<div slot="header" class="clearfix">
<span>Conditions of {{ rule.Method }} {{ rule.Path }}</span>
<el-button
style="float: right"
type="text" icon="el-icon-plus"
@click="openCondDialog(rule)"
>
新增 Condition
</el-button>
</div>
<el-table
:data="rule.Conditions"
row-key="__cid__"
size="mini"
style="width: 100%"
>
<el-table-column prop="Target" label="Target" />
<el-table-column prop="Operation" label="Operation" />
<el-table-column prop="Expression" label="Expression" />
<el-table-column
label="操作"
width="140"
fixed="right"
>
<template #default="{ row: cond }">
<el-button
type="text"
size="small"
@click="editCond(rule, cond)"
>编辑</el-button>
<el-button
type="text"
size="small"
style="color:red"
@click="deleteCond(rule, cond)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
</template>
</el-table-column>
<el-table-column prop="Type" label="Type" />
<el-table-column prop="Method" label="Method" />
<el-table-column prop="Path" label="Path" />
<el-table-column prop="MatchLogic" label="Logic" />
<el-table-column
label="操作"
width="140"
fixed="right"
>
<template #default="{ row: rule }">
<el-button
type="text"
size="small"
@click="editRule(parentFp(rule), rule)"
>编辑</el-button>
<el-button
type="text"
size="small"
style="color:red"
@click="deleteRule(parentFp(rule), rule)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
</template>
</el-table-column>
<el-table-column prop="Name" label="Name" />
<el-table-column label="Tags">
<template #default="{ row }">
<el-tag
v-for="(t,i) in row.Tags"
:key="i"
type="info"
style="margin-right:4px;"
>{{ t }}</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="140" fixed="right">
<template #default="{ row }">
<el-button type="text" size="small" @click="editFp(row)">编辑</el-button>
<el-button
type="text"
size="small"
style="color:red"
@click="deleteFp(row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<!-- Fingerprint 对话框 -->
<el-dialog
:title="fpForm.isEdit ? '编辑 Fingerprint' : '新增 Fingerprint'"
:visible.sync="fpForm.visible"
width="500px"
>
<el-form :model="fpForm.data" label-width="100px">
<el-form-item label="Name">
<el-input v-model="fpForm.data.Name" />
</el-form-item>
<el-form-item label="Tags">
<div class="tag-input">
<el-tag
v-for="(tag, idx) in fpForm.data.Tags"
:key="idx"
closable
@close="fpForm.data.Tags.splice(idx,1)"
>{{ tag }}</el-tag>
<input
v-model="fpForm.newTag"
@keyup.enter="addTag"
placeholder="回车添加"
/>
</div>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="fpForm.visible=false">取消</el-button>
<el-button type="primary" @click="saveFp">保存</el-button>
</div>
</el-dialog>
<!-- Rule 对话框 -->
<el-dialog
:title="ruleForm.isEdit ? '编辑 Rule' : '新增 Rule'"
:visible.sync="ruleForm.visible"
width="600px"
>
<el-form :model="ruleForm.data" label-width="120px">
<el-form-item label="Type">
<el-select v-model="ruleForm.data.Type" placeholder="请选择">
<el-option label="response" value="response" />
<el-option label="probe" value="probe" />
</el-select>
</el-form-item>
<el-form-item label="Method">
<el-input v-model="ruleForm.data.Method" />
</el-form-item>
<el-form-item label="Path">
<el-input v-model="ruleForm.data.Path" />
</el-form-item>
<el-form-item label="MatchLogic">
<el-select v-model="ruleForm.data.MatchLogic" placeholder="and/or">
<el-option label="and" value="and" />
<el-option label="or" value="or" />
</el-select>
</el-form-item>
<el-form-item label="Headers(JSON)">
<el-input
type="textarea"
rows="3"
v-model="ruleForm.headersText"
placeholder='{"Content-Type":"application/json"}'
/>
</el-form-item>
<el-form-item label="Body">
<el-input
type="textarea"
rows="3"
v-model="ruleForm.data.Body"
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="ruleForm.visible=false">取消</el-button>
<el-button type="primary" @click="saveRule">保存</el-button>
</div>
</el-dialog>
<!-- Condition 对话框 -->
<el-dialog
:title="condForm.isEdit ? '编辑 Condition' : '新增 Condition'"
:visible.sync="condForm.visible"
width="500px"
>
<el-form :model="condForm.data" label-width="120px">
<el-form-item label="Target">
<el-input v-model="condForm.data.Target" />
</el-form-item>
<el-form-item label="Operation">
<el-select v-model="condForm.data.Operation" placeholder="contains/regex/equal">
<el-option label="contains" value="contains" />
<el-option label="regex" value="regex" />
<el-option label="equal" value="equal" />
</el-select>
</el-form-item>
<el-form-item label="Expression">
<el-input v-model="condForm.data.Expression" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="condForm.visible=false">取消</el-button>
<el-button type="primary" @click="saveCond">保存</el-button>
</div>
</el-dialog>
</div>
<!-- Vue 3 & Element Plus -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/element-plus"></script>
<script>
const { createApp, reactive, ref } = Vue;
createApp({
setup() {
// Data
const fingerprints = ref([
// 示例
{
Name: "例子1",
Tags: ["tag1", "tag2"],
rules: [
{
__rid__: Date.now(),
Type: "response",
Method: "GET",
Path: "/",
Headers: { "Content-Type": "application/json" },
Body: "",
Conditions: [
{
__cid__: 1,
Target: "body",
Operation: "contains",
Expression: "hello"
}
],
MatchLogic: "and",
}
]
}
]);
// ===== Fingerprint 对话框 =====
const fpForm = reactive({
visible: false,
isEdit: false,
data: { Name: "", Tags: [], rules: [] },
newTag: ""
});
function openFpDialog(fp = null) {
if (fp) {
fpForm.isEdit = true;
fpForm.data = JSON.parse(JSON.stringify(fp));
} else {
fpForm.isEdit = false;
fpForm.data = { Name: "", Tags: [], rules: [] };
}
fpForm.newTag = "";
fpForm.visible = true;
}
function addTag() {
const v = fpForm.newTag.trim();
if (v && !fpForm.data.Tags.includes(v)) {
fpForm.data.Tags.push(v);
}
fpForm.newTag = "";
}
function saveFp() {
if (!fpForm.data.Name) return;
if (fpForm.isEdit) {
const idx = fingerprints.value.findIndex(f => f.Name === fpForm.data.Name);
if (idx !== -1) {
fingerprints.value[idx] = JSON.parse(JSON.stringify(fpForm.data));
}
} else {
// 保证唯一
if (fingerprints.value.find(f => f.Name === fpForm.data.Name)) {
alert("Name 已存在");
return;
}
fingerprints.value.push(JSON.parse(JSON.stringify(fpForm.data)));
}
fpForm.visible = false;
}
function editFp(fp) { openFpDialog(fp); }
function deleteFp(fp) {
fingerprints.value = fingerprints.value.filter(f => f.Name !== fp.Name);
}
// ===== Rule 对话框 =====
const ruleForm = reactive({
visible: false,
isEdit: false,
data: null,
headersText: "",
parent: null,
});
function openRuleDialog(fp, rule = null) {
ruleForm.parent = fp;
if (rule) {
ruleForm.isEdit = true;
ruleForm.data = JSON.parse(JSON.stringify(rule));
} else {
ruleForm.isEdit = false;
ruleForm.data = {
__rid__: Date.now(),
Type: "",
Method: "",
Path: "",
Headers: {},
Body: "",
Conditions: [],
MatchLogic: "and"
};
}
ruleForm.headersText = JSON.stringify(ruleForm.data.Headers, null, 2);
ruleForm.visible = true;
}
function saveRule() {
try {
ruleForm.data.Headers = JSON.parse(ruleForm.headersText || "{}");
} catch (e) {
alert("Headers JSON 格式错误");
return;
}
if (ruleForm.isEdit) {
const arr = ruleForm.parent.rules;
const idx = arr.findIndex(r => r.__rid__ === ruleForm.data.__rid__);
if (idx !== -1) arr[idx] = JSON.parse(JSON.stringify(ruleForm.data));
} else {
ruleForm.parent.rules.push(JSON.parse(JSON.stringify(ruleForm.data)));
}
ruleForm.visible = false;
}
function parentFp(rule) {
return fingerprints.value.find(f => f.rules.some(r => r.__rid__ === rule.__rid__));
}
function editRule(fp, rule) { openRuleDialog(fp, rule); }
function deleteRule(fp, rule) {
fp.rules = fp.rules.filter(r => r.__rid__ !== rule.__rid__);
}
// ===== Condition 对话框 =====
const condForm = reactive({
visible: false,
isEdit: false,
data: null,
parentRule: null,
});
function openCondDialog(rule, cond = null) {
condForm.parentRule = rule;
if (cond) {
condForm.isEdit = true;
condForm.data = JSON.parse(JSON.stringify(cond));
} else {
condForm.isEdit = false;
condForm.data = { __cid__: Date.now(), Target: "", Operation: "", Expression: "" };
}
condForm.visible = true;
}
function saveCond() {
if (condForm.isEdit) {
const arr = condForm.parentRule.Conditions;
const idx = arr.findIndex(c => c.__cid__ === condForm.data.__cid__);
if (idx !== -1) arr[idx] = JSON.parse(JSON.stringify(condForm.data));
} else {
condForm.parentRule.Conditions.push(JSON.parse(JSON.stringify(condForm.data)));
}
condForm.visible = false;
}
function editCond(rule, cond) { openCondDialog(rule, cond); }
function deleteCond(rule, cond) {
rule.Conditions = rule.Conditions.filter(c => c.__cid__ !== cond.__cid__);
}
return {
fingerprints,
fpForm, openFpDialog, saveFp, editFp, deleteFp, addTag,
ruleForm, openRuleDialog, saveRule, editRule, deleteRule, parentFp,
condForm, openCondDialog, saveCond, editCond, deleteCond
};
}
}).use(ElementPlus).mount("#app");
</script>
</body>
</html>
说明
- 整个页面只有一个 HTML 文件,通过 CDN 引入 Vue 3、Element Plus,无需额外构建。
- 父表格列出 Fingerprint,展开行后展示其 Rules;Rule 同样可展开显示内部的 Conditions。
- 使用三个
el-dialog 弹窗分别处理 Fingerprint/Rule/Condition 的增删改。
- Tags 输入框采用自定义的简单方案:回车添加标签,可关闭删除。
你可以根据实际后端 API 把 fingerprints 更换为从服务器拉取的数据,saveFp/saveRule/saveCond 中再调用对应的 REST 接口即可。这样就可以在一个页面内完成所有管理操作了。希望对你有帮助! 😃