feat: 添加盒子起始号建议功能,优化盒子创建和更新界面
This commit is contained in:
25
templates/error.html
Normal file
25
templates/error.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ status_code }} - {{ title }}</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<header class="hero slim">
|
||||
<h1>{{ status_code }} - {{ title }}</h1>
|
||||
<a class="btn btn-light" href="{{ url_for('index') }}">回到首页</a>
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
<section class="panel">
|
||||
<p class="alert">{{ message }}</p>
|
||||
<div class="actions" style="margin-top: 10px;">
|
||||
<a class="btn" href="{{ back_url }}">返回上一页</a>
|
||||
<button class="btn btn-light" type="button" onclick="history.back()">浏览器返回</button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -16,7 +16,7 @@
|
||||
<h2>容器列表</h2>
|
||||
|
||||
{% for key, meta in box_types.items() %}
|
||||
<section class="group-panel panel">
|
||||
<section class="group-panel panel" id="group-{{ key }}">
|
||||
<div class="group-title-row">
|
||||
<h3>{{ meta.label }}</h3>
|
||||
<span class="group-desc">{{ meta.default_desc }}</span>
|
||||
@@ -28,7 +28,9 @@
|
||||
<input type="text" name="slot_prefix" placeholder="前缀(如A/B/C)">
|
||||
<input type="number" name="start_number" min="0" value="1" placeholder="起始序号">
|
||||
<input type="text" name="description" placeholder="备注(可选)">
|
||||
<button class="btn btn-light suggest-start-btn" type="button" data-box-type="{{ key }}">建议起始号</button>
|
||||
<button class="btn" type="submit">新增盒子</button>
|
||||
<span class="hint suggest-preview"></span>
|
||||
</form>
|
||||
|
||||
<section class="box-list">
|
||||
@@ -67,7 +69,9 @@
|
||||
<input type="text" name="slot_prefix" value="{{ item.box.slot_prefix }}" required>
|
||||
<input type="number" name="start_number" min="0" value="{{ item.box.start_number }}" required>
|
||||
<input type="text" name="description" value="{{ item.box.description or '' }}">
|
||||
<button class="btn btn-light suggest-start-btn" type="button" data-box-id="{{ item.box.id }}" data-box-type="{{ item.box.box_type }}">建议起始号</button>
|
||||
<button class="btn" type="submit">保存设置</button>
|
||||
<span class="hint suggest-preview"></span>
|
||||
</form>
|
||||
</details>
|
||||
</article>
|
||||
@@ -78,5 +82,61 @@
|
||||
</section>
|
||||
{% endfor %}
|
||||
</main>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
function updateSuggest(form, payload) {
|
||||
var startInput = form.querySelector('input[name="start_number"]');
|
||||
var prefixInput = form.querySelector('input[name="slot_prefix"]');
|
||||
var preview = form.querySelector('.suggest-preview');
|
||||
|
||||
if (startInput) {
|
||||
startInput.value = payload.start_number;
|
||||
}
|
||||
if (prefixInput && !prefixInput.value.trim()) {
|
||||
prefixInput.value = payload.slot_prefix;
|
||||
}
|
||||
if (preview) {
|
||||
preview.textContent = '建议范围: ' + payload.preview_range;
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelectorAll('.suggest-start-btn').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var form = btn.closest('form');
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
|
||||
var prefixInput = form.querySelector('input[name="slot_prefix"]');
|
||||
var boxType = btn.dataset.boxType || 'small_28';
|
||||
var boxId = btn.dataset.boxId || '';
|
||||
var prefix = prefixInput ? prefixInput.value.trim() : '';
|
||||
|
||||
var params = new URLSearchParams();
|
||||
params.set('box_type', boxType);
|
||||
if (prefix) {
|
||||
params.set('slot_prefix', prefix);
|
||||
}
|
||||
if (boxId) {
|
||||
params.set('box_id', boxId);
|
||||
}
|
||||
|
||||
fetch('{{ url_for('suggest_start') }}?' + params.toString())
|
||||
.then(function (resp) { return resp.json(); })
|
||||
.then(function (data) {
|
||||
if (!data.ok) {
|
||||
alert(data.message || '建议起始号失败');
|
||||
return;
|
||||
}
|
||||
updateSuggest(form, data);
|
||||
})
|
||||
.catch(function () {
|
||||
alert('建议起始号失败,请稍后重试');
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user