feat: add version and updatedAt fields with export check and display
This commit is contained in:
+10
-1
@@ -431,6 +431,7 @@ body {
|
||||
<div class="header">
|
||||
<h1 id="configName">PC装机配置表 - 编辑器</h1>
|
||||
<div class="header-actions">
|
||||
<span class="version-info" style="font-size:13px;color:#999;margin-right:8px">版本: <input type="text" id="versionInput" value="1.0.0" style="width:80px;padding:2px 6px;border:1px solid #d9d9d9;border-radius:4px;font-size:13px" onchange="config.version=this.value"></span>
|
||||
<button class="btn btn-default btn-sm" onclick="openLocalFile()">打开文件</button>
|
||||
<button class="btn btn-primary btn-sm" onclick="exportJSON()">导出JSON</button>
|
||||
</div>
|
||||
@@ -551,7 +552,8 @@ body {
|
||||
|
||||
<script>
|
||||
// ========== State ==========
|
||||
let config = { configName: 'PC装机配置表', components: [] };
|
||||
let config = { configName: 'PC装机配置表', version: '1.0.0', updatedAt: '', components: [] };
|
||||
let initialVersion = '1.0.0';
|
||||
let tempAlts = [];
|
||||
|
||||
const PRESET_TYPES = ['CPU', '主板', '显卡', '内存', '硬盘', '电源', '机箱', '散热器', '显示器'];
|
||||
@@ -666,6 +668,8 @@ function handleFileImport(event) {
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
config = JSON.parse(e.target.result);
|
||||
initialVersion = config.version || '1.0.0';
|
||||
document.getElementById('versionInput').value = initialVersion;
|
||||
document.getElementById('configName').textContent = (config.configName || 'PC装机配置表') + ' - 编辑器';
|
||||
render();
|
||||
} catch (err) {
|
||||
@@ -677,6 +681,11 @@ function handleFileImport(event) {
|
||||
}
|
||||
|
||||
function exportJSON() {
|
||||
config.version = document.getElementById('versionInput').value.trim() || '1.0.0';
|
||||
if (config.version === initialVersion) {
|
||||
if (!confirm(`版本号仍为 ${config.version},未修改。是否继续导出?`)) return;
|
||||
}
|
||||
config.updatedAt = new Date().toISOString();
|
||||
const json = JSON.stringify(config, null, 2);
|
||||
const blob = new Blob([json], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
Reference in New Issue
Block a user