阶段七:完成Notifications React feature化与渠道绑定边界
This commit is contained in:
1 parent
b128ce60db
commit
2ec7bec05f
20 files changed
+1338
-1785
No files matched your search
+183
-867
File diff suppressed because it is too large.
Load diff
@@ -174,7 +174,8 @@ app shell / routes
|
||||
- 已完成阶段 7 第三个 PR 切片“React AccountList feature 化与账号运行状态行为边界”:按 `app/features/accounts` 提取账号 API 适配层、账号数据与运行状态 Hook、运行状态展示模型、账号编辑弹窗和登录/暂停状态模型;账号加载与运行状态轮询支持取消和请求代次门禁,密码登录响应按账号与代次隔离,旧组件入口保留兼容转发;行为测试覆盖账号切换、暂停/恢复、凭证失败、风控验证和过期响应;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 已完成阶段 7 第四个 PR 切片“React CardList feature 化与卡密库存/批量追加行为边界”:按 `app/features/cards` 提取卡密 API 适配层、库存数据 Hook、批量导入/追加状态 Hook 和弹窗组件;卡密筛选、追加预览、提交取消、失败重试与账号切换过期响应均由 feature 状态边界负责,保留旧组件入口和 API 路径;新增状态模型测试并通过前端类型检查、全量测试、注释检查和构建门禁,合并为一个可回滚提交;
|
||||
- 已完成阶段 7 第五个 PR 切片“React OrderList feature 化与订单导入/刷新行为边界”:按 `app/features/orders` 提取订单 API 适配层、查询/分页 Hook、导入 Hook、筛选栏和导入弹窗;订单查询与辅助数据支持并行加载、取消和代次门禁,导入支持文件预检、取消、失败重试和导入后刷新;新增筛选、导入归一化、API 取消信号和过期响应测试,保留旧组件入口和 API 路径;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 阶段 7 下一 PR 切片为“React Notifications feature 化与渠道/事件绑定行为边界”:提取通知 API、渠道数据 Hook 和通知绑定组件,补充渠道校验、保存取消、失败重试和过期响应测试;
|
||||
- 已完成阶段 7 第六个 PR 切片“React Notifications feature 化与渠道/事件绑定行为边界”:按 `app/features/notifications` 提取通知渠道/SMTP API 适配层、静态渠道配置、数据与动作 Hook、渠道列表、事件绑定选择器、渠道编辑弹窗和 SMTP 面板;渠道与 SMTP 请求支持取消和代次门禁,表单支持渠道字段/独立 SMTP 校验、保存失败重试和过期响应保护;更新架构字符串测试并新增状态/API 取消信号测试,保留旧页面入口和 API 路径;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 阶段 7 下一 PR 切片为“React Dashboard feature 化与统计/趋势查询行为边界”:提取 Dashboard API、统计数据 Hook 和趋势图表组件,补充并行查询、刷新取消、失败重试和过期响应测试;
|
||||
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
|
||||
|
||||
## 6. 阶段 0:治理文档与强约束
|
||||
@@ -598,3 +599,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-15 | 完成阶段 7 第三个 PR 切片“React AccountList feature 化与账号运行状态行为边界” | 新增 `app/features/accounts` 的 API 适配层、账号数据与运行状态 Hook、账号编辑弹窗、登录/暂停状态模型;账号加载和运行状态轮询具备取消与代次门禁,密码登录响应按账号与代次隔离,兼容入口保留;行为测试覆盖账号切换、暂停/恢复、凭证失败、风控验证和过期响应;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React CardList feature 化与卡密库存/批量追加行为边界 |
|
||||
| 2026-08-15 | 完成阶段 7 第四个 PR 切片“React CardList feature 化与卡密库存/批量追加行为边界” | 按 `app/features/cards` 提取卡密 API 适配层、库存数据 Hook、批量导入/追加状态 Hook 和弹窗组件;卡密筛选、追加预览、提交取消、失败重试与账号切换过期响应均由 feature 状态边界负责,保留旧组件入口和 API 路径;新增状态模型测试并通过前端类型检查、全量测试、注释检查和构建门禁,合并为一个可回滚提交 | 阶段 7:React OrderList feature 化与订单导入/刷新行为边界 |
|
||||
| 2026-08-15 | 完成阶段 7 第五个 PR 切片“React OrderList feature 化与订单导入/刷新行为边界” | 按 `app/features/orders` 提取订单 API 适配层、查询/分页 Hook、导入 Hook、筛选栏和导入弹窗;订单查询与辅助数据支持并行加载、取消和代次门禁,导入支持文件预检、取消、失败重试和导入后刷新;新增筛选、导入归一化、API 取消信号和过期响应测试,保留旧组件入口和 API 路径;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React Notifications feature 化与渠道/事件绑定行为边界 |
|
||||
| 2026-08-15 | 完成阶段 7 第六个 PR 切片“React Notifications feature 化与渠道/事件绑定行为边界” | 按 `app/features/notifications` 提取通知渠道/SMTP API 适配层、静态渠道配置、数据与动作 Hook、渠道列表、事件绑定选择器、渠道编辑弹窗和 SMTP 面板;渠道与 SMTP 请求支持取消和代次门禁,表单支持渠道字段/独立 SMTP 校验、保存失败重试和过期响应保护;更新架构字符串测试并新增状态/API 取消信号测试,保留旧页面入口和 API 路径;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React Dashboard feature 化与统计/趋势查询行为边界 |
|
||||
@@ -0,0 +1,11 @@
|
||||
export {
|
||||
createNotificationChannel,
|
||||
deleteNotificationChannel,
|
||||
getNotificationChannels,
|
||||
getSystemSettings,
|
||||
testNotificationChannel,
|
||||
updateNotificationChannel,
|
||||
updateSystemSettings,
|
||||
} from '../../../services/api';
|
||||
|
||||
// notifications feature 通过本适配层声明渠道和 SMTP API 的来源。
|
||||
@@ -0,0 +1,97 @@
|
||||
import React from 'react';
|
||||
import { Bell, Edit2, Loader2, Send, Trash2 } from 'lucide-react';
|
||||
import type { NotificationChannel } from '../../../../types';
|
||||
import { notificationChannelTypes, notificationEventSummary } from '../state';
|
||||
|
||||
// NotificationChannelListProps 描述通知渠道列表的操作边界。
|
||||
export interface NotificationChannelListProps {
|
||||
// channels 是当前可展示的通知渠道。
|
||||
channels: NotificationChannel[];
|
||||
// testingId 是当前正在测试发送的渠道 ID。
|
||||
testingId: string;
|
||||
// onEdit 打开指定渠道的编辑弹窗。
|
||||
onEdit: (channel: NotificationChannel) => void;
|
||||
// onDelete 删除指定渠道。
|
||||
onDelete: (channel: NotificationChannel) => void | Promise<void>;
|
||||
// onToggleEnabled 切换指定渠道的启用状态。
|
||||
onToggleEnabled: (channel: NotificationChannel) => void | Promise<void>;
|
||||
// onTest 发送指定渠道的测试通知。
|
||||
onTest: (channel: NotificationChannel) => void | Promise<void>;
|
||||
}
|
||||
|
||||
// NotificationChannelList 渲染渠道摘要、启用状态和操作按钮。
|
||||
export const NotificationChannelList: React.FC<NotificationChannelListProps> = ({ channels, testingId, onEdit, onDelete, onToggleEnabled, onTest }) => {
|
||||
// findChannel 从按钮数据属性中查找对应渠道。
|
||||
const findChannel = (event: React.MouseEvent<HTMLButtonElement>): NotificationChannel | null => channels.find(
|
||||
// channel 是当前待匹配的渠道数据。
|
||||
channel => channel.id === event.currentTarget.dataset.channelId,
|
||||
) || null;
|
||||
// handleToggleClick 处理渠道启用状态按钮点击。
|
||||
const handleToggleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
// channel 是按钮对应的渠道数据。
|
||||
const channel = findChannel(event);
|
||||
if (channel) void onToggleEnabled(channel);
|
||||
};
|
||||
// handleTestClick 处理渠道测试按钮点击。
|
||||
const handleTestClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
// channel 是按钮对应的渠道数据。
|
||||
const channel = findChannel(event);
|
||||
if (channel) void onTest(channel);
|
||||
};
|
||||
// handleEditClick 处理渠道编辑按钮点击。
|
||||
const handleEditClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
// channel 是按钮对应的渠道数据。
|
||||
const channel = findChannel(event);
|
||||
if (channel) onEdit(channel);
|
||||
};
|
||||
// handleDeleteClick 处理渠道删除按钮点击。
|
||||
const handleDeleteClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
// channel 是按钮对应的渠道数据。
|
||||
const channel = findChannel(event);
|
||||
if (channel) void onDelete(channel);
|
||||
};
|
||||
// renderChannel 渲染单个通知渠道卡片。
|
||||
const renderChannel = (channel: NotificationChannel) => {
|
||||
// meta 是当前渠道类型的静态展示配置。
|
||||
const meta = notificationChannelTypes[channel.type] || notificationChannelTypes.webhook;
|
||||
// Icon 是当前渠道类型对应的图标组件。
|
||||
const Icon = meta.icon;
|
||||
return (
|
||||
<div key={channel.id} className="ios-card rounded-xl p-5 bg-white flex items-center gap-4">
|
||||
<div className="w-11 h-11 rounded-xl bg-gray-100 flex items-center justify-center flex-shrink-0"><Icon className="w-5 h-5 text-gray-600" /></div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-bold text-gray-900 truncate">{channel.name}</span>
|
||||
<span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium">{meta.label}</span>
|
||||
{!channel.enabled && <span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium">已停用</span>}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500 mt-1 truncate">
|
||||
{meta.fields.map(
|
||||
// field 是当前渠道摘要需要读取的配置字段。
|
||||
field => channel.config?.[field.key],
|
||||
).filter(Boolean).map(
|
||||
// value 是渠道配置中非空的摘要值。
|
||||
(value, index) => <span key={index} className="mr-3">{String(value).length > 40 ? `${String(value).slice(0, 40)}…` : String(value)}</span>,
|
||||
)}
|
||||
</div>
|
||||
<div className="text-xs text-gray-400 mt-1 truncate">订阅:{notificationEventSummary(channel.event_types)}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<button data-channel-id={channel.id} onClick={handleToggleClick} className={`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${channel.enabled ? 'bg-green-50 text-green-700 hover:bg-green-100' : 'bg-gray-100 text-gray-500 hover:bg-gray-200'}`}>
|
||||
{channel.enabled ? '启用中' : '已停用'}
|
||||
</button>
|
||||
<button data-channel-id={channel.id} onClick={handleTestClick} disabled={testingId === channel.id} className="px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-brand hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50">
|
||||
{testingId === channel.id ? <Loader2 className="w-3 h-3 animate-spin" /> : <Send className="w-3 h-3" />}测试
|
||||
</button>
|
||||
<button data-channel-id={channel.id} onClick={handleEditClick} className="w-8 h-8 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center text-gray-600 transition-colors" title="编辑"><Edit2 className="w-4 h-4" /></button>
|
||||
<button data-channel-id={channel.id} onClick={handleDeleteClick} className="w-8 h-8 rounded-lg bg-red-50 hover:bg-red-100 flex items-center justify-center text-red-500 transition-colors" title="删除"><Trash2 className="w-4 h-4" /></button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
if (channels.length === 0) {
|
||||
return <div className="ios-card rounded-xl p-12 bg-white text-center"><Bell className="w-12 h-12 text-gray-300 mx-auto mb-4" /><p className="text-gray-500 font-medium">还没有配置任何通知渠道</p><p className="text-gray-400 text-sm mt-1">点击右上角「新建渠道」开始配置</p></div>;
|
||||
}
|
||||
return <div className="space-y-3">{channels.map(renderChannel)}</div>;
|
||||
};
|
||||
@@ -0,0 +1,153 @@
|
||||
import React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Bell, Check, Eye, EyeOff, Loader2, X } from 'lucide-react';
|
||||
import { enableCustomSMTP } from '../../../../notificationEmailConfig';
|
||||
import { notificationChannelTypes } from '../state';
|
||||
import { NotificationEventSelector } from './NotificationEventSelector';
|
||||
import type { NotificationChannel, NotificationChannelType, NotificationEventType, SystemSettings } from '../../../../types';
|
||||
import type { NotificationForm } from '../types';
|
||||
|
||||
// NotificationChannelModalProps 描述渠道编辑弹窗所需的状态和回调。
|
||||
export interface NotificationChannelModalProps {
|
||||
// showModal 表示弹窗是否打开。
|
||||
showModal: boolean;
|
||||
// editing 表示当前编辑的渠道,新增时为空。
|
||||
editing: NotificationChannel | null;
|
||||
// form 是当前渠道表单值。
|
||||
form: NotificationForm;
|
||||
// setForm 更新渠道表单值。
|
||||
setForm: React.Dispatch<React.SetStateAction<NotificationForm>>;
|
||||
// smtp 是系统 SMTP 配置,用于填充独立 SMTP 初始值。
|
||||
smtp: SystemSettings;
|
||||
// showChannelSmtpPassword 表示是否显示独立 SMTP 密码。
|
||||
showChannelSmtpPassword: boolean;
|
||||
// setShowChannelSmtpPassword 切换独立 SMTP 密码显示状态。
|
||||
setShowChannelSmtpPassword: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
// saving 表示渠道保存请求是否正在执行。
|
||||
saving: boolean;
|
||||
// onClose 关闭弹窗。
|
||||
onClose: () => void;
|
||||
// onSave 提交渠道表单。
|
||||
onSave: () => void | Promise<void>;
|
||||
}
|
||||
|
||||
// NotificationChannelModal 渲染渠道字段、SMTP 覆盖项和事件绑定表单。
|
||||
export const NotificationChannelModal: React.FC<NotificationChannelModalProps> = ({ showModal, editing, form, setForm, smtp, showChannelSmtpPassword, setShowChannelSmtpPassword, saving, onClose, onSave }) => {
|
||||
// meta 是当前渠道类型对应的字段和指南。
|
||||
const meta = notificationChannelTypes[form.type];
|
||||
// handleNameChange 更新渠道名称。
|
||||
const handleNameChange = (event: React.ChangeEvent<HTMLInputElement>) => setForm(
|
||||
// nextFormUpdater 使用函数式更新名称字段。
|
||||
current => ({ ...current, name: event.target.value }),
|
||||
);
|
||||
// handleTypeChange 切换渠道类型并清空旧类型配置。
|
||||
const handleTypeChange = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
// type 是按钮数据属性中的目标渠道类型。
|
||||
const type = event.currentTarget.dataset.type as NotificationChannelType | undefined;
|
||||
if (!type) return;
|
||||
setForm(
|
||||
// nextFormUpdater 使用函数式更新渠道类型。
|
||||
current => ({ ...current, type, config: {} }),
|
||||
);
|
||||
};
|
||||
// handleConfigFieldChange 更新普通或独立 SMTP 配置字段。
|
||||
const handleConfigFieldChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
// key 是输入框数据属性中的配置字段名。
|
||||
const key = event.currentTarget.dataset.field;
|
||||
if (!key) return;
|
||||
setForm(
|
||||
// nextFormUpdater 使用函数式更新配置字段。
|
||||
current => ({ ...current, config: { ...current.config, [key]: event.target.value } }),
|
||||
);
|
||||
};
|
||||
// handleToggleCustomSMTP 切换邮件渠道是否使用独立 SMTP。
|
||||
const handleToggleCustomSMTP = () => setForm(
|
||||
// nextFormUpdater 使用函数式更新 SMTP 来源模式。
|
||||
current => ({ ...current, config: current.config.use_custom_smtp === true ? { ...current.config, use_custom_smtp: false } : enableCustomSMTP(current.config, smtp) }),
|
||||
);
|
||||
// handleChannelTlsChange 切换独立 SMTP 的 STARTTLS 并保持模式互斥。
|
||||
const handleChannelTlsChange = (event: React.ChangeEvent<HTMLInputElement>) => setForm(
|
||||
// nextFormUpdater 使用函数式更新独立 SMTP 的 TLS/SSL 互斥字段。
|
||||
current => ({ ...current, config: { ...current.config, smtp_use_tls: event.target.checked, smtp_use_ssl: event.target.checked ? false : current.config.smtp_use_ssl } }),
|
||||
);
|
||||
// handleChannelSslChange 切换独立 SMTP 的 SSL 并保持模式互斥。
|
||||
const handleChannelSslChange = (event: React.ChangeEvent<HTMLInputElement>) => setForm(
|
||||
// nextFormUpdater 使用函数式更新独立 SMTP 的 SSL/TLS 互斥字段。
|
||||
current => ({ ...current, config: { ...current.config, smtp_use_ssl: event.target.checked, smtp_use_tls: event.target.checked ? false : current.config.smtp_use_tls } }),
|
||||
);
|
||||
// handleToggleEvent 使用函数式更新切换事件绑定。
|
||||
const handleToggleEvent = (event: NotificationEventType) => setForm(
|
||||
// nextFormUpdater 使用函数式更新事件绑定集合。
|
||||
current => ({ ...current, event_types: current.event_types.includes(event) ? current.event_types.filter(
|
||||
// item 是待保留的已有事件值。
|
||||
item => item !== event,
|
||||
) : [...current.event_types, event] }),
|
||||
);
|
||||
// handleToggleEnabled 使用函数式更新切换渠道启用状态。
|
||||
const handleToggleEnabled = () => setForm(
|
||||
// nextFormUpdater 使用函数式更新启用状态。
|
||||
current => ({ ...current, enabled: !current.enabled }),
|
||||
);
|
||||
// handleToggleChannelPassword 切换独立 SMTP 密码明文显示。
|
||||
const handleToggleChannelPassword = () => setShowChannelSmtpPassword(
|
||||
// nextPasswordState 使用函数式更新密码显示状态。
|
||||
value => !value,
|
||||
);
|
||||
// renderGuideStep 渲染当前渠道指南中的单个步骤。
|
||||
const renderGuideStep = (step: string, index: number) => <li key={index}>{step}</li>;
|
||||
|
||||
if (!showModal) return null;
|
||||
|
||||
return createPortal(
|
||||
<div className="modal-overlay">
|
||||
<div className="modal-container" style={{ maxWidth: '36rem' }}>
|
||||
<div className="px-6 py-5 border-b border-gray-100 flex items-center justify-between"><h3 className="text-xl font-extrabold text-gray-900">{editing ? '编辑通知渠道' : '新建通知渠道'}</h3><button onClick={onClose} className="w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center"><X className="w-5 h-5 text-gray-600" /></button></div>
|
||||
<div className="px-6 py-5 space-y-5 overflow-y-auto flex-1 min-h-0">
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">渠道名称</label><input type="text" value={form.name} onChange={handleNameChange} placeholder="例如:我的 Bark" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">渠道类型</label>
|
||||
<div className="grid grid-cols-3 sm:grid-cols-4 gap-2">
|
||||
{(Object.keys(notificationChannelTypes) as NotificationChannelType[]).map(
|
||||
// type 是当前渠道类型选择项。
|
||||
type => {
|
||||
// channelMeta 是当前类型的展示元数据。
|
||||
const channelMeta = notificationChannelTypes[type];
|
||||
// TypeIcon 是当前类型的图标组件。
|
||||
const TypeIcon = channelMeta.icon;
|
||||
// selected 表示当前类型是否已选中。
|
||||
const selected = form.type === type;
|
||||
return <button key={type} data-type={type} type="button" onClick={handleTypeChange} className={`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${selected ? 'border-brand bg-blue-50' : 'border-gray-100 hover:border-gray-300'}`}><TypeIcon className={`w-5 h-5 ${selected ? 'text-brand' : 'text-gray-500'}`} /><span className={`text-xs font-bold ${selected ? 'text-brand' : 'text-gray-600'}`}>{channelMeta.label}</span></button>;
|
||||
},
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-xl bg-amber-50 border border-amber-200 p-4 space-y-2"><div className="flex items-center gap-2"><Bell className="w-4 h-4 text-amber-600" /><span className="text-sm font-bold text-amber-800">如何获取 {meta.label} 配置?</span></div><ol className="space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5">{meta.guide.steps.map(renderGuideStep)}</ol>{meta.guide.urlFormat && <div className="text-xs text-amber-900/90"><span className="font-bold">格式示例:</span><code className="mt-1 block bg-amber-100/70 px-2.5 py-1.5 rounded-lg break-all font-mono text-[11px]">{meta.guide.urlFormat}</code></div>}{meta.guide.note && <p className="text-xs text-amber-800/80 leading-5 pt-1">💡 {meta.guide.note}</p>}</div>
|
||||
<div className="space-y-3">
|
||||
{meta.fields.map(
|
||||
// field 是当前渠道配置字段。
|
||||
field => <div key={field.key} className="space-y-2"><label className="block text-sm font-bold text-gray-800">{field.label}{field.required && <span className="text-red-500 ml-1">*</span>}</label><input data-field={field.key} type={field.type === 'password' ? 'password' : field.type === 'number' ? 'number' : 'text'} value={String(form.config[field.key] || '')} onChange={handleConfigFieldChange} placeholder={field.placeholder} className="w-full ios-input px-4 py-3 rounded-xl text-sm" />{field.help && <p className="text-xs text-gray-500">{field.help}</p>}</div>,
|
||||
)}
|
||||
</div>
|
||||
{form.type === 'email' && (
|
||||
<div className="overflow-hidden rounded-2xl border border-blue-100 bg-blue-50/40">
|
||||
<div className="flex items-center justify-between gap-4 p-4"><div><div className="text-sm font-extrabold text-gray-900">SMTP 来源</div><p className="mt-1 text-xs leading-5 text-gray-500">{form.config.use_custom_smtp === true ? '当前渠道使用一套完整、独立的发件配置。' : '当前渠道完整继承系统 SMTP,只单独设置收件邮箱。'}</p></div><button type="button" onClick={handleToggleCustomSMTP} className={`relative h-7 w-12 shrink-0 rounded-full transition-colors ${form.config.use_custom_smtp === true ? 'bg-brand' : 'bg-gray-300'}`} aria-label="使用独立 SMTP"><span className={`absolute left-1 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${form.config.use_custom_smtp === true ? 'translate-x-5' : ''}`} /></button></div>
|
||||
{form.config.use_custom_smtp === true && (
|
||||
<div className="space-y-4 border-t border-blue-100 bg-white/80 p-4">
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2"><div className="space-y-2"><label className="block text-sm font-bold text-gray-800">SMTP 服务器 <span className="text-red-500">*</span></label><input data-field="smtp_server" type="text" value={String(form.config.smtp_server || '')} onChange={handleConfigFieldChange} placeholder="smtp.qq.com" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div><div className="space-y-2"><label className="block text-sm font-bold text-gray-800">SMTP 端口 <span className="text-red-500">*</span></label><input data-field="smtp_port" type="number" value={String(form.config.smtp_port || 587)} onChange={handleConfigFieldChange} placeholder="587" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div></div>
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">登录邮箱 <span className="text-red-500">*</span></label><input data-field="smtp_user" type="email" value={String(form.config.smtp_user || '')} onChange={handleConfigFieldChange} placeholder="your-email@qq.com" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div>
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">密码 / 授权码 <span className="text-red-500">*</span></label><div className="relative"><input data-field="smtp_password" type={showChannelSmtpPassword ? 'text' : 'password'} value={String(form.config.smtp_password || '')} onChange={handleConfigFieldChange} placeholder="输入密码或授权码" className="w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm" /><button type="button" onClick={handleToggleChannelPassword} className="absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600">{showChannelSmtpPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}</button></div></div>
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2"><div className="space-y-2"><label className="block text-sm font-bold text-gray-800">发件人显示名(可选)</label><input data-field="smtp_from_name" type="text" value={String(form.config.smtp_from_name || '')} onChange={handleConfigFieldChange} placeholder="闲鱼自动回复系统" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div><div className="space-y-2"><label className="block text-sm font-bold text-gray-800">发件邮箱地址 <span className="text-red-500">*</span></label><input data-field="smtp_from_address" type="email" value={String(form.config.smtp_from_address || '')} onChange={handleConfigFieldChange} placeholder="your-email@qq.com" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div></div>
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2"><label className="flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700"><input type="checkbox" checked={form.config.smtp_use_tls !== false} onChange={handleChannelTlsChange} />STARTTLS(常用于 587)</label><label className="flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700"><input type="checkbox" checked={form.config.smtp_use_ssl === true} onChange={handleChannelSslChange} />SSL/TLS 直连(常用于 465)</label></div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<NotificationEventSelector selectedEvents={form.event_types} onToggleEvent={handleToggleEvent} />
|
||||
<label className="flex items-center gap-3 cursor-pointer"><button type="button" onClick={handleToggleEnabled} className={`relative w-11 h-6 rounded-full transition-colors ${form.enabled ? 'bg-brand' : 'bg-gray-300'}`}><span className={`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${form.enabled ? 'translate-x-5' : ''}`} /></button><span className="text-sm font-bold text-gray-800">启用此渠道</span></label>
|
||||
</div>
|
||||
<div className="px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3"><button onClick={onClose} className="px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors">取消</button><button onClick={onSave} disabled={saving} className="ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50">{saving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Check className="w-4 h-4" />}{saving ? '保存中...' : '保存'}</button></div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
import React from 'react';
|
||||
import { Check } from 'lucide-react';
|
||||
import { notificationEvents } from '../state';
|
||||
import type { NotificationEventType } from '../../../../types';
|
||||
|
||||
// NotificationEventSelectorProps 描述通知事件绑定组件的输入状态。
|
||||
export interface NotificationEventSelectorProps {
|
||||
// selectedEvents 是当前已选择的通知事件。
|
||||
selectedEvents: NotificationEventType[];
|
||||
// onToggleEvent 切换指定通知事件的绑定状态。
|
||||
onToggleEvent: (event: NotificationEventType) => void;
|
||||
}
|
||||
|
||||
// NotificationEventSelector 渲染通知渠道可订阅的事件列表。
|
||||
export const NotificationEventSelector: React.FC<NotificationEventSelectorProps> = ({ selectedEvents, onToggleEvent }) => {
|
||||
// handleEventClick 将用户点击的事件传回表单状态。
|
||||
const handleEventClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
// eventValue 是按钮数据属性中的后端事件类型。
|
||||
const eventValue = event.currentTarget.dataset.event as NotificationEventType | undefined;
|
||||
if (eventValue) onToggleEvent(eventValue);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-800">通知内容</label>
|
||||
<p className="text-xs text-gray-500 mt-1">不选择表示接收全部通知;选择后仅接收勾选类型。</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
{notificationEvents.map(
|
||||
// event 是当前通知事件定义。
|
||||
event => {
|
||||
// checked 表示当前事件是否已被选中。
|
||||
const checked = selectedEvents.includes(event.value);
|
||||
return (
|
||||
<button
|
||||
key={event.value}
|
||||
type="button"
|
||||
data-event={event.value}
|
||||
onClick={handleEventClick}
|
||||
className={`text-left rounded-xl border px-3 py-2.5 transition-colors ${checked ? 'border-brand bg-blue-50' : 'border-gray-100 hover:border-gray-300'}`}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`w-4 h-4 rounded border flex items-center justify-center ${checked ? 'bg-brand border-brand' : 'border-gray-300'}`}>
|
||||
{checked && <Check className="w-3 h-3 text-white" />}
|
||||
</span>
|
||||
<span className={`text-sm font-bold ${checked ? 'text-brand' : 'text-gray-800'}`}>{event.label}</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-1 pl-6 leading-5">{event.description}</p>
|
||||
</button>
|
||||
);
|
||||
},
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,97 @@
|
||||
import React from 'react';
|
||||
import { Eye, EyeOff, Loader2, Mail, Save } from 'lucide-react';
|
||||
import type { SystemSettings } from '../../../../types';
|
||||
|
||||
// NotificationSmtpSettingsProps 描述系统 SMTP 配置面板所需的状态和事件。
|
||||
export interface NotificationSmtpSettingsProps {
|
||||
// smtp 是当前系统 SMTP 配置。
|
||||
smtp: SystemSettings;
|
||||
// setSmtp 更新 SMTP 配置字段。
|
||||
setSmtp: React.Dispatch<React.SetStateAction<SystemSettings>>;
|
||||
// smtpSaving 表示 SMTP 保存请求是否正在执行。
|
||||
smtpSaving: boolean;
|
||||
// showPassword 表示是否显示 SMTP 密码明文。
|
||||
showPassword: boolean;
|
||||
// setShowPassword 切换 SMTP 密码明文显示。
|
||||
setShowPassword: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
// onSave 保存 SMTP 配置。
|
||||
onSave: () => void | Promise<void>;
|
||||
}
|
||||
|
||||
// NotificationSmtpSettings 渲染管理员可见的系统级 SMTP 设置。
|
||||
export const NotificationSmtpSettings: React.FC<NotificationSmtpSettingsProps> = ({ smtp, setSmtp, smtpSaving, showPassword, setShowPassword, onSave }) => {
|
||||
// handleTextChange 更新 SMTP 文本字段。
|
||||
const handleTextChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
// key 是文本输入框数据属性中的 SMTP 字段名。
|
||||
const key = event.currentTarget.dataset.field as 'smtp_server' | 'smtp_user' | 'smtp_from_name' | 'smtp_from_address' | undefined;
|
||||
if (!key) return;
|
||||
setSmtp(
|
||||
// nextSettingsUpdater 使用函数式更新避免覆盖并发输入。
|
||||
current => ({ ...current, [key]: event.target.value }),
|
||||
);
|
||||
};
|
||||
// handlePortChange 更新 SMTP 端口并在非法输入时回退默认端口。
|
||||
const handlePortChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setSmtp(
|
||||
// nextSettingsUpdater 使用函数式更新端口字段。
|
||||
current => ({ ...current, smtp_port: parseInt(event.target.value, 10) || 587 }),
|
||||
);
|
||||
};
|
||||
// handleTlsChange 切换 STARTTLS 并保持 TLS 与 SSL 互斥。
|
||||
const handleTlsChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setSmtp(
|
||||
// nextSettingsUpdater 使用函数式更新 TLS/SSL 互斥字段。
|
||||
current => ({ ...current, smtp_use_tls: event.target.checked, smtp_use_ssl: event.target.checked ? false : current.smtp_use_ssl }),
|
||||
);
|
||||
};
|
||||
// handleSslChange 切换直连 SSL 并保持 TLS 与 SSL 互斥。
|
||||
const handleSslChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setSmtp(
|
||||
// nextSettingsUpdater 使用函数式更新 SSL/TLS 互斥字段。
|
||||
current => ({ ...current, smtp_use_ssl: event.target.checked, smtp_use_tls: event.target.checked ? false : current.smtp_use_tls }),
|
||||
);
|
||||
};
|
||||
// handlePasswordChange 更新系统 SMTP 密码。
|
||||
const handlePasswordChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setSmtp(
|
||||
// nextSettingsUpdater 使用函数式更新密码字段。
|
||||
current => ({ ...current, smtp_password: event.target.value }),
|
||||
);
|
||||
};
|
||||
// handleTogglePassword 切换系统 SMTP 密码明文展示。
|
||||
const handleTogglePassword = () => setShowPassword(
|
||||
// nextPasswordState 使用函数式更新密码显示状态。
|
||||
value => !value,
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="ios-card rounded-xl p-6 bg-white space-y-5">
|
||||
<div className="flex items-start justify-between">
|
||||
<div><h3 className="text-lg font-extrabold text-gray-800">SMTP 邮件配置</h3><p className="text-sm text-gray-500 mt-1">系统级邮件发送服务,供邮件通知渠道复用</p></div>
|
||||
<div className="p-2 rounded-xl bg-blue-50 text-blue-600"><Mail className="w-5 h-5" /></div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">SMTP 服务器</label><input data-field="smtp_server" type="text" value={smtp.smtp_server || ''} onChange={handleTextChange} placeholder="smtp.qq.com" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div>
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">SMTP 端口</label><input type="number" value={smtp.smtp_port || 587} onChange={handlePortChange} placeholder="587" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div>
|
||||
</div>
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">发件邮箱</label><input data-field="smtp_user" type="email" value={smtp.smtp_user || ''} onChange={handleTextChange} placeholder="your-email@qq.com" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">邮箱密码 / 授权码</label>
|
||||
<div className="relative">
|
||||
<input type={showPassword ? 'text' : 'password'} value={smtp.smtp_password || ''} onChange={handlePasswordChange} placeholder="输入密码或授权码" className="w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm" />
|
||||
<button type="button" onClick={handleTogglePassword} className="absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors">{showPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}</button>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">发件人显示名(可选)</label><input data-field="smtp_from_name" type="text" value={smtp.smtp_from_name || ''} onChange={handleTextChange} placeholder="闲鱼自动回复系统" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div>
|
||||
<div className="space-y-2"><label className="block text-sm font-bold text-gray-800">发件邮箱地址</label><input data-field="smtp_from_address" type="email" value={smtp.smtp_from_address || smtp.smtp_user || ''} onChange={handleTextChange} placeholder="your-email@qq.com" className="w-full ios-input px-4 py-3 rounded-xl text-sm" /></div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<label className="flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700"><input type="checkbox" checked={smtp.smtp_use_tls !== false} onChange={handleTlsChange} />STARTTLS(常用于 587 端口)</label>
|
||||
<label className="flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700"><input type="checkbox" checked={smtp.smtp_use_ssl === true} onChange={handleSslChange} />SSL/TLS 直连(常用于 465 端口)</label>
|
||||
</div>
|
||||
<button onClick={onSave} disabled={smtpSaving} className="ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50">{smtpSaving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}{smtpSaving ? '保存中...' : '保存 SMTP 配置'}</button>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,344 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { NotificationChannel, NotificationChannelType, SystemSettings } from '../../../types';
|
||||
import { createNotificationChannel, deleteNotificationChannel, getNotificationChannels, getSystemSettings, testNotificationChannel, updateNotificationChannel, updateSystemSettings } from './api';
|
||||
import { buildNotificationPayload, emptyNotificationForm, isCurrentNotificationRequest, notificationErrorMessage, normalizeNotificationForm, validateNotificationForm } from './state';
|
||||
import type { NotificationForm, NotificationState } from './types';
|
||||
|
||||
// useNotifications 统一管理通知渠道、事件订阅和系统 SMTP 的异步状态。
|
||||
export const useNotifications = (isAdmin: boolean): NotificationState => {
|
||||
// channels 保存当前用户可用的通知渠道。
|
||||
const [channels, setChannels] = useState<NotificationChannel[]>([]);
|
||||
// loading 表示通知渠道列表是否正在加载。
|
||||
const [loading, setLoading] = useState(true);
|
||||
// showModal 表示渠道新建或编辑弹窗是否打开。
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
// editing 保存当前正在编辑的渠道。
|
||||
const [editing, setEditing] = useState<NotificationChannel | null>(null);
|
||||
// saving 表示渠道保存或删除动作是否正在执行。
|
||||
const [saving, setSaving] = useState(false);
|
||||
// testingId 保存当前正在测试发送的渠道 ID。
|
||||
const [testingId, setTestingId] = useState('');
|
||||
// toast 保存当前短暂操作提示。
|
||||
const [toast, setToast] = useState<NotificationState['toast']>(null);
|
||||
// smtp 保存系统级邮件发送配置。
|
||||
const [smtp, setSmtp] = useState<SystemSettings>({});
|
||||
// smtpSaving 表示系统 SMTP 保存是否正在执行。
|
||||
const [smtpSaving, setSmtpSaving] = useState(false);
|
||||
// showSmtpPassword 控制系统 SMTP 密码是否明文显示。
|
||||
const [showSmtpPassword, setShowSmtpPassword] = useState(false);
|
||||
// showChannelSmtpPassword 控制独立 SMTP 密码是否明文显示。
|
||||
const [showChannelSmtpPassword, setShowChannelSmtpPassword] = useState(false);
|
||||
// form 保存渠道编辑弹窗的当前表单。
|
||||
const [form, setForm] = useState<NotificationForm>(emptyNotificationForm);
|
||||
// channelGeneration 隔离渠道加载和刷新产生的旧响应。
|
||||
const channelGeneration = useRef(0);
|
||||
// channelAbort 保存当前渠道列表请求的取消控制器。
|
||||
const channelAbort = useRef<AbortController | null>(null);
|
||||
// smtpGeneration 隔离 SMTP 设置切换管理员状态后的旧响应。
|
||||
const smtpGeneration = useRef(0);
|
||||
// smtpAbort 保存当前 SMTP 设置请求的取消控制器。
|
||||
const smtpAbort = useRef<AbortController | null>(null);
|
||||
// actionGeneration 隔离保存、删除和测试动作的旧响应。
|
||||
const actionGeneration = useRef(0);
|
||||
// actionAbort 保存当前渠道变更动作的取消控制器。
|
||||
const actionAbort = useRef<AbortController | null>(null);
|
||||
// toastTimer 保存提示自动消失的定时器句柄。
|
||||
const toastTimer = useRef<number | null>(null);
|
||||
|
||||
// showToast 展示短暂提示并清理上一条提示的定时器。
|
||||
const showToast = useCallback(
|
||||
// 提示回调写入提示状态并安排自动清理。
|
||||
(type: NonNullable<NotificationState['toast']>['type'], text: string) => {
|
||||
setToast({ type, text });
|
||||
if (toastTimer.current !== null) window.clearTimeout(toastTimer.current);
|
||||
toastTimer.current = window.setTimeout(
|
||||
// toastCleanup 在提示展示三秒后清理状态。
|
||||
() => {
|
||||
toastTimer.current = null;
|
||||
setToast(null);
|
||||
},
|
||||
3000,
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// loadChannels 加载通知渠道并丢弃过期响应。
|
||||
const loadChannels = useCallback(
|
||||
// 渠道加载回调读取最新通知渠道列表。
|
||||
async () => {
|
||||
// generation 标记本次渠道查询的代次。
|
||||
const generation = ++channelGeneration.current;
|
||||
channelAbort.current?.abort();
|
||||
// controller 允许刷新或卸载时取消渠道请求。
|
||||
const controller = new AbortController();
|
||||
channelAbort.current = controller;
|
||||
setLoading(true);
|
||||
try {
|
||||
// result 是当前用户的通知渠道列表响应。
|
||||
const result = await getNotificationChannels({ signal: controller.signal });
|
||||
if (!isCurrentNotificationRequest(generation, channelGeneration.current)) return;
|
||||
setChannels(result.data || []);
|
||||
} catch (error: unknown /* 渠道加载异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, channelGeneration.current) && !controller.signal.aborted) {
|
||||
console.error('加载通知渠道失败', error);
|
||||
}
|
||||
} finally {
|
||||
if (isCurrentNotificationRequest(generation, channelGeneration.current)) setLoading(false);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// loadSmtp 加载管理员可见的系统 SMTP 配置并隔离过期响应。
|
||||
const loadSmtp = useCallback(
|
||||
// SMTP 加载回调读取管理员系统设置。
|
||||
async () => {
|
||||
// generation 标记本次 SMTP 查询的代次。
|
||||
const generation = ++smtpGeneration.current;
|
||||
smtpAbort.current?.abort();
|
||||
// controller 允许管理员状态变化时取消 SMTP 查询。
|
||||
const controller = new AbortController();
|
||||
smtpAbort.current = controller;
|
||||
try {
|
||||
// settings 是系统 SMTP 配置快照。
|
||||
const settings = await getSystemSettings({ signal: controller.signal });
|
||||
if (isCurrentNotificationRequest(generation, smtpGeneration.current)) setSmtp(settings || {});
|
||||
} catch (error: unknown /* SMTP 加载异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, smtpGeneration.current) && !controller.signal.aborted) {
|
||||
console.error('加载 SMTP 配置失败', error);
|
||||
}
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(
|
||||
// 通知数据副作用并行加载渠道和管理员 SMTP 配置。
|
||||
() => {
|
||||
void loadChannels();
|
||||
if (isAdmin) {
|
||||
void loadSmtp();
|
||||
} else {
|
||||
smtpGeneration.current += 1;
|
||||
smtpAbort.current?.abort();
|
||||
setSmtp({});
|
||||
}
|
||||
return (
|
||||
// 通知数据清理回调取消渠道和 SMTP 请求。
|
||||
() => {
|
||||
channelGeneration.current += 1;
|
||||
channelAbort.current?.abort();
|
||||
smtpGeneration.current += 1;
|
||||
smtpAbort.current?.abort();
|
||||
}
|
||||
);
|
||||
},
|
||||
[isAdmin, loadChannels, loadSmtp],
|
||||
);
|
||||
|
||||
useEffect(
|
||||
// 提示清理副作用负责页面卸载时释放自动消失定时器。
|
||||
() => (
|
||||
// toastCleanup 在页面卸载时释放定时器。
|
||||
() => {
|
||||
if (toastTimer.current !== null) window.clearTimeout(toastTimer.current);
|
||||
}
|
||||
),
|
||||
[],
|
||||
);
|
||||
|
||||
// openCreate 打开新建渠道表单并清理上一次编辑状态。
|
||||
const openCreate = useCallback(
|
||||
// 新建回调重置表单并打开渠道弹窗。
|
||||
() => {
|
||||
setEditing(null);
|
||||
setForm(emptyNotificationForm());
|
||||
setShowChannelSmtpPassword(false);
|
||||
setShowModal(true);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// openEdit 打开已有渠道并归一化邮件渠道配置。
|
||||
const openEdit = useCallback(
|
||||
// 编辑回调载入渠道配置并打开弹窗。
|
||||
(channel: NotificationChannel) => {
|
||||
setEditing(channel);
|
||||
setForm(normalizeNotificationForm(channel, smtp));
|
||||
setShowChannelSmtpPassword(false);
|
||||
setShowModal(true);
|
||||
},
|
||||
[smtp],
|
||||
);
|
||||
|
||||
// closeModal 关闭渠道弹窗并取消未完成的保存动作。
|
||||
const closeModal = useCallback(
|
||||
// 关闭回调使保存请求失效并隐藏弹窗。
|
||||
() => {
|
||||
actionGeneration.current += 1;
|
||||
actionAbort.current?.abort();
|
||||
setSaving(false);
|
||||
setShowModal(false);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// handleSave 校验并保存当前渠道表单,失败时保留表单供重试。
|
||||
const handleSave = useCallback(
|
||||
// 保存回调执行渠道校验、请求和成功刷新。
|
||||
async () => {
|
||||
// validationError 是渠道表单预检失败时的用户提示。
|
||||
const validationError = validateNotificationForm(form);
|
||||
if (validationError) {
|
||||
showToast('error', validationError);
|
||||
return;
|
||||
}
|
||||
// generation 标记当前渠道保存动作的代次。
|
||||
const generation = ++actionGeneration.current;
|
||||
actionAbort.current?.abort();
|
||||
// controller 允许关闭弹窗时取消保存请求。
|
||||
const controller = new AbortController();
|
||||
actionAbort.current = controller;
|
||||
setSaving(true);
|
||||
try {
|
||||
// payload 是后端渠道接口使用的规范化请求体。
|
||||
const payload = buildNotificationPayload(form);
|
||||
if (editing) {
|
||||
await updateNotificationChannel(editing.id, payload, { signal: controller.signal });
|
||||
} else {
|
||||
await createNotificationChannel(payload, { signal: controller.signal });
|
||||
}
|
||||
if (!isCurrentNotificationRequest(generation, actionGeneration.current)) return;
|
||||
setShowModal(false);
|
||||
await loadChannels();
|
||||
if (!isCurrentNotificationRequest(generation, actionGeneration.current)) return;
|
||||
showToast('success', editing ? '已更新' : '已创建');
|
||||
} catch (error: unknown /* 渠道保存异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, actionGeneration.current) && !controller.signal.aborted) {
|
||||
showToast('error', notificationErrorMessage(error, '保存失败'));
|
||||
}
|
||||
} finally {
|
||||
if (isCurrentNotificationRequest(generation, actionGeneration.current)) setSaving(false);
|
||||
}
|
||||
},
|
||||
[editing, form, loadChannels, showToast],
|
||||
);
|
||||
|
||||
// handleDelete 删除渠道并在成功后刷新列表。
|
||||
const handleDelete = useCallback(
|
||||
// 删除回调执行渠道删除请求并刷新列表。
|
||||
async (channel: NotificationChannel) => {
|
||||
if (!confirm(`确认删除渠道「${channel.name}」吗?已绑定该渠道的账号会自动解绑。`)) return;
|
||||
// generation 标记当前删除动作的代次。
|
||||
const generation = ++actionGeneration.current;
|
||||
actionAbort.current?.abort();
|
||||
// controller 允许刷新页面时取消删除请求。
|
||||
const controller = new AbortController();
|
||||
actionAbort.current = controller;
|
||||
try {
|
||||
await deleteNotificationChannel(channel.id, { signal: controller.signal });
|
||||
if (!isCurrentNotificationRequest(generation, actionGeneration.current)) return;
|
||||
await loadChannels();
|
||||
if (!isCurrentNotificationRequest(generation, actionGeneration.current)) return;
|
||||
showToast('success', '已删除');
|
||||
} catch (error: unknown /* 渠道删除异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, actionGeneration.current) && !controller.signal.aborted) {
|
||||
showToast('error', notificationErrorMessage(error, '删除失败'));
|
||||
}
|
||||
}
|
||||
},
|
||||
[loadChannels, showToast],
|
||||
);
|
||||
|
||||
// handleToggleEnabled 更新渠道启用状态并采用函数式局部更新。
|
||||
const handleToggleEnabled = useCallback(
|
||||
// 启用切换回调更新渠道状态并保留最新响应。
|
||||
async (channel: NotificationChannel) => {
|
||||
// generation 标记当前启用状态动作的代次。
|
||||
const generation = ++actionGeneration.current;
|
||||
actionAbort.current?.abort();
|
||||
// controller 允许新的渠道动作取消旧请求。
|
||||
const controller = new AbortController();
|
||||
actionAbort.current = controller;
|
||||
try {
|
||||
await updateNotificationChannel(channel.id, { enabled: !channel.enabled }, { signal: controller.signal });
|
||||
if (!isCurrentNotificationRequest(generation, actionGeneration.current)) return;
|
||||
setChannels(
|
||||
// nextChannelsUpdater 使用函数式更新渠道列表。
|
||||
current => current.map(
|
||||
// item 是当前待更新的渠道项。
|
||||
item => item.id === channel.id ? { ...item, enabled: !item.enabled } : item,
|
||||
),
|
||||
);
|
||||
} catch (error: unknown /* 渠道状态异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, actionGeneration.current) && !controller.signal.aborted) {
|
||||
showToast('error', notificationErrorMessage(error, '切换失败'));
|
||||
}
|
||||
}
|
||||
},
|
||||
[showToast],
|
||||
);
|
||||
|
||||
// handleTest 发送渠道测试通知并展示结果。
|
||||
const handleTest = useCallback(
|
||||
// 测试回调发送测试通知并显示结果。
|
||||
async (channel: NotificationChannel) => {
|
||||
setTestingId(channel.id);
|
||||
// generation 标记当前测试通知动作的代次。
|
||||
const generation = ++actionGeneration.current;
|
||||
actionAbort.current?.abort();
|
||||
// controller 允许新动作取消旧的测试发送。
|
||||
const controller = new AbortController();
|
||||
actionAbort.current = controller;
|
||||
try {
|
||||
await testNotificationChannel(channel.id, { signal: controller.signal });
|
||||
if (isCurrentNotificationRequest(generation, actionGeneration.current)) showToast('success', '测试通知已发送,请检查对应渠道');
|
||||
} catch (error: unknown /* 测试通知异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, actionGeneration.current) && !controller.signal.aborted) {
|
||||
showToast('error', notificationErrorMessage(error, '发送失败'));
|
||||
}
|
||||
} finally {
|
||||
if (isCurrentNotificationRequest(generation, actionGeneration.current)) setTestingId('');
|
||||
}
|
||||
},
|
||||
[showToast],
|
||||
);
|
||||
|
||||
// handleSaveSmtp 保存系统 SMTP 配置并支持取消旧保存请求。
|
||||
const handleSaveSmtp = useCallback(
|
||||
// SMTP 保存回调提交系统邮件配置。
|
||||
async () => {
|
||||
// generation 标记当前 SMTP 保存动作的代次。
|
||||
const generation = ++smtpGeneration.current;
|
||||
smtpAbort.current?.abort();
|
||||
// controller 允许重复保存时取消上一轮请求。
|
||||
const controller = new AbortController();
|
||||
smtpAbort.current = controller;
|
||||
setSmtpSaving(true);
|
||||
try {
|
||||
await updateSystemSettings({
|
||||
smtp_server: smtp.smtp_server || '', smtp_port: smtp.smtp_port || 587, smtp_user: smtp.smtp_user || '',
|
||||
smtp_password: smtp.smtp_password || '', smtp_from_name: smtp.smtp_from_name || '',
|
||||
smtp_from_address: smtp.smtp_from_address || smtp.smtp_user || '', smtp_use_tls: smtp.smtp_use_tls !== false,
|
||||
smtp_use_ssl: smtp.smtp_use_ssl === true,
|
||||
}, { signal: controller.signal });
|
||||
if (isCurrentNotificationRequest(generation, smtpGeneration.current)) showToast('success', 'SMTP 配置已保存');
|
||||
} catch (error: unknown /* SMTP 保存异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, smtpGeneration.current) && !controller.signal.aborted) {
|
||||
showToast('error', notificationErrorMessage(error, '保存失败'));
|
||||
}
|
||||
} finally {
|
||||
if (isCurrentNotificationRequest(generation, smtpGeneration.current)) setSmtpSaving(false);
|
||||
}
|
||||
},
|
||||
[showToast, smtp],
|
||||
);
|
||||
|
||||
return {
|
||||
channels, loading, showModal, editing, saving, testingId, toast, smtp, smtpSaving,
|
||||
showSmtpPassword, showChannelSmtpPassword, form, setForm, setSmtp, setShowSmtpPassword,
|
||||
setShowChannelSmtpPassword, loadChannels, openCreate, openEdit, closeModal, showToast,
|
||||
handleSave, handleDelete, handleToggleEnabled, handleTest, handleSaveSmtp,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import type { NotificationForm } from './types';
|
||||
import { buildNotificationPayload, isCurrentNotificationRequest, notificationEventSummary, validateNotificationForm } from './state';
|
||||
|
||||
// createForm 创建通知渠道校验使用的最小表单对象。
|
||||
const createForm = (overrides: Partial<NotificationForm> = {}): NotificationForm => ({
|
||||
name: '测试渠道', type: 'bark', enabled: true, config: { server_url: 'https://api.day.app', device_key: 'device-key' }, event_types: [], ...overrides,
|
||||
});
|
||||
|
||||
test('通知渠道校验阻止缺少名称和必填配置',
|
||||
// 渠道表单测试验证名称、渠道凭据和成功保存请求体。
|
||||
() => {
|
||||
expect(validateNotificationForm(createForm({ name: '' }))).toBe('请填写渠道名称');
|
||||
expect(validateNotificationForm(createForm({ config: {} }))).toContain('Bark 服务器');
|
||||
expect(validateNotificationForm(createForm())).toBe('');
|
||||
expect(buildNotificationPayload(createForm({ event_types: ['account_offline'] })).event_types).toEqual(['account_offline']);
|
||||
});
|
||||
|
||||
test('通知事件摘要为空时表示订阅全部事件',
|
||||
// 事件摘要测试验证空选择和多事件选择的展示语义。
|
||||
() => {
|
||||
expect(notificationEventSummary([])).toBe('全部事件');
|
||||
expect(notificationEventSummary(['account_offline', 'system_error'])).toBe('掉线通知、系统错误');
|
||||
});
|
||||
|
||||
test('通知请求代次拒绝过期响应',
|
||||
// 过期响应测试验证刷新或取消后旧请求不能覆盖当前状态。
|
||||
() => {
|
||||
expect(isCurrentNotificationRequest(5, 5)).toBe(true);
|
||||
expect(isCurrentNotificationRequest(4, 5)).toBe(false);
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
import { Bell, Mail, MessageCircle, Send as Telegram, Webhook } from 'lucide-react';
|
||||
import type { NotificationChannel, NotificationChannelType, NotificationEventType, SystemSettings } from '../../../types';
|
||||
import { buildEmailChannelConfig, enableCustomSMTP, normalizeEmailChannelConfig } from '../../../notificationEmailConfig';
|
||||
import type { NotificationChannelMeta, NotificationEventMeta, NotificationForm, NotificationPayload } from './types';
|
||||
|
||||
// notificationChannelTypes 是所有通知渠道的静态字段、图标和使用指南。
|
||||
export const notificationChannelTypes: Record<NotificationChannelType, NotificationChannelMeta> = {
|
||||
bark: {
|
||||
label: 'Bark', icon: Bell,
|
||||
fields: [
|
||||
{ key: 'server_url', label: 'Bark 服务器', placeholder: 'https://api.day.app', required: true },
|
||||
{ key: 'device_key', label: 'Device Key', placeholder: '你的 Bark 设备 Key', required: true },
|
||||
{ key: 'title', label: '标题(可选)', placeholder: 'Ydisks闲鱼助手' },
|
||||
{ key: 'sound', label: '铃声(可选)', placeholder: 'default' },
|
||||
{ key: 'group', label: '分组(可选)', placeholder: 'xianyu' },
|
||||
],
|
||||
guide: { steps: ['App Store 搜索并安装 Bark(免费)', '打开 Bark App,首页会显示一条测试 URL,形如 https://api.day.app/<key>/这是测试推送内容', 'URL 路径里 <key> 那一段就是 Device Key,复制填入', '服务器地址默认 https://api.day.app,自建服务端则填自建域名'], urlFormat: 'https://api.day.app/<你的key>/测试内容', note: '不需要 secret,Device Key 本身就是唯一凭证。' },
|
||||
},
|
||||
dingtalk: {
|
||||
label: '钉钉机器人', icon: MessageCircle,
|
||||
fields: [
|
||||
{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://oapi.dingtalk.com/robot/send?access_token=...', required: true },
|
||||
{ key: 'secret', label: '加签密钥', placeholder: 'SEC...', help: '安全设置勾选「加签」后生成,SEC 开头' },
|
||||
],
|
||||
guide: { steps: ['钉钉进入一个群(可建单人群)→ 右上角 群设置', '机器人 → 添加机器人 → 选择「自定义机器人」', '安全设置勾选「加签」', '完成页同时展示 Webhook 地址和 SEC 开头的 Secret,两个都复制', 'Webhook URL 填上面,Secret 填加签密钥'], urlFormat: 'https://oapi.dingtalk.com/robot/send?access_token=XXX', note: '加签密钥可选,但强烈建议启用,否则机器人可能被滥用。' },
|
||||
},
|
||||
feishu: {
|
||||
label: '飞书机器人', icon: MessageCircle,
|
||||
fields: [
|
||||
{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://open.feishu.cn/open-apis/bot/v2/hook/...', required: true },
|
||||
{ key: 'secret', label: '签名校验密钥', placeholder: 'sec-...', help: '安全设置选「签名校验」后生成' },
|
||||
],
|
||||
guide: { steps: ['飞书进入目标群 → 右上角 更多 → 设置', '群机器人 → 添加机器人 → 自定义机器人', '安全设置选择「签名校验」,复制生成的秘钥', '完成会给 Webhook 地址,复制', 'Webhook URL 填上面,秘钥填签名校验密钥'], urlFormat: 'https://open.feishu.cn/open-apis/bot/v2/hook/xxx', note: '签名密钥可选,建议启用。频率限制:单机器人 100 次/分钟。' },
|
||||
},
|
||||
wechat: {
|
||||
label: '企业微信机器人', icon: MessageCircle,
|
||||
fields: [{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...', required: true }],
|
||||
guide: { steps: ['企业微信进入一个内部群 → 右上角 … → 群设置', '找到「群机器人」(新版可能叫「消息推送」)', '添加 → 选择自定义机器人', '完成给 Webhook 地址(含 ?key=),复制填入'], urlFormat: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX', note: '不需要 secret,URL 里的 key 就是唯一凭证,注意不要泄露。频率限制 20 条/分钟。' },
|
||||
},
|
||||
webhook: {
|
||||
label: '自定义 Webhook', icon: Webhook,
|
||||
fields: [{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://your-server/notify', required: true }],
|
||||
guide: { steps: ['仅适用于自己有服务器的用户:在你自己的机器上起一个 HTTP 接口收 JSON', '系统会 POST 这个 URL,Content-Type: application/json', '请求体固定为右侧 JSON 格式,按需解析 message 字段'], urlFormat: '{"message":"告警正文","timestamp":"2026-07-05 12:00:00","source":"xianyu-auto-reply"}', note: '若用 Server酱 / PushPlus 等第三方推送服务,格式不兼容,需写中间脚本转发,或改用对应专用渠道。' },
|
||||
},
|
||||
telegram: {
|
||||
label: 'Telegram', icon: Telegram,
|
||||
fields: [{ key: 'bot_token', label: 'Bot Token', placeholder: '123456:ABC-DEF...', required: true }, { key: 'chat_id', label: 'Chat ID', placeholder: '-1001234567890 或你的用户 ID', required: true }],
|
||||
guide: { steps: ['在 Telegram 搜索 @BotFather,发送 /newbot,按提示创建机器人,拿到 Bot Token', '把你的 Bot 拉进一个群,或私聊它发一条消息', '浏览器访问 https://api.telegram.org/bot<你的Token>/getUpdates', '从返回 JSON 里找 "chat":{"id":xxx},xxx 就是 Chat ID(群是负数,私聊是正数)'], urlFormat: 'Bot Token: 123456:ABC-DEF... Chat ID: -1001234567890', note: '群聊需先把 Bot 设为管理员才能发消息。' },
|
||||
},
|
||||
email: {
|
||||
label: '邮件', icon: Mail,
|
||||
fields: [{ key: 'to_email', label: '收件邮箱', placeholder: 'receiver@example.com', required: true }],
|
||||
guide: { steps: ['通常先保存页面中的系统 SMTP 配置', '邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP', '只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置'], note: '继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。' },
|
||||
},
|
||||
};
|
||||
|
||||
// notificationEvents 是可绑定到通知渠道的事件定义。
|
||||
export const notificationEvents: NotificationEventMeta[] = [
|
||||
{ value: 'account_offline', label: '掉线通知', description: '账号过期、断线或登录态失效' },
|
||||
{ value: 'account_recovered', label: '恢复通知', description: '自动恢复成功并重新在线' },
|
||||
{ value: 'account_disabled', label: '禁用通知', description: '连续失败、账密错误等导致账号停用' },
|
||||
{ value: 'security_verification', label: '风控验证', description: '滑块、人脸、扫码验证等安全校验' },
|
||||
{ value: 'delivery_result', label: '交易通知', description: '订单发货、卡密发送等交易结果' },
|
||||
{ value: 'token_renewal', label: '续期通知', description: 'Cookie/token 续期和自动恢复过程' },
|
||||
{ value: 'system_error', label: '系统错误', description: '后台任务或系统级异常' },
|
||||
];
|
||||
|
||||
// emptyNotificationForm 返回新建渠道的初始表单。
|
||||
export const emptyNotificationForm = (): NotificationForm => ({ name: '', type: 'bark', enabled: true, config: {}, event_types: [] });
|
||||
|
||||
// notificationEventSummary 将事件值转换为渠道列表中的中文摘要。
|
||||
export const notificationEventSummary = (events?: NotificationEventType[]): string => {
|
||||
if (!events || events.length === 0) return '全部事件';
|
||||
return events.map(
|
||||
// event 是当前待转换的后端事件值。
|
||||
event => notificationEvents.find(
|
||||
// item 是当前事件定义。
|
||||
item => item.value === event,
|
||||
)?.label || event,
|
||||
).join('、');
|
||||
};
|
||||
|
||||
// normalizeNotificationForm 将编辑中的渠道配置复制为独立表单对象。
|
||||
export const normalizeNotificationForm = (channel: NotificationChannel, smtp: SystemSettings): NotificationForm => {
|
||||
// normalizedEmailConfig 是邮件渠道的兼容配置副本。
|
||||
const normalizedEmailConfig = channel.type === 'email' ? normalizeEmailChannelConfig({ ...(channel.config || {}) }) : null;
|
||||
// config 是编辑表单实际使用的渠道配置。
|
||||
const config = normalizedEmailConfig
|
||||
? (normalizedEmailConfig.use_custom_smtp === true ? enableCustomSMTP(normalizedEmailConfig, smtp) : normalizedEmailConfig)
|
||||
: { ...(channel.config || {}) };
|
||||
return { name: channel.name, type: channel.type, enabled: channel.enabled, config, event_types: channel.event_types || [] };
|
||||
};
|
||||
|
||||
// validateNotificationForm 校验渠道名称、渠道字段和独立 SMTP 必填项。
|
||||
export const validateNotificationForm = (form: NotificationForm): string => {
|
||||
// meta 是当前渠道类型的静态校验配置。
|
||||
const meta = notificationChannelTypes[form.type];
|
||||
// missingField 是第一个未填写的渠道必填字段。
|
||||
const missingField = meta.fields.find(
|
||||
// field 是当前渠道字段定义。
|
||||
field => field.required && !String(form.config[field.key] || '').trim(),
|
||||
);
|
||||
if (missingField) return `请填写 ${missingField.label}`;
|
||||
if (!form.name.trim()) return '请填写渠道名称';
|
||||
if (form.type === 'email') {
|
||||
// config 是邮件渠道归一化后的提交配置。
|
||||
const config = buildEmailChannelConfig(form.config);
|
||||
if (config.use_custom_smtp) {
|
||||
// requiredFields 是独立 SMTP 模式下必须填写的字段列表。
|
||||
const requiredFields: Array<[string, string]> = [
|
||||
['smtp_server', '独立 SMTP 服务器'], ['smtp_port', '独立 SMTP 端口'], ['smtp_user', '独立 SMTP 登录邮箱'],
|
||||
['smtp_password', '独立 SMTP 密码 / 授权码'], ['smtp_from_address', '独立 SMTP 发件地址'],
|
||||
];
|
||||
// missing 是独立 SMTP 模式下第一个缺失字段。
|
||||
const missing = requiredFields.find(
|
||||
// field 是字段名和用户可见名称的二元组。
|
||||
([key]) => !String(config[key] || '').trim(),
|
||||
);
|
||||
if (missing) return `请填写 ${missing[1]}`;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
// buildNotificationPayload 将表单转换为通知渠道保存请求。
|
||||
export const buildNotificationPayload = (form: NotificationForm): NotificationPayload => ({
|
||||
name: form.name.trim(),
|
||||
type: form.type,
|
||||
config: form.type === 'email' ? buildEmailChannelConfig(form.config) : form.config,
|
||||
event_types: form.event_types,
|
||||
enabled: form.enabled,
|
||||
});
|
||||
|
||||
// isCurrentNotificationRequest 判断异步通知请求是否仍属于最新代次。
|
||||
export const isCurrentNotificationRequest = (generation: number, currentGeneration: number): boolean => generation === currentGeneration;
|
||||
|
||||
// notificationErrorMessage 将未知异常转换为用户可读的通知错误。
|
||||
export const notificationErrorMessage = (error: unknown, fallback: string): string => error instanceof Error && error.message ? error.message : fallback;
|
||||
@@ -0,0 +1,142 @@
|
||||
import type { Dispatch, ElementType, SetStateAction } from 'react';
|
||||
import type { NotificationChannel, NotificationChannelType, NotificationEventType, SystemSettings } from '../../../types';
|
||||
|
||||
// NotificationField 描述通知渠道表单中的一个配置字段。
|
||||
export interface NotificationField {
|
||||
// key 是提交到渠道配置的字段名。
|
||||
key: string;
|
||||
// label 是字段在表单中的中文名称。
|
||||
label: string;
|
||||
// placeholder 是输入框的示例提示。
|
||||
placeholder?: string;
|
||||
// type 是输入控件的 HTML 类型。
|
||||
type?: 'text' | 'password' | 'number';
|
||||
// required 表示该字段是否必须填写。
|
||||
required?: boolean;
|
||||
// help 是字段下方的补充说明。
|
||||
help?: string;
|
||||
}
|
||||
|
||||
// NotificationGuide 描述如何获取某类通知渠道凭据。
|
||||
export interface NotificationGuide {
|
||||
// steps 是按顺序展示的配置步骤。
|
||||
steps: string[];
|
||||
// urlFormat 是可选的 URL 或请求格式示例。
|
||||
urlFormat?: string;
|
||||
// note 是渠道配置的额外注意事项。
|
||||
note?: string;
|
||||
}
|
||||
|
||||
// NotificationChannelMeta 描述通知渠道的静态表单和展示配置。
|
||||
export interface NotificationChannelMeta {
|
||||
// label 是渠道类型的中文名称。
|
||||
label: string;
|
||||
// icon 是渠道列表和表单中使用的图标组件。
|
||||
icon: ElementType;
|
||||
// fields 是渠道配置字段定义。
|
||||
fields: NotificationField[];
|
||||
// guide 是渠道凭据获取指南。
|
||||
guide: NotificationGuide;
|
||||
}
|
||||
|
||||
// NotificationEventMeta 描述可供渠道订阅的一类系统事件。
|
||||
export interface NotificationEventMeta {
|
||||
// value 是后端识别的事件类型值。
|
||||
value: NotificationEventType;
|
||||
// label 是事件的中文名称。
|
||||
label: string;
|
||||
// description 是事件在绑定组件中的说明。
|
||||
description: string;
|
||||
}
|
||||
|
||||
// NotificationForm 描述新建或编辑通知渠道的表单值。
|
||||
export interface NotificationForm {
|
||||
// name 是渠道名称。
|
||||
name: string;
|
||||
// type 是当前渠道类型。
|
||||
type: NotificationChannelType;
|
||||
// enabled 表示是否启用当前渠道。
|
||||
enabled: boolean;
|
||||
// config 保存渠道类型对应的配置值。
|
||||
config: Record<string, unknown>;
|
||||
// event_types 保存用户选择的通知事件,空数组表示全部事件。
|
||||
event_types: NotificationEventType[];
|
||||
}
|
||||
|
||||
// NotificationPayload 描述保存通知渠道时发送给 API 的请求体。
|
||||
export interface NotificationPayload {
|
||||
// name 是保存后的渠道名称。
|
||||
name: string;
|
||||
// type 是保存后的渠道类型。
|
||||
type: string;
|
||||
// config 是归一化后的渠道配置。
|
||||
config: Record<string, unknown>;
|
||||
// event_types 是保存后的事件订阅集合。
|
||||
event_types: NotificationEventType[];
|
||||
// enabled 是保存后的启用状态。
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
// NotificationToast 描述页面底部的短暂操作提示。
|
||||
export interface NotificationToast {
|
||||
// type 决定提示的成功或失败样式。
|
||||
type: 'success' | 'error';
|
||||
// text 是提示内容。
|
||||
text: string;
|
||||
}
|
||||
|
||||
// NotificationState 暴露通知页面的数据、表单和操作边界。
|
||||
export interface NotificationState {
|
||||
// channels 是当前用户可用的通知渠道列表。
|
||||
channels: NotificationChannel[];
|
||||
// loading 表示渠道列表是否正在加载。
|
||||
loading: boolean;
|
||||
// showModal 表示渠道编辑弹窗是否打开。
|
||||
showModal: boolean;
|
||||
// editing 是当前正在编辑的渠道,新增时为空。
|
||||
editing: NotificationChannel | null;
|
||||
// saving 表示渠道或 SMTP 配置是否正在保存。
|
||||
saving: boolean;
|
||||
// testingId 是当前正在发送测试通知的渠道 ID。
|
||||
testingId: string;
|
||||
// toast 是当前待展示的操作提示。
|
||||
toast: NotificationToast | null;
|
||||
// smtp 是系统级邮件配置。
|
||||
smtp: SystemSettings;
|
||||
// smtpSaving 表示系统 SMTP 是否正在保存。
|
||||
smtpSaving: boolean;
|
||||
// showSmtpPassword 控制系统 SMTP 密码明文展示。
|
||||
showSmtpPassword: boolean;
|
||||
// showChannelSmtpPassword 控制独立 SMTP 密码明文展示。
|
||||
showChannelSmtpPassword: boolean;
|
||||
// form 是当前渠道编辑表单值。
|
||||
form: NotificationForm;
|
||||
// setForm 更新渠道编辑表单。
|
||||
setForm: Dispatch<SetStateAction<NotificationForm>>;
|
||||
// setSmtp 更新系统 SMTP 配置表单。
|
||||
setSmtp: Dispatch<SetStateAction<SystemSettings>>;
|
||||
// setShowSmtpPassword 更新系统 SMTP 密码展示状态。
|
||||
setShowSmtpPassword: Dispatch<SetStateAction<boolean>>;
|
||||
// setShowChannelSmtpPassword 更新独立 SMTP 密码展示状态。
|
||||
setShowChannelSmtpPassword: Dispatch<SetStateAction<boolean>>;
|
||||
// loadChannels 刷新通知渠道列表。
|
||||
loadChannels: () => Promise<void>;
|
||||
// openCreate 打开新建渠道弹窗。
|
||||
openCreate: () => void;
|
||||
// openEdit 打开已有渠道编辑弹窗。
|
||||
openEdit: (channel: NotificationChannel) => void;
|
||||
// closeModal 关闭弹窗并取消当前保存请求。
|
||||
closeModal: () => void;
|
||||
// showToast 展示短暂的成功或失败提示。
|
||||
showToast: (type: NotificationToast['type'], text: string) => void;
|
||||
// handleSave 保存当前渠道配置。
|
||||
handleSave: () => Promise<void>;
|
||||
// handleDelete 删除指定通知渠道。
|
||||
handleDelete: (channel: NotificationChannel) => Promise<void>;
|
||||
// handleToggleEnabled 切换指定渠道的启用状态。
|
||||
handleToggleEnabled: (channel: NotificationChannel) => Promise<void>;
|
||||
// handleTest 发送指定渠道的测试通知。
|
||||
handleTest: (channel: NotificationChannel) => Promise<void>;
|
||||
// handleSaveSmtp 保存系统级 SMTP 配置。
|
||||
handleSaveSmtp: () => Promise<void>;
|
||||
}
|
||||
@@ -1,899 +1,42 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { NotificationChannel, NotificationChannelType, NotificationEventType, SystemSettings } from '../types';
|
||||
import {
|
||||
getNotificationChannels,
|
||||
createNotificationChannel,
|
||||
updateNotificationChannel,
|
||||
deleteNotificationChannel,
|
||||
testNotificationChannel,
|
||||
getSystemSettings,
|
||||
updateSystemSettings,
|
||||
} from '../services/api';
|
||||
import {
|
||||
Bell, Plus, Edit2, Trash2, X, Send, RefreshCw, Loader2,
|
||||
Check, MessageCircle, Mail, Webhook, Send as Telegram, Eye, EyeOff, Save,
|
||||
} from 'lucide-react';
|
||||
import { normalizeSMTPSettings } from '../smtpSettings';
|
||||
import { buildEmailChannelConfig, enableCustomSMTP, normalizeEmailChannelConfig } from '../notificationEmailConfig';
|
||||
|
||||
type ChannelTypeMeta = {
|
||||
label: string;
|
||||
icon: React.ElementType;
|
||||
fields: { key: string; label: string; placeholder?: string; type?: 'text' | 'password' | 'number'; required?: boolean; help?: string }[];
|
||||
guide: { steps: string[]; urlFormat?: string; note?: string };
|
||||
};
|
||||
|
||||
const CHANNEL_TYPES: Record<NotificationChannelType, ChannelTypeMeta> = {
|
||||
bark: {
|
||||
label: 'Bark',
|
||||
icon: Bell,
|
||||
fields: [
|
||||
{ key: 'server_url', label: 'Bark 服务器', placeholder: 'https://api.day.app', required: true },
|
||||
{ key: 'device_key', label: 'Device Key', placeholder: '你的 Bark 设备 Key', required: true },
|
||||
{ key: 'title', label: '标题(可选)', placeholder: 'Ydisks闲鱼助手' },
|
||||
{ key: 'sound', label: '铃声(可选)', placeholder: 'default' },
|
||||
{ key: 'group', label: '分组(可选)', placeholder: 'xianyu' },
|
||||
],
|
||||
guide: {
|
||||
steps: [
|
||||
'App Store 搜索并安装 Bark(免费)',
|
||||
'打开 Bark App,首页会显示一条测试 URL,形如 https://api.day.app/<key>/这是测试推送内容',
|
||||
'URL 路径里 <key> 那一段就是 Device Key,复制填入',
|
||||
'服务器地址默认 https://api.day.app,自建服务端则填自建域名',
|
||||
],
|
||||
urlFormat: 'https://api.day.app/<你的key>/测试内容',
|
||||
note: '不需要 secret,Device Key 本身就是唯一凭证。',
|
||||
},
|
||||
},
|
||||
dingtalk: {
|
||||
label: '钉钉机器人',
|
||||
icon: MessageCircle,
|
||||
fields: [
|
||||
{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://oapi.dingtalk.com/robot/send?access_token=...', required: true },
|
||||
{ key: 'secret', label: '加签密钥', placeholder: 'SEC...', help: '安全设置勾选「加签」后生成,SEC 开头' },
|
||||
],
|
||||
guide: {
|
||||
steps: [
|
||||
'钉钉进入一个群(可建单人群)→ 右上角 群设置',
|
||||
'机器人 → 添加机器人 → 选择「自定义机器人」',
|
||||
'安全设置勾选「加签」',
|
||||
'完成页同时展示 Webhook 地址和 SEC 开头的 Secret,两个都复制',
|
||||
'Webhook URL 填上面,Secret 填加签密钥',
|
||||
],
|
||||
urlFormat: 'https://oapi.dingtalk.com/robot/send?access_token=XXX',
|
||||
note: '加签密钥可选,但强烈建议启用,否则机器人可能被滥用。',
|
||||
},
|
||||
},
|
||||
feishu: {
|
||||
label: '飞书机器人',
|
||||
icon: MessageCircle,
|
||||
fields: [
|
||||
{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://open.feishu.cn/open-apis/bot/v2/hook/...', required: true },
|
||||
{ key: 'secret', label: '签名校验密钥', placeholder: 'sec-...', help: '安全设置选「签名校验」后生成' },
|
||||
],
|
||||
guide: {
|
||||
steps: [
|
||||
'飞书进入目标群 → 右上角 更多 → 设置',
|
||||
'群机器人 → 添加机器人 → 自定义机器人',
|
||||
'安全设置选择「签名校验」,复制生成的秘钥',
|
||||
'完成会给 Webhook 地址,复制',
|
||||
'Webhook URL 填上面,秘钥填签名校验密钥',
|
||||
],
|
||||
urlFormat: 'https://open.feishu.cn/open-apis/bot/v2/hook/xxx',
|
||||
note: '签名密钥可选,建议启用。频率限制:单机器人 100 次/分钟。',
|
||||
},
|
||||
},
|
||||
wechat: {
|
||||
label: '企业微信机器人',
|
||||
icon: MessageCircle,
|
||||
fields: [
|
||||
{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...', required: true },
|
||||
],
|
||||
guide: {
|
||||
steps: [
|
||||
'企业微信进入一个内部群 → 右上角 … → 群设置',
|
||||
'找到「群机器人」(新版可能叫「消息推送」)',
|
||||
'添加 → 选择自定义机器人',
|
||||
'完成给 Webhook 地址(含 ?key=),复制填入',
|
||||
],
|
||||
urlFormat: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX',
|
||||
note: '不需要 secret,URL 里的 key 就是唯一凭证,注意不要泄露。频率限制 20 条/分钟。',
|
||||
},
|
||||
},
|
||||
webhook: {
|
||||
label: '自定义 Webhook',
|
||||
icon: Webhook,
|
||||
fields: [
|
||||
{ key: 'webhook_url', label: 'Webhook URL', placeholder: 'https://your-server/notify', required: true },
|
||||
],
|
||||
guide: {
|
||||
steps: [
|
||||
'仅适用于自己有服务器的用户:在你自己的机器上起一个 HTTP 接口收 JSON',
|
||||
'系统会 POST 这个 URL,Content-Type: application/json',
|
||||
'请求体固定为右侧 JSON 格式,按需解析 message 字段',
|
||||
],
|
||||
urlFormat: '{"message":"告警正文","timestamp":"2026-07-05 12:00:00","source":"xianyu-auto-reply"}',
|
||||
note: '若用 Server酱 / PushPlus 等第三方推送服务,格式不兼容,需写中间脚本转发,或改用对应专用渠道。',
|
||||
},
|
||||
},
|
||||
telegram: {
|
||||
label: 'Telegram',
|
||||
icon: Telegram,
|
||||
fields: [
|
||||
{ key: 'bot_token', label: 'Bot Token', placeholder: '123456:ABC-DEF...', required: true },
|
||||
{ key: 'chat_id', label: 'Chat ID', placeholder: '-1001234567890 或你的用户 ID', required: true },
|
||||
],
|
||||
guide: {
|
||||
steps: [
|
||||
'在 Telegram 搜索 @BotFather,发送 /newbot,按提示创建机器人,拿到 Bot Token',
|
||||
'把你的 Bot 拉进一个群,或私聊它发一条消息',
|
||||
'浏览器访问 https://api.telegram.org/bot<你的Token>/getUpdates',
|
||||
'从返回 JSON 里找 "chat":{"id":xxx},xxx 就是 Chat ID(群是负数,私聊是正数)',
|
||||
],
|
||||
urlFormat: 'Bot Token: 123456:ABC-DEF... Chat ID: -1001234567890',
|
||||
note: '群聊需先把 Bot 设为管理员才能发消息。',
|
||||
},
|
||||
},
|
||||
email: {
|
||||
label: '邮件',
|
||||
icon: Mail,
|
||||
fields: [
|
||||
{ key: 'to_email', label: '收件邮箱', placeholder: 'receiver@example.com', required: true },
|
||||
],
|
||||
guide: {
|
||||
steps: [
|
||||
'通常先保存页面中的系统 SMTP 配置',
|
||||
'邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP',
|
||||
'只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置',
|
||||
],
|
||||
note: '继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const NOTIFICATION_EVENTS: { value: NotificationEventType; label: string; description: string }[] = [
|
||||
{ value: 'account_offline', label: '掉线通知', description: '账号过期、断线或登录态失效' },
|
||||
{ value: 'account_recovered', label: '恢复通知', description: '自动恢复成功并重新在线' },
|
||||
{ value: 'account_disabled', label: '禁用通知', description: '连续失败、账密错误等导致账号停用' },
|
||||
{ value: 'security_verification', label: '风控验证', description: '滑块、人脸、扫码验证等安全校验' },
|
||||
{ value: 'delivery_result', label: '交易通知', description: '订单发货、卡密发送等交易结果' },
|
||||
{ value: 'token_renewal', label: '续期通知', description: 'Cookie/token 续期和自动恢复过程' },
|
||||
{ value: 'system_error', label: '系统错误', description: '后台任务或系统级异常' },
|
||||
];
|
||||
|
||||
const notificationEventSummary = (events?: NotificationEventType[]) => {
|
||||
if (!events || events.length === 0) return '全部事件';
|
||||
const labels = events.map(event => NOTIFICATION_EVENTS.find(item => item.value === event)?.label || event);
|
||||
return labels.join('、');
|
||||
};
|
||||
import React from 'react';
|
||||
import { Bell, Check, Loader2, Plus, RefreshCw, X } from 'lucide-react';
|
||||
import { NotificationChannelList } from '../app/features/notifications/components/NotificationChannelList';
|
||||
import { NotificationChannelModal } from '../app/features/notifications/components/NotificationChannelModal';
|
||||
import { NotificationSmtpSettings } from '../app/features/notifications/components/NotificationSmtpSettings';
|
||||
import { useNotifications } from '../app/features/notifications/hooks';
|
||||
|
||||
// NotificationsProps 描述通知页面接收的权限上下文。
|
||||
interface NotificationsProps {
|
||||
// isAdmin 表示当前用户是否可以查看和保存系统 SMTP 配置。
|
||||
isAdmin?: boolean;
|
||||
}
|
||||
|
||||
// Notifications 渲染通知渠道列表、SMTP 配置和渠道编辑边界。
|
||||
const Notifications: React.FC<NotificationsProps> = ({ isAdmin = false }) => {
|
||||
const [channels, setChannels] = useState<NotificationChannel[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
const [editing, setEditing] = useState<NotificationChannel | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [testingId, setTestingId] = useState<string>('');
|
||||
const [toast, setToast] = useState<{ type: 'success' | 'error'; text: string } | null>(null);
|
||||
|
||||
// SMTP 系统级邮件配置(从系统设置加载/保存)
|
||||
const [smtp, setSmtp] = useState<SystemSettings>({});
|
||||
const [smtpSaving, setSmtpSaving] = useState(false);
|
||||
const [showSmtpPassword, setShowSmtpPassword] = useState(false);
|
||||
const [showChannelSmtpPassword, setShowChannelSmtpPassword] = useState(false);
|
||||
|
||||
const [form, setForm] = useState({
|
||||
name: '',
|
||||
type: 'bark' as NotificationChannelType,
|
||||
enabled: true,
|
||||
config: {} as Record<string, unknown>,
|
||||
event_types: [] as NotificationEventType[],
|
||||
});
|
||||
|
||||
const load = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await getNotificationChannels();
|
||||
setChannels(res.data || []);
|
||||
} catch (e) {
|
||||
console.error('加载通知渠道失败', e);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loadSmtp = async () => {
|
||||
try {
|
||||
const s = await getSystemSettings();
|
||||
setSmtp(normalizeSMTPSettings(s || {}));
|
||||
} catch (e) {
|
||||
console.error('加载 SMTP 配置失败', e);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveSmtp = async () => {
|
||||
setSmtpSaving(true);
|
||||
try {
|
||||
await updateSystemSettings({
|
||||
smtp_server: smtp.smtp_server || '',
|
||||
smtp_port: smtp.smtp_port || 587,
|
||||
smtp_user: smtp.smtp_user || '',
|
||||
smtp_password: smtp.smtp_password || '',
|
||||
smtp_from_name: smtp.smtp_from_name || '',
|
||||
smtp_from_address: smtp.smtp_from_address || smtp.smtp_user || '',
|
||||
smtp_use_tls: smtp.smtp_use_tls !== false,
|
||||
smtp_use_ssl: smtp.smtp_use_ssl === true,
|
||||
});
|
||||
showToast('success', 'SMTP 配置已保存');
|
||||
} catch (e: any) {
|
||||
showToast('error', e?.message || '保存失败');
|
||||
} finally {
|
||||
setSmtpSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
if (isAdmin) {
|
||||
loadSmtp();
|
||||
} else {
|
||||
setSmtp({});
|
||||
}
|
||||
}, [isAdmin]);
|
||||
|
||||
const showToast = (type: 'success' | 'error', text: string) => {
|
||||
setToast({ type, text });
|
||||
window.setTimeout(() => setToast(null), 3000);
|
||||
};
|
||||
|
||||
const openCreate = () => {
|
||||
setEditing(null);
|
||||
setForm({ name: '', type: 'bark', enabled: true, config: {}, event_types: [] });
|
||||
setShowChannelSmtpPassword(false);
|
||||
setShowModal(true);
|
||||
};
|
||||
|
||||
const openEdit = (ch: NotificationChannel) => {
|
||||
setEditing(ch);
|
||||
const normalizedEmailConfig = ch.type === 'email'
|
||||
? normalizeEmailChannelConfig({ ...(ch.config || {}) })
|
||||
: null;
|
||||
const config = normalizedEmailConfig
|
||||
? (normalizedEmailConfig.use_custom_smtp === true
|
||||
? enableCustomSMTP(normalizedEmailConfig, smtp)
|
||||
: normalizedEmailConfig)
|
||||
: { ...(ch.config || {}) };
|
||||
setForm({
|
||||
name: ch.name,
|
||||
type: ch.type,
|
||||
enabled: ch.enabled,
|
||||
config,
|
||||
event_types: ch.event_types || [],
|
||||
});
|
||||
setShowChannelSmtpPassword(false);
|
||||
setShowModal(true);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
const meta = CHANNEL_TYPES[form.type];
|
||||
for (const f of meta.fields) {
|
||||
if (f.required && !String(form.config[f.key] || '').trim()) {
|
||||
showToast('error', `请填写 ${f.label}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!form.name.trim()) {
|
||||
showToast('error', '请填写渠道名称');
|
||||
return;
|
||||
}
|
||||
let config = form.config;
|
||||
if (form.type === 'email') {
|
||||
config = buildEmailChannelConfig(form.config);
|
||||
if (config.use_custom_smtp) {
|
||||
const required = [
|
||||
['smtp_server', '独立 SMTP 服务器'],
|
||||
['smtp_port', '独立 SMTP 端口'],
|
||||
['smtp_user', '独立 SMTP 登录邮箱'],
|
||||
['smtp_password', '独立 SMTP 密码 / 授权码'],
|
||||
['smtp_from_address', '独立 SMTP 发件地址'],
|
||||
] as const;
|
||||
const missing = required.find(([key]) => !String(config[key] || '').trim());
|
||||
if (missing) {
|
||||
showToast('error', `请填写 ${missing[1]}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
const payload = { name: form.name.trim(), type: form.type, config, event_types: form.event_types, enabled: form.enabled };
|
||||
if (editing) {
|
||||
await updateNotificationChannel(editing.id, payload);
|
||||
} else {
|
||||
await createNotificationChannel(payload);
|
||||
}
|
||||
setShowModal(false);
|
||||
await load();
|
||||
showToast('success', editing ? '已更新' : '已创建');
|
||||
} catch (e: any) {
|
||||
console.error('保存失败', e);
|
||||
showToast('error', e?.message || '保存失败');
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (ch: NotificationChannel) => {
|
||||
if (!confirm(`确认删除渠道「${ch.name}」吗?已绑定该渠道的账号会自动解绑。`)) return;
|
||||
try {
|
||||
await deleteNotificationChannel(ch.id);
|
||||
await load();
|
||||
showToast('success', '已删除');
|
||||
} catch (e: any) {
|
||||
showToast('error', e?.message || '删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleEnabled = async (ch: NotificationChannel) => {
|
||||
try {
|
||||
await updateNotificationChannel(ch.id, {
|
||||
enabled: !ch.enabled,
|
||||
});
|
||||
setChannels(prev => prev.map(c => c.id === ch.id ? { ...c, enabled: !c.enabled } : c));
|
||||
} catch (e: any) {
|
||||
showToast('error', e?.message || '切换失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleTest = async (ch: NotificationChannel) => {
|
||||
setTestingId(ch.id);
|
||||
try {
|
||||
await testNotificationChannel(ch.id);
|
||||
showToast('success', '测试通知已发送,请检查对应渠道');
|
||||
} catch (e: any) {
|
||||
showToast('error', e?.message || '发送失败');
|
||||
} finally {
|
||||
setTestingId('');
|
||||
}
|
||||
};
|
||||
|
||||
const meta = CHANNEL_TYPES[form.type];
|
||||
// notificationState 统一提供通知页面的数据、表单和异步动作。
|
||||
const notificationState = useNotifications(isAdmin);
|
||||
|
||||
return (
|
||||
<div className="space-y-8 animate-fade-in">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col md:flex-row justify-between md:items-end gap-4">
|
||||
<div>
|
||||
<h2 className="text-4xl font-extrabold text-gray-900 tracking-tight">通知设置</h2>
|
||||
<p className="text-gray-500 mt-2 font-medium">配置通知渠道,账号异常时主动推送告警</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={load}
|
||||
className="px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors"
|
||||
>
|
||||
<RefreshCw className="w-4 h-4" />
|
||||
刷新
|
||||
</button>
|
||||
<button
|
||||
onClick={openCreate}
|
||||
className="ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
新建渠道
|
||||
</button>
|
||||
<div><h2 className="text-4xl font-extrabold text-gray-900 tracking-tight">通知设置</h2><p className="text-gray-500 mt-2 font-medium">配置通知渠道,账号异常时主动推送告警</p></div>
|
||||
<div className="flex items-center gap-3">
|
||||
<button onClick={notificationState.loadChannels} className="px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors"><RefreshCw className="w-4 h-4" />刷新</button>
|
||||
<button onClick={notificationState.openCreate} className="ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2"><Plus className="w-4 h-4" />新建渠道</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 说明 */}
|
||||
<div className="ios-card rounded-xl p-5 bg-blue-50/50 border border-blue-100">
|
||||
<div className="flex items-start gap-3">
|
||||
<Bell className="w-5 h-5 text-brand mt-0.5 flex-shrink-0" />
|
||||
<div className="text-sm text-gray-700 leading-6">
|
||||
配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:
|
||||
<ul className="mt-2 space-y-1 text-gray-600">
|
||||
<li>• <strong>账号 session 失效</strong>:系统正在尝试自动恢复(警告)</li>
|
||||
<li>• <strong>自动恢复失败</strong>:账号已停止,需人工处理(严重)</li>
|
||||
<li>• <strong>触发风控验证</strong>:可能需要扫码完成验证(警告)</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start gap-3"><Bell className="w-5 h-5 text-brand mt-0.5 flex-shrink-0" /><div className="text-sm text-gray-700 leading-6">配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:<ul className="mt-2 space-y-1 text-gray-600"><li>• <strong>账号 session 失效</strong>:系统正在尝试自动恢复(警告)</li><li>• <strong>自动恢复失败</strong>:账号已停止,需人工处理(严重)</li><li>• <strong>触发风控验证</strong>:可能需要扫码完成验证(警告)</li></ul></div></div>
|
||||
</div>
|
||||
|
||||
{/* 渠道列表 */}
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-20">
|
||||
<Loader2 className="w-8 h-8 text-brand animate-spin" />
|
||||
</div>
|
||||
) : channels.length === 0 ? (
|
||||
<div className="ios-card rounded-xl p-12 bg-white text-center">
|
||||
<Bell className="w-12 h-12 text-gray-300 mx-auto mb-4" />
|
||||
<p className="text-gray-500 font-medium">还没有配置任何通知渠道</p>
|
||||
<p className="text-gray-400 text-sm mt-1">点击右上角「新建渠道」开始配置</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{channels.map(ch => {
|
||||
const tMeta = CHANNEL_TYPES[ch.type] || CHANNEL_TYPES.webhook;
|
||||
const Icon = tMeta.icon;
|
||||
return (
|
||||
<div key={ch.id} className="ios-card rounded-xl p-5 bg-white flex items-center gap-4">
|
||||
<div className="w-11 h-11 rounded-xl bg-gray-100 flex items-center justify-center flex-shrink-0">
|
||||
<Icon className="w-5 h-5 text-gray-600" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-bold text-gray-900 truncate">{ch.name}</span>
|
||||
<span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium">{tMeta.label}</span>
|
||||
{!ch.enabled && (
|
||||
<span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium">已停用</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500 mt-1 truncate">
|
||||
{tMeta.fields.map(f => ch.config?.[f.key]).filter(Boolean).map((v, i) => (
|
||||
<span key={i} className="mr-3">{String(v).length > 40 ? String(v).slice(0, 40) + '…' : String(v)}</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="text-xs text-gray-400 mt-1 truncate">
|
||||
订阅:{notificationEventSummary(ch.event_types)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<button
|
||||
onClick={() => handleToggleEnabled(ch)}
|
||||
className={`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${ch.enabled ? 'bg-green-50 text-green-700 hover:bg-green-100' : 'bg-gray-100 text-gray-500 hover:bg-gray-200'}`}
|
||||
>
|
||||
{ch.enabled ? '启用中' : '已停用'}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleTest(ch)}
|
||||
disabled={testingId === ch.id}
|
||||
className="px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-brand hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50"
|
||||
>
|
||||
{testingId === ch.id ? <Loader2 className="w-3 h-3 animate-spin" /> : <Send className="w-3 h-3" />}
|
||||
测试
|
||||
</button>
|
||||
<button
|
||||
onClick={() => openEdit(ch)}
|
||||
className="w-8 h-8 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center text-gray-600 transition-colors"
|
||||
title="编辑"
|
||||
>
|
||||
<Edit2 className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDelete(ch)}
|
||||
className="w-8 h-8 rounded-lg bg-red-50 hover:bg-red-100 flex items-center justify-center text-red-500 transition-colors"
|
||||
title="删除"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{notificationState.loading ? <div className="flex justify-center py-20"><Loader2 className="w-8 h-8 text-brand animate-spin" /></div> : <NotificationChannelList channels={notificationState.channels} testingId={notificationState.testingId} onEdit={notificationState.openEdit} onDelete={notificationState.handleDelete} onToggleEnabled={notificationState.handleToggleEnabled} onTest={notificationState.handleTest} />}
|
||||
|
||||
{/* SMTP 邮件配置(系统级,用于邮件通知渠道) */}
|
||||
{isAdmin && (
|
||||
<section className="ios-card rounded-xl p-6 bg-white space-y-5">
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<h3 className="text-lg font-extrabold text-gray-800">SMTP 邮件配置</h3>
|
||||
<p className="text-sm text-gray-500 mt-1">系统级邮件发送服务,供邮件通知渠道复用</p>
|
||||
</div>
|
||||
<div className="p-2 rounded-xl bg-blue-50 text-blue-600">
|
||||
<Mail className="w-5 h-5" />
|
||||
</div>
|
||||
</div>
|
||||
{isAdmin && <NotificationSmtpSettings smtp={notificationState.smtp} setSmtp={notificationState.setSmtp} smtpSaving={notificationState.smtpSaving} showPassword={notificationState.showSmtpPassword} setShowPassword={notificationState.setShowSmtpPassword} onSave={notificationState.handleSaveSmtp} />}
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">SMTP 服务器</label>
|
||||
<input
|
||||
type="text"
|
||||
value={smtp.smtp_server || ''}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_server: e.target.value })}
|
||||
placeholder="smtp.qq.com"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">SMTP 端口</label>
|
||||
<input
|
||||
type="number"
|
||||
value={smtp.smtp_port || 587}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_port: parseInt(e.target.value) || 587 })}
|
||||
placeholder="587"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<NotificationChannelModal showModal={notificationState.showModal} editing={notificationState.editing} form={notificationState.form} setForm={notificationState.setForm} smtp={notificationState.smtp} showChannelSmtpPassword={notificationState.showChannelSmtpPassword} setShowChannelSmtpPassword={notificationState.setShowChannelSmtpPassword} saving={notificationState.saving} onClose={notificationState.closeModal} onSave={notificationState.handleSave} />
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">发件邮箱</label>
|
||||
<input
|
||||
type="email"
|
||||
value={smtp.smtp_user || ''}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_user: e.target.value })}
|
||||
placeholder="your-email@qq.com"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">邮箱密码 / 授权码</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type={showSmtpPassword ? 'text' : 'password'}
|
||||
value={smtp.smtp_password || ''}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_password: e.target.value })}
|
||||
placeholder="输入密码或授权码"
|
||||
className="w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowSmtpPassword(!showSmtpPassword)}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors"
|
||||
>
|
||||
{showSmtpPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">发件人显示名(可选)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={smtp.smtp_from_name || ''}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_from_name: e.target.value })}
|
||||
placeholder="闲鱼自动回复系统"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">发件邮箱地址</label>
|
||||
<input
|
||||
type="email"
|
||||
value={smtp.smtp_from_address || smtp.smtp_user || ''}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_from_address: e.target.value })}
|
||||
placeholder="your-email@qq.com"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<label className="flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={smtp.smtp_use_tls !== false}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_use_tls: e.target.checked, smtp_use_ssl: e.target.checked ? false : smtp.smtp_use_ssl })}
|
||||
/>
|
||||
STARTTLS(常用于 587 端口)
|
||||
</label>
|
||||
<label className="flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={smtp.smtp_use_ssl === true}
|
||||
onChange={e => setSmtp({ ...smtp, smtp_use_ssl: e.target.checked, smtp_use_tls: e.target.checked ? false : smtp.smtp_use_tls })}
|
||||
/>
|
||||
SSL/TLS 直连(常用于 465 端口)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={handleSaveSmtp}
|
||||
disabled={smtpSaving}
|
||||
className="ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
{smtpSaving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
|
||||
{smtpSaving ? '保存中...' : '保存 SMTP 配置'}
|
||||
</button>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* 新建/编辑弹窗 */}
|
||||
{showModal && createPortal(
|
||||
<div className="modal-overlay">
|
||||
<div className="modal-container" style={{ maxWidth: '36rem' }}>
|
||||
<div className="px-6 py-5 border-b border-gray-100 flex items-center justify-between">
|
||||
<h3 className="text-xl font-extrabold text-gray-900">{editing ? '编辑通知渠道' : '新建通知渠道'}</h3>
|
||||
<button
|
||||
onClick={() => setShowModal(false)}
|
||||
className="w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center"
|
||||
>
|
||||
<X className="w-5 h-5 text-gray-600" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-5 space-y-5 overflow-y-auto flex-1 min-h-0">
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">渠道名称</label>
|
||||
<input
|
||||
type="text"
|
||||
value={form.name}
|
||||
onChange={e => setForm({ ...form, name: e.target.value })}
|
||||
placeholder="例如:我的 Bark"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">渠道类型</label>
|
||||
<div className="grid grid-cols-3 sm:grid-cols-4 gap-2">
|
||||
{(Object.keys(CHANNEL_TYPES) as NotificationChannelType[]).map(t => {
|
||||
const m = CHANNEL_TYPES[t];
|
||||
const TIcon = m.icon;
|
||||
const selected = form.type === t;
|
||||
return (
|
||||
<button
|
||||
key={t}
|
||||
type="button"
|
||||
onClick={() => setForm({ ...form, type: t, config: {} })}
|
||||
className={`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${selected ? 'border-brand bg-blue-50' : 'border-gray-100 hover:border-gray-300'}`}
|
||||
>
|
||||
<TIcon className={`w-5 h-5 ${selected ? 'text-brand' : 'text-gray-500'}`} />
|
||||
<span className={`text-xs font-bold ${selected ? 'text-brand' : 'text-gray-600'}`}>{m.label}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 配置指南:选中类型后显示对应获取步骤 */}
|
||||
<div className="rounded-xl bg-amber-50 border border-amber-200 p-4 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Bell className="w-4 h-4 text-amber-600" />
|
||||
<span className="text-sm font-bold text-amber-800">如何获取 {meta.label} 配置?</span>
|
||||
</div>
|
||||
<ol className="space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5">
|
||||
{meta.guide.steps.map((step, i) => (
|
||||
<li key={i}>{step}</li>
|
||||
))}
|
||||
</ol>
|
||||
{meta.guide.urlFormat && (
|
||||
<div className="text-xs text-amber-900/90">
|
||||
<span className="font-bold">格式示例:</span>
|
||||
<code className="mt-1 block bg-amber-100/70 px-2.5 py-1.5 rounded-lg break-all font-mono text-[11px]">{meta.guide.urlFormat}</code>
|
||||
</div>
|
||||
)}
|
||||
{meta.guide.note && (
|
||||
<p className="text-xs text-amber-800/80 leading-5 pt-1">💡 {meta.guide.note}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
{meta.fields.map(f => (
|
||||
<div key={f.key} className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">
|
||||
{f.label}
|
||||
{f.required && <span className="text-red-500 ml-1">*</span>}
|
||||
</label>
|
||||
<input
|
||||
type={f.type === 'password' ? 'password' : f.type === 'number' ? 'number' : 'text'}
|
||||
value={String(form.config[f.key] || '')}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, [f.key]: e.target.value } })}
|
||||
placeholder={f.placeholder}
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
{f.help && <p className="text-xs text-gray-500">{f.help}</p>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{form.type === 'email' && (
|
||||
<div className="overflow-hidden rounded-2xl border border-blue-100 bg-blue-50/40">
|
||||
<div className="flex items-center justify-between gap-4 p-4">
|
||||
<div>
|
||||
<div className="text-sm font-extrabold text-gray-900">SMTP 来源</div>
|
||||
<p className="mt-1 text-xs leading-5 text-gray-500">
|
||||
{form.config.use_custom_smtp === true
|
||||
? '当前渠道使用一套完整、独立的发件配置。'
|
||||
: '当前渠道完整继承系统 SMTP,只单独设置收件邮箱。'}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const useCustom = form.config.use_custom_smtp === true;
|
||||
setForm({
|
||||
...form,
|
||||
config: useCustom
|
||||
? { ...form.config, use_custom_smtp: false }
|
||||
: enableCustomSMTP(form.config, smtp),
|
||||
});
|
||||
}}
|
||||
className={`relative h-7 w-12 shrink-0 rounded-full transition-colors ${form.config.use_custom_smtp === true ? 'bg-brand' : 'bg-gray-300'}`}
|
||||
aria-label="使用独立 SMTP"
|
||||
>
|
||||
<span className={`absolute left-1 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${form.config.use_custom_smtp === true ? 'translate-x-5' : ''}`} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{form.config.use_custom_smtp === true && (
|
||||
<div className="space-y-4 border-t border-blue-100 bg-white/80 p-4">
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">SMTP 服务器 <span className="text-red-500">*</span></label>
|
||||
<input
|
||||
type="text"
|
||||
value={String(form.config.smtp_server || '')}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_server: e.target.value } })}
|
||||
placeholder="smtp.qq.com"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">SMTP 端口 <span className="text-red-500">*</span></label>
|
||||
<input
|
||||
type="number"
|
||||
value={String(form.config.smtp_port || 587)}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_port: e.target.value } })}
|
||||
placeholder="587"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">登录邮箱 <span className="text-red-500">*</span></label>
|
||||
<input
|
||||
type="email"
|
||||
value={String(form.config.smtp_user || '')}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_user: e.target.value } })}
|
||||
placeholder="your-email@qq.com"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">密码 / 授权码 <span className="text-red-500">*</span></label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type={showChannelSmtpPassword ? 'text' : 'password'}
|
||||
value={String(form.config.smtp_password || '')}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_password: e.target.value } })}
|
||||
placeholder="输入密码或授权码"
|
||||
className="w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowChannelSmtpPassword(value => !value)}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600"
|
||||
>
|
||||
{showChannelSmtpPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">发件人显示名(可选)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={String(form.config.smtp_from_name || '')}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_from_name: e.target.value } })}
|
||||
placeholder="闲鱼自动回复系统"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">发件邮箱地址 <span className="text-red-500">*</span></label>
|
||||
<input
|
||||
type="email"
|
||||
value={String(form.config.smtp_from_address || '')}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_from_address: e.target.value } })}
|
||||
placeholder="your-email@qq.com"
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
<label className="flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.config.smtp_use_tls !== false}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_use_tls: e.target.checked, smtp_use_ssl: e.target.checked ? false : form.config.smtp_use_ssl } })}
|
||||
/>
|
||||
STARTTLS(常用于 587)
|
||||
</label>
|
||||
<label className="flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.config.smtp_use_ssl === true}
|
||||
onChange={e => setForm({ ...form, config: { ...form.config, smtp_use_ssl: e.target.checked, smtp_use_tls: e.target.checked ? false : form.config.smtp_use_tls } })}
|
||||
/>
|
||||
SSL/TLS 直连(常用于 465)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-800">通知内容</label>
|
||||
<p className="text-xs text-gray-500 mt-1">不选择表示接收全部通知;选择后仅接收勾选类型。</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
{NOTIFICATION_EVENTS.map(event => {
|
||||
const checked = form.event_types.includes(event.value);
|
||||
return (
|
||||
<button
|
||||
key={event.value}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const next = checked
|
||||
? form.event_types.filter(item => item !== event.value)
|
||||
: [...form.event_types, event.value];
|
||||
setForm({ ...form, event_types: next });
|
||||
}}
|
||||
className={`text-left rounded-xl border px-3 py-2.5 transition-colors ${checked ? 'border-brand bg-blue-50' : 'border-gray-100 hover:border-gray-300'}`}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`w-4 h-4 rounded border flex items-center justify-center ${checked ? 'bg-brand border-brand' : 'border-gray-300'}`}>
|
||||
{checked && <Check className="w-3 h-3 text-white" />}
|
||||
</span>
|
||||
<span className={`text-sm font-bold ${checked ? 'text-brand' : 'text-gray-800'}`}>{event.label}</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-1 pl-6 leading-5">{event.description}</p>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label className="flex items-center gap-3 cursor-pointer">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setForm({ ...form, enabled: !form.enabled })}
|
||||
className={`relative w-11 h-6 rounded-full transition-colors ${form.enabled ? 'bg-brand' : 'bg-gray-300'}`}
|
||||
>
|
||||
<span className={`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${form.enabled ? 'translate-x-5' : ''}`} />
|
||||
</button>
|
||||
<span className="text-sm font-bold text-gray-800">启用此渠道</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3">
|
||||
<button
|
||||
onClick={() => setShowModal(false)}
|
||||
className="px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={saving}
|
||||
className="ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
{saving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Check className="w-4 h-4" />}
|
||||
{saving ? '保存中...' : '保存'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body
|
||||
)}
|
||||
|
||||
{/* Toast */}
|
||||
{toast && (
|
||||
<div className={`fixed bottom-8 left-1/2 -translate-x-1/2 z-[10000] px-5 py-3 rounded-xl shadow-lg font-bold text-sm flex items-center gap-2 animate-fade-in text-white ${toast.type === 'success' ? 'bg-success-500' : 'bg-danger-500'}`}>
|
||||
{toast.type === 'success' ? <Check className="w-4 h-4" /> : <X className="w-4 h-4" />}
|
||||
{toast.text}
|
||||
</div>
|
||||
)}
|
||||
{notificationState.toast && <div className={`fixed bottom-8 left-1/2 -translate-x-1/2 z-[10000] px-5 py-3 rounded-xl shadow-lg font-bold text-sm flex items-center gap-2 animate-fade-in text-white ${notificationState.toast.type === 'success' ? 'bg-success-500' : 'bg-danger-500'}`}>{notificationState.toast.type === 'success' ? <Check className="w-4 h-4" /> : <X className="w-4 h-4" />}{notificationState.toast.text}</div>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -80,13 +80,15 @@ describe('frontend navigation routing', () => {
|
||||
|
||||
test('email notification config separates system and custom SMTP modes', () => {
|
||||
const notifications = readFrontendFile('components/Notifications.tsx');
|
||||
const notificationState = readFrontendFile('app/features/notifications/state.ts');
|
||||
const notificationModal = readFrontendFile('app/features/notifications/components/NotificationChannelModal.tsx');
|
||||
|
||||
expect(notifications).toContain('interface NotificationsProps');
|
||||
expect(notifications).toContain('isAdmin && (');
|
||||
expect(notifications).toContain("key: 'to_email'");
|
||||
expect(notifications).toContain('完整继承系统 SMTP');
|
||||
expect(notifications).toContain('use_custom_smtp');
|
||||
expect(notifications).not.toContain("key: 'from'");
|
||||
expect(notifications).toContain('{isAdmin && <NotificationSmtpSettings');
|
||||
expect(notificationState).toContain("key: 'to_email'");
|
||||
expect(notificationModal).toContain('完整继承系统 SMTP');
|
||||
expect(notificationModal).toContain('use_custom_smtp');
|
||||
expect(notificationState).not.toContain("key: 'from'");
|
||||
expect(notifications).not.toContain('注册验证码');
|
||||
});
|
||||
|
||||
|
||||
@@ -160,6 +160,26 @@ test('订单查询和导入 API 转发外部取消信号', async () => {
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/orders/import', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
|
||||
test('通知渠道和 SMTP API 转发外部取消信号', async () => {
|
||||
// fetchMock 验证渠道读取、保存和 SMTP 读写都支持取消控制。
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse([]))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ data: {} }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
// controller 是通知 feature 传给服务 API 的共享取消控制器。
|
||||
const controller = new AbortController();
|
||||
await getNotificationChannels({ signal: controller.signal });
|
||||
await updateNotificationChannel('channel-1', { enabled: false }, { signal: controller.signal });
|
||||
await getSystemSettings({ signal: controller.signal });
|
||||
await updateSystemSettings({ smtp_server: 'smtp.example.com' }, { signal: controller.signal });
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/notifications/channels', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/notifications/channels/channel-1', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/settings/system', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(4, '/api/v1/settings/system', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
|
||||
test('getShippingRulesPage sends filters and preserves pagination metadata', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({
|
||||
data: [{ id: 7, name: '付款规则', trigger_type: 'order_paid', enabled: false, actions: [] }],
|
||||
|
||||
+12
-12
@@ -880,16 +880,16 @@ export const deleteReplyRule = async (id: string, cookieId: string): Promise<Ope
|
||||
}
|
||||
|
||||
// Settings
|
||||
export const getSystemSettings = async (): Promise<SystemSettings> => {
|
||||
const res = await get<{data: SystemSettings}>('/api/v1/settings/system');
|
||||
export const getSystemSettings = async (options?: RequestControlOptions): Promise<SystemSettings> => {
|
||||
const res = await get<{data: SystemSettings}>('/api/v1/settings/system', undefined, options);
|
||||
return normalizeSettings(res.data || res); // handle {success:true, data: {...}} wrapper if exists
|
||||
};
|
||||
|
||||
export const updateSystemSettings = async (settings: Partial<SystemSettings>): Promise<OperationResponse> => {
|
||||
export const updateSystemSettings = async (settings: Partial<SystemSettings>, options?: RequestControlOptions): Promise<OperationResponse> => {
|
||||
const payload = Object.fromEntries(
|
||||
Object.entries(settings).filter(([, value]) => value !== undefined && value !== null),
|
||||
);
|
||||
return put('/api/v1/settings/system', payload);
|
||||
return put('/api/v1/settings/system', payload, options);
|
||||
};
|
||||
|
||||
export const getAccountAISettings = async (cookieId: string, options?: RequestControlOptions): Promise<AIReplySettingsResponse> => {
|
||||
@@ -956,15 +956,15 @@ export const getNotificationChannels = async (options?: RequestControlOptions):
|
||||
return { success: true, data: channels };
|
||||
}
|
||||
|
||||
export const createNotificationChannel = async (data: { name: string; type: string; config: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<MutationIDResponse> => {
|
||||
export const createNotificationChannel = async (data: { name: string; type: string; config: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }, options?: RequestControlOptions): Promise<MutationIDResponse> => {
|
||||
return post('/api/v1/notifications/channels', {
|
||||
...data,
|
||||
config: JSON.stringify(data.config),
|
||||
event_types: stringifyNotificationEventTypes(data.event_types)
|
||||
});
|
||||
}, options);
|
||||
}
|
||||
|
||||
export const updateNotificationChannel = async (channelId: string, data: { name?: string; type?: string; config?: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<OperationResponse> => {
|
||||
export const updateNotificationChannel = async (channelId: string, data: { name?: string; type?: string; config?: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }, options?: RequestControlOptions): Promise<OperationResponse> => {
|
||||
const payload: Record<string, unknown> = { ...data };
|
||||
if ('config' in data) {
|
||||
payload.config = JSON.stringify(data.config);
|
||||
@@ -972,11 +972,11 @@ export const updateNotificationChannel = async (channelId: string, data: { name?
|
||||
if ('event_types' in data) {
|
||||
payload.event_types = stringifyNotificationEventTypes(data.event_types);
|
||||
}
|
||||
return put(`/api/v1/notifications/channels/${channelId}`, payload);
|
||||
return put(`/api/v1/notifications/channels/${channelId}`, payload, options);
|
||||
}
|
||||
|
||||
export const deleteNotificationChannel = async (channelId: string): Promise<OperationResponse> => {
|
||||
return del(`/api/v1/notifications/channels/${channelId}`);
|
||||
export const deleteNotificationChannel = async (channelId: string, options?: RequestControlOptions): Promise<OperationResponse> => {
|
||||
return del(`/api/v1/notifications/channels/${channelId}`, undefined, options);
|
||||
}
|
||||
|
||||
// Message Notifications
|
||||
@@ -1021,8 +1021,8 @@ export const setAccountBindings = async (cookieId: string, channelIds: number[])
|
||||
}
|
||||
|
||||
// 测试发送
|
||||
export const testNotificationChannel = async (channelId: string): Promise<OperationResponse> => {
|
||||
return post(`/api/v1/notifications/channels/${channelId}/test`, {});
|
||||
export const testNotificationChannel = async (channelId: string, options?: RequestControlOptions): Promise<OperationResponse> => {
|
||||
return post(`/api/v1/notifications/channels/${channelId}/test`, {}, options);
|
||||
}
|
||||
|
||||
// Default Reply
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import{j as e,r as l,c as Ns,b as Oe,d as Ga}from"./react-vendor-C_od1ZSF.js";import{L as Qa,U as ma,M as cs,C as _s,B as ua,S as pa,Z as ds,a as ft,b as vs,G as Is,c as ws,d as ks,e as Va,f as at,A as Os,D as Ka,g as Rs,P as ha,h as Et,E as ga,T as Ha,i as Za,j as we,X as Le,k as Ya,l as Xa,m as Cs,n as ba,o as Ye,p as Ve,q as ya,K as el,r as nt,s as st,Q as Ht,t as ot,u as yt,v as Rt,R as Ue,w as fa,x as tl,y as Qe,z as Nt,F as Pt,H as Xe,I as Ps,J as jt,N as sl,O as al,V as ll,W as ja,Y as Na,_ as _a,$ as rl,a0 as nl,a1 as Zt,a2 as Mt,a3 as xs,a4 as il,a5 as ol,a6 as ms,a7 as $s,a8 as cl,a9 as dl,aa as $t,ab as Es,ac as Jt,ad as va,ae as xl,af as ml,ag as Vt,ah as wa,ai as ul,aj as pl,ak as hl,al as gl,am as bl,an as yl,ao as Ts}from"./icons-vendor-BJ6r5aOc.js";import{R as Bt,B as fl,X as Ds,Y as Ms,T as qt,a as jl,C as Yt,A as Nl,b as _l,c as vl,P as Bs,d as qs,L as wl}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))n(r);new MutationObserver(r=>{for(const f of r)if(f.type==="childList")for(const p of f.addedNodes)p.tagName==="LINK"&&p.rel==="modulepreload"&&n(p)}).observe(document,{childList:!0,subtree:!0});function a(r){const f={};return r.integrity&&(f.integrity=r.integrity),r.referrerPolicy&&(f.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?f.credentials="include":r.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function n(r){if(r.ep)return;r.ep=!0;const f=a(r);fetch(r.href,f)}})();const kl=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),us=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(vs,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:qe,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:le,children:"取消"}),e.jsxs("button",{onClick:c,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:le,children:[le?e.jsx(we,{className:"w-4 h-4 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4"}),le?"保存中...":"保存"]})]})})]})}),document.body)]})},pn=[{key:"all",label:"全部"},{key:"processing",label:"处理中"},{key:"shipped",label:"已发货"},{key:"pending_ship",label:"待发货"},{key:"completed",label:"已完成"},{key:"cancelled",label:"已取消"},{key:"refunding",label:"退款中"}],hn=t=>{const s=typeof t=="object"&&t!==null?t:{},a=Array.isArray(s.results)?s.results:[];return{total:Number(s.total||0),success_count:Number(s.success_count||0),failed_count:Number(s.failed_count||0),results:a.map(gn)}},gn=t=>{const s=typeof t=="object"&&t!==null?t:{};return{order_id:String(s.order_id||"unknown"),success:s.success===!0,message:String(s.message||"")}},bn=t=>(t==null?void 0:t.results.filter(yn))||[],yn=t=>!t.success,fn=(t,s)=>t!==null&&!s,jn=t=>{if(!t)return"请选择订单文件";const s=t.name.toLowerCase().split(".").pop()||"";return["xlsx","csv","tsv","json"].includes(s)?"":"仅支持 .xlsx、.csv、.tsv、.json 格式"},it=(t,s)=>t===s,Nn=(t,s)=>t instanceof Error&&t.message?t.message:s,_n=({filter:t,onFilterChange:s,accountFilter:a,onAccountFilterChange:n,accounts:r,accountName:f,searchText:p,onSearchChange:w})=>{const m=C=>s(C.currentTarget.dataset.status||"all"),k=C=>n(C.target.value),u=C=>w(C.target.value);return e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:pn.map(C=>e.jsx("button",{"data-status":C.key,onClick:m,className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${t===C.key?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:C.label},C.key))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ot,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{"aria-label":"按账号筛选订单",value:a,onChange:k,className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),r.map(C=>e.jsx("option",{value:C.id,children:f(C.id)},C.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Nt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:p,onChange:u,className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]})},vn=t=>{const s=f=>{var p;t.setImportFile(((p=f.target.files)==null?void 0:p[0])||null)},a=()=>t.closeImportModal(),n=()=>void t.handleImportOrders(),r=()=>void t.handleRetryImport();return t.showImportModal?Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:a,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Le,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:s,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xl
Line truncated
|
||||
VIP-002
|
||||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["预览:",a.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),a.appendError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-200 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:a.appendError}),e.jsx("button",{type:"button",onClick:u,disabled:a.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),a.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",a.appendResult.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:p,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),a.batchTab==="create"?e.jsxs("button",{onClick:K,disabled:!a.batchFile||a.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(we,{className:"w-4 h-4 animate-spin"}):e.jsx(Pt,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:W,disabled:!a.appendTargetId||a.appendPreview.length===0||a.batchBusy||t.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(we,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},Ln=({type:t})=>{switch(t){case"text":return e.jsx(Na,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(ja,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(ll,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(_s,{className:"w-5 h-5 text-gray-500"})}},An=(t,s,a)=>{const n=a.trim().toLocaleLowerCase();return t.filter(r=>(!s||r.type===s)&&(!n||r.name.toLocaleLowerCase().includes(n)))},Ma=t=>t.split(`
|
||||
`).map(s=>s.trim()).filter(Boolean),In=(t,s,a)=>!!(t&&Ma(s).length>0&&!a),gt=(t,s,a,n)=>t===s&&a===n,On=()=>{const[t,s]=l.useState([]),[a,n]=l.useState(!0),r=l.useRef(0),f=l.useRef(null),p=l.useCallback(async()=>{var k;const w=++r.current;(k=f.current)==null||k.abort();const m=new AbortController;f.current=m,n(!0);try{const u=await Ls({signal:m.signal});if(w!==r.current)return;s(u)}catch(u){w===r.current&&!m.signal.aborted&&console.error("加载卡密库存失败:",u)}finally{w===r.current&&n(!1)}},[]);return l.useEffect(()=>(p(),()=>{var m;r.current+=1,(m=f.current)==null||m.abort()}),[p]),{cards:t,setCards:s,loading:a,loadCards:p}},Rn=t=>{const s=t.dataCards,a=t.loadCards,[n,r]=l.useState(!1),[f,p]=l.useState("create"),[w,m]=l.useState(null),[k,u]=l.useState(null),[C,M]=l.useState(!1),[K,W]=l.useState(""),[j,R]=l.useState(""),[T,X]=l.useState(null),[V,se]=l.useState(""),Z=l.useRef(0),F=l.useRef(null),S=l.useRef(""),P=l.useMemo(()=>Ma(j),[j]),ee=l.useCallback(()=>{var L;p("create"),m(null),u(null),W((L=s[0])!=null&&L.id?String(s[0].id):""),R(""),X(null),se(""),r(!0)},[s]),d=l.useCallback(()=>{var L;Z.current+=1,(L=F.current)==null||L.abort(),M(!1),r(!1)},[]),G=l.useCallback(async()=>{var I;if(!w||C)return;const L=++Z.current;(I=F.current)==null||I.abort();const q=new AbortController;F.current=q,M(!0),u(null);try{const B=await hr(w,{signal:q.signal});if(!gt(L,Z.current,"",""))return;u(B),B.created>0&&await a()}catch(B){if(!gt(L,Z.current,"",""))return;u({error:(B==null?void 0:B.message)||"上传失败"})}finally{gt(L,Z.current,"","")&&M(!1)}},[C,w,a]),U=l.useCallback(async()=>{var B;if(!In(K,j,C))return;const L=K,q=++Z.current;S.current=L,(B=F.current)==null||B.abort();const I=new AbortController;F.current=I,M(!0),X(null),se("");try{const $=await gr(L,j,{signal:I.signal});if(!gt(q,Z.current,L,K))return;X({added:$.added}),R(""),await a()}catch($){if(!gt(q,Z.current,L,K))return;se(($==null?void 0:$.message)||"追加失败")}finally{gt(q,Z.current,L,K)&&M(!1)}},[j,K,C,a]),E=l.useCallback(async()=>{await G()},[G]),A=l.useCallback(async()=>{S.current&&K!==S.current||await U()},[K,U]);return{showBatchModal:n,setShowBatchModal:r,batchTab:f,setBatchTab:p,batchFile:w,setBatchFile:m,batchResult:k,batchBusy:C,appendTargetId:K,setAppendTargetId:W,appendContent:j,setAppendContent:R,appendResult:T,appendError:V,appendPreview:P,openBatchModal:ee,closeBatchModal:d,handleBatchCreate:G,handleBatchAppend:U,handleRetryBatchCreate:E,handleRetryBatchAppend:A}},Zs=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),Pn=()=>{const{cards:t,loadCards:s}=On(),[a,n]=l.useState(!1),[r,f]=l.useState(!1),[p,w]=l.useState(null),[m,k]=l.useState({}),[u,C]=l.useState(Zs),[M,K]=l.useState(""),[W,j]=l.useState(""),R=l.useMemo(()=>t.filter(d=>d.type==="data"),[t]),T=Rn({dataCards:R,loadCards:s}),X=d=>{var G,U,E,A,L;w(d),k({id:d.id,name:d.name||"",type:d.type||"text",api_url:((G=d.api_config)==null?void 0:G.url)||"",api_method:((U=d.api_config)==null?void 0:U.method)||"GET",api_timeout:((E=d.api_config)==null?void 0:E.timeout)||10,api_headers:((A=d.api_config)==null?void 0:A.headers)||"",api_params:((L=d.api_config)==null?void 0:L.params)||"",text_content:d.text_content||"",data_content:d.data_content||"",image_url:d.image_url||"",delay_seconds:d.delay_seconds||0,description:d.description||"",enabled:d.enabled}),n(!0)},V=async()=>{var d,G,U,E,A,L,q,I;if(p){if(!((d=m.name)!=null&&d.trim())){alert("请输入卡密名称");return}if(!m.type){alert("请选择卡密类型");return}try{const B={name:m.name.trim(),type:m.type,description:(G=m.description)==null?void 0:G.trim(),delay_seconds:m.delay_seconds||0,enabled:m.enabled??!0};m.type==="api"?B.api_config={url:((U=m.api_url)==null?void 0:U.trim())||"",method:m.api_method,timeout:m.api_timeout||10,headers:((E=m.api_headers)==null?void 0:E.trim())||void 0,params:((A=m.api_params)==null?void 0:A.trim())||void 0}:m.type==="text"?B.text_content=((L=m.text_content)==null?void 0:L.trim())||"":m.type==="data"?B.data_content=((q=m.data_content)==null?void 0:q.trim())||"":m.type==="image"&&(B.image_url=((I=m.image_url)==null?void 0:I.trim())||""),await Js(p.id,B),n(!1),await s()}catch(B){console.error("更新卡密失败:",B),alert("更新失败,请重试")}}},se=async d=>{if(confirm("确认删除该卡密吗?"))try{await pr(d),await s()}catch(G){console.error("删除卡密失败:",G),alert("删除失败,请重试")}},Z=async()=>{if(!u.name.trim()){alert("请输入卡密名称");return}if(!u.content.trim()){alert(u.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const d={name:u.name.trim(),type:u.type,description:u.description.trim(),enabled:u.enabled,delay_seconds:u.delay_seconds};u.type==="text"&&(d.text_content=u.content.trim()),u.type==="data"&&(d.data_content=u.content.trim()),u.type==="image"&&(d.image_url=u.content.trim()),u.type==="api"&&(d.api_config={url:u.content.trim(),method:u
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(q=>q.map(I=>`"${String(I).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),E=new Blob(["\uFEFF"+U],{type:"text/csv;charset=utf-8"}),A=URL.createObjectURL(E),L=document.createElement("a");L.href=A,L.download="卡密组批量导入模板.csv",document.body.appendChild(L),L.click(),L.remove(),URL.revokeObjectURL(A)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:T.openBatchModal,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Pt,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>f(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(Xe,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(_a,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:M,onChange:d=>K(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(Nt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:W,onChange:d=>j(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",P.length," / ",t.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:P.map(d=>{let G="";return d.type==="data"&&d.data_content?G=`库存: ${d.data_content.split(`
|
||||
`).filter(E=>E.trim()).length} 条`:d.type==="text"&&d.text_content?G=d.text_content:d.type==="api"&&d.api_config?G=d.api_config.url:d.type==="image"&&d.image_url&&(G="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(Ln,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>S(d.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(rl,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${d.type==="text"?"bg-blue-50 text-blue-600":d.type==="data"?"bg-purple-50 text-purple-600":d.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:d.type==="text"?"文本":d.type==="data"?"批量":d.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:G,children:G})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:d.description||"-",children:d.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>F(d),className:`w-12 h-8 rounded-full relative transition-colors ${d.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${d.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>X(d),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(jt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>se(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Qe,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),P.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ha,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&p&&Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>n(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Le,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:m.name||"",onChange:d=>k({...m,name:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:m.type||"text",onChange:d=>k({...m,type:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(p==null?void 0:p.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),m.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:m.api_url||"",onChange:d=>k({...m,api_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxLine truncated
|
||||
卡号1:密码1
|
||||
卡号2:密码2
|
||||
或者
|
||||
兑换码1
|
||||
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:m.data_content?m.data_content.split(`
|
||||
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),m.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:m.image_url||"",onChange:d=>k({...m,image_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),m.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:m.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:m.delay_seconds||0,onChange:d=>k({...m,delay_seconds:parseInt(d.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:m.description||"",onChange:d=>k({...m,description:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>k({...m,enabled:!m.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${m.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${m.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>n(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:V,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),r&&Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>f(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(Le,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:u.name,onChange:d=>C({...u,name:d.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>C({...u,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${u.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(_s,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>C({...u,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${u.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Na,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>C({...u,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${u.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:
Line truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),u.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:u.content.split(`
|
||||
`).filter(d=>d.trim()).length})," 条"]})]}),u.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:u.api_method,onChange:d=>C({...u,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:u.api_timeout,onChange:d=>C({...u,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:u.api_headers,onChange:d=>C({...u,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:u.api_params,onChange:d=>C({...u,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:u.description,onChange:d=>C({...u,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:u.delay_seconds,onChange:d=>C({...u,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>f(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:Z,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Xe,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),e.jsx(Sn,{dataCards:R,downloadCardTemplate:ee,...T})]})},Ys="ydisks-amap-js-api",$n="c9b68d4ce9a2a97f22a4a439404488ca";let Lt=null;const En=()=>$n,Tn=()=>window.AMap?Promise.resolve(window.AMap):Lt||(Lt=new Promise((t,s)=>{const a=document.getElementById(Ys),n=a||document.createElement("script"),r=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(p)},f=()=>{window.AMap?(r(),t(window.AMap)):(r(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},p=window.setTimeout(()=>{r(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=f,n.id=Ys,n.async=!0,n.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(En())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,n.onerror=()=>{r(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(n)}).catch(t=>{throw Lt=null,t}),Lt),Qt=t=>Number.isFinite(t)&&t!==0,Dn=t=>{var r,f;const s=Number((r=t.location)==null?void 0:r.lng),a=Number((f=t.location)==null?void 0:f.lat),n={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:a,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!n.division_id||!n.province||!n.city||!n.poi_id||!n.poi_name||!Qt(s)||!Qt(a)||s<-180||s>180||a<-90||a>90?null:n},Mn=async(t,s)=>{if(!Qt(t)||!Qt(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await Tn();return new Promise((n,r)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(p,w)=>{var k;if(p!=="complete"){if(p==="no_data"){n([]);return}r(new Error("高德地图附近地址查询失败,请稍后重试"));return}const m=(((k=w==null?void 0:w.poiList)==null?void 0:k.pois)||[]).map(Dn).filter(u=>u!==null);n(m)})})},Bn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),fs=t=>t==="running"||t==="canceling",qn=t=>!!(t!=null&&t.prev
Line truncated
|
||||
`),Ie=new Blob(["\uFEFF"+me],{type:"text/csv;charset=utf-8"}),Ge=URL.createObjectURL(Ie),qe=document.createElement("a");qe.href=Ge,qe.download="批量铺货模板.csv",document.body.appendChild(qe),qe.click(),qe.remove(),URL.revokeObjectURL(Ge)},kt=()=>{q(c=>({...c,cookie_id:w||c.cookie_id})),X(!0)},ct=()=>{B(c=>({...c,cookie_id:w||c.cookie_id})),se(!0)},dt=async c=>{if(!(c?w:I.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");F(!0),navigator.geolocation.getCurrentPosition(async me=>{try{const Ie=await Mn(me.coords.longitude,me.coords.latitude);if(!Ie.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(_(Ie),O(Ie[0])):(P(Ie),d(Ie[0]))}catch(Ie){alert((Ie==null?void 0:Ie.message)||"获取发货地失败")}finally{F(!1)}},me=>{F(!1),alert(me.code===me.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Ct=c=>n.filter(z=>z.cookie_id===c.cookie_id&&z.item_id===c.item_id).length>0?n.filter(z=>z.cookie_id===c.cookie_id&&z.item_id===c.item_id):n.filter(z=>z.cookie_id===c.cookie_id&&!z.item_id),xt=l.useMemo(()=>new Map(f.map(c=>[c.id,c])),[f]),mt=l.useMemo(()=>k?s.filter(c=>c.cookie_id===k):s,[k,s]),He=c=>{const z=xt.get(c),me=(z==null?void 0:z.remark)||(z==null?void 0:z.nickname);return me?`${me} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},ut=c=>{const z=xt.get(c);return(z==null?void 0:z.remark)||(z==null?void 0:z.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(nl,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:k,onChange:c=>u(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),f.map(c=>e.jsx("option",{value:c.id,children:He(c.id)},c.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(ot,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:w,onChange:c=>m(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),f.map(c=>e.jsx("option",{value:c.id,children:He(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:ke,disabled:C||!w,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Ue,{className:`w-4 h-4 ${C?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:kt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(Xe,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:ct,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Zt,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Y(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Mt,{className:"w-4 h-4"}),re&&["running","canceling"].includes(re.status)?"继续批量任务":"批量铺货"]}),re&&!["running","canceling"].includes(re.status)&&e.jsx("button",{onClick:()=>void ve(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[mt.map(c=>{const z=Ct(c),me=z.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex flex
Line truncated
|
||||
@@ -0,0 +1,20 @@
|
||||
import{j as e,r as l,c as _s,b as Ee,d as Ka}from"./react-vendor-C_od1ZSF.js";import{L as Ha,U as ua,M as xs,C as ws,B as pa,S as ha,Z as ms,a as _t,b as ks,G as Os,c as Cs,d as Ss,e as Za,f as lt,A as Ps,D as Ya,g as Ts,P as ga,h as Dt,E as ba,T as Xa,i as el,j as Ae,X as Oe,k as tl,l as sl,m as As,n as fa,o as Xe,p as Ke,q as ya,K as al,r as it,s as at,Q as Yt,t as ct,u as ft,v as Tt,R as We,w as ja,x as ll,y as Ve,z as Nt,F as Et,H as et,I as Es,J as yt,N as rl,O as nl,V as il,W as Na,Y as va,_ as _a,$ as ol,a0 as cl,a1 as Xt,a2 as qt,a3 as us,a4 as dl,a5 as xl,a6 as ps,a7 as $s,a8 as ml,a9 as ul,aa as $t,ab as Ds,ac as Qt,ad as wa,ae as pl,af as hl,ag as Ht,ah as ka,ai as gl,aj as bl,ak as fl,al as yl,am as jl,an as Nl,ao as Ms}from"./icons-vendor-BJ6r5aOc.js";import{R as Ft,B as vl,X as Bs,Y as qs,T as zt,a as _l,C as es,A as wl,b as kl,c as Cl,P as Fs,d as zs,L as Sl}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))r(n);new MutationObserver(n=>{for(const h of n)if(h.type==="childList")for(const u of h.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&r(u)}).observe(document,{childList:!0,subtree:!0});function a(n){const h={};return n.integrity&&(h.integrity=n.integrity),n.referrerPolicy&&(h.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?h.credentials="include":n.crossOrigin==="anonymous"?h.credentials="omit":h.credentials="same-origin",h}function r(n){if(n.ep)return;n.ep=!0;const h=a(n);fetch(n.href,h)}})();const Al=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),hs=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(ks,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:Fe,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:ne,children:"取消"}),e.jsxs("button",{onClick:c,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:ne,children:[ne?e.jsx(Ae,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),ne?"保存中...":"保存"]})]})})]})}),document.body)]})},bn=[{key:"all",label:"全部"},{key:"processing",label:"处理中"},{key:"shipped",label:"已发货"},{key:"pending_ship",label:"待发货"},{key:"completed",label:"已完成"},{key:"cancelled",label:"已取消"},{key:"refunding",label:"退款中"}],fn=t=>{const s=typeof t=="object"&&t!==null?t:{},a=Array.isArray(s.results)?s.results:[];return{total:Number(s.total||0),success_count:Number(s.success_count||0),failed_count:Number(s.failed_count||0),results:a.map(yn)}},yn=t=>{const s=typeof t=="object"&&t!==null?t:{};return{order_id:String(s.order_id||"unknown"),success:s.success===!0,message:String(s.message||"")}},jn=t=>(t==null?void 0:t.results.filter(Nn))||[],Nn=t=>!t.success,vn=(t,s)=>t!==null&&!s,_n=t=>{if(!t)return"请选择订单文件";const s=t.name.toLowerCase().split(".").pop()||"";return["xlsx","csv","tsv","json"].includes(s)?"":"仅支持 .xlsx、.csv、.tsv、.json 格式"},ot=(t,s)=>t===s,wn=(t,s)=>t instanceof Error&&t.message?t.message:s,kn=({filter:t,onFilterChange:s,accountFilter:a,onAccountFilterChange:r,accounts:n,accountName:h,searchText:u,onSearchChange:j})=>{const m=_=>s(_.currentTarget.dataset.status||"all"),v=_=>r(_.target.value),x=_=>j(_.target.value);return e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:bn.map(_=>e.jsx("button",{"data-status":_.key,onClick:m,className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${t===_.key?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:_.label},_.key))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ct,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{"aria-label":"按账号筛选订单",value:a,onChange:v,className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),n.map(_=>e.jsx("option",{value:_.id,children:h(_.id)},_.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Nt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:u,onChange:x,className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]})},Cn=t=>{const s=h=>{var u;t.setImportFile(((u=h.target.files)==null?void 0:u[0])||null)},a=()=>t.closeImportModal(),r=()=>void t.handleImportOrders(),n=()=>void t.handleRetryImport();return t.showImportModal?Ee.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:a,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Oe,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:s,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xl
Line truncated
|
||||
VIP-002
|
||||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["预览:",a.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),a.appendError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-200 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:a.appendError}),e.jsx("button",{type:"button",onClick:x,disabled:a.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),a.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",a.appendResult.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:u,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),a.batchTab==="create"?e.jsxs("button",{onClick:O,disabled:!a.batchFile||a.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(Ae,{className:"w-4 h-4 animate-spin"}):e.jsx(Et,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:z,disabled:!a.appendTargetId||a.appendPreview.length===0||a.batchBusy||t.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(Ae,{className:"w-4 h-4 animate-spin"}):e.jsx(et,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},Rn=({type:t})=>{switch(t){case"text":return e.jsx(va,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(Na,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(il,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(ws,{className:"w-5 h-5 text-gray-500"})}},On=(t,s,a)=>{const r=a.trim().toLocaleLowerCase();return t.filter(n=>(!s||n.type===s)&&(!r||n.name.toLocaleLowerCase().includes(r)))},Ba=t=>t.split(`
|
||||
`).map(s=>s.trim()).filter(Boolean),Pn=(t,s,a)=>!!(t&&Ba(s).length>0&&!a),bt=(t,s,a,r)=>t===s&&a===r,Tn=()=>{const[t,s]=l.useState([]),[a,r]=l.useState(!0),n=l.useRef(0),h=l.useRef(null),u=l.useCallback(async()=>{var v;const j=++n.current;(v=h.current)==null||v.abort();const m=new AbortController;h.current=m,r(!0);try{const x=await Is({signal:m.signal});if(j!==n.current)return;s(x)}catch(x){j===n.current&&!m.signal.aborted&&console.error("加载卡密库存失败:",x)}finally{j===n.current&&r(!1)}},[]);return l.useEffect(()=>(u(),()=>{var m;n.current+=1,(m=h.current)==null||m.abort()}),[u]),{cards:t,setCards:s,loading:a,loadCards:u}},En=t=>{const s=t.dataCards,a=t.loadCards,[r,n]=l.useState(!1),[h,u]=l.useState("create"),[j,m]=l.useState(null),[v,x]=l.useState(null),[_,w]=l.useState(!1),[O,z]=l.useState(""),[N,$]=l.useState(""),[D,Z]=l.useState(null),[Q,ae]=l.useState(""),I=l.useRef(0),P=l.useRef(null),G=l.useRef(""),q=l.useMemo(()=>Ba(N),[N]),Y=l.useCallback(()=>{var k;u("create"),m(null),x(null),z((k=s[0])!=null&&k.id?String(s[0].id):""),$(""),Z(null),ae(""),n(!0)},[s]),d=l.useCallback(()=>{var k;I.current+=1,(k=P.current)==null||k.abort(),w(!1),n(!1)},[]),U=l.useCallback(async()=>{var L;if(!j||_)return;const k=++I.current;(L=P.current)==null||L.abort();const E=new AbortController;P.current=E,w(!0),x(null);try{const F=await fr(j,{signal:E.signal});if(!bt(k,I.current,"",""))return;x(F),F.created>0&&await a()}catch(F){if(!bt(k,I.current,"",""))return;x({error:(F==null?void 0:F.message)||"上传失败"})}finally{bt(k,I.current,"","")&&w(!1)}},[_,j,a]),V=l.useCallback(async()=>{var F;if(!Pn(O,N,_))return;const k=O,E=++I.current;G.current=k,(F=P.current)==null||F.abort();const L=new AbortController;P.current=L,w(!0),Z(null),ae("");try{const B=await yr(k,N,{signal:L.signal});if(!bt(E,I.current,k,O))return;Z({added:B.added}),$(""),await a()}catch(B){if(!bt(E,I.current,k,O))return;ae((B==null?void 0:B.message)||"追加失败")}finally{bt(E,I.current,k,O)&&w(!1)}},[N,O,_,a]),R=l.useCallback(async()=>{await U()},[U]),C=l.useCallback(async()=>{G.current&&O!==G.current||await V()},[O,V]);return{showBatchModal:r,setShowBatchModal:n,batchTab:h,setBatchTab:u,batchFile:j,setBatchFile:m,batchResult:v,batchBusy:_,appendTargetId:O,setAppendTargetId:z,appendContent:N,setAppendContent:$,appendResult:D,appendError:Q,appendPreview:q,openBatchModal:Y,closeBatchModal:d,handleBatchCreate:U,handleBatchAppend:V,handleRetryBatchCreate:R,handleRetryBatchAppend:C}},Xs=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),$n=()=>{const{cards:t,loadCards:s}=Tn(),[a,r]=l.useState(!1),[n,h]=l.useState(!1),[u,j]=l.useState(null),[m,v]=l.useState({}),[x,_]=l.useState(Xs),[w,O]=l.useState(""),[z,N]=l.useState(""),$=l.useMemo(()=>t.filter(d=>d.type==="data"),[t]),D=En({dataCards:$,loadCards:s}),Z=d=>{var U,V,R,C,k;j(d),v({id:d.id,name:d.name||"",type:d.type||"text",api_url:((U=d.api_config)==null?void 0:U.url)||"",api_method:((V=d.api_config)==null?void 0:V.method)||"GET",api_timeout:((R=d.api_config)==null?void 0:R.timeout)||10,api_headers:((C=d.api_config)==null?void 0:C.headers)||"",api_params:((k=d.api_config)==null?void 0:k.params)||"",text_content:d.text_content||"",data_content:d.data_content||"",image_url:d.image_url||"",delay_seconds:d.delay_seconds||0,description:d.description||"",enabled:d.enabled}),r(!0)},Q=async()=>{var d,U,V,R,C,k,E,L;if(u){if(!((d=m.name)!=null&&d.trim())){alert("请输入卡密名称");return}if(!m.type){alert("请选择卡密类型");return}try{const F={name:m.name.trim(),type:m.type,description:(U=m.description)==null?void 0:U.trim(),delay_seconds:m.delay_seconds||0,enabled:m.enabled??!0};m.type==="api"?F.api_config={url:((V=m.api_url)==null?void 0:V.trim())||"",method:m.api_method,timeout:m.api_timeout||10,headers:((R=m.api_headers)==null?void 0:R.trim())||void 0,params:((C=m.api_params)==null?void 0:C.trim())||void 0}:m.type==="text"?F.text_content=((k=m.text_content)==null?void 0:k.trim())||"":m.type==="data"?F.data_content=((E=m.data_content)==null?void 0:E.trim())||"":m.type==="image"&&(F.image_url=((L=m.image_url)==null?void 0:L.trim())||""),await Qs(u.id,F),r(!1),await s()}catch(F){console.error("更新卡密失败:",F),alert("更新失败,请重试")}}},ae=async d=>{if(confirm("确认删除该卡密吗?"))try{await br(d),await s()}catch(U){console.error("删除卡密失败:",U),alert("删除失败,请重试")}},I=async()=>{if(!x.name.trim()){alert("请输入卡密名称");return}if(!x.content.trim()){alert(x.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const d={name:x.name.trim(),type:x.type,description:x.description.trim(),enabled:x.enabled,delay_seconds:x.delay_seconds};x.type==="text"&&(d.text_content=x.content.trim()),x.type==="data"&&(d.data_content=x.content.trim()),x.type==="image"&&(d.image_url=x.content.trim()),x.type==="api"&&(d.api_config={url:x.content.trim(),method:x.a
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(E=>E.map(L=>`"${String(L).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),R=new Blob(["\uFEFF"+V],{type:"text/csv;charset=utf-8"}),C=URL.createObjectURL(R),k=document.createElement("a");k.href=C,k.download="卡密组批量导入模板.csv",document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(C)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:D.openBatchModal,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Et,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>h(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(et,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(_a,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:w,onChange:d=>O(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(Nt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:z,onChange:d=>N(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",q.length," / ",t.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:q.map(d=>{let U="";return d.type==="data"&&d.data_content?U=`库存: ${d.data_content.split(`
|
||||
`).filter(R=>R.trim()).length} 条`:d.type==="text"&&d.text_content?U=d.text_content:d.type==="api"&&d.api_config?U=d.api_config.url:d.type==="image"&&d.image_url&&(U="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(Rn,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>G(d.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(ol,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${d.type==="text"?"bg-blue-50 text-blue-600":d.type==="data"?"bg-purple-50 text-purple-600":d.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:d.type==="text"?"文本":d.type==="data"?"批量":d.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:U,children:U})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:d.description||"-",children:d.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>P(d),className:`w-12 h-8 rounded-full relative transition-colors ${d.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${d.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>Z(d),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(yt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ae(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ve,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),q.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ga,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&u&&Ee.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>r(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Oe,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:m.name||"",onChange:d=>v({...m,name:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:m.type||"text",onChange:d=>v({...m,type:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(u==null?void 0:u.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),m.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:m.api_url||"",onChange:d=>v({...m,api_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxLine truncated
|
||||
卡号1:密码1
|
||||
卡号2:密码2
|
||||
或者
|
||||
兑换码1
|
||||
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:m.data_content?m.data_content.split(`
|
||||
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),m.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:m.image_url||"",onChange:d=>v({...m,image_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),m.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:m.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:m.delay_seconds||0,onChange:d=>v({...m,delay_seconds:parseInt(d.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:m.description||"",onChange:d=>v({...m,description:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>v({...m,enabled:!m.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${m.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${m.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>r(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:Q,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Xe,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),n&&Ee.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>h(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(Oe,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:x.name,onChange:d=>_({...x,name:d.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>_({...x,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${x.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(ws,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>_({...x,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${x.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(va,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>_({...x,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${x.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:
Line truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),x.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:x.content.split(`
|
||||
`).filter(d=>d.trim()).length})," 条"]})]}),x.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:x.api_method,onChange:d=>_({...x,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:x.api_timeout,onChange:d=>_({...x,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:x.api_headers,onChange:d=>_({...x,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:x.api_params,onChange:d=>_({...x,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:x.description,onChange:d=>_({...x,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:x.delay_seconds,onChange:d=>_({...x,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>h(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:I,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),e.jsx(In,{dataCards:$,downloadCardTemplate:Y,...D})]})},ea="ydisks-amap-js-api",Dn="c9b68d4ce9a2a97f22a4a439404488ca";let Lt=null;const Mn=()=>Dn,Bn=()=>window.AMap?Promise.resolve(window.AMap):Lt||(Lt=new Promise((t,s)=>{const a=document.getElementById(ea),r=a||document.createElement("script"),n=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(u)},h=()=>{window.AMap?(n(),t(window.AMap)):(n(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},u=window.setTimeout(()=>{n(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=h,r.id=ea,r.async=!0,r.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(Mn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,r.onerror=()=>{n(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(r)}).catch(t=>{throw Lt=null,t}),Lt),Kt=t=>Number.isFinite(t)&&t!==0,qn=t=>{var n,h;const s=Number((n=t.location)==null?void 0:n.lng),a=Number((h=t.location)==null?void 0:h.lat),r={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:a,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!r.division_id||!r.province||!r.city||!r.poi_id||!r.poi_name||!Kt(s)||!Kt(a)||s<-180||s>180||a<-90||a>90?null:r},Fn=async(t,s)=>{if(!Kt(t)||!Kt(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await Bn();return new Promise((r,n)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(u,j)=>{var v;if(u!=="complete"){if(u==="no_data"){r([]);return}n(new Error("高德地图附近地址查询失败,请稍后重试"));return}const m=(((v=j==null?void 0:j.poiList)==null?void 0:v.pois)||[]).map(qn).filter(x=>x!==null);r(m)})})},zn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),Ns=t=>t==="running"||t==="canceling",Un=t=>!!(t!=null&&t.previ
Line truncated
|
||||
`),Pe=new Blob(["\uFEFF"+ge],{type:"text/csv;charset=utf-8"}),Qe=URL.createObjectURL(Pe),Fe=document.createElement("a");Fe.href=Qe,Fe.download="批量铺货模板.csv",document.body.appendChild(Fe),Fe.click(),Fe.remove(),URL.revokeObjectURL(Qe)},Ct=()=>{E(c=>({...c,cookie_id:j||c.cookie_id})),Z(!0)},dt=()=>{F(c=>({...c,cookie_id:j||c.cookie_id})),ae(!0)},xt=async c=>{if(!(c?j:L.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");P(!0),navigator.geolocation.getCurrentPosition(async ge=>{try{const Pe=await Fn(ge.coords.longitude,ge.coords.latitude);if(!Pe.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(y(Pe),T(Pe[0])):(q(Pe),d(Pe[0]))}catch(Pe){alert((Pe==null?void 0:Pe.message)||"获取发货地失败")}finally{P(!1)}},ge=>{P(!1),alert(ge.code===ge.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},St=c=>r.filter(W=>W.cookie_id===c.cookie_id&&W.item_id===c.item_id).length>0?r.filter(W=>W.cookie_id===c.cookie_id&&W.item_id===c.item_id):r.filter(W=>W.cookie_id===c.cookie_id&&!W.item_id),mt=l.useMemo(()=>new Map(h.map(c=>[c.id,c])),[h]),ut=l.useMemo(()=>v?s.filter(c=>c.cookie_id===v):s,[v,s]),Ze=c=>{const W=mt.get(c),ge=(W==null?void 0:W.remark)||(W==null?void 0:W.nickname);return ge?`${ge} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},pt=c=>{const W=mt.get(c);return(W==null?void 0:W.remark)||(W==null?void 0:W.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(cl,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:v,onChange:c=>x(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),h.map(c=>e.jsx("option",{value:c.id,children:Ze(c.id)},c.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(ct,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:j,onChange:c=>m(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),h.map(c=>e.jsx("option",{value:c.id,children:Ze(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:Le,disabled:_||!j,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(We,{className:`w-4 h-4 ${_?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Ct,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:dt,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Xt,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void ee(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(qt,{className:"w-4 h-4"}),ie&&["running","canceling"].includes(ie.status)?"继续批量任务":"批量铺货"]}),ie&&!["running","canceling"].includes(ie.status)&&e.jsx("button",{onClick:()=>void Se(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[ut.map(c=>{const W=St(c),ge=W.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex fle
Line truncated
|
||||
@@ -0,0 +1 @@
|
||||
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
|
||||
@@ -1 +0,0 @@
|
||||
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
|
||||
@@ -6,12 +6,12 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Ydisks闲鱼助手 - 自动发货与管家系统</title>
|
||||
<meta name="description" content="Ydisks闲鱼助手 - 自动回复、自动发货、订单管理、AI智能议价一体化解决方案" />
|
||||
<script type="module" crossorigin src="/static/assets/index-7zzRZ1Ef.js"></script>
|
||||
<script type="module" crossorigin src="/static/assets/index-CdHtgMYc.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-BJ6r5aOc.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/vendor-D-Edl3pr.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/charts-vendor-BxxJOyEX.js">
|
||||
<link rel="stylesheet" crossorigin href="/static/assets/index-DBrkfYTo.css">
|
||||
<link rel="stylesheet" crossorigin href="/static/assets/index-Cot5X9Jj.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
Reference in new issue
Block a user