mockData.js 29.5 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
/**
 * @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))
}

// ============================================================================
// 真实的测试文件地址(可预览)
// ============================================================================

/**
 * 真实的可预览测试文件地址
 * 来源:GitHub 和其他公开的测试资源
 */
const TEST_FILES = {
  // PDF 文档
  pdf: [
    'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
    'https://www.africau.edu/images/default/sample.pdf',
    'https://www.adobe.com/support/products/reader/pdfs/Reader9Welcome.pdf'
  ],

  // 图片
  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年新产品上线通知',
  '系统升级维护公告',
  '您的保单已生效提醒',
  '理赔进度更新通知',
  '续费提醒',
  '活动邀请:财富管理讲座',
  '客户服务满意度调查',
  '最新培训资料已上线',
  '合规要求更新通知',
  '节日问候与祝福',
  '产品停售通知',
  '核保政策调整',
  '理赔流程优化说明',
  '客户权益保障计划',
  '数字化服务升级公告'
]

/**
 * 生成消息列表项
 */
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)

  return {
    id: id,
    title: title,
    intro: `这是一条关于"${title}"的重要通知,请及时查看详情...`,
    content: `这是一条关于"${title}"的重要通知,请及时查看详情。如需了解更多信息,请联系客服。`,
    create_time: formatDate(createDate),
    is_read: Math.random() > 0.5 ? 1 : 0,
    type: Math.random() > 0.5 ? 'notice' : 'system'
  }
}

/**
 * 格式化日期
 */
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 (消息列表)
 */
export async function mockMessageListAPI(params) {
  await mockDelay()

  const { page = 1, limit = 10 } = params
  const totalPages = 8

  if (page > totalPages) {
    return { code: 1, msg: 'success', data: { list: [] } }
  }

  const list = []
  const startIndex = (page - 1) * limit

  for (let i = 0; i < limit; i++) {
    list.push(generateMessageItem(startIndex + i + 1))
  }

  console.log(`[Mock] myListAPI - 第${page}页,共${list.length}条`)

  return {
    code: 1,
    msg: 'success',
    data: { list }
  }
}

// ============================================================================
// 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 '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 }
  }
}