重构Cookie监控系统:添加Web管理后台、Vue3前端界面、Cookie Cloud参数支持、5秒倒计时自动刷新、专业UI配色

This commit is contained in:
bwstudio
2026-04-17 22:37:28 +08:00
parent ed95ce5b23
commit 70802b9b50
44 changed files with 2923 additions and 3654 deletions
+527
View File
@@ -0,0 +1,527 @@
/* Cookie监控管理系统 - 专业版样式 */
:root {
--primary-color: #4f6ef7;
--primary-dark: #3b5bdb;
--primary-light: #e8edff;
--success-color: #10b981;
--success-light: #d1fae5;
--danger-color: #ef4444;
--danger-light: #fee2e2;
--warning-color: #f59e0b;
--warning-light: #fef3c7;
--info-color: #6b7280;
--info-light: #f3f4f6;
--header-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
--card-bg: #ffffff;
--page-bg: #f0f2f5;
--text-primary: #1f2937;
--text-secondary: #6b7280;
--text-light: #9ca3af;
--border-color: #e5e7eb;
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
--radius: 8px;
--radius-lg: 12px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
background-color: var(--page-bg);
color: var(--text-primary);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.container {
min-height: 100vh;
background: var(--page-bg);
}
.el-header {
background: var(--header-bg);
color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 32px;
height: 64px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.header-left {
display: flex;
align-items: center;
gap: 20px;
}
.el-header h1 {
font-size: 20px;
font-weight: 600;
letter-spacing: 0.5px;
margin: 0;
background: linear-gradient(135deg, #fff 0%, #e0e7ff 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.header-right {
display: flex;
align-items: center;
gap: 12px;
}
.header-right .el-button {
background: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.2);
color: rgba(255, 255, 255, 0.9);
font-weight: 500;
transition: all 0.2s;
}
.header-right .el-button:hover {
background: rgba(255, 255, 255, 0.2);
border-color: rgba(255, 255, 255, 0.3);
color: #fff;
}
.auto-refresh-indicator {
display: flex;
align-items: center;
gap: 6px;
color: rgba(255, 255, 255, 0.8);
font-size: 13px;
padding: 6px 12px;
background: rgba(255, 255, 255, 0.08);
border-radius: 20px;
backdrop-filter: blur(4px);
}
.rotating-icon {
animation: rotate 5s linear infinite;
color: var(--primary-color);
}
.refresh-text {
font-size: 13px;
font-weight: 500;
}
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.el-main {
background: var(--page-bg);
padding: 24px 32px;
min-height: calc(100vh - 64px);
}
/* 仪表板样式 */
.dashboard-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 28px;
padding-bottom: 20px;
border-bottom: 1px solid var(--border-color);
}
.dashboard-header h2 {
font-size: 24px;
font-weight: 700;
color: var(--text-primary);
margin: 0;
letter-spacing: -0.5px;
}
.dashboard-stats {
display: flex;
gap: 24px;
}
.dashboard-stats .el-statistic {
padding: 16px 24px;
background: var(--card-bg);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-sm);
min-width: 140px;
text-align: center;
transition: all 0.2s;
}
.dashboard-stats .el-statistic:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-md);
}
.dashboard-stats .el-statistic__title {
font-size: 12px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
font-weight: 600;
}
.dashboard-stats .el-statistic__content {
font-size: 28px;
font-weight: 700;
color: var(--text-primary);
}
/* 用户区域卡片 */
.user-section {
background: var(--card-bg);
border-radius: var(--radius-lg);
padding: 24px;
margin-bottom: 20px;
box-shadow: var(--shadow-sm);
border: 1px solid var(--border-color);
transition: box-shadow 0.2s;
}
.user-section:hover {
box-shadow: var(--shadow-md);
}
.user-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 16px;
border-bottom: 2px solid var(--primary-light);
}
.user-header h3 {
margin: 0;
color: var(--text-primary);
font-size: 18px;
font-weight: 600;
display: flex;
align-items: center;
gap: 8px;
}
.user-header h3::before {
content: '';
display: inline-block;
width: 4px;
height: 20px;
background: var(--primary-color);
border-radius: 2px;
}
.user-header .el-tag {
padding: 6px 14px;
border-radius: 20px;
font-weight: 600;
font-size: 13px;
border: none;
}
/* 表格样式优化 */
.el-table {
border-radius: var(--radius);
overflow: hidden;
}
.el-table th.el-table__cell {
background: var(--page-bg);
color: var(--text-secondary);
font-weight: 600;
font-size: 13px;
text-transform: uppercase;
letter-spacing: 0.3px;
border-bottom: 2px solid var(--border-color);
}
.el-table td.el-table__cell {
font-size: 14px;
color: var(--text-primary);
border-bottom: 1px solid var(--border-color);
}
.el-table--enable-row-hover .el-table__body tr:hover > td.el-table__cell {
background-color: var(--primary-light);
}
.el-table::before {
display: none;
}
/* 状态标签样式 */
.el-tag {
border-radius: 20px;
padding: 4px 12px;
font-weight: 500;
border: none;
}
.el-tag--success {
background: var(--success-light);
color: var(--success-color);
}
.el-tag--danger {
background: var(--danger-light);
color: var(--danger-color);
}
.el-tag--warning {
background: var(--warning-light);
color: var(--warning-color);
}
.el-tag--info {
background: var(--info-light);
color: var(--info-color);
}
/* 按钮样式 */
.el-button--primary {
background: var(--primary-color);
border-color: var(--primary-color);
font-weight: 500;
border-radius: var(--radius);
}
.el-button--primary:hover {
background: var(--primary-dark);
border-color: var(--primary-dark);
}
.el-button--success {
background: var(--success-color);
border-color: var(--success-color);
font-weight: 500;
border-radius: var(--radius);
}
.el-button--success:hover {
background: #059669;
border-color: #059669;
}
.el-button--warning {
background: var(--warning-color);
border-color: var(--warning-color);
font-weight: 500;
}
.el-button--primary.is-plain {
background: transparent;
color: var(--primary-color);
border-color: var(--primary-color);
}
.el-button--primary.is-plain:hover {
background: var(--primary-light);
}
/* 链接样式 */
.el-link--primary {
color: var(--primary-color);
font-weight: 500;
}
.el-link:hover {
opacity: 0.8;
}
/* 设置页面样式 */
.website-manage-header,
.admin-header {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 24px;
padding-bottom: 16px;
border-bottom: 2px solid var(--primary-light);
}
.website-manage-header h2,
.admin-header h2 {
margin: 0;
font-size: 24px;
font-weight: 700;
color: var(--text-primary);
}
.el-tabs {
background: var(--card-bg);
border-radius: var(--radius-lg);
padding: 20px;
box-shadow: var(--shadow-sm);
border: 1px solid var(--border-color);
}
.el-tabs__header {
margin-bottom: 20px;
}
.el-tabs__item {
font-weight: 500;
font-size: 14px;
color: var(--text-secondary);
}
.el-tabs__item.is-active {
color: var(--primary-color);
font-weight: 600;
}
.el-tabs__active-bar {
background: var(--primary-color);
height: 3px;
border-radius: 2px;
}
/* 表单样式 */
.el-form-item__label {
font-weight: 500;
color: var(--text-secondary);
}
.el-input__inner {
border-radius: var(--radius);
border: 1px solid var(--border-color);
transition: all 0.2s;
}
.el-input__inner:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 3px var(--primary-light);
}
.el-input-number {
border-radius: var(--radius);
}
/* 对话框样式 */
.el-dialog {
border-radius: var(--radius-lg);
box-shadow: var(--shadow-lg);
}
.el-dialog__header {
border-bottom: 1px solid var(--border-color);
padding-bottom: 16px;
margin-bottom: 20px;
}
.el-dialog__title {
font-weight: 600;
color: var(--text-primary);
}
.el-dialog__footer {
border-top: 1px solid var(--border-color);
padding-top: 16px;
}
.el-divider__text {
font-weight: 600;
color: var(--primary-color);
background: var(--card-bg);
padding: 0 12px;
}
/* Cookie值样式 */
.cookie-value {
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
font-size: 12px;
color: var(--text-secondary);
word-break: break-all;
background: var(--page-bg);
padding: 4px 8px;
border-radius: 4px;
}
/* 筛选表单 */
.filter-form {
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 12px;
}
/* 空状态 */
.el-empty {
padding: 60px 0;
}
.el-empty__description {
color: var(--text-secondary);
font-size: 14px;
}
/* 统计数字卡片颜色 */
.stat-total .el-statistic__content {
color: var(--primary-color);
}
.stat-online .el-statistic__content {
color: var(--success-color);
}
.stat-offline .el-statistic__content {
color: var(--danger-color);
}
.stat-unknown .el-statistic__content {
color: var(--info-color);
}
/* 响应式适配 */
@media (max-width: 768px) {
.el-header {
padding: 0 16px;
}
.el-main {
padding: 16px;
}
.dashboard-header {
flex-direction: column;
gap: 20px;
align-items: flex-start;
}
.dashboard-stats {
flex-wrap: wrap;
}
.user-section {
padding: 16px;
}
}
/* 滚动条美化 */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: var(--page-bg);
}
::-webkit-scrollbar-thumb {
background: var(--text-light);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--text-secondary);
}
+594
View File
@@ -0,0 +1,594 @@
const { createApp, ref, onMounted, computed } = Vue;
createApp({
setup() {
const activeTab = ref('dashboard');
const settingsTab = ref('users');
const manageTab = ref('cookies');
const currentWebsite = ref(null);
const currentUser = ref(null);
const isAdmin = ref(false);
const users = ref([]);
const websites = ref([]);
const dashboardData = ref([]);
const websiteCookies = ref([]);
const websiteDetections = ref([]);
const detections = ref([]);
const notifications = ref([]);
const stats = ref({ totalWebsites: 0, onlineCount: 0, offlineCount: 0, unknownCount: 0 });
const countdown = ref(5);
const adminLoginVisible = ref(false);
const adminLoginForm = ref({ password: '' });
const userDialogVisible = ref(false);
const userDialogTitle = ref('添加用户');
const userForm = ref({ id: null, name: '', iyuu_token: '', max_fail_count: 3, cookie_cloud_uuid: '', cookie_cloud_password: '', cookie_cloud_api_url: '' });
const websiteDialogVisible = ref(false);
const websiteDialogTitle = ref('添加网站');
const websiteFormDialog = ref({
id: null, user_id: null, name: '', url: '',
login_check_selector: '', success_text: '',
interval_minutes: 30, status: 1
});
const cookieDialogVisible = ref(false);
const cookieDialogTitle = ref('添加Cookie');
const cookieForm = ref({ id: null, name: '', value: '', domain: '', path: '/' });
const websiteForm = ref({
id: null, user_id: null, name: '', url: '',
login_check_selector: '', success_text: '',
interval_minutes: 30
});
const filterWebsiteUser = ref(null);
const currentUserWebsites = computed(() => {
if (!currentUser.value) return [];
return websites.value.filter(w => w.user_id === currentUser.value.id);
});
const filteredWebsites = computed(() => {
if (!filterWebsiteUser.value) return websites.value;
return websites.value.filter(w => w.user_id === filterWebsiteUser.value);
});
const checkAdminStatus = async () => {
try {
const response = await axios.get('/api/admin/status');
isAdmin.value = response.data.logged_in;
} catch (error) {
isAdmin.value = false;
}
};
const showAdminLogin = () => {
adminLoginForm.value = { password: '' };
adminLoginVisible.value = true;
};
const adminLogin = async () => {
try {
const response = await axios.post('/api/admin/login', adminLoginForm.value);
if (response.data.success) {
isAdmin.value = true;
adminLoginVisible.value = false;
ElementPlus.ElMessage.success('登录成功');
activeTab.value = 'settings';
settingsTab.value = 'users';
await loadUsersWithWebsites();
}
} catch (error) {
ElementPlus.ElMessage.error('密码错误');
}
};
const handleAdminCommand = async (command) => {
if (command === 'settings') {
stopAutoRefresh();
activeTab.value = 'settings';
settingsTab.value = 'users';
await loadUsersWithWebsites();
} else if (command === 'dashboard') {
activeTab.value = 'dashboard';
await loadDashboard();
startAutoRefresh();
} else if (command === 'logout') {
await axios.post('/api/admin/logout');
isAdmin.value = false;
activeTab.value = 'dashboard';
ElementPlus.ElMessage.success('已退出');
}
};
const loadUsers = async () => {
try {
const response = await axios.get('/api/users');
users.value = response.data;
} catch (error) {
console.error('加载用户失败:', error);
}
};
const loadUsersWithWebsites = async () => {
try {
const usersRes = await axios.get('/api/users');
const websitesRes = await axios.get('/api/websites');
users.value = usersRes.data;
websites.value = websitesRes.data;
users.value = users.value.map(user => ({
...user,
website_count: websitesRes.data.filter(w => w.user_id === user.id).length
}));
} catch (error) {
console.error('加载用户失败:', error);
}
};
const loadWebsites = async () => {
try {
const response = await axios.get('/api/websites');
websites.value = response.data;
} catch (error) {
console.error('加载网站失败:', error);
}
};
const loadDashboard = async () => {
try {
const usersRes = await axios.get('/api/users');
const websitesRes = await axios.get('/api/websites');
const latestDetectionsRes = await axios.get('/api/detections/latest');
const networkRes = await axios.get('/api/websites/check-network');
const usersData = usersRes.data;
const allWebsites = websitesRes.data;
const latestDetections = latestDetectionsRes.data;
const networkStatus = networkRes.data;
let onlineCount = 0, offlineCount = 0, unknownCount = 0, totalWebsites = allWebsites.length;
dashboardData.value = usersData.map(user => {
const userWebsites = allWebsites.filter(w => w.user_id === user.id);
return {
id: user.id,
name: user.name,
websites: userWebsites.map(w => {
const detection = latestDetections[w.id];
const net = networkStatus[w.id];
let loginStatus = 'unknown';
let lastCheckTime = '-';
let networkStatusValue = 'unknown';
if (net) {
networkStatusValue = net.reachable ? 'online' : 'offline';
}
if (detection) {
if (detection.status === 1) {
loginStatus = 'success';
onlineCount++;
} else {
loginStatus = 'failed';
offlineCount++;
}
lastCheckTime = new Date(detection.created_at).toLocaleString();
} else {
unknownCount++;
}
return {
...w,
networkStatus: networkStatusValue,
loginStatus: loginStatus,
lastCheckTime: lastCheckTime
};
})
};
});
stats.value = { totalWebsites, onlineCount, offlineCount, unknownCount };
} catch (error) {
console.error('加载仪表板失败:', error);
}
};
const refreshDashboardStatus = async () => {
if (activeTab.value !== 'dashboard') return;
if (isRefreshing) return;
isRefreshing = true;
try {
const [detectionsRes, networkRes] = await Promise.all([
axios.get('/api/detections/latest'),
axios.get('/api/websites/check-network')
]);
const latestDetections = detectionsRes.data;
const networkStatus = networkRes.data;
let onlineCount = 0, offlineCount = 0, unknownCount = 0;
dashboardData.value = dashboardData.value.map(user => {
return {
...user,
websites: user.websites.map(w => {
const detection = latestDetections[w.id];
const net = networkStatus[w.id];
let loginStatus = w.loginStatus;
let lastCheckTime = w.lastCheckTime;
let networkStatusValue = 'unknown';
if (net) {
networkStatusValue = net.reachable ? 'online' : 'offline';
}
if (detection) {
if (detection.status === 1) {
loginStatus = 'success';
onlineCount++;
} else {
loginStatus = 'failed';
offlineCount++;
}
lastCheckTime = new Date(detection.created_at).toLocaleString();
} else {
unknownCount++;
}
return {
...w,
networkStatus: networkStatusValue,
loginStatus: loginStatus,
lastCheckTime: lastCheckTime
};
})
};
});
stats.value = {
totalWebsites: onlineCount + offlineCount + unknownCount,
onlineCount,
offlineCount,
unknownCount
};
} catch (error) {
// 静默失败,不显示错误提示
} finally {
isRefreshing = false;
if (activeTab.value === 'dashboard') {
countdown.value = 5;
startCountdown();
}
}
};
let refreshTimer = null;
let countdownTimer = null;
let isRefreshing = false;
const startAutoRefresh = () => {
stopAutoRefresh();
countdown.value = 5;
startCountdown();
};
const startCountdown = () => {
if (countdownTimer) clearInterval(countdownTimer);
countdownTimer = setInterval(() => {
countdown.value--;
if (countdown.value <= 0) {
clearInterval(countdownTimer);
countdownTimer = null;
refreshDashboardStatus();
}
}, 1000);
};
const stopAutoRefresh = () => {
if (refreshTimer) {
clearInterval(refreshTimer);
refreshTimer = null;
}
if (countdownTimer) {
clearInterval(countdownTimer);
countdownTimer = null;
}
countdown.value = 5;
};
const checkLogin = async (website) => {
website.loginStatus = 'checking';
try {
const response = await axios.post(`/api/websites/check-login/${website.id}`);
if (response.data.success) {
website.loginStatus = 'success';
updateStats(website.id, 'success');
ElementPlus.ElMessage.success(response.data.message);
} else {
website.loginStatus = 'failed';
updateStats(website.id, 'failed');
ElementPlus.ElMessage.error(response.data.message);
}
website.lastCheckTime = new Date().toLocaleString();
} catch (error) {
website.loginStatus = 'failed';
updateStats(website.id, 'failed');
ElementPlus.ElMessage.error('检测失败');
}
};
const updateStats = (websiteId, status) => {
let onlineCount = 0, offlineCount = 0, unknownCount = 0;
dashboardData.value.forEach(user => {
user.websites.forEach(w => {
if (w.id === websiteId) {
if (status === 'success') onlineCount++;
else if (status === 'failed') offlineCount++;
} else {
if (w.loginStatus === 'success') onlineCount++;
else if (w.loginStatus === 'failed') offlineCount++;
else unknownCount++;
}
});
});
stats.value = { totalWebsites: onlineCount + offlineCount + unknownCount, onlineCount, offlineCount, unknownCount };
};
const manageWebsite = async (website) => {
stopAutoRefresh();
currentWebsite.value = website;
websiteForm.value = { ...website };
activeTab.value = 'website_manage';
manageTab.value = 'cookies';
await loadWebsiteCookies();
};
const manageUserWebsites = (user) => {
stopAutoRefresh();
currentUser.value = user;
activeTab.value = 'user_websites';
};
const loadWebsiteCookies = async () => {
if (!currentWebsite.value) return;
try {
const response = await axios.get(`/api/cookies/websites/${currentWebsite.value.id}`);
websiteCookies.value = response.data;
} catch (error) {
console.error('加载Cookie失败:', error);
}
};
const loadWebsiteDetections = async () => {
if (!currentWebsite.value) return;
try {
const response = await axios.get(`/api/detections?website_id=${currentWebsite.value.id}`);
websiteDetections.value = response.data;
} catch (error) {
console.error('加载检测记录失败:', error);
}
};
const showAddUserDialog = () => {
userDialogTitle.value = '添加用户';
userForm.value = { id: null, name: '', iyuu_token: '', max_fail_count: 3, cookie_cloud_uuid: '', cookie_cloud_password: '', cookie_cloud_api_url: '' };
userDialogVisible.value = true;
};
const editUser = (user) => {
userDialogTitle.value = '编辑用户';
userForm.value = {
id: user.id,
name: user.name,
iyuu_token: user.iyuu_token,
max_fail_count: user.max_fail_count,
cookie_cloud_uuid: user.cookie_cloud_uuid || '',
cookie_cloud_password: user.cookie_cloud_password || '',
cookie_cloud_api_url: user.cookie_cloud_api_url || ''
};
userDialogVisible.value = true;
};
const saveUser = async () => {
try {
if (userForm.value.id) {
await axios.put(`/api/users/${userForm.value.id}`, userForm.value);
ElementPlus.ElMessage.success('更新成功');
} else {
await axios.post('/api/users', userForm.value);
ElementPlus.ElMessage.success('添加成功');
}
userDialogVisible.value = false;
await loadUsersWithWebsites();
} catch (error) {
ElementPlus.ElMessage.error('保存失败');
}
};
const deleteUser = async (user) => {
try {
await ElementPlus.ElMessageBox.confirm('确定要删除该用户吗?', '提示', { type: 'warning' });
await axios.delete(`/api/users/${user.id}`);
ElementPlus.ElMessage.success('删除成功');
await loadUsersWithWebsites();
} catch (error) {
if (error !== 'cancel') {
ElementPlus.ElMessage.error('删除失败');
}
}
};
const showAddWebsiteDialog = () => {
websiteDialogTitle.value = '添加网站';
websiteFormDialog.value = {
id: null, user_id: filterWebsiteUser.value || users.value[0]?.id,
name: '', url: '', login_check_selector: '', success_text: '',
interval_minutes: 30, status: 1
};
websiteDialogVisible.value = true;
};
const showAddWebsiteDialogForUser = () => {
websiteDialogTitle.value = '添加网站';
websiteFormDialog.value = {
id: null, user_id: currentUser.value?.id,
name: '', url: '', login_check_selector: '', success_text: '',
interval_minutes: 30, status: 1
};
websiteDialogVisible.value = true;
};
const editWebsite = (website) => {
websiteDialogTitle.value = '编辑网站';
websiteFormDialog.value = { ...website };
websiteDialogVisible.value = true;
};
const saveWebsite = async () => {
try {
if (websiteFormDialog.value.id) {
await axios.put(`/api/websites/${websiteFormDialog.value.id}`, websiteFormDialog.value);
ElementPlus.ElMessage.success('更新成功');
} else {
await axios.post('/api/websites', websiteFormDialog.value);
ElementPlus.ElMessage.success('添加成功');
}
websiteDialogVisible.value = false;
await loadWebsites();
await loadUsersWithWebsites();
} catch (error) {
ElementPlus.ElMessage.error('保存失败');
}
};
const deleteWebsite = async (website) => {
try {
await ElementPlus.ElMessageBox.confirm('确定要删除该网站吗?', '提示', { type: 'warning' });
await axios.delete(`/api/websites/${website.id}`);
ElementPlus.ElMessage.success('删除成功');
await loadWebsites();
await loadUsersWithWebsites();
} catch (error) {
if (error !== 'cancel') {
ElementPlus.ElMessage.error('删除失败');
}
}
};
const showAddCookieDialog = () => {
cookieDialogTitle.value = '添加Cookie';
cookieForm.value = { id: null, name: '', value: '', domain: currentWebsite.value?.url ? new URL(currentWebsite.value.url).hostname : '', path: '/' };
cookieDialogVisible.value = true;
};
const editCookie = (cookie) => {
cookieDialogTitle.value = '编辑Cookie';
cookieForm.value = { ...cookie };
cookieDialogVisible.value = true;
};
const saveCookie = async () => {
try {
if (cookieForm.value.id) {
await axios.put(`/api/cookies/${cookieForm.value.id}`, cookieForm.value);
ElementPlus.ElMessage.success('更新成功');
} else {
await axios.post(`/api/cookies/websites/${currentWebsite.value.id}`, cookieForm.value);
ElementPlus.ElMessage.success('添加成功');
}
cookieDialogVisible.value = false;
await loadWebsiteCookies();
} catch (error) {
ElementPlus.ElMessage.error('保存失败');
}
};
const deleteCookie = async (cookie) => {
try {
await ElementPlus.ElMessageBox.confirm('确定要删除该Cookie吗?', '提示', { type: 'warning' });
await axios.delete(`/api/cookies/${cookie.id}`);
ElementPlus.ElMessage.success('删除成功');
await loadWebsiteCookies();
} catch (error) {
if (error !== 'cancel') {
ElementPlus.ElMessage.error('删除失败');
}
}
};
const saveWebsiteSettings = async () => {
try {
await axios.put(`/api/websites/${currentWebsite.value.id}`, websiteForm.value);
ElementPlus.ElMessage.success('保存成功');
} catch (error) {
ElementPlus.ElMessage.error('保存失败');
}
};
const maskCookieValue = (value) => {
if (!value) return '';
return value.length > 30 ? value.substring(0, 30) + '...' : value;
};
const loadDetections = async () => {
try {
const response = await axios.get('/api/detections');
detections.value = response.data;
} catch (error) {
console.error('加载检测结果失败:', error);
}
};
const loadNotifications = async () => {
try {
const response = await axios.get('/api/notifications');
notifications.value = response.data;
} catch (error) {
console.error('加载通知失败:', error);
}
};
const viewNotificationDetail = (notification) => {
ElementPlus.ElMessageBox.alert(notification.content, notification.title, { confirmButtonText: '确定' });
};
onMounted(async () => {
await checkAdminStatus();
await loadUsers();
await loadWebsites();
await loadDashboard();
startAutoRefresh();
});
return {
activeTab, settingsTab, manageTab, currentWebsite, currentUser, isAdmin,
users, websites, dashboardData, websiteCookies, websiteDetections, detections, notifications,
stats, countdown,
adminLoginVisible, adminLoginForm,
userDialogVisible, userDialogTitle, userForm,
websiteDialogVisible, websiteDialogTitle, websiteFormDialog,
cookieDialogVisible, cookieDialogTitle, cookieForm,
websiteForm, filterWebsiteUser,
currentUserWebsites, filteredWebsites,
checkAdminStatus, showAdminLogin, adminLogin, handleAdminCommand,
loadUsers, loadUsersWithWebsites, loadWebsites, loadDashboard, refreshDashboardStatus,
startAutoRefresh, stopAutoRefresh,
checkLogin, manageWebsite, manageUserWebsites,
loadWebsiteCookies, loadWebsiteDetections,
showAddUserDialog, editUser, saveUser, deleteUser,
showAddWebsiteDialog, showAddWebsiteDialogForUser, editWebsite, saveWebsite, deleteWebsite,
showAddCookieDialog, editCookie, saveCookie, deleteCookie,
saveWebsiteSettings, maskCookieValue,
loadDetections, loadNotifications, viewNotificationDetail
};
}
}).use(ElementPlus).mount('#app');