mockData.js
55.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
/**
* @Description: Mock 数据生成工具 - 用于测试分页加载功能
* @Date: 2026-02-08
* @update 2026-02-27: 添加文章模块 Mock 数据支持
*
* 支持的 API Mock:
* - weekHotAPI: 周热门资料(已废弃,使用 articleWeekHotAPI)
* - fileListAPI: 资料列表(已废弃,使用 articleListAPI)
* - listAPI: 产品列表
* - searchAPI: 搜索(产品+资料)
* - myListAPI: 消息列表
* - favoriteListAPI: 收藏列表(已废弃,使用 articleFavoriteAPI)
* - feedbackListAPI: 意见反馈列表
* - planListAPI: 计划书列表
* - articleListAPI: 文章列表(新增)
* - articleWeekHotAPI: 热门文章(新增)
* - articleDetailAPI: 文章详情(新增)
* - articleFavoriteAPI: 文章收藏列表(新增)
*/
// ============================================================================
// 工具函数
// ============================================================================
/**
* 生成随机文件大小
* @returns {string} 文件大小(如 "2.5MB")
*/
function generateRandomSize() {
const sizeInMB = (Math.random() * 10 + 0.5).toFixed(1)
return `${sizeInMB}MB`
}
/**
* 生成随机学习人数
* @returns {number} 学习人数(100-5000之间)
*/
function generateRandomReadCount() {
return Math.floor(Math.random() * 4900) + 100
}
/**
* 生成随机学习百分比
* @returns {number} 学习百分比(0-100之间)
*/
function generateRandomReadPercent() {
return Math.floor(Math.random() * 100)
}
/**
* 生成随机收藏状态
* @returns {string} '1' 或 '0'
*/
function generateRandomFavorite() {
return Math.random() > 0.7 ? '1' : '0'
}
/**
* 模拟网络延迟
* @param {number} min 最小延迟(ms)
* @param {number} max 最大延迟(ms)
* @returns {Promise}
*/
function mockDelay(min = 100, max = 300) {
const delay = Math.random() * (max - min) + min
return new Promise(resolve => setTimeout(resolve, delay))
}
// ============================================================================
// 真实的测试文件地址(可预览)
// ============================================================================
/**
* 真实的可预览测试文件地址
*
* 来源说明:
* - 项目 CDN: cdn.ipadbiz.cn(项目自有 CDN,最稳定)
* - calibre-ebook.com: Calibre 官方测试文件
* - filesamples.com: 文件格式测试样本
* - Microsoft: 官方示例文件
*/
const TEST_FILES = {
// PDF 文档(优先使用项目 CDN)
pdf: [
'https://cdn.ipadbiz.cn/manulife/document/test.pdf', // 项目 CDN(最可靠)
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
'https://www.africau.edu/images/default/sample.pdf'
],
// Word 文档 (docx)
docx: [
'https://calibre-ebook.com/downloads/demos/demo.docx'
],
// Excel 表格 (xlsx)
xlsx: [
'https://filesamples.com/samples/document/xlsx/sample1.xlsx', // filesamples 更稳定
'https://go.microsoft.com/fwlink/?LinkID=512104&clcid=0x0409'
],
// PPT 演示文稿 (ppt/pptx)
pptx: [
'https://www.africau.edu/images/default/sample.pptx',
'https://filesamples.com/samples/document/ppt/sample1.ppt'
],
// 图片
jpg: [
'https://picsum.photos/seed/test1/800/600.jpg',
'https://picsum.photos/seed/test2/800/600.jpg',
'https://picsum.photos/seed/test3/800/600.jpg'
],
// PNG 图片
png: [
'https://picsum.photos/seed/test4/800/600.png',
'https://picsum.photos/seed/test5/800/600.png'
],
// 文本文件(使用 GitHub raw)
txt: [
'https://raw.githubusercontent.com/torvalds/linux/master/README',
'https://raw.githubusercontent.com/github/gitignore/main/README'
]
}
/**
* 根据文件类型获取测试文件地址
* @param {string} extension - 文件扩展名
* @param {number} seed - 随机种子
* @returns {string} 测试文件地址
*/
function getTestFileUrl(extension, seed = 0) {
const files = TEST_FILES[extension] || TEST_FILES.pdf
const index = seed % files.length
return files[index]
}
// ============================================================================
// 1. 周热门资料 Mock (weekHotAPI)
// ============================================================================
const WEEK_HOT_MATERIALS = [
'财富管理基础知识指南',
'保险产品销售技巧',
'客户关系管理实战',
'家庭资产配置方案',
'税务筹划实用手册',
'退休规划完整教程',
'投资组合管理策略',
'风险控制与合规要求',
'高净值客户开发指南',
'理财产品营销话术',
'基金定投实战技巧',
'保单整理服务流程',
'传承规划案例分析',
'健康险产品对比分析',
'年金保险销售指南',
'重疾险核保知识',
'教育金规划方案',
'房贷规划实务操作',
'家族信托业务介绍',
'私募股权投资指南'
]
const FILE_TYPES = [
{ extension: 'pdf', name: 'PDF文档' },
{ extension: 'doc', name: 'Word文档' },
{ extension: 'docx', name: 'Word文档' },
{ extension: 'xls', name: 'Excel表格' },
{ extension: 'xlsx', name: 'Excel表格' },
{ extension: 'ppt', name: 'PPT演示文稿' },
{ extension: 'pptx', name: 'PPT演示文稿' },
{ extension: 'txt', name: '文本文件' },
{ extension: 'jpg', name: '图片' },
{ extension: 'png', name: '图片' }
]
/**
* 生成周热门资料数据
*/
function generateWeekHotItem(id) {
const fileType = FILE_TYPES[Math.floor(Math.random() * FILE_TYPES.length)]
const materialName = WEEK_HOT_MATERIALS[Math.floor(Math.random() * WEEK_HOT_MATERIALS.length)]
// 获取真实的测试文件地址
const testFileUrl = getTestFileUrl(fileType.extension, id)
return {
meta_id: id,
name: `${materialName} ${fileType.name.toUpperCase()}`,
src: `https://picsum.photos/seed/material-${id}-${fileType.extension}/100/100`,
size: generateRandomSize(),
read_people_count: generateRandomReadCount(),
read_people_percent: generateRandomReadPercent(),
is_favorite: generateRandomFavorite(),
extension: fileType.extension,
downloadUrl: testFileUrl // 使用真实的测试文件地址
}
}
/**
* Mock: weekHotAPI
*/
export async function mockWeekHotAPI(params) {
await mockDelay()
const { page = 0, limit = 20 } = params
const totalPages = 5
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [] } }
}
const list = []
const startIndex = page * limit
for (let i = 0; i < limit; i++) {
list.push(generateWeekHotItem(startIndex + i + 1))
}
console.log(`[Mock] weekHotAPI - 第${page}页,共${list.length}条`)
return { code: 1, msg: 'success', data: { list } }
}
// ============================================================================
// 2. 资料列表 Mock (fileListAPI)
// ============================================================================
const MATERIAL_NAMES = [
'2024年保险行业发展趋势报告',
'高净值客户开发实战手册',
'家庭保障需求分析模板',
'养老规划产品对比表',
'教育金储备方案',
'重疾险条款解读',
'百万医疗险销售指南',
'年金险产品培训资料',
'终身寿险销售技巧',
'车险理赔流程说明',
'企业财产险基础知识',
'责任险产品介绍',
'意外险保障方案',
'健康险核保手册',
'投保实务操作指南',
'客户异议处理话术',
'保单托管服务流程',
'理赔案例分析',
'保险法律法规汇编',
'行业合规要求解读'
]
/**
* 生成资料列表项
*/
function generateMaterialItem(id) {
const fileType = FILE_TYPES[Math.floor(Math.random() * FILE_TYPES.length)]
const materialName = MATERIAL_NAMES[Math.floor(Math.random() * MATERIAL_NAMES.length)]
// 获取真实的测试文件地址
const testFileUrl = getTestFileUrl(fileType.extension, id)
return {
id: id,
meta_id: id,
name: materialName,
title: materialName,
fileName: `${materialName}.${fileType.extension}`,
desc: '这是一份详细的培训资料,包含丰富的案例和实战技巧...',
size: generateRandomSize(),
extension: fileType.extension,
collected: generateRandomFavorite() === '1',
src: `https://picsum.photos/seed/file-${id}-${fileType.extension}/100/100`,
downloadUrl: testFileUrl, // 使用真实的测试文件地址
post_date: new Date().toISOString(),
value: testFileUrl // 使用真实的测试文件地址
}
}
/**
* Mock: fileListAPI
*/
export async function mockFileListAPI(params) {
await mockDelay()
const { page = 0, limit = 20, cid, keyword, child_id } = params
const totalPages = 8
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [], total: totalPages * limit } }
}
const list = []
const startIndex = page * limit
for (let i = 0; i < limit; i++) {
const item = generateMaterialItem(startIndex + i + 1)
// 如果有关键词搜索,过滤数据
if (keyword && !item.name.includes(keyword)) {
continue
}
list.push(item)
}
console.log(`[Mock] fileListAPI - 第${page}页,共${list.length}条`)
return {
code: 1,
msg: 'success',
data: {
list,
total: totalPages * limit,
max_level: 2,
cate: {
id: parseInt(cid) || 1,
category_name: '培训资料',
category_parent: 0,
category_description: null
}
}
}
}
// ============================================================================
// 3. 产品列表 Mock (listAPI)
// ============================================================================
const PRODUCT_NAMES = [
'百万年金保险计划',
'终身寿险至尊版',
'重疾险保障计划',
'百万医疗险',
'意外伤害保险',
'教育金保险计划',
'养老理财保险',
'高端医疗险',
'定期寿险',
'终身寿险',
'企业年金保险',
'团体意外险',
'家庭财产保险',
'责任保险系列',
'旅游保险',
'留学保险',
'健康保险计划',
'车辆保险',
'财产一切险',
'工程保险'
]
const PRODUCT_TAGS = [
{ id: 1, name: '热销', bg_color: '#FEE2E2', text_color: '#DC2626' },
{ id: 2, name: '新品', bg_color: '#DBEAFE', text_color: '#2563EB' },
{ id: 3, name: '推荐', bg_color: '#D1FAE5', text_color: '#059669' },
{ id: 4, name: '限时', bg_color: '#FEF3C7', text_color: '#D97706' }
]
const PRODUCT_CATEGORIES = [
{ id: 1, name: '人寿保险' },
{ id: 2, name: '健康保险' },
{ id: 3, name: '意外保险' },
{ id: 4, name: '财产保险' }
]
/**
* 生成产品列表项
*/
/**
* 生成产品列表项(符合真实 API 结构)
*
* @param {number} id - 产品 ID
* @param {string} formSn - 表单标识(可选)
* @returns {Object} 产品对象
*/
function generateProductItem(id, formSn) {
const productName = PRODUCT_NAMES[Math.floor(Math.random() * PRODUCT_NAMES.length)]
const recommend = Math.random() > 0.7 ? 'hot' : ''
// 随机选择1-2个标签
const tags = []
const tagCount = Math.floor(Math.random() * 2) + 1
const availableTags = [...PRODUCT_TAGS].sort(() => Math.random() - 0.5)
for (let i = 0; i < tagCount; i++) {
tags.push(availableTags[i])
}
// 随机选择分类
const categoryId = Math.floor(Math.random() * 4) + 1
const category = PRODUCT_CATEGORIES.find(c => parseInt(c.id) === categoryId)
return {
id: id,
product_name: productName,
cover_image: `https://picsum.photos/seed/product-${id}/400/300`,
recommend: recommend,
form_sn: formSn || `product-template-${categoryId}`, // 关键:对应模板的 form_sn
created_time: new Date().toISOString(),
categories: [category], // ✅ 真实 API 结构:categories 是数组
tags: tags
}
}
/**
* Mock: listAPI (产品列表)
*/
export async function mockProductListAPI(params) {
await mockDelay()
const { page = 0, limit = 10, cid, keyword } = params
const totalPages = 10
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [], categories: [], total: 0 } }
}
const list = []
const startIndex = page * limit
// 🔧 测试商品:第一页前两位固定为测试产品
if (page === 0) {
const testCategory = PRODUCT_CATEGORIES.find(c => parseInt(c.id) === 1)
// 测试商品1: 储蓄产品
const testProduct1 = {
id: 'savings-2-148b3acd',
product_name: '测试计划书-智享未来2(form_sn:savings-2-148b3acd)',
cover_image: 'https://picsum.photos/seed/savings-2-148b3acd/400/300',
recommend: 'hot',
form_sn: 'savings-2-148b3acd', // ✅ 关键字段:对应真实 API 的 form_sn
created_time: new Date().toISOString(),
categories: [testCategory], // ✅ 符合真实 API 结构:categories 是数组
tags: [{ id: '1', name: '热销', bg_color: '#FEE2E2', text_color: '#DC2626' }],
// 测试标识(不影响业务逻辑)
_test: true,
_test_note: 'form_sn:savings-2-148b3acd'
}
// 测试商品2: 人寿保险产品
const testProduct2 = {
id: 'life-insurance-3-d8fde07d',
product_name: '测试计划书-人生无忧3(form_sn:life-insurance-3-d8fde07d)',
cover_image: 'https://picsum.photos/seed/life-insurance-3-d8fde07d/400/300',
recommend: 'hot',
form_sn: 'life-insurance-3-d8fde07d', // ✅ 关键字段:对应真实 API 的 form_sn
created_time: new Date().toISOString(),
categories: [testCategory], // ✅ 符合真实 API 结构:categories 是数组
tags: [{ id: '1', name: '热销', bg_color: '#FEE2E2', text_color: '#DC2626' }],
// 测试标识(不影响业务逻辑)
_test: true,
_test_note: 'form_sn:life-insurance-3-d8fde07d'
}
// 检查分类和关键词过滤,依次添加测试商品
const testProducts = [testProduct1, testProduct2]
testProducts.forEach((testProduct, index) => {
let shouldInclude = true
if (cid && !testProduct.categories.some(c => parseInt(c.id) === parseInt(cid))) {
shouldInclude = false
}
if (keyword && !testProduct.product_name.includes(keyword)) {
shouldInclude = false
}
if (shouldInclude) {
list.push(testProduct)
console.log(`[Mock] listAPI - 测试商品${index + 1}已置顶: form_sn=${testProduct.form_sn}`)
}
})
}
for (let i = 0; i < limit; i++) {
const item = generateProductItem(startIndex + i + 1)
// 如果有分类过滤
if (cid && item.category_id !== parseInt(cid)) {
continue
}
// 如果有关键词搜索
if (keyword && !item.product_name.includes(keyword)) {
continue
}
list.push(item)
}
console.log(`[Mock] listAPI - 第${page}页,共${list.length}条`)
return {
code: 1,
msg: 'success',
data: {
list,
categories: PRODUCT_CATEGORIES,
total: totalPages * limit
}
}
}
// ============================================================================
// 4. 搜索 Mock (searchAPI)
// ============================================================================
/**
* Mock: searchAPI (支持产品和资料搜索)
*/
export async function mockSearchAPI(params) {
await mockDelay()
const { page = 0, limit = 20, keyword, type } = params
if (!keyword) {
// 🔧 优化:如果没有关键词,返回更多推荐数据用于测试
// 生成20个产品和20个文章作为默认搜索结果
const defaultProducts = []
const defaultArticles = []
for (let i = 0; i < 20; i++) {
const productItem = generateProductItem(i + 1)
defaultProducts.push({
...productItem,
id: i + 1,
cover_image: productItem.cover_image
})
const articleItem = generateArticleItem(i + 1)
defaultArticles.push(articleItem)
}
console.log(`[Mock] searchAPI - 无关键词,返回默认数据:产品${defaultProducts.length}条,文章${defaultArticles.length}条`)
return {
code: 1,
msg: 'success',
data: {
products: { list: defaultProducts, total: defaultProducts.length * 5 },
article: { list: defaultArticles, total: defaultArticles.length * 5 }
}
}
}
const totalPages = 5
if (page >= totalPages) {
return {
code: 1,
msg: 'success',
data: {
products: { list: [], total: 0 },
article: { list: [], total: 0 }
}
}
}
const products = []
const articles = []
const startIndex = page * limit
// 🔧 优化:每次循环都生成数据和尝试匹配,增加命中率
for (let i = 0; i < limit / 2; i++) {
// 产品
const productItem = generateProductItem(startIndex + i + 1)
const productName = productItem.product_name.toLowerCase()
const searchKeyword = keyword.toLowerCase()
// 🔧 优化:更宽松的搜索条件
// 1. 完全匹配
// 2. 拆分关键词,包含任意一个字符即可
// 3. 关键词长度 >= 2 时,只要产品名称包含任意连续2个字符
const keywords = searchKeyword.split('').filter(k => k.trim())
const hasAnyChar = keywords.length > 0 && keywords.some(k => productName.includes(k))
const hasBigram = searchKeyword.length >= 2 && keywords.slice(0, -1).some((k, idx) => productName.includes(k + keywords[idx + 1]))
if (productName.includes(searchKeyword) || hasAnyChar || hasBigram) {
products.push({
...productItem,
id: startIndex + i + 1,
cover_image: productItem.cover_image
})
}
// 文章
const articleItem = generateArticleItem(startIndex + i + 100)
const articleTitle = articleItem.post_title.toLowerCase()
const hasAnyCharArticle = keywords.length > 0 && keywords.some(k => articleTitle.includes(k))
const hasBigramArticle = searchKeyword.length >= 2 && keywords.slice(0, -1).some((k, idx) => articleTitle.includes(k + keywords[idx + 1]))
if (articleTitle.includes(searchKeyword) || hasAnyCharArticle || hasBigramArticle) {
articles.push(articleItem)
}
}
// 🔧 优化:如果没有匹配到任何数据,返回一些推荐数据
if (products.length === 0 && articles.length === 0) {
console.log(`[Mock] searchAPI - 无匹配结果,返回推荐数据`)
// 生成 5 个推荐产品
for (let i = 0; i < 5; i++) {
const productItem = generateProductItem(startIndex + i + 1)
products.push({
...productItem,
id: startIndex + i + 1,
cover_image: productItem.cover_image
})
const articleItem = generateArticleItem(startIndex + i + 100)
articles.push(articleItem)
}
}
console.log(`[Mock] searchAPI - 第${page}页,关键词"${keyword}",产品${products.length}条,文章${articles.length}条`)
return {
code: 1,
msg: 'success',
data: {
products: { list: products, total: products.length * totalPages },
article: { list: articles, total: articles.length * totalPages }
}
}
}
// ============================================================================
// 5. 消息列表 Mock (myListAPI)
// ============================================================================
const MESSAGE_TITLES = [
'关于2024年新产品上线通知',
'系统升级维护公告',
'您的保单已生效提醒',
'理赔进度更新通知',
'续费提醒',
'活动邀请:财富管理讲座',
'客户服务满意度调查',
'最新培训资料已上线',
'合规要求更新通知',
'节日问候与祝福',
'产品停售通知',
'核保政策调整',
'理赔流程优化说明',
'客户权益保障计划',
'数字化服务升级公告'
]
/**
* 生成消息列表项
*
* @description 按 API 规范生成消息 Mock 数据
* @param {number} id - 消息 ID
* @returns {Object} 消息对象
*/
function generateMessageItem(id) {
const title = MESSAGE_TITLES[Math.floor(Math.random() * MESSAGE_TITLES.length)]
const now = new Date()
const createDate = new Date(now.getTime() - Math.random() * 30 * 24 * 60 * 60 * 1000)
const isUnread = Math.random() > 0.5
return {
id: id,
title: title, // API 返回的标题字段
note: `这是一条关于"${title}"的通知。\n点击查看详情了解更多信息。`, // 消息内容(note 字段)
created_time: formatDate(createDate), // 发消息时间
status: isUnread ? 'send' : 'read', // send=已发送未读取,read=已读取
pk_id: Math.floor(Math.random() * 10000) // 计划书订单 ID(可选)
}
}
/**
* 格式化日期
*/
function formatDate(date) {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
/**
* Mock: myListAPI (消息列表)
*
* @description 第1页(page=0)前面会插入三条测试消息用于测试计划书查看功能
*/
export async function mockMessageListAPI(params) {
await mockDelay()
const { page = 0, limit = 10 } = params // 前端传的是从0开始的页码
const totalPages = 8
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [] } }
}
const list = []
// 第1页(page=0):在前面插入三条测试消息(用于测试计划书查看)
if (page === 0) {
list.push(
{
id: '1001',
title: '【测试】已生成计划书(单文件)',
note: '测试场景:状态为"已生成",只有一个计划书文件,可直接查看。',
created_time: '2026-02-13',
status: 'send'
},
{
id: '1002',
title: '【测试】已生成计划书(多文件)',
note: '测试场景:状态为"已生成",有3个计划书文件,点击后会显示选择弹框。',
created_time: '2026-02-13',
status: 'send'
},
{
id: '1003',
title: '【测试】已查看计划书',
note: '测试场景:状态为"已查看",查看后不会再次标记。',
created_time: '2026-02-13',
status: 'read'
}
)
}
const startIndex = page * limit
const remainingCount = limit - list.length
for (let i = 0; i < remainingCount; i++) {
list.push(generateMessageItem(startIndex + i + 1))
}
console.log(`[Mock] myListAPI - 第${page}页,共${list.length}条`)
return {
code: 1,
msg: 'success',
data: { list }
}
}
/**
* Mock: detailAPI (消息详情)
*
* @description 根据 ID 返回消息详情,包含完整的 proposal 数据
* @param {Object} params 请求参数
* @param {string|number} params.i 消息ID
* @returns {Promise} 详情数据
*
* @description 测试数据说明:
* - id='1001': 已生成 + 单文件
* - id='1002': 已生成 + 多文件 (3个文件)
* - id='1003': 已查看 + 单文件
* - 其他ID: 待处理状态 + 2个文件
*/
export async function mockDetailAPI(params) {
await mockDelay()
const { i: id } = params
if (!id) {
return { code: 0, msg: '消息ID不能为空', data: null }
}
// 生成基础消息数据
const messageItem = generateMessageItem(id)
// 根据消息 ID 返回不同状态的计划书数据(用于测试)
let proposal = null
if (id === '1001') {
// 场景1: 已生成 + 单文件
proposal = {
id: 1001,
customer_name: '张三',
product_name: '年金险产品A',
categories: [{ id: '1', name: '基本信息' }],
created_time: messageItem.created_time,
order_status: '7', // 已生成
proposal_files: [
{
id: 1,
file_name: '计划书.pdf',
file_url: TEST_FILES.pdf[0] // 使用真实的 PDF 测试文件
}
]
}
} else if (id === '1002') {
// 场景2: 已生成 + 多文件 (3个文件)
proposal = {
id: 1002,
customer_name: '李四',
product_name: '终身寿险产品B',
categories: [
{ id: '1', name: '基本信息' },
{ id: '2', name: '保障内容' },
{ id: '3', name: '缴费方式' }
],
created_time: messageItem.created_time,
order_status: '7', // 已生成
proposal_files: [
{
id: 1,
file_name: '计划书完整版.pdf',
file_url: TEST_FILES.pdf[0]
},
{
id: 2,
file_name: '产品条款说明书.pdf',
file_url: TEST_FILES.pdf[0]
},
{
id: 3,
file_name: '费率表.pdf',
file_url: TEST_FILES.pdf[0]
}
]
}
} else if (id === '1003') {
// 场景3: 已查看 + 单文件
proposal = {
id: 1003,
customer_name: '王五',
product_name: '重疾险产品C',
categories: [{ id: '1', name: '基本信息' }],
created_time: messageItem.created_time,
order_status: '9', // 已查看
proposal_files: [
{
id: 1,
file_name: '计划书.pdf',
file_url: TEST_FILES.pdf[0]
}
]
}
} else {
// 默认: 待处理状态 + 2个文件(无法查看)
proposal = {
id: id,
customer_name: '测试用户',
product_name: '测试产品',
categories: [{ id: '1', name: '基本信息' }],
created_time: messageItem.created_time,
order_status: '3', // 待处理
proposal_files: [
{
id: 1,
file_name: '计划书文件.pdf',
file_url: TEST_FILES.pdf[0]
},
{
id: 2,
file_name: '产品说明.pdf',
file_url: TEST_FILES.pdf[0]
}
]
}
}
console.log(`[Mock] detailAPI - 消息ID: ${id}, 计划书状态: ${proposal.order_status}`)
return {
code: 1,
msg: 'success',
data: {
...messageItem,
proposal
}
}
}
// ============================================================================
// 6. 收藏列表 Mock (favoriteListAPI)
// ============================================================================
const FAVORITE_MATERIALS = [
'财富管理基础知识指南',
'保险产品销售技巧',
'客户关系管理实战',
'家庭资产配置方案',
'税务筹划实用手册',
'退休规划完整教程',
'投资组合管理策略',
'风险控制与合规要求',
'高净值客户开发指南',
'理财产品营销话术',
'基金定投实战技巧',
'保单整理服务流程',
'传承规划案例分析',
'健康险产品对比分析',
'年金保险销售指南',
'重疾险核保知识',
'教育金规划方案',
'房贷规划实务操作',
'家族信托业务介绍',
'私募股权投资指南'
]
/**
* 生成收藏列表项
*/
function generateFavoriteItem(id) {
const fileType = FILE_TYPES[Math.floor(Math.random() * FILE_TYPES.length)]
const materialName = FAVORITE_MATERIALS[Math.floor(Math.random() * FAVORITE_MATERIALS.length)]
const now = new Date()
const createDate = new Date(now.getTime() - Math.random() * 90 * 24 * 60 * 60 * 1000)
// 获取真实的测试文件地址
const testFileUrl = getTestFileUrl(fileType.extension, id)
return {
meta_id: id,
name: `${materialName}.${fileType.extension}`,
size: generateRandomSize(),
src: `https://picsum.photos/seed/favorite-${id}-${fileType.extension}/100/100`,
downloadUrl: testFileUrl, // 添加下载地址
extension: fileType.extension, // 添加文件扩展名
created_time: formatDate(createDate)
}
}
/**
* Mock: favoriteListAPI (收藏列表)
*/
export async function mockFavoriteListAPI(params) {
await mockDelay()
const { page = 0, limit = 20 } = params
const totalPages = 3
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [] } }
}
const list = []
const startIndex = page * limit
for (let i = 0; i < limit; i++) {
list.push(generateFavoriteItem(startIndex + i + 1))
}
console.log(`[Mock] favoriteListAPI - 第${page}页,共${list.length}条`)
return {
code: 1,
msg: 'success',
data: { list }
}
}
// ============================================================================
// 7. 意见反馈列表 Mock (feedbackListAPI)
// ============================================================================
const FEEDBACK_CATEGORIES = ['1', '3', '7'] // 1=功能建议, 3=问题反馈, 7=其他问题
const FEEDBACK_NOTES = [
'希望能够增加资料下载功能',
'产品详情页加载速度较慢',
'收藏功能使用不便,建议优化',
'搜索结果不够准确',
'希望能够添加学习进度跟踪',
'界面颜色有点太深了',
'建议添加夜间模式',
'资料分类不够清晰',
'希望能够离线查看资料',
'登录后总是会重新要求登录',
'视频播放有时会卡顿',
'希望能够支持分享到朋友圈',
'字体大小无法调整',
'建议增加资料收藏夹分类',
'消息通知太频繁了',
'希望能够批量管理收藏',
'产品对比功能不够直观',
'建议添加更多实用工具',
'客服回复速度有待提升'
]
const FEEDBACK_REPLIES = [
'感谢您的宝贵建议,我们会尽快优化!',
'您反馈的问题我们已经记录,技术团队正在处理中。',
'好的,我们会考虑您的建议。',
'非常感谢您的反馈,这对我们改进产品很有帮助。',
'您提到的问题我们已经收到,会在下个版本中优化。',
'感谢您的支持,我们会继续改进产品体验。'
]
/**
* 生成反馈列表项
*/
function generateFeedbackItem(id) {
const category = FEEDBACK_CATEGORIES[Math.floor(Math.random() * FEEDBACK_CATEGORIES.length)]
const note = FEEDBACK_NOTES[Math.floor(Math.random() * FEEDBACK_NOTES.length)]
const status = Math.random() > 0.6 ? 5 : 1 // 60%概率已处理
const hasReply = status === 5 && Math.random() > 0.3 // 已处理的有70%概率有回复
const hasImages = Math.random() > 0.7 // 30%概率有图片
const now = new Date()
const createDate = new Date(now.getTime() - Math.random() * 60 * 24 * 60 * 60 * 1000)
const replyDate = new Date(createDate.getTime() + Math.random() * 7 * 24 * 60 * 60 * 1000)
// 生成随机图片
const images = []
if (hasImages) {
const imageCount = Math.floor(Math.random() * 3) + 1
for (let i = 0; i < imageCount; i++) {
images.push(`https://picsum.photos/seed/feedback-${id}-${i}/200/200`)
}
}
return {
id: id,
category: category,
status: status,
note: note,
images: images,
contact: Math.random() > 0.5 ? '138****8888' : '',
reply: hasReply ? FEEDBACK_REPLIES[Math.floor(Math.random() * FEEDBACK_REPLIES.length)] : '',
reply_time: hasReply ? formatDate(replyDate) : ''
}
}
/**
* Mock: feedbackListAPI (意见反馈列表)
*/
export async function mockFeedbackListAPI(params) {
await mockDelay()
const { page = 0, limit = 10 } = params
const totalPages = 5
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [] } }
}
const list = []
const startIndex = page * limit
for (let i = 0; i < limit; i++) {
list.push(generateFeedbackItem(startIndex + i + 1))
}
console.log(`[Mock] feedbackListAPI - 第${page}页,共${list.length}条`)
return {
code: 1,
msg: 'success',
data: { list }
}
}
// ============================================================================
// 8. 计划书列表 Mock (planListAPI)
// ============================================================================
const PLAN_PRODUCT_NAMES = [
'终身寿险至尊版',
'重疾险保障计划',
'百万年金保险计划',
'高端医疗险',
'养老理财保险',
'教育金保险计划',
'意外伤害保险',
'定期寿险',
'终身寿险',
'企业年金保险',
'团体意外险',
'健康保险计划'
]
const PLAN_STATUS = ['3', '5', '7', '9'] // 3=待处理, 5=处理中, 7=已生成, 9=已查看
const PLAN_CATEGORIES = [
{ id: '1', name: '人寿保险' },
{ id: '2', name: '重疾险' },
{ id: '3', name: '医疗险' },
{ id: '4', name: '年金险' },
{ id: '5', name: '意外险' }
]
const CUSTOMER_NAMES = [
'张三', '李四', '王五', '赵六', '钱七',
'孙八', '周九', '吴十', '郑十一', '陈十二',
'刘十三', '黄十四', '杨十五', '朱十六', '胡十七'
]
/**
* 生成计划书列表项
* @param {number} id - 计划书ID
* @returns {Object} 计划书对象
*/
function generatePlanItem(id) {
const productName = PLAN_PRODUCT_NAMES[Math.floor(Math.random() * PLAN_PRODUCT_NAMES.length)]
const customerName = CUSTOMER_NAMES[Math.floor(Math.random() * CUSTOMER_NAMES.length)]
const orderStatus = PLAN_STATUS[Math.floor(Math.random() * PLAN_STATUS.length)]
const category = PLAN_CATEGORIES[Math.floor(Math.random() * PLAN_CATEGORIES.length)]
// 生成创建时间(最近30天内)
const now = new Date()
const createTime = new Date(now.getTime() - Math.random() * 30 * 24 * 60 * 60 * 1000)
// 根据状态决定是否有计划书文件
const hasFiles = orderStatus === '7' || orderStatus === '9' // 已生成或已查看才有文件
const proposalFiles = []
if (hasFiles) {
// 生成1-3个计划书文件
const fileCount = Math.floor(Math.random() * 3) + 1
for (let i = 0; i < fileCount; i++) {
proposalFiles.push({
id: id * 10 + i,
file_name: `${customerName}-${productName}-计划书.pdf`,
file_url: `https://picsum.photos/seed/plan-${id}-${i}/400/300`
})
}
}
return {
id: id,
customer_name: customerName,
product_name: productName,
categories: [category],
created_time: formatDate(createTime),
order_status: orderStatus,
proposal_files: proposalFiles
}
}
/**
* Mock: planListAPI (计划书列表)
* @description 支持分页、状态筛选、关键词搜索
* @param {Object} params - 请求参数
* @param {number} params.page - 页码(从0开始)
* @param {number} params.limit - 每页数量(默认20)
* @param {string} [params.status] - 状态筛选(3=待处理, 5=处理中, 7=已生成, 9=已查看)
* @param {string} [params.keyword] - 搜索关键字
* @returns {Promise<Object>} Mock 响应
*/
export async function mockPlanListAPI(params) {
await mockDelay()
const { page = 0, limit = 20, status, keyword } = params
const totalPages = 10
// 如果超过总页数,返回空列表
if (page >= totalPages) {
console.log(`[Mock] planListAPI - 第${page}页,共0条(已到最后一页)`)
return {
code: 1,
msg: 'success',
data: {
list: [],
total: totalPages * limit
}
}
}
const list = []
const startIndex = page * limit
// 生成数据并过滤
for (let i = 0; i < limit; i++) {
const item = generatePlanItem(startIndex + i + 1)
// 状态筛选
if (status && item.order_status !== status) {
continue
}
// 关键词搜索(搜索产品名或客户名)
if (keyword) {
const searchKeyword = keyword.toLowerCase()
const productName = item.product_name.toLowerCase()
const customerName = item.customer_name.toLowerCase()
if (!productName.includes(searchKeyword) && !customerName.includes(searchKeyword)) {
continue
}
}
list.push(item)
}
console.log(`[Mock] planListAPI - 第${page}页,共${list.length}条,状态筛选:${status || '无'},关键词:"${keyword || '无'}"`)
return {
code: 1,
msg: 'success',
data: {
list,
total: totalPages * limit
}
}
}
// ============================================================================
// 9. 文章模块 Mock
// ============================================================================
const ARTICLE_TITLES = [
'财富管理基础知识指南',
'保险产品销售技巧',
'客户关系管理实战',
'家庭资产配置方案',
'税务筹划实用手册',
'退休规划完整教程',
'投资组合管理策略',
'风险控制与合规要求',
'高净值客户开发指南',
'理财产品营销话术',
'基金定投实战技巧',
'保单整理服务流程',
'传承规划案例分析',
'健康险产品对比分析',
'年金保险销售指南',
'重疾险核保知识',
'教育金规划方案',
'房贷规划实务操作',
'家族信托业务介绍',
'私募股权投资指南',
'终身寿险销售技巧',
'车险理赔流程说明',
'企业财产险基础知识',
'责任险产品介绍',
'意外险保障方案',
'健康险核保手册',
'投保实务操作指南',
'客户异议处理话术',
'理赔案例分析',
'保险法律法规汇编'
]
const ARTICLE_EXCERPTS = [
'这是一篇关于财富管理的基础知识文章,帮助您了解投资理财的基本概念和方法。',
'保险产品销售技巧分享,从客户需求分析到产品推荐的完整流程。',
'高净值客户开发与维护实战指南,分享成功的客户管理经验。',
'家庭资产配置方案设计,综合考虑风险、收益和流动性需求。',
'税务筹划实用手册,合法合规地降低税负,提高财务效率。',
'退休规划完整教程,为您打造安心舒适的退休生活。',
'投资组合管理策略,分散风险,实现稳健收益。',
'风险控制与合规要求解读,确保业务健康发展。',
'高净值客户开发指南,提升客户开发成功率。',
'理财产品营销话术,让客户更容易接受产品推荐。'
]
const ARTICLE_AUTHORS = [
'财富管理专家',
'保险规划师',
'投资顾问',
'税务筹划师',
'法律顾问',
'风险管理师'
]
const ARTICLE_COVER_IMAGES = [
'https://picsum.photos/seed/article1/800/450',
'https://picsum.photos/seed/article2/800/450',
'https://picsum.photos/seed/article3/800/450',
'https://picsum.photos/seed/article4/800/450',
'https://picsum.photos/seed/article5/800/450'
]
/**
* 生成文章列表项
*/
function generateArticleItem(id) {
const title = ARTICLE_TITLES[Math.floor(Math.random() * ARTICLE_TITLES.length)]
const excerpt = ARTICLE_EXCERPTS[Math.floor(Math.random() * ARTICLE_EXCERPTS.length)]
const author = ARTICLE_AUTHORS[Math.floor(Math.random() * ARTICLE_AUTHORS.length)]
const coverUrl = ARTICLE_COVER_IMAGES[Math.floor(Math.random() * ARTICLE_COVER_IMAGES.length)]
// 生成随机日期(最近30天内)
const now = new Date()
const postDate = new Date(now.getTime() - Math.random() * 30 * 24 * 60 * 60 * 1000)
return {
id: id,
post_title: title,
post_excerpt: excerpt,
post_link: '',
post_date: formatDate(postDate),
is_favorite: generateRandomFavorite(),
read_people_count: generateRandomReadCount(),
read_people_percent: generateRandomReadPercent(),
author_name: author
}
}
/**
* Mock: 文章列表 API (listAPI - article)
* @param {Object} params - 请求参数
*/
export async function mockArticleListAPI(params) {
await mockDelay()
const { page = 0, limit = 20, cid, child_id, keyword } = params
const totalPages = 10
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [], total: totalPages * limit } }
}
// 文章分类数据(模拟分类结构)
const ARTICLE_CATEGORIES = {
1: { // 第一层:入职前
id: 1,
category_name: '入职前',
level: 1,
children: [
{ id: 11, category_name: '公司介绍', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 12, category_name: '企业文化', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 13, category_name: '产品知识', level: 2, icon: '', max_depth: 2, list: [] }
]
},
2: { // 第一层:入职中
id: 2,
category_name: '入职中',
level: 1,
children: [
{ id: 21, category_name: '销售技巧', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 22, category_name: '客户服务', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 23, category_name: '合规要求', level: 2, icon: '', max_depth: 2, list: [] }
]
},
3: { // 第一层:入职后
id: 3,
category_name: '入职后',
level: 1,
children: [
{ id: 31, category_name: '进阶培训', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 32, category_name: '管理技能', level: 2, icon: '', max_depth: 2, list: [] }
]
},
// 兼容后端返回的分类 ID
3129684: {
id: 3129684,
category_name: '培训资料',
level: 1,
children: [
{ id: 3129685, category_name: '销售培训', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 3129686, category_name: '产品培训', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 3129687, category_name: '服务培训', level: 2, icon: '', max_depth: 2, list: [] },
{ id: 3129688, category_name: '合规培训', level: 2, icon: '', max_depth: 2, list: [] }
]
}
}
// 如果有分类 ID,生成该分类的子分类数据
let selectedCategory = null
let children = []
let cate = null
if (cid) {
const categoryId = parseInt(cid)
// 查找对应的分类
for (const key in ARTICLE_CATEGORIES) {
if (parseInt(key) === categoryId) {
selectedCategory = ARTICLE_CATEGORIES[key]
break
}
}
// 如果找不到精确匹配,生成默认分类结构(兼容任何分类 ID)
if (!selectedCategory) {
console.log(`[Mock] 未找到分类 ${cid},生成默认分类结构`)
selectedCategory = {
id: categoryId,
category_name: `分类${categoryId}`,
level: 1,
children: [
{ id: categoryId * 10 + 1, category_name: '子分类1', level: 2, icon: '', max_depth: 2, list: [] },
{ id: categoryId * 10 + 2, category_name: '子分类2', level: 2, icon: '', max_depth: 2, list: [] },
{ id: categoryId * 10 + 3, category_name: '子分类3', level: 2, icon: '', max_depth: 2, list: [] }
]
}
}
// 如果找到了,返回其子分类
if (selectedCategory) {
cate = {
id: selectedCategory.id,
category_name: selectedCategory.category_name,
category_parent: 0,
category_description: null
}
// 为每个子分类生成 5-15 篇文章的占位数据
children = selectedCategory.children.map(child => ({
...child,
list: Array.from({ length: Math.floor(Math.random() * 10) + 5 }, (_, i) => ({
name: `${child.category_name}文章${i + 1}`,
value: `https://example.com/article-${child.id}-${i + 1}`,
extension: 'pdf',
post_date: formatDate(new Date()),
is_favorite: generateRandomFavorite(),
id: child.id * 100 + i + 1
}))
}))
}
}
// 如果有分类 ID,返回分类结构;否则返回文章列表
if (cid) {
console.log(`[Mock] mockArticleListAPI - 分类 ${cid},子分类 ${children.length} 个`)
return {
code: 1,
msg: 'success',
data: {
cate: cate || { id: cid || 1, category_name: '文章分类', category_parent: 0, category_description: null },
children: children,
list: [], // 分类模式下,列表为空
total: 0,
max_level: 2
}
}
}
// 无分类 ID 时,返回文章列表
let list = []
const startIndex = page * limit
// 生成基础数据
for (let i = 0; i < limit; i++) {
list.push(generateArticleItem(startIndex + i + 1))
}
// 关键词搜索过滤
if (keyword) {
const searchKeyword = keyword.toLowerCase()
list = list.filter(article =>
article.post_title.toLowerCase().includes(searchKeyword)
)
}
console.log(`[Mock] mockArticleListAPI - 第${page}页,共${list.length}条,关键词:"${keyword || '无'}"`)
return {
code: 1,
msg: 'success',
data: {
cate: { id: 1, category_name: '全部文章', category_parent: 0, category_description: null },
children: [],
list: list,
total: list.length >= limit ? totalPages * limit : list.length,
max_level: 2
}
}
}
/**
* Mock: 热门文章 API (weekHotAPI - article)
* @param {Object} params - 请求参数
*/
export async function mockArticleWeekHotAPI(params) {
await mockDelay()
const { page = 0, limit = 20 } = params
const totalPages = 5
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [] } }
}
const list = []
const startIndex = page * limit
for (let i = 0; i < limit; i++) {
list.push(generateArticleItem(startIndex + i + 1))
}
console.log(`[Mock] mockArticleWeekHotAPI - 第${page}页,共${list.length}条`)
return { code: 1, msg: 'success', data: { list } }
}
/**
* Mock: 文章详情 API (articleDetailAPI)
* @param {Object} params - 请求参数
* @param {string} params.i - 文章ID
*/
export async function mockArticleDetailAPI(params) {
await mockDelay(300, 500) // 详情页延迟稍长,模拟真实加载
const { i } = params
const id = parseInt(i) || 1
const article = generateArticleItem(id)
// 模拟文章内容(HTML格式)
const content = `
<div style="font-size: 16px; line-height: 1.8; color: #333;">
<h2 style="font-size: 20px; font-weight: bold; margin-bottom: 16px;">${article.post_title}</h2>
<p style="margin-bottom: 16px;">${article.post_excerpt}</p>
<h3 style="font-size: 18px; font-weight: bold; margin: 24px 0 12px;">一、背景介绍</h3>
<p style="margin-bottom: 16px;">随着财富管理行业的快速发展,专业知识和技能的重要性日益凸显。本文将为您详细介绍相关的核心概念和实践方法。</p>
<h3 style="font-size: 18px; font-weight: bold; margin: 24px 0 12px;">二、核心要点</h3>
<ul style="margin-bottom: 16px; padding-left: 20px;">
<li>深入理解客户需求,提供个性化解决方案</li>
<li>持续学习行业知识,提升专业能力</li>
<li>建立长期客户关系,增强客户黏性</li>
<li>注重风险控制,保障客户资产安全</li>
</ul>
<h3 style="font-size: 18px; font-weight: bold; margin: 24px 0 12px;">三、实践建议</h3>
<p style="margin-bottom: 16px;">在日常工作中,建议您:</p>
<ol style="margin-bottom: 16px; padding-left: 20px;">
<li>定期参加行业培训和研讨会</li>
<li>建立完善的客户档案系统</li>
<li>与团队成员保持良好沟通</li>
<li>关注市场动态,及时调整策略</li>
</ol>
<h3 style="font-size: 18px; font-weight: bold; margin: 24px 0 12px;">四、总结</h3>
<p style="margin-bottom: 16px;">通过系统的学习和实践,您将能够更好地为客户服务,实现个人和团队的共同成长。</p>
<p style="color: #666; font-size: 14px; margin-top: 24px;">作者:${article.author_name}</p>
<p style="color: #666; font-size: 14px;">发布日期:${article.post_date}</p>
</div>
`
console.log(`[Mock] mockArticleDetailAPI - 文章ID: ${id}`)
return {
code: 1,
msg: 'success',
data: {
...article,
post_content: content
}
}
}
/**
* Mock: 文章收藏列表 API (favoriteAPI - article)
* @param {Object} params - 请求参数
*/
export async function mockArticleFavoriteAPI(params) {
await mockDelay()
const { page = 0, limit = 20, keyword } = params
const totalPages = 3
if (page >= totalPages) {
return { code: 1, msg: 'success', data: { list: [], total: 0 } }
}
let list = []
const startIndex = page * limit
// 生成收藏列表(只返回已收藏的)
for (let i = 0; i < Math.min(limit, 10); i++) {
const article = generateArticleItem(startIndex + i + 1)
// 标记为已收藏,并添加收藏时间
const now = new Date()
const favoriteTime = new Date(now.getTime() - Math.random() * 60 * 24 * 60 * 60 * 1000)
list.push({
id: article.id,
post_title: article.post_title,
post_excerpt: article.post_excerpt,
post_link: article.post_link,
post_date: article.post_date,
favorite_time: formatDate(favoriteTime)
})
}
// 关键词搜索过滤
if (keyword) {
const searchKeyword = keyword.toLowerCase()
list = list.filter(article =>
article.post_title.toLowerCase().includes(searchKeyword)
)
}
console.log(`[Mock] mockArticleFavoriteAPI - 第${page}页,共${list.length}条`)
return {
code: 1,
msg: 'success',
data: {
list: list,
total: list.length >= limit ? totalPages * limit : list.length
}
}
}
// ============================================================================
// 导出统一 Mock API 调用器
// ============================================================================
/**
* Mock API 调用器
* @param {string} apiName - API 名称
* @param {Object} params - 请求参数
* @returns {Promise}
*/
export async function mockAPI(apiName, params) {
switch (apiName) {
case 'weekHotAPI':
return await mockWeekHotAPI(params)
case 'fileListAPI':
return await mockFileListAPI(params)
case 'listAPI':
return await mockProductListAPI(params)
case 'searchAPI':
return await mockSearchAPI(params)
case 'myListAPI':
return await mockMessageListAPI(params)
case 'detailAPI':
return await mockDetailAPI(params)
case 'favoriteListAPI':
return await mockFavoriteListAPI(params)
case 'feedbackListAPI':
return await mockFeedbackListAPI(params)
case 'planListAPI':
return await mockPlanListAPI(params)
// 文章模块 Mock(直接调用独立函数,这里仅为兼容性保留)
case 'articleListAPI':
return await mockArticleListAPI(params)
case 'articleWeekHotAPI':
return await mockArticleWeekHotAPI(params)
case 'articleDetailAPI':
return await mockArticleDetailAPI(params)
case 'articleFavoriteAPI':
return await mockArticleFavoriteAPI(params)
default:
console.warn(`[Mock] 未知的 API: ${apiName}`)
return { code: 0, msg: 'Unknown API', data: null }
}
}
// ============================================================================
// POST 请求 Mock API(AI 测试专用)
// ============================================================================
/**
* 解析 URL 参数
* @param {string} url - 完整 URL
* @param {string} key - 参数名
* @returns {string|null} 参数值
*/
function getUrlParam(url, key) {
const regex = new RegExp(`[?&]${key}=([^&#]*)`)
const match = url.match(regex)
return match ? decodeURIComponent(match[1]) : null
}
/**
* POST Mock 路由器
* @description 根据 URL 中的 a 和 t 参数路由到对应的 Mock 函数
* @param {string} url - 请求 URL
* @param {any} data - 请求体
* @returns {Promise<{code:number, msg:string, data:any}>} Mock 响应
*/
export async function mockPostAPI(url, data) {
await mockDelay(100, 300)
// 解析 action 和 type 参数
const action = getUrlParam(url, 'a')
const type = getUrlParam(url, 't')
console.log(`[Mock] POST 请求 - a=${action}, t=${type}`)
// 路由到具体 Mock 函数
switch (action) {
// 收藏模块
case 'favorite':
if (type === 'add') return mockFavoriteAddAPI(data)
if (type === 'del') return mockFavoriteDelAPI(data)
break
// 埋点模块
case 'event':
if (type === 'add') return mockEventAddAPI(data)
break
// 验证码
case 'sms':
return mockSmsAPI(data)
// 文件上传
case 'upload':
if (type === 'save_file') return mockSaveFileAPI(data)
return mockQiniuTokenAPI(data)
// 小程序授权
case 'openid':
return mockMiniProgramAuthAPI(data)
// 计划书模块
case 'proposal':
if (type === 'add') return mockProposalAddAPI(data)
if (type === 'del') return mockProposalDeleteAPI(data)
if (type === 'view') return mockProposalViewAPI(data)
break
// 用户模块
case 'user':
if (type === 'login') return mockLoginAPI(data)
if (type === 'logout') return mockLogoutAPI(data)
if (type === 'update_profile') return mockUpdateProfileAPI(data)
break
// 反馈模块
case 'feedback':
if (type === 'add') return mockFeedbackAddAPI(data)
break
// 微信支付
case 'icbc_pay_wxamp':
return mockWxPayAPI(data)
default:
console.warn(`[Mock] 未定义的 POST API: a=${action}, t=${type}`)
}
// 默认响应
return { code: 1, msg: 'success (mock)', data: null }
}
// ============================================================================
// 具体实现
// ============================================================================
/**
* Mock: 添加收藏
*/
async function mockFavoriteAddAPI(data) {
console.log('[Mock] favorite/add - data:', data)
return { code: 1, msg: '收藏成功', data: null }
}
/**
* Mock: 取消收藏
*/
async function mockFavoriteDelAPI(data) {
console.log('[Mock] favorite/del - data:', data)
return { code: 1, msg: '取消成功', data: null }
}
/**
* Mock: 埋点
*/
async function mockEventAddAPI(data) {
console.log('[Mock] event/add - data:', data)
return { code: 1, msg: 'success', data: null }
}
/**
* Mock: 发送验证码
*/
async function mockSmsAPI(data) {
console.log('[Mock] sms - data:', data)
return { code: 1, msg: '发送成功', data: null }
}
/**
* Mock: 七牛 Token
*/
async function mockQiniuTokenAPI(data) {
console.log('[Mock] upload (qiniu token) - data:', data)
return {
code: 1,
msg: 'success',
data: {
token: 'mock_qiniu_token_' + Date.now(),
upload_url: 'https://mock.qiniu.com/putb64/-1'
}
}
}
/**
* Mock: 保存文件
*/
async function mockSaveFileAPI(data) {
console.log('[Mock] upload/save_file - data:', data)
return {
code: 1,
msg: '保存成功',
data: {
src: 'https://cdn.ipadbiz.cn/manulife/mock/' + Date.now() + '.jpg'
}
}
}
/**
* Mock: 小程序授权
*/
async function mockMiniProgramAuthAPI(data) {
await mockDelay(500, 800) // 授权延迟稍长
console.log('[Mock] openid (授权) - data:', data)
return {
code: 1,
msg: '授权成功',
data: {
user: {
id: 1,
avatar_url: 'https://cdn.ipadbiz.cn/manulife/avatar/default.png',
name: 'AI测试用户'
}
}
}
}
/**
* Mock: 新增计划书
*/
async function mockProposalAddAPI(data) {
await mockDelay(300, 500)
console.log('[Mock] proposal/add - data:', data)
return {
code: 1,
msg: '创建成功',
data: {
order_id: 'mock_order_' + Date.now()
}
}
}
/**
* Mock: 删除计划书
*/
async function mockProposalDeleteAPI(data) {
console.log('[Mock] proposal/del - data:', data)
return { code: 1, msg: '删除成功', data: null }
}
/**
* Mock: 查看计划书
*/
async function mockProposalViewAPI(data) {
await mockDelay(500, 800)
console.log('[Mock] proposal/view - data:', data)
return {
code: 1,
msg: 'success',
data: {
status: 7, // 已生成
pdf_url: 'https://cdn.ipadbiz.cn/manulife/mock/proposal.pdf'
}
}
}
/**
* Mock: 登录
*/
async function mockLoginAPI(data) {
await mockDelay(500, 800)
console.log('[Mock] user/login - data:', data)
return {
code: 1,
msg: '登录成功',
data: {
userid: 'mock_test_user',
username: 'AI测试用户',
avatar: 'https://cdn.ipadbiz.cn/manulife/avatar/default.png'
}
}
}
/**
* Mock: 登出
*/
async function mockLogoutAPI(data) {
console.log('[Mock] user/logout - data:', data)
return { code: 1, msg: '退出成功', data: null }
}
/**
* Mock: 更新个人资料
*/
async function mockUpdateProfileAPI(data) {
console.log('[Mock] user/update_profile - data:', data)
return { code: 1, msg: '更新成功', data: { ...data } }
}
/**
* Mock: 提交反馈
*/
async function mockFeedbackAddAPI(data) {
console.log('[Mock] feedback/add - data:', data)
return {
code: 1,
msg: '提交成功',
data: { id: Date.now() }
}
}
/**
* Mock: 微信支付
*/
async function mockWxPayAPI(data) {
await mockDelay(500, 1000) // 支付延迟较长
console.log('[Mock] icbc_pay_wxamp - data:', data)
return {
code: 1,
msg: 'success',
data: {
timeStamp: String(Date.now()),
nonceStr: 'mock_nonce_' + Date.now(),
package: 'prepay_id=mock_prepay_id',
signType: 'RSA',
paySign: 'mock_sign_' + Date.now()
}
}
}