jwy87 commited on
Commit
718bcca
·
1 Parent(s): 98bb76b

增加抽奖链接、备注、价格获取

Browse files
server/prisma/schema.prisma CHANGED
@@ -20,22 +20,24 @@ model Site {
20
  name String
21
  baseUrl String
22
  apiKeyEnc String
23
- apiType String @default("other") // newapi, veloera, donehub, voapi, other
24
- userId String? // 用户ID,用于Newapi和Veloera
25
- billingUrl String? // 自定义billing URL(用于"other"类型)
26
- billingAuthType String @default("token") // token, cookie
27
- billingAuthValue String? // 鉴权值(加密存储)
28
- billingLimitField String? // 自定义billing限额字段名
29
- billingUsageField String? // 自定义billing使用量字段名
30
- unlimitedQuota Boolean @default(false) // 标记为无限余额
31
- enableCheckIn Boolean @default(false) // 是否启用签到(仅Veloera支持)
32
- checkInMode String @default("both") // 定时检测模式:model(仅模型)、checkin(仅签到)、both(两者都检测)
33
  scheduleCron String?
34
  timezone String @default("UTC")
35
  pinned Boolean @default(false)
36
  excludeFromBatch Boolean @default(false)
37
- categoryId String? // 所属分类ID
38
  category Category? @relation(fields: [categoryId], references: [id])
 
 
39
  lastCheckedAt DateTime?
40
  createdAt DateTime @default(now())
41
  snapshots ModelSnapshot[]
 
20
  name String
21
  baseUrl String
22
  apiKeyEnc String
23
+ apiType String @default("other")
24
+ userId String?
25
+ billingUrl String?
26
+ billingAuthType String @default("token")
27
+ billingAuthValue String?
28
+ billingLimitField String?
29
+ billingUsageField String?
30
+ unlimitedQuota Boolean @default(false)
31
+ enableCheckIn Boolean @default(false)
32
+ checkInMode String @default("both")
33
  scheduleCron String?
34
  timezone String @default("UTC")
35
  pinned Boolean @default(false)
36
  excludeFromBatch Boolean @default(false)
37
+ categoryId String?
38
  category Category? @relation(fields: [categoryId], references: [id])
39
+ extralink String?
40
+ remark String?
41
  lastCheckedAt DateTime?
42
  createdAt DateTime @default(now())
43
  snapshots ModelSnapshot[]
server/src/routes.js CHANGED
@@ -277,6 +277,8 @@ async function routes(fastify) {
277
  unlimitedQuota: { type: 'boolean' },
278
  enableCheckIn: { type: 'boolean' },
279
  checkInMode: { type: 'string', enum: ['model', 'checkin', 'both'] },
 
 
280
  },
281
  },
282
  },
@@ -287,7 +289,8 @@ async function routes(fastify) {
287
  categoryId = null,
288
  billingUrl = null, billingAuthType = 'token', billingAuthValue = null,
289
  billingLimitField = null, billingUsageField = null, unlimitedQuota = false,
290
- enableCheckIn = false, checkInMode = 'both'
 
291
  } = request.body;
292
 
293
  const apiKeyEnc = encrypt(apiKey);
@@ -299,10 +302,11 @@ async function routes(fastify) {
299
  const site = await prisma.site.create({
300
  data: {
301
  name, baseUrl, apiKeyEnc, apiType, userId, scheduleCron, timezone, pinned, excludeFromBatch,
302
- categoryId: categoryId || null, // 空字符串转换为 null
303
  billingUrl, billingAuthType, billingAuthValue: billingAuthValueEnc,
304
  billingLimitField, billingUsageField, unlimitedQuota,
305
- enableCheckIn, checkInMode
 
306
  }
307
  });
308
  onSiteUpdated(site, fastify);
@@ -334,6 +338,8 @@ async function routes(fastify) {
334
  unlimitedQuota: { type: 'boolean' },
335
  enableCheckIn: { type: 'boolean' },
336
  checkInMode: { type: 'string', enum: ['model', 'checkin', 'both'] },
 
 
337
  },
338
  },
339
  },
@@ -344,7 +350,8 @@ async function routes(fastify) {
344
  name, baseUrl, apiKey, apiType, userId, scheduleCron, timezone, pinned, excludeFromBatch,
345
  categoryId,
346
  billingUrl, billingAuthType, billingAuthValue, billingLimitField, billingUsageField, unlimitedQuota,
347
- enableCheckIn, checkInMode
 
348
  } = request.body || {};
349
 
350
  try {
@@ -356,7 +363,6 @@ async function routes(fastify) {
356
  if (timezone) data.timezone = timezone;
357
  if (pinned !== undefined) data.pinned = pinned;
358
  if (excludeFromBatch !== undefined) data.excludeFromBatch = excludeFromBatch;
359
- // categoryId: 空字符串转换为 null,避免外键约束错误
360
  if (categoryId !== undefined) data.categoryId = categoryId || null;
361
  if (billingUrl !== undefined) data.billingUrl = billingUrl;
362
  if (billingAuthType) data.billingAuthType = billingAuthType;
@@ -367,11 +373,10 @@ async function routes(fastify) {
367
  if (billingUsageField !== undefined) data.billingUsageField = billingUsageField;
368
  if (unlimitedQuota !== undefined) data.unlimitedQuota = unlimitedQuota;
369
  if (enableCheckIn !== undefined) data.enableCheckIn = enableCheckIn;
370
- // checkInMode: 只在有值时更新
371
- if (checkInMode) {
372
- data.checkInMode = checkInMode;
373
- }
374
  if (apiKey) data.apiKeyEnc = encrypt(apiKey);
 
 
375
 
376
  fastify.log.info({ updateData: data }, 'Updating site');
377
 
@@ -413,7 +418,87 @@ async function routes(fastify) {
413
  }
414
  });
415
 
416
- // 获取单个站点详情(用于令牌管理等功能)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  fastify.get('/api/sites/:id', {
418
  schema: {
419
  params: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] }
@@ -732,13 +817,11 @@ async function routes(fastify) {
732
  'Content-Type': 'application/json'
733
  };
734
  if (site.userId) {
735
- // 不同站点类型使用不同的用户ID请求头
736
  if (site.apiType === 'newapi') {
737
  headers['New-Api-User'] = site.userId;
738
  } else if (site.apiType === 'veloera') {
739
  headers['Veloera-User'] = site.userId;
740
  }
741
- // 其他类型不需要用户ID请求头
742
  }
743
 
744
  const res = await fetch(url, {
@@ -748,7 +831,6 @@ async function routes(fastify) {
748
  });
749
  const data = await res.json();
750
 
751
- // 直接返回站点API的响应
752
  return data;
753
  } catch (e) {
754
  fastify.log.error({ error: e.message, siteId: id, key }, 'Error redeeming code');
 
277
  unlimitedQuota: { type: 'boolean' },
278
  enableCheckIn: { type: 'boolean' },
279
  checkInMode: { type: 'string', enum: ['model', 'checkin', 'both'] },
280
+ extralink: { type: 'string' },
281
+ remark: { type: 'string' },
282
  },
283
  },
284
  },
 
289
  categoryId = null,
290
  billingUrl = null, billingAuthType = 'token', billingAuthValue = null,
291
  billingLimitField = null, billingUsageField = null, unlimitedQuota = false,
292
+ enableCheckIn = false, checkInMode = 'both',
293
+ extralink = null, remark = null
294
  } = request.body;
295
 
296
  const apiKeyEnc = encrypt(apiKey);
 
302
  const site = await prisma.site.create({
303
  data: {
304
  name, baseUrl, apiKeyEnc, apiType, userId, scheduleCron, timezone, pinned, excludeFromBatch,
305
+ categoryId: categoryId || null,
306
  billingUrl, billingAuthType, billingAuthValue: billingAuthValueEnc,
307
  billingLimitField, billingUsageField, unlimitedQuota,
308
+ enableCheckIn, checkInMode,
309
+ extralink, remark
310
  }
311
  });
312
  onSiteUpdated(site, fastify);
 
338
  unlimitedQuota: { type: 'boolean' },
339
  enableCheckIn: { type: 'boolean' },
340
  checkInMode: { type: 'string', enum: ['model', 'checkin', 'both'] },
341
+ extralink: { type: 'string' },
342
+ remark: { type: 'string' },
343
  },
344
  },
345
  },
 
350
  name, baseUrl, apiKey, apiType, userId, scheduleCron, timezone, pinned, excludeFromBatch,
351
  categoryId,
352
  billingUrl, billingAuthType, billingAuthValue, billingLimitField, billingUsageField, unlimitedQuota,
353
+ enableCheckIn, checkInMode,
354
+ extralink, remark
355
  } = request.body || {};
356
 
357
  try {
 
363
  if (timezone) data.timezone = timezone;
364
  if (pinned !== undefined) data.pinned = pinned;
365
  if (excludeFromBatch !== undefined) data.excludeFromBatch = excludeFromBatch;
 
366
  if (categoryId !== undefined) data.categoryId = categoryId || null;
367
  if (billingUrl !== undefined) data.billingUrl = billingUrl;
368
  if (billingAuthType) data.billingAuthType = billingAuthType;
 
373
  if (billingUsageField !== undefined) data.billingUsageField = billingUsageField;
374
  if (unlimitedQuota !== undefined) data.unlimitedQuota = unlimitedQuota;
375
  if (enableCheckIn !== undefined) data.enableCheckIn = enableCheckIn;
376
+ if (checkInMode) data.checkInMode = checkInMode;
 
 
 
377
  if (apiKey) data.apiKeyEnc = encrypt(apiKey);
378
+ if (extralink !== undefined) data.extralink = extralink;
379
+ if (remark !== undefined) data.remark = remark;
380
 
381
  fastify.log.info({ updateData: data }, 'Updating site');
382
 
 
418
  }
419
  });
420
 
421
+ fastify.get('/api/sites/:id/pricing', {
422
+ schema: {
423
+ params: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] }
424
+ }
425
+ }, async (request, reply) => {
426
+ const { id } = request.params;
427
+ const { decrypt } = require('./crypto');
428
+
429
+ try {
430
+ const site = await prisma.site.findUnique({ where: { id } });
431
+ if (!site) {
432
+ reply.code(404);
433
+ return { error: '站点不存在' };
434
+ }
435
+
436
+ if (site.apiType !== 'newapi' && site.apiType !== 'veloera' && site.apiType !== 'donehub' && site.apiType !== 'voapi') {
437
+ reply.code(400);
438
+ return { error: '此站点类型不支持pricing接口' };
439
+ }
440
+
441
+ const baseUrl = site.baseUrl.replace(/\/$/, '');
442
+ let url, headers, token;
443
+
444
+ if (site.apiType === 'donehub') {
445
+ token = site.apiKeyEnc ? decrypt(site.apiKeyEnc) : null;
446
+ if (!token) {
447
+ reply.code(400);
448
+ return { error: '站点未配置API令牌' };
449
+ }
450
+ url = `${baseUrl}/api/available_model`;
451
+ headers = {
452
+ 'Authorization': `Bearer ${token}`,
453
+ 'Content-Type': 'application/json'
454
+ };
455
+ } else if (site.apiType === 'voapi') {
456
+ token = site.billingAuthValue ? decrypt(site.billingAuthValue) : null;
457
+ if (!token) {
458
+ reply.code(400);
459
+ return { error: '站点未配置JWT令牌' };
460
+ }
461
+ url = `${baseUrl}/api/models`;
462
+ headers = {
463
+ 'Authorization': token,
464
+ 'Content-Type': 'application/json',
465
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
466
+ 'Accept': 'application/json'
467
+ };
468
+ } else {
469
+ token = site.apiKeyEnc ? decrypt(site.apiKeyEnc) : null;
470
+ if (!token) {
471
+ reply.code(400);
472
+ return { error: '站点未配置API令牌' };
473
+ }
474
+ url = `${baseUrl}/api/pricing`;
475
+ headers = {
476
+ 'Content-Type': 'application/json'
477
+ };
478
+ if (site.userId) {
479
+ const userHeader = site.apiType === 'newapi' ? 'New-Api-User' : 'Veloera-User';
480
+ headers[userHeader] = site.userId;
481
+ }
482
+ }
483
+
484
+ const res = await fetch(url, {
485
+ method: 'GET',
486
+ headers
487
+ });
488
+ const data = await res.json();
489
+
490
+ if (!res.ok) {
491
+ throw new Error(data.message || '获取pricing信息失败');
492
+ }
493
+
494
+ return data;
495
+ } catch (e) {
496
+ fastify.log.error({ error: e.message, siteId: id }, 'Error fetching pricing');
497
+ reply.code(500);
498
+ return { error: e.message || '获取pricing信息失败' };
499
+ }
500
+ });
501
+
502
  fastify.get('/api/sites/:id', {
503
  schema: {
504
  params: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] }
 
817
  'Content-Type': 'application/json'
818
  };
819
  if (site.userId) {
 
820
  if (site.apiType === 'newapi') {
821
  headers['New-Api-User'] = site.userId;
822
  } else if (site.apiType === 'veloera') {
823
  headers['Veloera-User'] = site.userId;
824
  }
 
825
  }
826
 
827
  const res = await fetch(url, {
 
831
  });
832
  const data = await res.json();
833
 
 
834
  return data;
835
  } catch (e) {
836
  fastify.log.error({ error: e.message, siteId: id, key }, 'Error redeeming code');
web/src/pages/SiteDetail.jsx CHANGED
@@ -32,8 +32,8 @@ export default function SiteDetail() {
32
  const [snapshot, setSnapshot] = useState([])
33
  const [loading, setLoading] = useState(false)
34
  const [modelsExpanded, setModelsExpanded] = useState(true)
 
35
 
36
- // 令牌管理相关状态
37
  const [tokenModalVisible, setTokenModalVisible] = useState(false)
38
  const [tokens, setTokens] = useState([])
39
  const [tokenLoading, setTokenLoading] = useState(false)
@@ -42,12 +42,15 @@ export default function SiteDetail() {
42
  const [groups, setGroups] = useState([])
43
  const [form] = Form.useForm()
44
 
45
- // 兑换码相关状态
46
  const [redeemModalVisible, setRedeemModalVisible] = useState(false)
47
  const [redeemCodes, setRedeemCodes] = useState('')
48
  const [redeemLoading, setRedeemLoading] = useState(false)
49
  const [redeemResults, setRedeemResults] = useState([])
50
 
 
 
 
 
51
  const copyToClipboard = useCallback((text, successMsg = '复制成功') => {
52
  navigator.clipboard.writeText(text).then(() => {
53
  message.success(successMsg)
@@ -64,6 +67,43 @@ export default function SiteDetail() {
64
  const names = models.map(m => m.id).join(',')
65
  copyToClipboard(names, `已复制 ${models.length} 个模型名称`)
66
  }, [copyToClipboard])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  // 获取令牌列表(通过后端代理)
69
  const loadTokens = async () => {
@@ -101,8 +141,17 @@ export default function SiteDetail() {
101
  }
102
  }
103
 
104
- // 获取分组列表(通过后端代理)
105
  const loadGroups = async () => {
 
 
 
 
 
 
 
 
 
 
106
  try {
107
  const res = await fetch(`/api/sites/${id}/groups`, {
108
  headers: authHeaders()
@@ -113,14 +162,13 @@ export default function SiteDetail() {
113
  }
114
  const data = await res.json()
115
  if (data.success && data.data) {
116
- // 只显示从API获取的分组,不添加"用户分组"
117
  const groupList = Object.keys(data.data).map(key => ({
118
  value: key,
119
  label: data.data[key].name || data.data[key].desc || key
120
  }))
121
  setGroups(groupList)
122
  console.log('分组列表加载成功:', groupList)
123
- return groupList // 返回分组列表
124
  } else {
125
  console.warn('获取分组列表响应格式不正确:', data)
126
  setGroups([])
@@ -270,7 +318,6 @@ export default function SiteDetail() {
270
  setEditModalVisible(true)
271
  }
272
 
273
- // 打开令牌管理弹窗
274
  const openTokenModal = () => {
275
  setTokenModalVisible(true)
276
  loadGroups()
@@ -341,7 +388,143 @@ export default function SiteDetail() {
341
  }
342
  }
343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  const load = async () => {
 
345
  try {
346
  const res = await fetch(`/api/sites/${id}/diffs?limit=50`, { headers: authHeaders() })
347
  if (!res.ok) {
@@ -366,6 +549,9 @@ export default function SiteDetail() {
366
  } catch (e) {
367
  message.error(e.message || '加载模型列表失败,请稍后重试')
368
  }
 
 
 
369
  }
370
 
371
  useEffect(() => {
@@ -682,6 +868,18 @@ export default function SiteDetail() {
682
  >
683
  {modelsExpanded ? '收起' : '展开'}
684
  </Button>
 
 
 
 
 
 
 
 
 
 
 
 
685
  <Button
686
  icon={<CopyOutlined />}
687
  onClick={() => copyAllModels(snapshot)}
@@ -755,7 +953,7 @@ export default function SiteDetail() {
755
  position: 'bottom',
756
  style: { marginTop: 16, textAlign: 'center' }
757
  } : false}
758
- renderItem={(m) => <ModelCard key={m.id} model={m} onCopy={copyToClipboard} />}
759
  />
760
  )
761
  )}
@@ -1147,8 +1345,7 @@ export default function SiteDetail() {
1147
  )
1148
  }
1149
 
1150
- // 模型卡片组件 - 使用 memo 优化
1151
- const ModelCard = memo(({ model, onCopy }) => (
1152
  <List.Item>
1153
  <Card
1154
  size="small"
@@ -1190,11 +1387,42 @@ const ModelCard = memo(({ model, onCopy }) => (
1190
  type="secondary"
1191
  style={{
1192
  fontSize: 12,
1193
- display: 'block'
 
1194
  }}
1195
  >
1196
  {model.owned_by || model.ownedBy || '未知'}
1197
  </Typography.Text>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1198
  </Card>
1199
  </List.Item>
1200
  ))
 
32
  const [snapshot, setSnapshot] = useState([])
33
  const [loading, setLoading] = useState(false)
34
  const [modelsExpanded, setModelsExpanded] = useState(true)
35
+ const [siteInfo, setSiteInfo] = useState(null)
36
 
 
37
  const [tokenModalVisible, setTokenModalVisible] = useState(false)
38
  const [tokens, setTokens] = useState([])
39
  const [tokenLoading, setTokenLoading] = useState(false)
 
42
  const [groups, setGroups] = useState([])
43
  const [form] = Form.useForm()
44
 
 
45
  const [redeemModalVisible, setRedeemModalVisible] = useState(false)
46
  const [redeemCodes, setRedeemCodes] = useState('')
47
  const [redeemLoading, setRedeemLoading] = useState(false)
48
  const [redeemResults, setRedeemResults] = useState([])
49
 
50
+ const [pricingData, setPricingData] = useState(null)
51
+ const [selectedGroup, setSelectedGroup] = useState('')
52
+ const [availableGroups, setAvailableGroups] = useState([])
53
+
54
  const copyToClipboard = useCallback((text, successMsg = '复制成功') => {
55
  navigator.clipboard.writeText(text).then(() => {
56
  message.success(successMsg)
 
67
  const names = models.map(m => m.id).join(',')
68
  copyToClipboard(names, `已复制 ${models.length} 个模型名称`)
69
  }, [copyToClipboard])
70
+
71
+ const getModelPricing = useCallback((modelId) => {
72
+ if (!pricingData) return null
73
+ if (pricingData.notSupported) {
74
+ return { available: true, type: 'not_supported' }
75
+ }
76
+ if (!pricingData.data) return null
77
+ const modelInfo = pricingData.data.find(m => m.model_name === modelId)
78
+ if (!modelInfo) return null
79
+
80
+ const groupRatio = (pricingData.group_ratio && pricingData.group_ratio[selectedGroup]) || 1
81
+ const isAvailable = modelInfo.enable_groups && modelInfo.enable_groups.includes(selectedGroup)
82
+
83
+ if (!isAvailable) {
84
+ return { available: false }
85
+ }
86
+
87
+ if (modelInfo.quota_type === 1 && modelInfo.model_price) {
88
+ const price = modelInfo.model_price * groupRatio
89
+ return {
90
+ available: true,
91
+ type: 'per_call',
92
+ price: price.toFixed(2)
93
+ }
94
+ } else if (modelInfo.quota_type === 0 && modelInfo.model_ratio) {
95
+ const inputPrice = 2 * modelInfo.model_ratio * groupRatio
96
+ const outputPrice = inputPrice * (modelInfo.completion_ratio || 1)
97
+ return {
98
+ available: true,
99
+ type: 'per_token',
100
+ inputPrice: inputPrice.toFixed(2),
101
+ outputPrice: outputPrice.toFixed(2)
102
+ }
103
+ }
104
+
105
+ return { available: true, type: 'free' }
106
+ }, [pricingData, selectedGroup])
107
 
108
  // 获取令牌列表(通过后端代理)
109
  const loadTokens = async () => {
 
141
  }
142
  }
143
 
 
144
  const loadGroups = async () => {
145
+ if (pricingData && pricingData.usable_group) {
146
+ const groupList = Object.keys(pricingData.usable_group).map(key => ({
147
+ value: key || '__user_group__',
148
+ label: pricingData.usable_group[key] || '用户分组'
149
+ }))
150
+ setGroups(groupList)
151
+ console.log('从pricing数据加载分组成功:', groupList)
152
+ return groupList
153
+ }
154
+
155
  try {
156
  const res = await fetch(`/api/sites/${id}/groups`, {
157
  headers: authHeaders()
 
162
  }
163
  const data = await res.json()
164
  if (data.success && data.data) {
 
165
  const groupList = Object.keys(data.data).map(key => ({
166
  value: key,
167
  label: data.data[key].name || data.data[key].desc || key
168
  }))
169
  setGroups(groupList)
170
  console.log('分组列表加载成功:', groupList)
171
+ return groupList
172
  } else {
173
  console.warn('获取分组列表响应格式不正确:', data)
174
  setGroups([])
 
318
  setEditModalVisible(true)
319
  }
320
 
 
321
  const openTokenModal = () => {
322
  setTokenModalVisible(true)
323
  loadGroups()
 
388
  }
389
  }
390
 
391
+ const loadSiteInfo = async () => {
392
+ try {
393
+ const res = await fetch(`/api/sites/${id}`, { headers: authHeaders() })
394
+ if (res.ok) {
395
+ const data = await res.json()
396
+ setSiteInfo(data)
397
+ return data
398
+ }
399
+ } catch (e) {
400
+ console.error('加载站点信息失败:', e)
401
+ }
402
+ return null
403
+ }
404
+
405
+ const loadPricing = async (apiType) => {
406
+ if (apiType !== 'newapi' && apiType !== 'veloera' && apiType !== 'donehub' && apiType !== 'voapi') {
407
+ console.log('站点类型不支持pricing:', apiType)
408
+ if (apiType === 'other') {
409
+ setPricingData({ notSupported: true })
410
+ }
411
+ return
412
+ }
413
+ console.log('开始加载pricing信息,站点ID:', id, '类型:', apiType)
414
+ try {
415
+ const res = await fetch(`/api/sites/${id}/pricing`, { headers: authHeaders() })
416
+ console.log('pricing请求状态:', res.status, res.statusText)
417
+ if (res.ok) {
418
+ const data = await res.json()
419
+ console.log('收到pricing数据:', data)
420
+ if (data.code === 0 && apiType === 'voapi' && data.data) {
421
+ const { models = [], groups = [] } = data.data
422
+ const allGroups = new Set()
423
+ const groupMap = {}
424
+ groups.forEach(g => {
425
+ allGroups.add(g.id)
426
+ groupMap[g.id] = {
427
+ name: g.name || `分组${g.id}`,
428
+ ratio: g.ratio || 1
429
+ }
430
+ })
431
+ const normalizedModels = models.map(model => {
432
+ const modelGroups = model.ac || []
433
+ modelGroups.forEach(gid => allGroups.add(gid))
434
+ return {
435
+ model_name: model.idKey,
436
+ quota_type: model.chargingType === 1 ? 0 : 1,
437
+ model_price: model.chargingType !== 1 ? parseFloat(model.singlePrice || 0) : null,
438
+ model_ratio: model.chargingType === 1 ? parseFloat(model.inputPrice || 0) / 2 : null,
439
+ completion_ratio: model.chargingType === 1 && parseFloat(model.inputPrice || 0) > 0
440
+ ? parseFloat(model.outputPrice || 0) / parseFloat(model.inputPrice || 0)
441
+ : 1,
442
+ enable_groups: modelGroups.map(String)
443
+ }
444
+ })
445
+ const usableGroup = {}
446
+ const groupRatio = {}
447
+ allGroups.forEach(gid => {
448
+ const gInfo = groupMap[gid]
449
+ if (gInfo) {
450
+ usableGroup[gid] = gInfo.name
451
+ groupRatio[gid] = gInfo.ratio
452
+ } else {
453
+ usableGroup[gid] = `分组${gid}`
454
+ groupRatio[gid] = 1
455
+ }
456
+ })
457
+ const normalizedData = {
458
+ success: true,
459
+ data: normalizedModels,
460
+ usable_group: usableGroup,
461
+ group_ratio: groupRatio
462
+ }
463
+ setPricingData(normalizedData)
464
+ const groupList = Array.from(allGroups).map(String)
465
+ setAvailableGroups(groupList)
466
+ const defaultGroup = groupList.includes('1') ? '1' : groupList[0]
467
+ setSelectedGroup(defaultGroup)
468
+ console.log('VOAPI pricing数据加载成功,已转换为标准格式,可用分组:', groupList)
469
+ } else if (data.success) {
470
+ if (apiType === 'donehub' && data.data) {
471
+ const allGroups = new Set()
472
+ const normalizedModels = Object.entries(data.data).map(([modelName, info]) => {
473
+ const groups = info.groups || ['default']
474
+ groups.forEach(g => allGroups.add(g))
475
+ return {
476
+ model_name: modelName,
477
+ quota_type: info.price.channel_type,
478
+ model_price: info.price.channel_type === 1 ? info.price.input * 0.001 : null,
479
+ model_ratio: info.price.channel_type === 0 ? info.price.input : null,
480
+ completion_ratio: info.price.channel_type === 0 && info.price.output ? info.price.output / info.price.input : 1,
481
+ enable_groups: groups
482
+ }
483
+ })
484
+ const usableGroup = {}
485
+ const groupRatio = {}
486
+ allGroups.forEach(g => {
487
+ usableGroup[g] = g === 'default' ? '默认分组' : g
488
+ groupRatio[g] = 1
489
+ })
490
+ const normalizedData = {
491
+ success: true,
492
+ data: normalizedModels,
493
+ usable_group: usableGroup,
494
+ group_ratio: groupRatio
495
+ }
496
+ setPricingData(normalizedData)
497
+ const groupList = Array.from(allGroups)
498
+ setAvailableGroups(groupList)
499
+ const defaultGroup = groupList.includes('default') ? 'default' : groupList[0]
500
+ setSelectedGroup(defaultGroup)
501
+ console.log('DoneHub pricing数据加载成功,已转换为标准格式,可用分组:', groupList)
502
+ } else if (data.usable_group) {
503
+ setPricingData(data)
504
+ const groupList = Object.keys(data.usable_group || {}).filter(key => key !== '')
505
+ setAvailableGroups(groupList)
506
+ if (groupList.length > 0) {
507
+ const defaultGroup = groupList.includes('default') ? 'default' : groupList[0]
508
+ setSelectedGroup(defaultGroup)
509
+ console.log('pricing数据加载成功,可用分组:', groupList, '默认选择:', defaultGroup)
510
+ } else {
511
+ console.log('pricing数据加载成功,可用分组:', groupList)
512
+ }
513
+ } else {
514
+ console.warn('pricing数据格式不正确:', data)
515
+ }
516
+ }
517
+ } else {
518
+ const errorData = await res.json().catch(() => ({}))
519
+ console.error('加载pricing失败,状态码:', res.status, '错误:', errorData)
520
+ }
521
+ } catch (e) {
522
+ console.error('加载pricing信息失败:', e)
523
+ }
524
+ }
525
+
526
  const load = async () => {
527
+ const site = await loadSiteInfo()
528
  try {
529
  const res = await fetch(`/api/sites/${id}/diffs?limit=50`, { headers: authHeaders() })
530
  if (!res.ok) {
 
549
  } catch (e) {
550
  message.error(e.message || '加载模型列表失败,请稍后重试')
551
  }
552
+ if (site && site.type) {
553
+ loadPricing(site.type)
554
+ }
555
  }
556
 
557
  useEffect(() => {
 
868
  >
869
  {modelsExpanded ? '收起' : '展开'}
870
  </Button>
871
+ {availableGroups.length > 1 && pricingData && (
872
+ <Select
873
+ value={selectedGroup}
874
+ onChange={setSelectedGroup}
875
+ size="large"
876
+ style={{ width: 150 }}
877
+ options={availableGroups.map(group => ({
878
+ value: group,
879
+ label: pricingData.usable_group[group] || group
880
+ }))}
881
+ />
882
+ )}
883
  <Button
884
  icon={<CopyOutlined />}
885
  onClick={() => copyAllModels(snapshot)}
 
953
  position: 'bottom',
954
  style: { marginTop: 16, textAlign: 'center' }
955
  } : false}
956
+ renderItem={(m) => <ModelCard key={m.id} model={m} onCopy={copyToClipboard} pricing={getModelPricing(m.id)} />}
957
  />
958
  )
959
  )}
 
1345
  )
1346
  }
1347
 
1348
+ const ModelCard = memo(({ model, onCopy, pricing }) => (
 
1349
  <List.Item>
1350
  <Card
1351
  size="small"
 
1387
  type="secondary"
1388
  style={{
1389
  fontSize: 12,
1390
+ display: 'block',
1391
+ marginBottom: pricing ? 4 : 0
1392
  }}
1393
  >
1394
  {model.owned_by || model.ownedBy || '未知'}
1395
  </Typography.Text>
1396
+ {pricing && (
1397
+ pricing.available ? (
1398
+ pricing.type === 'per_call' ? (
1399
+ <Tag color="blue" style={{ fontSize: 11, marginTop: 4 }}>
1400
+ 按次计费: ${pricing.price}/次
1401
+ </Tag>
1402
+ ) : pricing.type === 'per_token' ? (
1403
+ <div style={{ marginTop: 4 }}>
1404
+ <Tag color="green" style={{ fontSize: 10, marginRight: 4 }}>
1405
+ 输入: ${pricing.inputPrice}/M
1406
+ </Tag>
1407
+ <Tag color="orange" style={{ fontSize: 10 }}>
1408
+ 输出: ${pricing.outputPrice}/M
1409
+ </Tag>
1410
+ </div>
1411
+ ) : pricing.type === 'not_supported' ? (
1412
+ <Tag color="default" style={{ fontSize: 11, marginTop: 4 }}>
1413
+ 暂不支持获取价格
1414
+ </Tag>
1415
+ ) : (
1416
+ <Tag color="cyan" style={{ fontSize: 11, marginTop: 4 }}>
1417
+ 免费
1418
+ </Tag>
1419
+ )
1420
+ ) : (
1421
+ <Tag color="default" style={{ fontSize: 11, marginTop: 4 }}>
1422
+ 无价格
1423
+ </Tag>
1424
+ )
1425
+ )}
1426
  </Card>
1427
  </List.Item>
1428
  ))
web/src/pages/Sites.jsx CHANGED
@@ -6,12 +6,7 @@ import dayjs from 'dayjs'
6
 
7
  // 添加金光闪闪动画样式
8
  const shimmerStyle = document.createElement('style');
9
- shimmerStyle.textContent = `
10
- @keyframes shimmer {
11
- 0% { background-position: 200% 0; }
12
- 100% { background-position: -200% 0; }
13
- }
14
- `;
15
  document.head.appendChild(shimmerStyle);
16
 
17
  function authHeaders(includeJson = false) {
@@ -41,7 +36,6 @@ export default function Sites() {
41
  const [scheduleForm] = Form.useForm()
42
  const [scheduleConfig, setScheduleConfig] = useState({ enabled: false, hour: 9, minute: 0, interval: 30 })
43
  const [currentPage, setCurrentPage] = useState(() => {
44
- // 从 localStorage 恢复页码
45
  const saved = localStorage.getItem('sitesCurrentPage')
46
  return saved ? parseInt(saved, 10) : 1
47
  })
@@ -53,7 +47,6 @@ export default function Sites() {
53
  const [hasLastResult, setHasLastResult] = useState(false)
54
  const [billingConfigExpanded, setBillingConfigExpanded] = useState(false)
55
 
56
- // 搜索和分类相关状态
57
  const [searchKeyword, setSearchKeyword] = useState('')
58
  const [categories, setCategories] = useState([])
59
  const [categoryModalOpen, setCategoryModalOpen] = useState(false)
@@ -61,7 +54,6 @@ export default function Sites() {
61
  const [editingCategory, setEditingCategory] = useState(null)
62
  const [categoryCheckingId, setCategoryCheckingId] = useState(null)
63
  const [collapsedGroups, setCollapsedGroups] = useState(() => {
64
- // 优先从 sessionStorage 恢复状态
65
  const saved = sessionStorage.getItem('sitesCollapsedGroups')
66
  if (saved) {
67
  try {
@@ -88,7 +80,7 @@ export default function Sites() {
88
  const data = await res.json()
89
  setList(data)
90
  } catch (e) {
91
- message.error(e.message || '加载站点列表失败,请检查网络连接')
92
  } finally { setLoading(false) }
93
  }
94
 
@@ -98,7 +90,6 @@ export default function Sites() {
98
  if (res.ok) {
99
  const data = await res.json()
100
  setCategories(data)
101
- // 只在没有恢复状态时才设置默认值
102
  const saved = sessionStorage.getItem('sitesCollapsedGroups')
103
  if (!saved) {
104
  setCollapsedGroups(new Set(['pinned', 'uncategorized', ...data.map(c => c.id)]))
@@ -109,7 +100,6 @@ export default function Sites() {
109
  }
110
  }
111
 
112
- // 切换分组展开/收起
113
  const toggleGroupCollapse = (groupId) => {
114
  const newCollapsed = new Set(collapsedGroups)
115
  if (newCollapsed.has(groupId)) {
@@ -169,13 +159,11 @@ export default function Sites() {
169
  initData()
170
  }, [location])
171
 
172
- // 搜索处理
173
  const handleSearch = (value) => {
174
  setSearchKeyword(value)
175
  load(value)
176
  }
177
 
178
- // 分类管理函数
179
  const openCategoryModal = (category = null) => {
180
  setEditingCategory(category)
181
  if (category) {
@@ -479,7 +467,6 @@ export default function Sites() {
479
  const onAdd = async () => {
480
  try {
481
  const v = await form.validateFields()
482
- // 若设置了北京时间时分,则转换为 cron 并设置时区
483
  if (v.cnHour !== undefined && v.cnMinute !== undefined && v.cnHour !== null && v.cnMinute !== null) {
484
  const h = Math.max(0, Math.min(23, Number(v.cnHour)))
485
  const m = Math.max(0, Math.min(59, Number(v.cnMinute)))
@@ -487,11 +474,7 @@ export default function Sites() {
487
  v.timezone = 'Asia/Shanghai'
488
  }
489
  delete v.cnHour; delete v.cnMinute
490
-
491
- // 设置默认 apiType
492
  if (!v.apiType) v.apiType = 'other'
493
-
494
- // 设置签到默认值
495
  if (v.enableCheckIn && !v.checkInMode) v.checkInMode = 'both'
496
 
497
  const res = await fetch('/api/sites', { method: 'POST', headers: authHeaders(true), body: JSON.stringify(v) })
@@ -501,7 +484,7 @@ export default function Sites() {
501
  }
502
  setOpen(false); form.resetFields(); await load(); message.success('站点创建成功')
503
  } catch (e) {
504
- message.error(e.message || '创建站点失败,请检查输入信息')
505
  }
506
  }
507
 
@@ -509,7 +492,6 @@ export default function Sites() {
509
  setEditMode(true)
510
  setEditingSite(site)
511
 
512
- // 解析定时计划
513
  let cnHour = undefined, cnMinute = undefined
514
  if (site.scheduleCron && site.timezone === 'Asia/Shanghai') {
515
  const parts = String(site.scheduleCron).trim().split(/\s+/)
@@ -522,7 +504,7 @@ export default function Sites() {
522
  form.setFieldsValue({
523
  name: site.name,
524
  baseUrl: site.baseUrl,
525
- apiKey: '', // 不显示原密钥
526
  apiType: site.apiType || 'other',
527
  userId: site.userId || '',
528
  cnHour,
@@ -533,11 +515,13 @@ export default function Sites() {
533
  unlimitedQuota: site.unlimitedQuota || false,
534
  billingUrl: site.billingUrl || '',
535
  billingAuthType: site.billingAuthType || 'token',
536
- billingAuthValue: '', // 不显示原认证值
537
  billingLimitField: site.billingLimitField || '',
538
  billingUsageField: site.billingUsageField || '',
539
  enableCheckIn: site.enableCheckIn || false,
540
- checkInMode: site.checkInMode || 'both'
 
 
541
  })
542
  setOpen(true)
543
  }
@@ -546,7 +530,6 @@ export default function Sites() {
546
  try {
547
  const v = await form.validateFields()
548
 
549
- // 构建更新数据
550
  const updateData = {
551
  name: v.name,
552
  baseUrl: v.baseUrl,
@@ -561,29 +544,27 @@ export default function Sites() {
561
  billingAuthValue: v.billingAuthValue || null,
562
  billingLimitField: v.billingLimitField || null,
563
  billingUsageField: v.billingUsageField || null,
564
- enableCheckIn: v.enableCheckIn || false
 
 
565
  }
566
 
567
- // 只在启用签到时才发送 checkInMode
568
  if (v.enableCheckIn && v.checkInMode) {
569
  updateData.checkInMode = v.checkInMode
570
  } else if (v.enableCheckIn) {
571
  updateData.checkInMode = 'both'
572
  }
573
 
574
- // 如果输入了新密钥,则更新
575
  if (v.apiKey && v.apiKey.trim()) {
576
  updateData.apiKey = v.apiKey
577
  }
578
 
579
- // 处理定时计划
580
  if (v.cnHour !== undefined && v.cnMinute !== undefined && v.cnHour !== null && v.cnMinute !== null) {
581
  const h = Math.max(0, Math.min(23, Number(v.cnHour)))
582
  const m = Math.max(0, Math.min(59, Number(v.cnMinute)))
583
  updateData.scheduleCron = `${m} ${h} * * *`
584
  updateData.timezone = 'Asia/Shanghai'
585
  } else {
586
- // 清空定时计划
587
  updateData.scheduleCron = null
588
  updateData.timezone = 'UTC'
589
  }
@@ -685,18 +666,15 @@ export default function Sites() {
685
  const onCheck = async (id) => {
686
  const hide = message.loading('正在检测中...', 0)
687
  try {
688
- // 手动检测不发送邮件通知
689
  const res = await fetch(`/api/sites/${id}/check?skipNotification=true`, { method: 'POST', headers: authHeaders() })
690
  const data = await res.json().catch(() => ({}))
691
  if (!res.ok) throw new Error(data?.error || '检测失败')
692
  hide()
693
 
694
- // 检查是否有模型变更
695
  if (data.hasChanges && data.diff) {
696
  const site = list.find(s => s.id === id)
697
  const siteName = site?.name || '未知站点'
698
 
699
- // 显示模型变更弹窗
700
  Modal.info({
701
  title: '🔄 检测到模型变更',
702
  width: 600,
@@ -939,27 +917,40 @@ export default function Sites() {
939
  dataIndex: 'name',
940
  width: 200,
941
  render: (text, record) => (
942
- <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
943
- <Tooltip title={record.baseUrl} placement="topLeft">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
944
  <Typography.Link
945
- href={record.baseUrl}
946
  target="_blank"
947
  rel="noopener noreferrer"
948
- strong
949
- style={{ fontSize: 15, color: '#40a9ff' }}
950
  >
951
- {text}
952
  </Typography.Link>
953
- </Tooltip>
954
- {record.pinned && (
955
- <Tooltip title="已置顶">
956
- <PushpinFilled style={{ color: '#fa8c16', fontSize: 13 }} />
957
- </Tooltip>
958
- )}
959
- {record.excludeFromBatch && (
960
- <Tooltip title="不参与一键检测">
961
- <span style={{ fontSize: 14, cursor: 'help' }}>🚫</span>
962
- </Tooltip>
963
  )}
964
  </div>
965
  )
@@ -1152,6 +1143,7 @@ export default function Sites() {
1152
  title: <span style={{ fontSize: 15, fontWeight: 600 }}>上次检测</span>,
1153
  dataIndex: 'lastCheckedAt',
1154
  width: 180,
 
1155
  render: v => v
1156
  ? <Typography.Text type="secondary" style={{ fontSize: 13, whiteSpace: 'nowrap' }}>{new Date(v).toLocaleString('zh-CN')}</Typography.Text>
1157
  : <Typography.Text type="secondary" style={{ fontSize: 13 }}>未检测</Typography.Text>
@@ -1159,85 +1151,100 @@ export default function Sites() {
1159
  {
1160
  title: <span style={{ fontSize: 15, fontWeight: 600 }}>操作</span>,
1161
  key: 'actions',
1162
- width: 280,
 
1163
  render: (_, r) => (
1164
- <Space size={4} wrap>
1165
- <Tooltip title="查看详情">
1166
- <Button
1167
- type="primary"
1168
- className="hover-lift"
1169
- icon={<EyeOutlined />}
1170
- onClick={() => {
1171
- // 保存当前页码、滚动位置和分类展开状态
1172
- localStorage.setItem('sitesCurrentPage', currentPage)
1173
- sessionStorage.setItem('sitesScrollPosition', window.scrollY.toString())
1174
- sessionStorage.setItem('sitesCollapsedGroups', JSON.stringify([...collapsedGroups]))
1175
- nav(`/sites/${r.id}`)
1176
- }}
1177
- size="middle"
1178
- />
1179
- </Tooltip>
1180
- <Tooltip title="立即检测">
1181
- <Button
1182
- type="default"
1183
- className="hover-lift"
1184
- icon={<ThunderboltOutlined />}
1185
- onClick={() => onCheck(r.id)}
1186
- size="middle"
1187
- style={{ color: '#52c41a', fontWeight: 600, borderColor: '#52c41a' }}
1188
- />
1189
- </Tooltip>
1190
- <Tooltip title="请求详情">
1191
- <Button
1192
- type="default"
1193
- icon={<BugOutlined />}
1194
- onClick={() => openDebugModal(r)}
1195
- size="middle"
1196
- style={{ color: '#fa8c16', borderColor: '#fa8c16' }}
1197
- />
1198
- </Tooltip>
1199
- <Tooltip title="设置时间">
1200
- <Button
1201
- type="default"
1202
- icon={<ClockCircleOutlined />}
1203
- onClick={() => openTimeModal(r)}
1204
- size="middle"
1205
- />
1206
- </Tooltip>
1207
- <Tooltip title="编辑">
1208
- <Button
1209
- type="default"
1210
- icon={<EditOutlined />}
1211
- onClick={() => openEditModal(r)}
1212
- size="middle"
1213
- style={{ color: '#1890ff', borderColor: '#1890ff' }}
1214
- />
1215
- </Tooltip>
1216
- <Popconfirm
1217
- title="删除站点"
1218
- description={
1219
- <div style={{ maxWidth: 300 }}>
1220
- <p>确定要删除站点 <strong>{r.name}</strong> 吗?</p>
1221
- <p style={{ color: '#ff4d4f', marginTop: 8 }}>
1222
- 删除后将清除所有历史检测数据,此操作不可恢复!
1223
- </p>
1224
- </div>
1225
- }
1226
- onConfirm={() => onDelete(r)}
1227
- okText="确定删除"
1228
- cancelText="取消"
1229
- okButtonProps={{ danger: true }}
1230
- icon={<ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />}
1231
- >
1232
- <Tooltip title="删除">
1233
  <Button
1234
- danger
1235
- icon={<DeleteOutlined />}
 
 
 
 
 
 
 
1236
  size="middle"
1237
  />
1238
  </Tooltip>
1239
- </Popconfirm>
1240
- </Space>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1241
  )
1242
  }
1243
  ]
@@ -2079,39 +2086,70 @@ export default function Sites() {
2079
  </Form.Item>
2080
  </Space>
2081
  </Form.Item>
 
2082
  <Form.Item
2083
- name="pinned"
2084
- label={<span style={{ fontSize: 15, fontWeight: 500 }}>置顶设置</span>}
2085
- valuePropName="checked"
2086
- extra="置顶后,此站点将在列表中优先显示,不参与分类"
2087
- >
2088
- <Switch
2089
- checkedChildren="已置顶"
2090
- unCheckedChildren="未置顶"
2091
- />
2092
- </Form.Item>
2093
- <Form.Item
2094
- name="excludeFromBatch"
2095
- label={<span style={{ fontSize: 15, fontWeight: 500 }}>一键检测选项</span>}
2096
- valuePropName="checked"
2097
- extra="勾选后,此站点不会参与“一键检测”,但仍会执行定时检测"
2098
  >
2099
- <Switch
2100
- checkedChildren="排除"
2101
- unCheckedChildren="参与"
2102
  />
2103
  </Form.Item>
 
2104
  <Form.Item
2105
- name="unlimitedQuota"
2106
- label={<span style={{ fontSize: 15, fontWeight: 500 }}>余额类型</span>}
2107
- valuePropName="checked"
2108
- extra="勾选后,此站点将标记为无限余额,不会检测用量信息"
2109
  >
2110
- <Switch
2111
- checkedChildren="无限余额"
2112
- unCheckedChildren="普通余额"
2113
  />
2114
  </Form.Item>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2115
 
2116
  {/* 签到配置 - 仅Veloera类型显示 */}
2117
  <Form.Item
 
6
 
7
  // 添加金光闪闪动画样式
8
  const shimmerStyle = document.createElement('style');
9
+ shimmerStyle.textContent = `@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }`;
 
 
 
 
 
10
  document.head.appendChild(shimmerStyle);
11
 
12
  function authHeaders(includeJson = false) {
 
36
  const [scheduleForm] = Form.useForm()
37
  const [scheduleConfig, setScheduleConfig] = useState({ enabled: false, hour: 9, minute: 0, interval: 30 })
38
  const [currentPage, setCurrentPage] = useState(() => {
 
39
  const saved = localStorage.getItem('sitesCurrentPage')
40
  return saved ? parseInt(saved, 10) : 1
41
  })
 
47
  const [hasLastResult, setHasLastResult] = useState(false)
48
  const [billingConfigExpanded, setBillingConfigExpanded] = useState(false)
49
 
 
50
  const [searchKeyword, setSearchKeyword] = useState('')
51
  const [categories, setCategories] = useState([])
52
  const [categoryModalOpen, setCategoryModalOpen] = useState(false)
 
54
  const [editingCategory, setEditingCategory] = useState(null)
55
  const [categoryCheckingId, setCategoryCheckingId] = useState(null)
56
  const [collapsedGroups, setCollapsedGroups] = useState(() => {
 
57
  const saved = sessionStorage.getItem('sitesCollapsedGroups')
58
  if (saved) {
59
  try {
 
80
  const data = await res.json()
81
  setList(data)
82
  } catch (e) {
83
+ message.error(e.message || '加载站点列表失败')
84
  } finally { setLoading(false) }
85
  }
86
 
 
90
  if (res.ok) {
91
  const data = await res.json()
92
  setCategories(data)
 
93
  const saved = sessionStorage.getItem('sitesCollapsedGroups')
94
  if (!saved) {
95
  setCollapsedGroups(new Set(['pinned', 'uncategorized', ...data.map(c => c.id)]))
 
100
  }
101
  }
102
 
 
103
  const toggleGroupCollapse = (groupId) => {
104
  const newCollapsed = new Set(collapsedGroups)
105
  if (newCollapsed.has(groupId)) {
 
159
  initData()
160
  }, [location])
161
 
 
162
  const handleSearch = (value) => {
163
  setSearchKeyword(value)
164
  load(value)
165
  }
166
 
 
167
  const openCategoryModal = (category = null) => {
168
  setEditingCategory(category)
169
  if (category) {
 
467
  const onAdd = async () => {
468
  try {
469
  const v = await form.validateFields()
 
470
  if (v.cnHour !== undefined && v.cnMinute !== undefined && v.cnHour !== null && v.cnMinute !== null) {
471
  const h = Math.max(0, Math.min(23, Number(v.cnHour)))
472
  const m = Math.max(0, Math.min(59, Number(v.cnMinute)))
 
474
  v.timezone = 'Asia/Shanghai'
475
  }
476
  delete v.cnHour; delete v.cnMinute
 
 
477
  if (!v.apiType) v.apiType = 'other'
 
 
478
  if (v.enableCheckIn && !v.checkInMode) v.checkInMode = 'both'
479
 
480
  const res = await fetch('/api/sites', { method: 'POST', headers: authHeaders(true), body: JSON.stringify(v) })
 
484
  }
485
  setOpen(false); form.resetFields(); await load(); message.success('站点创建成功')
486
  } catch (e) {
487
+ message.error(e.message || '创建站点失败')
488
  }
489
  }
490
 
 
492
  setEditMode(true)
493
  setEditingSite(site)
494
 
 
495
  let cnHour = undefined, cnMinute = undefined
496
  if (site.scheduleCron && site.timezone === 'Asia/Shanghai') {
497
  const parts = String(site.scheduleCron).trim().split(/\s+/)
 
504
  form.setFieldsValue({
505
  name: site.name,
506
  baseUrl: site.baseUrl,
507
+ apiKey: '',
508
  apiType: site.apiType || 'other',
509
  userId: site.userId || '',
510
  cnHour,
 
515
  unlimitedQuota: site.unlimitedQuota || false,
516
  billingUrl: site.billingUrl || '',
517
  billingAuthType: site.billingAuthType || 'token',
518
+ billingAuthValue: '',
519
  billingLimitField: site.billingLimitField || '',
520
  billingUsageField: site.billingUsageField || '',
521
  enableCheckIn: site.enableCheckIn || false,
522
+ checkInMode: site.checkInMode || 'both',
523
+ extralink: site.extralink || '',
524
+ remark: site.remark || ''
525
  })
526
  setOpen(true)
527
  }
 
530
  try {
531
  const v = await form.validateFields()
532
 
 
533
  const updateData = {
534
  name: v.name,
535
  baseUrl: v.baseUrl,
 
544
  billingAuthValue: v.billingAuthValue || null,
545
  billingLimitField: v.billingLimitField || null,
546
  billingUsageField: v.billingUsageField || null,
547
+ enableCheckIn: v.enableCheckIn || false,
548
+ extralink: v.extralink || null,
549
+ remark: v.remark || null
550
  }
551
 
 
552
  if (v.enableCheckIn && v.checkInMode) {
553
  updateData.checkInMode = v.checkInMode
554
  } else if (v.enableCheckIn) {
555
  updateData.checkInMode = 'both'
556
  }
557
 
 
558
  if (v.apiKey && v.apiKey.trim()) {
559
  updateData.apiKey = v.apiKey
560
  }
561
 
 
562
  if (v.cnHour !== undefined && v.cnMinute !== undefined && v.cnHour !== null && v.cnMinute !== null) {
563
  const h = Math.max(0, Math.min(23, Number(v.cnHour)))
564
  const m = Math.max(0, Math.min(59, Number(v.cnMinute)))
565
  updateData.scheduleCron = `${m} ${h} * * *`
566
  updateData.timezone = 'Asia/Shanghai'
567
  } else {
 
568
  updateData.scheduleCron = null
569
  updateData.timezone = 'UTC'
570
  }
 
666
  const onCheck = async (id) => {
667
  const hide = message.loading('正在检测中...', 0)
668
  try {
 
669
  const res = await fetch(`/api/sites/${id}/check?skipNotification=true`, { method: 'POST', headers: authHeaders() })
670
  const data = await res.json().catch(() => ({}))
671
  if (!res.ok) throw new Error(data?.error || '检测失败')
672
  hide()
673
 
 
674
  if (data.hasChanges && data.diff) {
675
  const site = list.find(s => s.id === id)
676
  const siteName = site?.name || '未知站点'
677
 
 
678
  Modal.info({
679
  title: '🔄 检测到模型变更',
680
  width: 600,
 
917
  dataIndex: 'name',
918
  width: 200,
919
  render: (text, record) => (
920
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
921
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
922
+ <Tooltip title={record.baseUrl} placement="topLeft">
923
+ <Typography.Link
924
+ href={record.baseUrl}
925
+ target="_blank"
926
+ rel="noopener noreferrer"
927
+ strong
928
+ style={{ fontSize: 15, color: '#40a9ff' }}
929
+ >
930
+ {text}
931
+ </Typography.Link>
932
+ </Tooltip>
933
+ {record.pinned && (
934
+ <Tooltip title="已置顶">
935
+ <PushpinFilled style={{ color: '#fa8c16', fontSize: 13 }} />
936
+ </Tooltip>
937
+ )}
938
+ {record.excludeFromBatch && (
939
+ <Tooltip title="不参与一键检测">
940
+ <span style={{ fontSize: 14, cursor: 'help' }}>🚫</span>
941
+ </Tooltip>
942
+ )}
943
+ </div>
944
+ {record.extralink && (
945
  <Typography.Link
946
+ href={record.extralink}
947
  target="_blank"
948
  rel="noopener noreferrer"
949
+ type="secondary"
950
+ style={{ fontSize: 11 }}
951
  >
952
+ {record.extralink}
953
  </Typography.Link>
 
 
 
 
 
 
 
 
 
 
954
  )}
955
  </div>
956
  )
 
1143
  title: <span style={{ fontSize: 15, fontWeight: 600 }}>上次检测</span>,
1144
  dataIndex: 'lastCheckedAt',
1145
  width: 180,
1146
+ align: 'center',
1147
  render: v => v
1148
  ? <Typography.Text type="secondary" style={{ fontSize: 13, whiteSpace: 'nowrap' }}>{new Date(v).toLocaleString('zh-CN')}</Typography.Text>
1149
  : <Typography.Text type="secondary" style={{ fontSize: 13 }}>未检测</Typography.Text>
 
1151
  {
1152
  title: <span style={{ fontSize: 15, fontWeight: 600 }}>操作</span>,
1153
  key: 'actions',
1154
+ width: 240,
1155
+ align: 'center',
1156
  render: (_, r) => (
1157
+ <div style={{ display: 'flex', justifyContent: 'center' }}>
1158
+ <div style={{ display: 'inline-grid', gridTemplateColumns: 'repeat(3, auto)', gap: '2px 2px' }}>
1159
+ <Tooltip title="查看详情">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1160
  <Button
1161
+ type="primary"
1162
+ className="hover-lift"
1163
+ icon={<EyeOutlined />}
1164
+ onClick={() => {
1165
+ localStorage.setItem('sitesCurrentPage', currentPage)
1166
+ sessionStorage.setItem('sitesScrollPosition', window.scrollY.toString())
1167
+ sessionStorage.setItem('sitesCollapsedGroups', JSON.stringify([...collapsedGroups]))
1168
+ nav(`/sites/${r.id}`)
1169
+ }}
1170
  size="middle"
1171
  />
1172
  </Tooltip>
1173
+ <Tooltip title="立即检测">
1174
+ <Button
1175
+ type="default"
1176
+ className="hover-lift"
1177
+ icon={<ThunderboltOutlined />}
1178
+ onClick={() => onCheck(r.id)}
1179
+ size="middle"
1180
+ style={{ color: '#52c41a', fontWeight: 600, borderColor: '#52c41a' }}
1181
+ />
1182
+ </Tooltip>
1183
+ <Tooltip title="请求详情">
1184
+ <Button
1185
+ type="default"
1186
+ icon={<BugOutlined />}
1187
+ onClick={() => openDebugModal(r)}
1188
+ size="middle"
1189
+ style={{ color: '#fa8c16', borderColor: '#fa8c16' }}
1190
+ />
1191
+ </Tooltip>
1192
+ <Tooltip title="设置时间">
1193
+ <Button
1194
+ type="default"
1195
+ icon={<ClockCircleOutlined />}
1196
+ onClick={() => openTimeModal(r)}
1197
+ size="middle"
1198
+ />
1199
+ </Tooltip>
1200
+ <Tooltip title="编辑">
1201
+ <Button
1202
+ type="default"
1203
+ icon={<EditOutlined />}
1204
+ onClick={() => openEditModal(r)}
1205
+ size="middle"
1206
+ style={{ color: '#1890ff', borderColor: '#1890ff' }}
1207
+ />
1208
+ </Tooltip>
1209
+ <Popconfirm
1210
+ title="删除站点"
1211
+ description={
1212
+ <div style={{ maxWidth: 300 }}>
1213
+ <p>确定要删除站点 <strong>{r.name}</strong> 吗?</p>
1214
+ <p style={{ color: '#ff4d4f', marginTop: 8 }}>
1215
+ 删除后将清除所有历史检测数据,此操作不可恢复!
1216
+ </p>
1217
+ </div>
1218
+ }
1219
+ onConfirm={() => onDelete(r)}
1220
+ okText="确定删除"
1221
+ cancelText="取消"
1222
+ okButtonProps={{ danger: true }}
1223
+ icon={<ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />}
1224
+ >
1225
+ <Tooltip title="删除">
1226
+ <Button
1227
+ danger
1228
+ icon={<DeleteOutlined />}
1229
+ size="middle"
1230
+ />
1231
+ </Tooltip>
1232
+ </Popconfirm>
1233
+ </div>
1234
+ </div>
1235
+ )
1236
+ },
1237
+ {
1238
+ title: <span style={{ fontSize: 15, fontWeight: 600 }}>备注</span>,
1239
+ dataIndex: 'remark',
1240
+ width: 220,
1241
+ align: 'center',
1242
+ render: (text) => text ? (
1243
+ <Typography.Text type="secondary" style={{ fontSize: 12 }}>
1244
+ {text}
1245
+ </Typography.Text>
1246
+ ) : (
1247
+ <Typography.Text type="secondary" style={{ fontSize: 12 }}>-</Typography.Text>
1248
  )
1249
  }
1250
  ]
 
2086
  </Form.Item>
2087
  </Space>
2088
  </Form.Item>
2089
+
2090
  <Form.Item
2091
+ name="extralink"
2092
+ label={<span style={{ fontSize: 15, fontWeight: 500 }}>附加链接(可选)</span>}
2093
+ extra="显示在站点名称下方的附加签到站链接"
 
 
 
 
 
 
 
 
 
 
 
 
2094
  >
2095
+ <Input
2096
+ placeholder="例如:https://extra.example.com"
2097
+ style={{ borderRadius: 8, fontSize: 15 }}
2098
  />
2099
  </Form.Item>
2100
+
2101
  <Form.Item
2102
+ name="remark"
2103
+ label={<span style={{ fontSize: 15, fontWeight: 500 }}>备注(可选)</span>}
2104
+ extra="显示在操作列后方的备注信息"
 
2105
  >
2106
+ <Input
2107
+ placeholder="例如:测试站点"
2108
+ style={{ borderRadius: 8, fontSize: 15 }}
2109
  />
2110
  </Form.Item>
2111
+
2112
+ <div style={{ display: 'flex', gap: 24, marginBottom: 24 }}>
2113
+ <Form.Item
2114
+ name="pinned"
2115
+ valuePropName="checked"
2116
+ style={{ marginBottom: 0, flex: 1 }}
2117
+ >
2118
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
2119
+ <span style={{ fontSize: 14, fontWeight: 500 }}>置顶设置</span>
2120
+ <Switch
2121
+ checkedChildren="已置顶"
2122
+ unCheckedChildren="未置顶"
2123
+ />
2124
+ </div>
2125
+ </Form.Item>
2126
+ <Form.Item
2127
+ name="excludeFromBatch"
2128
+ valuePropName="checked"
2129
+ style={{ marginBottom: 0, flex: 1 }}
2130
+ >
2131
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
2132
+ <span style={{ fontSize: 14, fontWeight: 500 }}>一键检测</span>
2133
+ <Switch
2134
+ checkedChildren="排除"
2135
+ unCheckedChildren="参与"
2136
+ />
2137
+ </div>
2138
+ </Form.Item>
2139
+ <Form.Item
2140
+ name="unlimitedQuota"
2141
+ valuePropName="checked"
2142
+ style={{ marginBottom: 0, flex: 1 }}
2143
+ >
2144
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
2145
+ <span style={{ fontSize: 14, fontWeight: 500 }}>余额类型</span>
2146
+ <Switch
2147
+ checkedChildren="无限余额"
2148
+ unCheckedChildren="普通余额"
2149
+ />
2150
+ </div>
2151
+ </Form.Item>
2152
+ </div>
2153
 
2154
  {/* 签到配置 - 仅Veloera类型显示 */}
2155
  <Form.Item