优化结构

This commit is contained in:
zhinianboke 2025-08-03 20:55:31 +08:00
parent 7386db9496
commit 04a391616f

View File

@ -1,4 +1,4 @@
// 全局变量 // ==================== 全局变量 ====================
const apiBase = location.origin; const apiBase = location.origin;
let keywordsData = {}; let keywordsData = {};
let currentCookieId = ''; let currentCookieId = '';
@ -14,6 +14,8 @@ let accountKeywordCache = {};
let cacheTimestamp = 0; let cacheTimestamp = 0;
const CACHE_DURATION = 30000; // 30秒缓存 const CACHE_DURATION = 30000; // 30秒缓存
// ==================== 页面导航功能 ====================
// 菜单切换功能 // 菜单切换功能
function showSection(sectionName) { function showSection(sectionName) {
console.log('切换到页面:', sectionName); // 调试信息 console.log('切换到页面:', sectionName); // 调试信息
@ -99,6 +101,8 @@ function toggleSidebar() {
document.getElementById('sidebar').classList.toggle('show'); document.getElementById('sidebar').classList.toggle('show');
} }
// ==================== 仪表盘管理 ====================
// 加载仪表盘数据 // 加载仪表盘数据
async function loadDashboard() { async function loadDashboard() {
try { try {
@ -239,6 +243,8 @@ function updateDashboardAccountsList(accounts) {
}); });
} }
// ==================== 关键词缓存管理 ====================
// 获取账号关键词数量(带缓存)- 包含普通关键词和商品关键词 // 获取账号关键词数量(带缓存)- 包含普通关键词和商品关键词
async function getAccountKeywordCount(accountId) { async function getAccountKeywordCount(accountId) {
const now = Date.now(); const now = Date.now();
@ -280,6 +286,8 @@ function clearKeywordCache() {
cacheTimestamp = 0; cacheTimestamp = 0;
} }
// ==================== 账号列表管理 ====================
// 刷新账号列表(用于自动回复页面) // 刷新账号列表(用于自动回复页面)
async function refreshAccountList() { async function refreshAccountList() {
try { try {
@ -339,7 +347,7 @@ async function refreshAccountList() {
// 分组显示:先显示启用的账号,再显示禁用的账号 // 分组显示:先显示启用的账号,再显示禁用的账号
const enabledAccounts = accountsWithKeywords.filter(account => { const enabledAccounts = accountsWithKeywords.filter(account => {
const enabled = account.enabled === undefined ? true : account.enabled; const enabled = account.enabled === undefined ? true : account.enabled;
console.log(`账号 ${account.id} 过滤状态: enabled=${account.enabled}, 判断为启用=${enabled}`); // 调试信息 console.log(`账号 ${account.id} 过滤状态: enabled=${account.enabled}, 判断为启用=${enabled}`);
return enabled; return enabled;
}); });
const disabledAccounts = accountsWithKeywords.filter(account => { const disabledAccounts = accountsWithKeywords.filter(account => {
@ -875,6 +883,8 @@ async function deleteKeyword(cookieId, index) {
} }
} }
// ==================== 通用工具函数 ====================
// 显示/隐藏加载动画 // 显示/隐藏加载动画
function toggleLoading(show) { function toggleLoading(show) {
document.getElementById('loading').classList.toggle('d-none', !show); document.getElementById('loading').classList.toggle('d-none', !show);
@ -959,6 +969,8 @@ async function fetchJSON(url, opts = {}) {
} }
} }
// ==================== Cookie管理 ====================
// 加载Cookie列表 // 加载Cookie列表
async function loadCookies() { async function loadCookies() {
try { try {
@ -1181,8 +1193,13 @@ async function delCookie(id) {
} }
} }
// 内联编辑Cookie /**
function editCookieInline(id, currentValue) { * 内联编辑Cookie
* @param {string} id - 账号ID
* @param {string} currentValue - 当前Cookie值
* @param {Event} event - 点击事件对象
*/
function editCookieInline(id, currentValue, event) {
const row = event.target.closest('tr'); const row = event.target.closest('tr');
const cookieValueCell = row.querySelector('.cookie-value'); const cookieValueCell = row.querySelector('.cookie-value');
const originalContent = cookieValueCell.innerHTML; const originalContent = cookieValueCell.innerHTML;
@ -1562,11 +1579,14 @@ async function checkAuth() {
} }
} }
// ==================== 应用初始化 ====================
// 初始化事件监听 // 初始化事件监听
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
// 首先检查认证状态 // 首先检查认证状态
const isAuthenticated = await checkAuth(); const isAuthenticated = await checkAuth();
if (!isAuthenticated) return; if (!isAuthenticated) return;
// 添加Cookie表单提交 // 添加Cookie表单提交
document.getElementById('addForm').addEventListener('submit', async (e) => { document.getElementById('addForm').addEventListener('submit', async (e) => {
e.preventDefault(); e.preventDefault();
@ -1857,8 +1877,12 @@ async function saveDefaultReply() {
} }
} }
// 测试默认回复(占位函数) /**
* 测试默认回复占位函数
* @param {string} accountId - 账号ID
*/
function testDefaultReply(accountId) { function testDefaultReply(accountId) {
console.log('测试默认回复功能账号ID:', accountId);
showToast('测试功能开发中...', 'info'); showToast('测试功能开发中...', 'info');
} }