feat: 首页添加导出按钮,一键导出JSON格式
This commit is contained in:
@@ -246,6 +246,9 @@ INDEX_TEMPLATE = '''
|
|||||||
<option value="todo">待办</option>
|
<option value="todo">待办</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<button class="btn btn-outline-success me-2" onclick="exportData()" title="导出JSON">
|
||||||
|
<i class="bi bi-download"></i> 导出
|
||||||
|
</button>
|
||||||
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addModal">
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addModal">
|
||||||
<i class="bi bi-plus-lg"></i> 添加
|
<i class="bi bi-plus-lg"></i> 添加
|
||||||
</button>
|
</button>
|
||||||
@@ -948,6 +951,29 @@ async function deleteTagManager(id, name) {
|
|||||||
loadItems();
|
loadItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 导出数据
|
||||||
|
async function exportData() {
|
||||||
|
const res = await fetch(`${API_BASE}/items?limit=1000`);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
if (!data.success) {
|
||||||
|
alert('导出失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化JSON
|
||||||
|
const jsonStr = JSON.stringify(data.data, null, 2);
|
||||||
|
|
||||||
|
// 创建下载
|
||||||
|
const blob = new Blob([jsonStr], { type: 'application/json' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = `xian_favor_export_${new Date().toISOString().slice(0,10)}.json`;
|
||||||
|
a.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
function debounce(fn, delay) {
|
function debounce(fn, delay) {
|
||||||
let timer;
|
let timer;
|
||||||
return function(...args) {
|
return function(...args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user