version.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * 版本管理工具
  3. * 用于管理更新通知的版本号
  4. */
  5. // 当前版本号
  6. export const CURRENT_VERSION = '1.2.1';
  7. // 版本历史记录
  8. export const VERSION_HISTORY = [
  9. {
  10. version: '1.2.1',
  11. date: '2025-12-11',
  12. description: '本次更新涉及知识库中的一些功能改进,解决了使用过程中的一些体验问题。',
  13. },
  14. {
  15. version: '1.1',
  16. date: '2025-11-04',
  17. description: '应用广场优化、知识库增强、智能问答改进',
  18. },
  19. ];
  20. /**
  21. * 获取当前版本号
  22. */
  23. export const getCurrentVersion = (): string => {
  24. return CURRENT_VERSION;
  25. };
  26. /**
  27. * 比较版本号
  28. * @param v1
  29. * @param v2
  30. * @returns
  31. */
  32. export const compareVersions = (v1: string, v2: string): number => {
  33. const parts1 = v1.split('.').map(Number);
  34. const parts2 = v2.split('.').map(Number);
  35. for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
  36. const num1 = parts1[i] || 0;
  37. const num2 = parts2[i] || 0;
  38. if (num1 > num2) return 1;
  39. if (num1 < num2) return -1;
  40. }
  41. return 0;
  42. };
  43. /**
  44. *
  45. * @param lastViewedVersion
  46. * @returns true: 需要显示, false: 不需要显示
  47. */
  48. export const shouldShowUpdate = (lastViewedVersion: string | null): boolean => {
  49. if (!lastViewedVersion) return true;
  50. // 三重保险:严格相等 + 字符串比较 + 版本号比较
  51. const isStrictEqual = CURRENT_VERSION === lastViewedVersion;
  52. const isStringEqual = String(CURRENT_VERSION) === String(lastViewedVersion);
  53. const isVersionEqual = compareVersions(CURRENT_VERSION, lastViewedVersion) === 0;
  54. // 只有三个条件都满足时才不显示,否则都要弹
  55. return !(isStrictEqual && isStringEqual && isVersionEqual);
  56. };
  57. /**
  58. * 获取版本历史
  59. */
  60. export const getVersionHistory = () => {
  61. return VERSION_HISTORY;
  62. };
  63. /**
  64. * 重置查看记录
  65. */
  66. export const resetViewedVersion = (): void => {
  67. localStorage.removeItem('lastViewedUpdateVersion');
  68. };
  69. /**
  70. * 强制禁用更新通知
  71. */
  72. export const disableUpdateNotification = (): void => {
  73. localStorage.setItem('disableUpdateNotification', 'true');
  74. };
  75. /**
  76. * 启用更新通知
  77. */
  78. export const enableUpdateNotification = (): void => {
  79. localStorage.removeItem('disableUpdateNotification');
  80. };
  81. /**
  82. * 检查更新通知是否被禁用
  83. */
  84. export const isUpdateNotificationDisabled = (): boolean => {
  85. return localStorage.getItem('disableUpdateNotification') === 'true';
  86. };