feat: 添加系统配置功能
- AI自动添加的大模型接口配置(URL/Key/Model) - 服务器连接状态刷新频率配置 - 数据列表每页显示条数配置 - 草稿自动保存间隔配置 - 显示统计/阅读次数开关 - 配置保存到localStorage
This commit is contained in:
@@ -1398,6 +1398,8 @@ INDEX_TEMPLATE = '''
|
|||||||
<a href="#" onclick="showBackupManager(); return false;"><i class="bi bi-archive"></i> 备份管理</a>
|
<a href="#" onclick="showBackupManager(); return false;"><i class="bi bi-archive"></i> 备份管理</a>
|
||||||
<a href="#" onclick="showDrafts(); return false;"><i class="bi bi-file-earmark"></i> 草稿箱</a>
|
<a href="#" onclick="showDrafts(); return false;"><i class="bi bi-file-earmark"></i> 草稿箱</a>
|
||||||
<a href="#" onclick="showTrash(); return false;"><i class="bi bi-trash"></i> 回收站</a>
|
<a href="#" onclick="showTrash(); return false;"><i class="bi bi-trash"></i> 回收站</a>
|
||||||
|
<hr class="my-2">
|
||||||
|
<a href="#" onclick="showSystemConfig(); return false;"><i class="bi bi-gear"></i> 系统配置</a>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -2161,6 +2163,101 @@ INDEX_TEMPLATE = '''
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 系统配置模态框 -->
|
||||||
|
<div class="modal fade" id="systemConfigModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title"><i class="bi bi-gear"></i> 系统配置</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<!-- AI添加配置 -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<h6 class="mb-3"><i class="bi bi-robot"></i> AI自动添加配置</h6>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">大模型接口地址</label>
|
||||||
|
<input type="text" id="configAIUrl" class="form-control" placeholder="http://192.168.2.5:1234/v1">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">API Key(可选)</label>
|
||||||
|
<input type="text" id="configAIKey" class="form-control" placeholder="sk-xxx">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">模型名称</label>
|
||||||
|
<input type="text" id="configAIModel" class="form-control" placeholder="qwen3.5-4b">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 连接状态配置 -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<h6 class="mb-3"><i class="bi bi-wifi"></i> 连接状态检测</h6>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">刷新频率(秒)</label>
|
||||||
|
<select id="configCheckInterval" class="form-select">
|
||||||
|
<option value="3">3秒</option>
|
||||||
|
<option value="5" selected>5秒</option>
|
||||||
|
<option value="10">10秒</option>
|
||||||
|
<option value="30">30秒</option>
|
||||||
|
<option value="60">60秒</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 显示配置 -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<h6 class="mb-3"><i class="bi bi-list"></i> 数据显示配置</h6>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">每页显示条数</label>
|
||||||
|
<select id="configPageSize" class="form-select">
|
||||||
|
<option value="10">10条</option>
|
||||||
|
<option value="20" selected>20条</option>
|
||||||
|
<option value="30">30条</option>
|
||||||
|
<option value="50">50条</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 其他配置 -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<h6 class="mb-3"><i class="bi bi-sliders"></i> 其他配置</h6>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">草稿自动保存间隔(秒)</label>
|
||||||
|
<select id="configDraftInterval" class="form-select">
|
||||||
|
<option value="2">2秒</option>
|
||||||
|
<option value="5" selected>5秒</option>
|
||||||
|
<option value="10">10秒</option>
|
||||||
|
<option value="30">30秒</option>
|
||||||
|
<option value="60">60秒</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="configShowStats" checked>
|
||||||
|
<label class="form-check-label" for="configShowStats">
|
||||||
|
显示内容统计(行数/字数)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="configShowViews" checked>
|
||||||
|
<label class="form-check-label" for="configShowViews">
|
||||||
|
显示阅读次数
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-outline-warning" onclick="resetSystemConfig()">恢复默认</button>
|
||||||
|
<button type="button" class="btn btn-primary" onclick="saveSystemConfig()">保存配置</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const API_BASE = '/api';
|
const API_BASE = '/api';
|
||||||
@@ -2168,11 +2265,11 @@ let currentFilter = { type: '', status: '', starred: null, folder_id: null };
|
|||||||
let currentSort = { sort_by: '', sort_order: '' };
|
let currentSort = { sort_by: '', sort_order: '' };
|
||||||
let currentItems = []; // 保存当前显示的数据,用于切换显示模式时重新渲染
|
let currentItems = []; // 保存当前显示的数据,用于切换显示模式时重新渲染
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
const pageSize = 20;
|
let pageSize = 20; // 可配置的每页条数
|
||||||
let allFolders = {}; // 按类型存储文件夹
|
let allFolders = {}; // 按类型存储文件夹
|
||||||
let isOnline = true;
|
let isOnline = true;
|
||||||
let connectionCheckTimer = null;
|
let connectionCheckTimer = null;
|
||||||
const CONNECTION_CHECK_INTERVAL = 5000; // 5秒检测一次
|
let CONNECTION_CHECK_INTERVAL = 5000; // 可配置的连接检测间隔(毫秒)
|
||||||
const CONNECTION_TIMEOUT = 3000; // 3秒超时
|
const CONNECTION_TIMEOUT = 3000; // 3秒超时
|
||||||
|
|
||||||
function updateConnectionStatus(status) {
|
function updateConnectionStatus(status) {
|
||||||
@@ -2295,6 +2392,9 @@ function debounce(fn, delay) {
|
|||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
// 加载系统配置
|
||||||
|
loadSystemConfig();
|
||||||
|
|
||||||
// 启动连接状态检测
|
// 启动连接状态检测
|
||||||
startConnectionCheck();
|
startConnectionCheck();
|
||||||
|
|
||||||
@@ -3923,6 +4023,122 @@ function addTagToInput(inputId, tag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ 系统配置功能 ============
|
||||||
|
|
||||||
|
// 系统配置对象
|
||||||
|
let systemConfig = {
|
||||||
|
aiUrl: '',
|
||||||
|
aiKey: '',
|
||||||
|
aiModel: 'qwen3.5-4b',
|
||||||
|
checkInterval: 5,
|
||||||
|
pageSize: 20,
|
||||||
|
draftInterval: 5,
|
||||||
|
showStats: true,
|
||||||
|
showViews: true
|
||||||
|
};
|
||||||
|
|
||||||
|
// 加载配置
|
||||||
|
function loadSystemConfig() {
|
||||||
|
const saved = localStorage.getItem('xianFavorConfig');
|
||||||
|
if (saved) {
|
||||||
|
try {
|
||||||
|
systemConfig = JSON.parse(saved);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('加载配置失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 应用配置
|
||||||
|
applySystemConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 应用配置到系统
|
||||||
|
function applySystemConfig() {
|
||||||
|
// 更新pageSize
|
||||||
|
if (systemConfig.pageSize) {
|
||||||
|
pageSize = systemConfig.pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新连接检测间隔
|
||||||
|
if (systemConfig.checkInterval) {
|
||||||
|
CONNECTION_CHECK_INTERVAL = systemConfig.checkInterval * 1000;
|
||||||
|
if (connectionCheckTimer) {
|
||||||
|
clearInterval(connectionCheckTimer);
|
||||||
|
connectionCheckTimer = setInterval(checkConnection, CONNECTION_CHECK_INTERVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示系统配置弹框
|
||||||
|
function showSystemConfig() {
|
||||||
|
// 填充当前配置值
|
||||||
|
document.getElementById('configAIUrl').value = systemConfig.aiUrl || '';
|
||||||
|
document.getElementById('configAIKey').value = systemConfig.aiKey || '';
|
||||||
|
document.getElementById('configAIModel').value = systemConfig.aiModel || 'qwen3.5-4b';
|
||||||
|
document.getElementById('configCheckInterval').value = systemConfig.checkInterval || 5;
|
||||||
|
document.getElementById('configPageSize').value = systemConfig.pageSize || 20;
|
||||||
|
document.getElementById('configDraftInterval').value = systemConfig.draftInterval || 5;
|
||||||
|
document.getElementById('configShowStats').checked = systemConfig.showStats !== false;
|
||||||
|
document.getElementById('configShowViews').checked = systemConfig.showViews !== false;
|
||||||
|
|
||||||
|
new bootstrap.Modal(document.getElementById('systemConfigModal')).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存系统配置
|
||||||
|
function saveSystemConfig() {
|
||||||
|
systemConfig = {
|
||||||
|
aiUrl: document.getElementById('configAIUrl').value.trim(),
|
||||||
|
aiKey: document.getElementById('configAIKey').value.trim(),
|
||||||
|
aiModel: document.getElementById('configAIModel').value.trim() || 'qwen3.5-4b',
|
||||||
|
checkInterval: parseInt(document.getElementById('configCheckInterval').value) || 5,
|
||||||
|
pageSize: parseInt(document.getElementById('configPageSize').value) || 20,
|
||||||
|
draftInterval: parseInt(document.getElementById('configDraftInterval').value) || 5,
|
||||||
|
showStats: document.getElementById('configShowStats').checked,
|
||||||
|
showViews: document.getElementById('configShowViews').checked
|
||||||
|
};
|
||||||
|
|
||||||
|
// 保存到localStorage
|
||||||
|
localStorage.setItem('xianFavorConfig', JSON.stringify(systemConfig));
|
||||||
|
|
||||||
|
// 应用配置
|
||||||
|
applySystemConfig();
|
||||||
|
|
||||||
|
bootstrap.Modal.getInstance(document.getElementById('systemConfigModal')).hide();
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
alert('配置已保存!\n部分配置需要刷新页面才能生效。');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置为默认配置
|
||||||
|
function resetSystemConfig() {
|
||||||
|
if (!confirm('确认恢复默认配置?')) return;
|
||||||
|
|
||||||
|
systemConfig = {
|
||||||
|
aiUrl: '',
|
||||||
|
aiKey: '',
|
||||||
|
aiModel: 'qwen3.5-4b',
|
||||||
|
checkInterval: 5,
|
||||||
|
pageSize: 20,
|
||||||
|
draftInterval: 5,
|
||||||
|
showStats: true,
|
||||||
|
showViews: true
|
||||||
|
};
|
||||||
|
|
||||||
|
localStorage.setItem('xianFavorConfig', JSON.stringify(systemConfig));
|
||||||
|
|
||||||
|
// 更新表单显示
|
||||||
|
showSystemConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取AI配置
|
||||||
|
function getAIConfig() {
|
||||||
|
return {
|
||||||
|
url: systemConfig.aiUrl || 'http://192.168.2.5:1234/v1',
|
||||||
|
key: systemConfig.aiKey || '',
|
||||||
|
model: systemConfig.aiModel || 'qwen3.5-4b'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async function showTagManager() {
|
async function showTagManager() {
|
||||||
await loadTagManagerList();
|
await loadTagManagerList();
|
||||||
new bootstrap.Modal(document.getElementById('tagManagerModal')).show();
|
new bootstrap.Modal(document.getElementById('tagManagerModal')).show();
|
||||||
|
|||||||
Reference in New Issue
Block a user