mockData.js
34.8 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
/**
* @Description: Mock 数据生成工具 - 用于测试分页加载功能
* @Date: 2026-02-08
*
* 支持的 API Mock:
* - weekHotAPI: 周热门资料
* - fileListAPI: 资料列表
* - listAPI: 产品列表
* - searchAPI: 搜索(产品+资料)
* - myListAPI: 消息列表
* - favoriteListAPI: 收藏列表
* - feedbackListAPI: 意见反馈列表
* - planListAPI: 计划书列表(新增)
*/
// ============================================================================
// 工具函数
// ============================================================================
/**
* 生成随机文件大小
* @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: '财产保险' }
]
/**
* 生成产品列表项
*/
function generateProductItem(id) {
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])
}
return {
id: id,
product_name: productName,
name: productName,
cover_image: `https://picsum.photos/seed/product-${id}/400/300`,
recommend: recommend,
tags: tags,
description: '这是一款优质的保险产品,为您的家庭提供全面保障...',
premium: Math.floor(Math.random() * 10000 + 1000),
category_id: Math.floor(Math.random() * 4) + 1
}
}
/**
* 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
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 defaultFiles = []
for (let i = 0; i < 20; i++) {
const productItem = generateProductItem(i + 1)
defaultProducts.push({
...productItem,
id: i + 1,
cover_image: productItem.cover_image
})
const materialItem = generateMaterialItem(i + 1)
// 确保使用真实的测试文件地址
const testFileUrl = getTestFileUrl(materialItem.extension, i)
defaultFiles.push({
...materialItem,
id: i + 1,
fileName: materialItem.fileName,
fileSize: materialItem.size,
learners: `${materialItem.read_people_count}人学习`,
readPeoplePercent: materialItem.read_people_percent,
collected: materialItem.collected,
extension: materialItem.extension,
downloadUrl: testFileUrl, // 覆盖为真实的测试文件地址
title: materialItem.title,
src: materialItem.src
})
}
console.log(`[Mock] searchAPI - 无关键词,返回默认数据:产品${defaultProducts.length}条,资料${defaultFiles.length}条`)
return {
code: 1,
msg: 'success',
data: {
products: { list: defaultProducts, total: defaultProducts.length * 5 },
files: { list: defaultFiles, total: defaultFiles.length * 5 }
}
}
}
const totalPages = 5
if (page >= totalPages) {
return {
code: 1,
msg: 'success',
data: {
products: { list: [], total: 0 },
files: { list: [], total: 0 }
}
}
}
const products = []
const files = []
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 materialItem = generateMaterialItem(startIndex + i + 100)
const materialName = materialItem.name.toLowerCase()
const hasAnyCharMaterial = keywords.length > 0 && keywords.some(k => materialName.includes(k))
const hasBigramMaterial = searchKeyword.length >= 2 && keywords.slice(0, -1).some((k, idx) => materialName.includes(k + keywords[idx + 1]))
if (materialName.includes(searchKeyword) || hasAnyCharMaterial || hasBigramMaterial) {
// 确保使用真实的测试文件地址
const testFileUrl = getTestFileUrl(materialItem.extension, startIndex + i + 100)
files.push({
...materialItem,
id: startIndex + i + 100,
fileName: materialItem.fileName,
fileSize: materialItem.size,
learners: `${materialItem.read_people_count}人学习`,
readPeoplePercent: materialItem.read_people_percent,
collected: materialItem.collected,
extension: materialItem.extension,
downloadUrl: testFileUrl, // 覆盖为真实的测试文件地址
title: materialItem.title,
src: materialItem.src
})
}
}
// 🔧 优化:如果没有匹配到任何数据,返回一些推荐数据
if (products.length === 0 && files.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 materialItem = generateMaterialItem(startIndex + i + 100)
// 确保使用真实的测试文件地址
const testFileUrl = getTestFileUrl(materialItem.extension, startIndex + i + 100)
files.push({
...materialItem,
id: startIndex + i + 100,
fileName: materialItem.fileName,
fileSize: materialItem.size,
learners: `${materialItem.read_people_count}人学习`,
readPeoplePercent: materialItem.read_people_percent,
collected: materialItem.collected,
extension: materialItem.extension,
downloadUrl: testFileUrl, // 覆盖为真实的测试文件地址
title: materialItem.title,
src: materialItem.src
})
}
}
console.log(`[Mock] searchAPI - 第${page}页,关键词"${keyword}",产品${products.length}条,资料${files.length}条`)
return {
code: 1,
msg: 'success',
data: {
products: { list: products, total: products.length * totalPages },
files: { list: files, total: files.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
}
}
}
// ============================================================================
// 导出统一 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)
default:
console.warn(`[Mock] 未知的 API: ${apiName}`)
return { code: 0, msg: 'Unknown API', data: null }
}
}