v1.0.0提交

This commit is contained in:
2026-03-31 15:54:32 +08:00
parent 79bfeb0e18
commit 314e53bf9c
16 changed files with 2110 additions and 1 deletions

82
pages/json.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
/**
* PerToolBox Front - JSON 校验器页面
*
* Copyright (C) 2024 Sea Network Technology Studio
* Author: Canglan <admin@sea-studio.top>
* License: AGPL v3
*/
require_once '../config.php';
include_once '../header.php';
include_once '../sidebar.php';
?>
<div class="main-content">
<div class="card">
<h1 class="text-2xl font-bold mb-6">📋 JSON 校验器</h1>
<div class="mb-4">
<label class="form-label">输入 JSON</label>
<textarea id="jsonInput" rows="10" placeholder='{"key": "value"}' class="form-input font-mono text-sm"></textarea>
</div>
<button id="validateBtn" class="btn btn-primary mb-6">校验并格式化</button>
<div id="resultArea" class="hidden">
<div class="flex justify-between items-center mb-2">
<h3 class="font-semibold">结果:</h3>
<button id="copyBtn" class="text-sm text-blue-500 hover:text-blue-700">复制</button>
</div>
<pre id="jsonResult" class="bg-gray-50 p-4 rounded-lg overflow-x-auto font-mono text-sm"></pre>
</div>
<div id="errorArea" class="hidden">
<div class="bg-red-50 border border-red-200 rounded-lg p-4">
<div class="text-red-600 font-semibold mb-2">❌ JSON 无效</div>
<div id="errorMsg" class="text-red-500 text-sm"></div>
</div>
</div>
</div>
</div>
<script>
document.getElementById('validateBtn').addEventListener('click', async () => {
const jsonString = document.getElementById('jsonInput').value;
if (!jsonString) {
showToast('请输入 JSON', 'error');
return;
}
try {
const data = await apiRequest('/json/validate', {
method: 'POST',
body: JSON.stringify({ json_string: jsonString })
});
if (data.valid) {
document.getElementById('resultArea').classList.remove('hidden');
document.getElementById('errorArea').classList.add('hidden');
document.getElementById('jsonResult').textContent = data.formatted;
} else {
document.getElementById('resultArea').classList.add('hidden');
document.getElementById('errorArea').classList.remove('hidden');
document.getElementById('errorMsg').textContent = `第 ${data.error.line} 行,第 ${data.error.column} 列:${data.error.message}`;
}
} catch (error) {
showToast(error.message, 'error');
}
});
document.getElementById('copyBtn').addEventListener('click', () => {
const result = document.getElementById('jsonResult').textContent;
if (result) {
navigator.clipboard.writeText(result);
showToast('已复制到剪贴板');
}
});
recordUsage('json');
</script>
<?php include_once '../footer.php'; ?>