+ showLoading();
+ fetch(`/account/${encodeURIComponent(email)}/usage`)
+ .then((res) => res.json())
+ .then((data) => {
+ hideLoading();
+ if (data.success) {
+ // 创建并显示用量信息模态框
+ const modal = $(`
+
- 剩余额度: ${data.usage.remaining_balance !== null ? data.usage.remaining_balance : '未知'}
+ 剩余额度: ${
+ data.usage.remaining_balance !== null
+ ? data.usage.remaining_balance
+ : '未知'
+ }
- 剩余天数: ${data.usage.remaining_days !== null ? data.usage.remaining_days : '未知'}
+ 剩余天数: ${
+ data.usage.remaining_days !== null
+ ? data.usage.remaining_days
+ : '未知'
+ }
状态:
-
- ${data.usage.status === 'active' ? '活跃' : '不活跃'}
+
+ ${
+ data.usage.status === 'active'
+ ? '活跃'
+ : '不活跃'
+ }
- 更新时间: ${formatDateTime(data.timestamp)}
+ 更新时间: ${formatDateTime(
+ data.timestamp
+ )}
`);
-
- $('body').append(modal);
- const modalInstance = new bootstrap.Modal(modal[0]);
- modalInstance.show();
-
- // 模态框关闭时移除DOM
- modal[0].addEventListener('hidden.bs.modal', function() {
- modal.remove();
- });
- }
- })
- .catch(error => {
- console.error('获取账号用量失败:', error);
- showAlert('获取账号用量失败', 'danger');
- hideLoading();
+
+ $('body').append(modal);
+ const modalInstance = new bootstrap.Modal(modal[0]);
+ modalInstance.show();
+
+ // 模态框关闭时移除DOM并清理背景
+ modal[0].addEventListener('hidden.bs.modal', function () {
+ modal.remove();
+ cleanupModalBackdrops();
});
+ }
+ })
+ .catch((error) => {
+ console.error('获取账号用量失败:', error);
+ showAlert('获取账号用量失败', 'danger');
+ hideLoading();
+ });
}
// 更新账号用量到数据库
function updateAccountUsageLimit(email, usageLimit) {
- fetch(`/account/${encodeURIComponent(email)}/update-usage`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ usage_limit: usageLimit })
+ fetch(`/account/${encodeURIComponent(email)}/update-usage`, {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ usage_limit: usageLimit }),
+ })
+ .then((res) => res.json())
+ .then((data) => {
+ if (data.success) {
+ console.log(`账号 ${email} 用量数据已更新到数据库`);
+ } else {
+ console.error(`更新账号 ${email} 用量数据失败:`, data.message);
+ }
})
- .then(res => res.json())
- .then(data => {
- if (data.success) {
- console.log(`账号 ${email} 用量数据已更新到数据库`);
- } else {
- console.error(`更新账号 ${email} 用量数据失败:`, data.message);
- }
- })
- .catch(error => {
- console.error(`更新账号 ${email} 用量数据时发生错误:`, error);
+ .catch((error) => {
+ console.error(`更新账号 ${email} 用量数据时发生错误:`, error);
});
}
// 修复任务状态更新问题
function startTaskManually() {
- showLoading();
- fetch('/registration/start', {
- method: 'GET'
+ showLoading();
+ fetch('/registration/start', {
+ method: 'GET',
+ })
+ .then((res) => res.json())
+ .then((data) => {
+ hideLoading();
+ if (data.success) {
+ showAlert('定时任务已成功启动', 'success');
+ checkTaskStatus();
+ } else {
+ showAlert(`启动任务失败: ${data.message || '未知错误'}`, 'danger');
+ }
})
- .then(res => res.json())
- .then(data => {
- hideLoading();
- if (data.success) {
- showAlert('定时任务已成功启动', 'success');
- checkTaskStatus();
- } else {
- showAlert(`启动任务失败: ${data.message || '未知错误'}`, 'danger');
- }
- })
- .catch(error => {
- console.error('启动任务时发生错误:', error);
- hideLoading();
- showAlert('启动任务失败,请稍后重试', 'danger');
+ .catch((error) => {
+ console.error('启动任务时发生错误:', error);
+ hideLoading();
+ showAlert('启动任务失败,请稍后重试', 'danger');
});
}
// 同样添加到停止任务函数
function stopTaskManually() {
- showLoading();
- fetch('/registration/stop', {
- method: 'GET'
+ showLoading();
+ fetch('/registration/stop', {
+ method: 'GET',
+ })
+ .then((res) => res.json())
+ .then((data) => {
+ hideLoading();
+ if (data.success) {
+ showAlert('定时任务已成功停止', 'success');
+
+ // 立即更新任务状态 - 添加这段代码
+ fetch('/registration/status')
+ .then((res) => res.json())
+ .then((statusData) => {
+ updateTaskStatusUI(statusData);
+ });
+ } else {
+ showAlert(`停止任务失败: ${data.message || '未知错误'}`, 'danger');
+ }
})
- .then(res => res.json())
- .then(data => {
- hideLoading();
- if (data.success) {
- showAlert('定时任务已成功停止', 'success');
-
- // 立即更新任务状态 - 添加这段代码
- fetch('/registration/status')
- .then(res => res.json())
- .then(statusData => {
- updateTaskStatusUI(statusData);
- });
- } else {
- showAlert(`停止任务失败: ${data.message || '未知错误'}`, 'danger');
- }
- })
- .catch(error => {
- console.error('停止任务时发生错误:', error);
- hideLoading();
- showAlert('停止任务失败,请稍后重试', 'danger');
+ .catch((error) => {
+ console.error('停止任务时发生错误:', error);
+ hideLoading();
+ showAlert('停止任务失败,请稍后重试', 'danger');
});
}
// 复制到剪贴板
function copyToClipboard(text) {
- navigator.clipboard.writeText(text).then(() => {
- showAlert('复制成功,Token已复制到剪贴板', 'success');
- }).catch(err => {
- console.error('复制失败:', err);
- showAlert('复制失败', 'danger');
+ navigator.clipboard
+ .writeText(text)
+ .then(() => {
+ showAlert('复制成功,Token已复制到剪贴板', 'success');
+ })
+ .catch((err) => {
+ console.error('复制失败:', err);
+ showAlert('复制失败', 'danger');
});
}
// 显示通知
function showAlert(message, type, isSpecial = false) {
- const alertId = 'alert-' + Date.now();
- const alertClass = isSpecial ?
- `alert-${type} special-alert animate__animated animate__bounceIn` :
- `alert-${type} animate__animated animate__fadeInRight`;
-
- const alert = $(`
+ const alertId = 'alert-' + Date.now();
+ const alertClass = isSpecial
+ ? `alert-${type} special-alert animate__animated animate__bounceIn`
+ : `alert-${type} animate__animated animate__fadeInRight`;
+
+ const alert = $(`
${isSpecial ? '' : ''}${message}
`);
-
- $("#alert-container").append(alert);
-
- // 5秒后自动消失
- setTimeout(() => {
- $(`#${alertId}`).alert('close');
- }, 5000);
+
+ $('#alert-container').append(alert);
+
+ // 5秒后自动消失
+ setTimeout(() => {
+ $(`#${alertId}`).alert('close');
+ }, 5000);
}
// 日期时间格式化
function formatDateTime(dateTimeString) {
- if (!dateTimeString) return '-';
-
- try {
- const date = new Date(dateTimeString);
- if (isNaN(date.getTime())) return dateTimeString;
-
- const year = date.getFullYear();
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
- const day = date.getDate().toString().padStart(2, '0');
- const hours = date.getHours().toString().padStart(2, '0');
- const minutes = date.getMinutes().toString().padStart(2, '0');
- const seconds = date.getSeconds().toString().padStart(2, '0');
-
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
- } catch (error) {
- return dateTimeString;
- }
+ if (!dateTimeString) return '-';
+
+ try {
+ const date = new Date(dateTimeString);
+ if (isNaN(date.getTime())) return dateTimeString;
+
+ const year = date.getFullYear();
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
+ const day = date.getDate().toString().padStart(2, '0');
+ const hours = date.getHours().toString().padStart(2, '0');
+ const minutes = date.getMinutes().toString().padStart(2, '0');
+ const seconds = date.getSeconds().toString().padStart(2, '0');
+
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
+ } catch (error) {
+ return dateTimeString;
+ }
}
// 修改掩码函数,增加对用户名的特殊处理
function maskText(text, showChars = 6, isUsername = false) {
- if (!text) return '';
-
- // 用户名特殊处理 - 只显示前1/3
- if (isUsername) {
- const showLength = Math.ceil(text.length / 3);
- if (text.length <= showLength) return text;
- return `${text.substring(0, showLength)}...`;
- }
-
- // 其他文本使用标准处理
- if (text.length <= showChars) return text;
- return `${text.substring(0, showChars)}...`;
+ if (!text) return '';
+
+ // 用户名特殊处理 - 只显示前1/3
+ if (isUsername) {
+ const showLength = Math.ceil(text.length / 3);
+ if (text.length <= showLength) return text;
+ return `${text.substring(0, showLength)}...`;
+ }
+
+ // 其他文本使用标准处理
+ if (text.length <= showChars) return text;
+ return `${text.substring(0, showChars)}...`;
}
// 隐藏密码
function maskPassword(password) {
- if (!password) return '';
- return '•'.repeat(password.length);
+ if (!password) return '';
+ return '•'.repeat(password.length);
}
// 页面加载动画
-document.addEventListener('DOMContentLoaded', function() {
- // 修改动画类添加代码,删除对已删除元素的引用
- const elements = [
- {selector: '.card', animation: 'animate__fadeIn', delay: 0.2}
- ];
-
- elements.forEach(item => {
- const elems = document.querySelectorAll(item.selector);
- elems.forEach((el, index) => {
- el.classList.add('animate__animated', item.animation);
-
- if (item.delay) {
- const delay = item.stagger ? item.delay * (index + 1) : item.delay;
- el.style.animationDelay = `${delay}s`;
- }
- });
+document.addEventListener('DOMContentLoaded', function () {
+ // 修改动画类添加代码,删除对已删除元素的引用
+ const elements = [
+ { selector: '.card', animation: 'animate__fadeIn', delay: 0.2 },
+ ];
+
+ elements.forEach((item) => {
+ const elems = document.querySelectorAll(item.selector);
+ elems.forEach((el, index) => {
+ el.classList.add('animate__animated', item.animation);
+
+ if (item.delay) {
+ const delay = item.stagger ? item.delay * (index + 1) : item.delay;
+ el.style.animationDelay = `${delay}s`;
+ }
});
+ });
});
// 烟花动画实现
const Fireworks = {
- canvas: null,
- ctx: null,
- particles: [],
-
- init: function() {
- this.canvas = document.getElementById('fireworks-canvas');
- this.ctx = this.canvas.getContext('2d');
- this.resizeCanvas();
- window.addEventListener('resize', () => this.resizeCanvas());
- },
-
- resizeCanvas: function() {
- this.canvas.width = window.innerWidth;
- this.canvas.height = window.innerHeight;
- },
-
- start: function() {
- this.canvas.style.display = 'block';
- this.particles = [];
-
- // 创建5次烟花,间隔300ms
- for (let i = 0; i < 5; i++) {
- setTimeout(() => {
- const x = Math.random() * this.canvas.width;
- const y = Math.random() * this.canvas.height * 0.6;
- this.createParticles(x, y);
- }, i * 300);
- }
-
- this.animate();
-
- // 5秒后停止动画
- setTimeout(() => {
- this.canvas.style.display = 'none';
- }, 5000);
- },
-
- createParticles: function(x, y) {
- const colors = ['#ff595e', '#ffca3a', '#8ac926', '#1982c4', '#6a4c93'];
-
- for (let i = 0; i < 80; i++) {
- const particle = {
- x: x,
- y: y,
- size: Math.random() * 4 + 1,
- color: colors[Math.floor(Math.random() * colors.length)],
- velocity: {
- x: (Math.random() - 0.5) * 8,
- y: (Math.random() - 0.5) * 8
- },
- alpha: 1,
- decay: Math.random() * 0.02 + 0.01
- };
-
- this.particles.push(particle);
- }
- },
-
- animate: function() {
- if (this.particles.length === 0) return;
-
- requestAnimationFrame(() => this.animate());
-
- this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
-
- for (let i = 0; i < this.particles.length; i++) {
- const p = this.particles[i];
-
- // 添加重力
- p.velocity.y += 0.05;
-
- // 更新位置
- p.x += p.velocity.x;
- p.y += p.velocity.y;
-
- // 减少透明度
- p.alpha -= p.decay;
-
- // 绘制粒子
- this.ctx.save();
- this.ctx.globalAlpha = p.alpha;
- this.ctx.fillStyle = p.color;
- this.ctx.beginPath();
- this.ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
- this.ctx.fill();
- this.ctx.restore();
-
- // 移除消失的粒子
- if (p.alpha <= 0) {
- this.particles.splice(i, 1);
- i--;
- }
- }
+ canvas: null,
+ ctx: null,
+ particles: [],
+
+ init: function () {
+ this.canvas = document.getElementById('fireworks-canvas');
+ this.ctx = this.canvas.getContext('2d');
+ this.resizeCanvas();
+ window.addEventListener('resize', () => this.resizeCanvas());
+ },
+
+ resizeCanvas: function () {
+ this.canvas.width = window.innerWidth;
+ this.canvas.height = window.innerHeight;
+ },
+
+ start: function () {
+ this.canvas.style.display = 'block';
+ this.particles = [];
+
+ // 创建5次烟花,间隔300ms
+ for (let i = 0; i < 5; i++) {
+ setTimeout(() => {
+ const x = Math.random() * this.canvas.width;
+ const y = Math.random() * this.canvas.height * 0.6;
+ this.createParticles(x, y);
+ }, i * 300);
}
+
+ this.animate();
+
+ // 5秒后停止动画
+ setTimeout(() => {
+ this.canvas.style.display = 'none';
+ }, 5000);
+ },
+
+ createParticles: function (x, y) {
+ const colors = ['#ff595e', '#ffca3a', '#8ac926', '#1982c4', '#6a4c93'];
+
+ for (let i = 0; i < 80; i++) {
+ const particle = {
+ x: x,
+ y: y,
+ size: Math.random() * 4 + 1,
+ color: colors[Math.floor(Math.random() * colors.length)],
+ velocity: {
+ x: (Math.random() - 0.5) * 8,
+ y: (Math.random() - 0.5) * 8,
+ },
+ alpha: 1,
+ decay: Math.random() * 0.02 + 0.01,
+ };
+
+ this.particles.push(particle);
+ }
+ },
+
+ animate: function () {
+ if (this.particles.length === 0) return;
+
+ requestAnimationFrame(() => this.animate());
+
+ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
+
+ for (let i = 0; i < this.particles.length; i++) {
+ const p = this.particles[i];
+
+ // 添加重力
+ p.velocity.y += 0.05;
+
+ // 更新位置
+ p.x += p.velocity.x;
+ p.y += p.velocity.y;
+
+ // 减少透明度
+ p.alpha -= p.decay;
+
+ // 绘制粒子
+ this.ctx.save();
+ this.ctx.globalAlpha = p.alpha;
+ this.ctx.fillStyle = p.color;
+ this.ctx.beginPath();
+ this.ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
+ this.ctx.fill();
+ this.ctx.restore();
+
+ // 移除消失的粒子
+ if (p.alpha <= 0) {
+ this.particles.splice(i, 1);
+ i--;
+ }
+ }
+ },
};
// 初始化烟花
@@ -917,210 +1226,229 @@ Fireworks.init();
// 绑定表格交互事件
function bindTableEvents() {
- // 显示/隐藏用户名
- $('.toggle-username').off('click').on('click', function() {
- const username = $(this).data('username');
- const usernameText = $(this).prev('.username-text');
-
- if (usernameText.text() === username) {
- usernameText.text(maskText(username, 6, true));
- } else {
- usernameText.text(username);
- }
- });
-
- // 显示/隐藏密码
- $('.toggle-password').off('click').on('click', function() {
- const password = $(this).data('password');
- const passwordText = $(this).prev('.password-text');
-
- if (passwordText.text() === password) {
- passwordText.text(maskPassword(password));
- } else {
- passwordText.text(password);
- }
- });
-
- // 显示/隐藏Token
- $('.toggle-token').off('click').on('click', function() {
- const token = $(this).data('token');
- const tokenText = $(this).prev('.token-text');
-
- if (tokenText.text() === token) {
- tokenText.text(maskText(token));
- } else {
- tokenText.text(token);
- }
- });
-
- // 复制按钮
- $('.copy-btn').off('click').on('click', function() {
- const textToCopy = $('#tokenFullText').val();
- copyToClipboard(textToCopy);
- });
-
- // 获取用量按钮
- $('.get-usage-btn').off('click').on('click', function() {
- const email = $(this).data('email');
- getAccountUsage(email);
- });
-
- // 查看使用记录按钮
- $('.view-records-btn').off('click').on('click', function() {
- const email = $(this).data('email');
- const id = $(this).data('id');
- getAccountUsageRecords(email, id);
+ // 显示/隐藏用户名
+ $('.toggle-username')
+ .off('click')
+ .on('click', function () {
+ const username = $(this).data('username');
+ const usernameText = $(this).prev('.username-text');
+
+ if (usernameText.text() === username) {
+ usernameText.text(maskText(username, 6, true));
+ } else {
+ usernameText.text(username);
+ }
});
- // 删除按钮
- $('.delete-account-btn').off('click').on('click', function() {
- const email = $(this).data('email');
- const id = $(this).data('id');
- $('#deleteEmailConfirm').text(email);
- $('#deleteIdConfirm').text(id || '无');
-
- // 重置并重新绑定确认删除按钮事件
- $('#confirmDeleteBtn').off('click').on('click', function() {
- deleteAccount(email, id, true);
+ // 显示/隐藏密码
+ $('.toggle-password')
+ .off('click')
+ .on('click', function () {
+ const password = $(this).data('password');
+ const passwordText = $(this).prev('.password-text');
+
+ if (passwordText.text() === password) {
+ passwordText.text(maskPassword(password));
+ } else {
+ passwordText.text(password);
+ }
+ });
+
+ // 显示/隐藏Token
+ $('.toggle-token')
+ .off('click')
+ .on('click', function () {
+ const token = $(this).data('token');
+ const tokenText = $(this).prev('.token-text');
+
+ if (tokenText.text() === token) {
+ tokenText.text(maskText(token));
+ } else {
+ tokenText.text(token);
+ }
+ });
+
+ // 查看Token按钮
+ $('.view-token-btn')
+ .off('click')
+ .on('click', function () {
+ const token = $(this).data('token');
+ const accountId = $(this).data('account-id');
+
+ // 确保token不为空
+ if (!token) {
+ showAlert('Token数据为空或无效', 'danger');
+ return;
+ }
+
+ $('#tokenFullText').val(token);
+ $('#useTokenBtn').data('account-id', accountId);
+
+ // 确保每次打开模态框时都重新绑定复制按钮事件
+ $('#copyTokenBtn')
+ .off('click')
+ .on('click', function () {
+ const textToCopy = $('#tokenFullText').val();
+ copyToClipboard(textToCopy);
});
-
- const deleteModal = new bootstrap.Modal(document.getElementById('deleteConfirmModal'));
- deleteModal.show();
+
+ new bootstrap.Modal(document.getElementById('tokenViewModal')).show();
});
- // 状态操作按钮
- $('.status-action').off('click').on('click', function(e) {
- e.preventDefault();
- const email = $(this).data('email');
- const id = $(this).data('id');
- const status = $(this).data('status');
- updateAccountStatus(email, id, status);
+ // 复制按钮
+ $('.copy-btn')
+ .off('click')
+ .on('click', function () {
+ const textToCopy = $(this).data('copy');
+ copyToClipboard(textToCopy);
});
- // 查看Token按钮
- $('.view-token-btn').off('click').on('click', function() {
- const token = $(this).data('token');
- const accountId = $(this).data('account-id');
- $('#tokenFullText').val(token);
- $('#useTokenBtn').data('account-id', accountId);
- new bootstrap.Modal(document.getElementById('tokenViewModal')).show();
+ // 获取用量按钮
+ $('.get-usage-btn')
+ .off('click')
+ .on('click', function () {
+ const email = $(this).data('email');
+ getAccountUsage(email);
});
-
- // 使用Token按钮
- $('#useTokenBtn').off('click').on('click', function() {
- const accountId = $(this).data('account-id');
- if (!accountId) {
- showAlert('账号ID无效', 'danger');
- return;
- }
-
- showLoading();
- fetch(`/account/use-token/${accountId}`, {
- method: 'POST'
- })
- .then(res => res.json())
- .then(data => {
- hideLoading();
- if (data.success) {
- showAlert(data.message, 'success');
- $('#tokenViewModal').modal('hide');
- } else {
- showAlert(`使用Token失败: ${data.message || '未知错误'}`, 'danger');
- }
- })
- .catch(error => {
- console.error('使用Token时发生错误:', error);
- hideLoading();
- showAlert('使用Token失败,请稍后重试', 'danger');
- });
+
+ // 查看使用记录按钮
+ $('.view-records-btn')
+ .off('click')
+ .on('click', function () {
+ const email = $(this).data('email');
+ const id = $(this).data('id');
+ getAccountUsageRecords(email, id);
+ });
+
+ // 删除按钮
+ $('.delete-account-btn')
+ .off('click')
+ .on('click', function () {
+ const email = $(this).data('email');
+ const id = $(this).data('id');
+
+ // 检查ID是否有效
+ if (!id) {
+ showAlert('无法删除:账号ID无效', 'danger');
+ return;
+ }
+
+ // 设置确认对话框的值
+ $('#deleteEmailConfirm').text(email);
+ $('#deleteIdConfirm').text(id);
+ $('#deleteAccountId').val(id);
+
+ // 显示删除确认对话框
+ const deleteModal = new bootstrap.Modal(
+ document.getElementById('deleteConfirmModal')
+ );
+ deleteModal.show();
+ });
+
+ // 状态操作按钮
+ $('.status-action')
+ .off('click')
+ .on('click', function (e) {
+ e.preventDefault();
+ const email = $(this).data('email');
+ const id = $(this).data('id');
+ const status = $(this).data('status');
+ updateAccountStatus(email, id, status);
});
}
// 更新删除确认按钮事件处理
-$('#confirmDeleteBtn').click(function() {
- const email = $(this).data('email');
- const id = $(this).data('id');
- deleteAccount(email, id, true);
-});
+function deleteAccount() {
+ const accountId = $('#deleteAccountId').val();
+ const email = $('#deleteEmailConfirm').text();
+
+ if (!accountId || accountId === '无') {
+ showAlert('账号ID无效,无法执行删除操作', 'danger');
+ return;
+ }
+
+ showLoading('账号删除中...');
+
+ // 构建API URL
+ const apiUrl = `/account/id/${accountId}?hard_delete=true`;
+
+ fetch(apiUrl, {
+ method: 'DELETE',
+ })
+ .then((res) => res.json())
+ .then((data) => {
+ $('#deleteConfirmModal').modal('hide');
+ cleanupModalBackdrops(); // 添加清理
+ hideLoading();
+
+ if (data.success) {
+ showAlert(`账号 ${email} 已成功删除`, 'success');
+ // 重新加载账号列表
+ loadAccounts(currentPage, itemsPerPage);
+ } else {
+ showAlert(`删除失败: ${data.message || '未知错误'}`, 'danger');
+ }
+ })
+ .catch((error) => {
+ console.error('删除账号时发生错误:', error);
+ $('#deleteConfirmModal').modal('hide');
+ cleanupModalBackdrops(); // 添加清理
+ hideLoading();
+ showAlert('删除账号失败,请稍后重试', 'danger');
+ });
+}
// 修改updateAccountStatus函数,确保正确发送请求体
function updateAccountStatus(email, id, status) {
- showLoading();
- // 优先使用ID API,如果ID存在的话
- const apiUrl = id ?
- `/account/id/${id}/status` :
- `/account/${encodeURIComponent(email)}/status`;
-
- fetch(apiUrl, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ status: status }) // 确保这里的字段名是status
+ showLoading();
+ // 优先使用ID API,如果ID存在的话
+ const apiUrl = id
+ ? `/account/id/${id}/status`
+ : `/account/${encodeURIComponent(email)}/status`;
+
+ fetch(apiUrl, {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ status: status }), // 确保这里的字段名是status
+ })
+ .then((res) => res.json())
+ .then((data) => {
+ hideLoading();
+ if (data.success) {
+ let statusText = '';
+ if (status === 'active') statusText = '正常';
+ else if (status === 'disabled') statusText = '停用';
+ else if (status === 'deleted') statusText = '删除';
+
+ showAlert(
+ `账号${
+ id ? '(ID:' + id + ')' : ''
+ } ${email} 已成功设置为${statusText}状态`,
+ 'success'
+ );
+ loadAccounts(1, itemsPerPage);
+ } else {
+ showAlert(`更新账号状态失败: ${data.message || '未知错误'}`, 'danger');
+ }
})
- .then(res => res.json())
- .then(data => {
- hideLoading();
- if (data.success) {
- let statusText = '';
- if (status === 'active') statusText = '正常';
- else if (status === 'disabled') statusText = '停用';
- else if (status === 'deleted') statusText = '删除';
-
- showAlert(`账号${id ? '(ID:'+id+')' : ''} ${email} 已成功设置为${statusText}状态`, 'success');
- loadAccounts(1, itemsPerPage);
- } else {
- showAlert(`更新账号状态失败: ${data.message || '未知错误'}`, 'danger');
- }
- })
- .catch(error => {
- console.error('更新账号状态时发生错误:', error);
- hideLoading();
- showAlert('更新账号状态失败,请稍后重试', 'danger');
+ .catch((error) => {
+ console.error('更新账号状态时发生错误:', error);
+ hideLoading();
+ showAlert('更新账号状态失败,请稍后重试', 'danger');
});
}
-// 修改deleteAccount函数,支持通过ID删除
-function deleteAccount(email, id, hardDelete = true) {
- showLoading();
- // 优先使用ID API,如果ID存在的话
- const apiUrl = id ?
- `/account/id/${id}${hardDelete ? '?hard_delete=true' : ''}` :
- `/account/${encodeURIComponent(email)}${hardDelete ? '?hard_delete=true' : ''}`;
-
- fetch(apiUrl, {
- method: 'DELETE'
- })
- .then(res => res.json())
- .then(data => {
- hideLoading();
- if (data.success) {
- showAlert(`账号${id ? '(ID:'+id+')' : ''} ${email} 已成功删除`, 'success');
- // 关闭模态框
- $('#deleteConfirmModal').modal('hide');
- // 重新加载账号列表
- loadAccounts(1, itemsPerPage);
- } else {
- showAlert(`删除账号失败: ${data.message || '未知错误'}`, 'danger');
- }
- })
- .catch(error => {
- console.error('删除账号时发生错误:', error);
- hideLoading();
- showAlert('删除账号失败,请稍后重试', 'danger');
- });
-}
-
-
// 完全重构额度显示函数,精确匹配参考代码
function renderUsageProgress(usageLimit) {
- // 计算使用进度
- const premiumUsed = 150 - usageLimit;
- const premiumTotal = 150;
- const premiumRemaining = premiumTotal - premiumUsed;
- const premiumPercent = Math.round((premiumUsed / premiumTotal) * 100);
-
- return `
+ // 计算使用进度
+ const premiumUsed = 150 - usageLimit;
+ const premiumTotal = 150;
+ const premiumRemaining = premiumTotal - premiumUsed;
+ const premiumPercent = Math.round((premiumUsed / premiumTotal) * 100);
+
+ return `
${premiumUsed}
@@ -1128,7 +1456,9 @@ function renderUsageProgress(usageLimit) {
${premiumTotal}
(剩余: ${premiumRemaining})
-
+
@@ -1149,7 +1479,7 @@ function renderUsageProgress(usageLimit) {
// 修改Token列的渲染方式
function renderTokenColumn(token, accountId, email) {
- return `
+ return `
| |