180 lines
4.7 KiB
HTML
180 lines
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>字段配置示例</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial;
|
|
padding: 20px;
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
th,
|
|
td {
|
|
border: 1px solid #ccc;
|
|
padding: 8px;
|
|
}
|
|
|
|
.config-row td {
|
|
background: #fafafa;
|
|
padding: 15px;
|
|
}
|
|
|
|
.config-panel {
|
|
display: flex;
|
|
gap: 20px;
|
|
}
|
|
|
|
.config-group {
|
|
flex: 1;
|
|
border: 1px solid #ddd;
|
|
padding: 10px;
|
|
border-radius: 6px;
|
|
background: white;
|
|
}
|
|
|
|
.config-group h4 {
|
|
margin-top: 0;
|
|
}
|
|
|
|
.config-item {
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.config-item label {
|
|
display: block;
|
|
font-size: 12px;
|
|
color: #666;
|
|
}
|
|
|
|
.config-item input[type="text"],
|
|
.config-item input[type="number"],
|
|
.config-item textarea {
|
|
width: 100%;
|
|
padding: 5px;
|
|
margin-top: 2px;
|
|
box-sizing: border-box;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>字段配置示例</h2>
|
|
|
|
<table id="fieldTable">
|
|
<thead>
|
|
<tr>
|
|
<th>字段名</th>
|
|
<th>类型</th>
|
|
<th>必填</th>
|
|
<th style="width: 80px">操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="fieldTableBody">
|
|
</tbody>
|
|
</table>
|
|
|
|
<script>
|
|
const fields = [
|
|
{ id: 1, name: "username", type: "string", required: true, default: "", repeat: false, maxLen: 20, desc: "" },
|
|
{ id: 2, name: "age", type: "number", required: false, default: 0, repeat: false, maxLen: 3, desc: "" },
|
|
];
|
|
|
|
let openConfigRowId = null;
|
|
|
|
function renderTable() {
|
|
const tbody = document.getElementById("fieldTableBody");
|
|
tbody.innerHTML = "";
|
|
|
|
fields.forEach(field => {
|
|
// 主行
|
|
const tr = document.createElement("tr");
|
|
tr.innerHTML = `
|
|
<td>${field.name}</td>
|
|
<td>${field.type}</td>
|
|
<td>${field.required ? "是" : "否"}</td>
|
|
<td><button onclick="toggleConfig(${field.id})">配置</button></td>
|
|
`;
|
|
tbody.appendChild(tr);
|
|
|
|
// 配置行
|
|
if (openConfigRowId === field.id) {
|
|
const cfgRow = document.createElement("tr");
|
|
cfgRow.className = "config-row";
|
|
cfgRow.innerHTML = `
|
|
<td colspan="4">
|
|
${renderConfigPanel(field)}
|
|
</td>
|
|
`;
|
|
tbody.appendChild(cfgRow);
|
|
}
|
|
});
|
|
}
|
|
|
|
function toggleConfig(id) {
|
|
openConfigRowId = openConfigRowId === id ? null : id;
|
|
renderTable();
|
|
}
|
|
|
|
function renderConfigPanel(field) {
|
|
return `
|
|
<div class="config-panel">
|
|
|
|
<div class="config-group">
|
|
<h4>基础配置</h4>
|
|
<div class="config-item">
|
|
<label>字段名</label>
|
|
<input type="text" value="${field.name}" oninput="updateField(${field.id}, 'name', this.value)">
|
|
</div>
|
|
<div class="config-item">
|
|
<label>默认值</label>
|
|
<input type="text" value="${field.default}" oninput="updateField(${field.id}, 'default', this.value)">
|
|
</div>
|
|
<div class="config-item">
|
|
<label><input type="checkbox" ${field.repeat ? "checked" : ""} onchange="updateField(${field.id}, 'repeat', this.checked)"> 可重复</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="config-group">
|
|
<h4>校验配置</h4>
|
|
<div class="config-item">
|
|
<label>必填</label>
|
|
<input type="checkbox" ${field.required ? "checked" : ""} onchange="updateField(${field.id}, 'required', this.checked)">
|
|
</div>
|
|
<div class="config-item">
|
|
<label>最大长度</label>
|
|
<input type="number" value="${field.maxLen}" oninput="updateField(${field.id}, 'maxLen', this.value)">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="config-group">
|
|
<h4>展示配置</h4>
|
|
<div class="config-item">
|
|
<label>说明</label>
|
|
<textarea rows="4" oninput="updateField(${field.id}, 'desc', this.value)">${field.desc}</textarea>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function updateField(id, key, value) {
|
|
const field = fields.find(f => f.id === id);
|
|
field[key] = value;
|
|
}
|
|
|
|
renderTable();
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html> |