version.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * 版本管理工具
  3. * 用于管理更新通知的版本号
  4. */
  5. // 当前版本号
  6. export const CURRENT_VERSION = '1.1.0';
  7. // 版本历史记录
  8. export const VERSION_HISTORY = [
  9. {
  10. version: '1.1.0',
  11. date: '2025-12-05',
  12. description: '应用广场优化、知识库增强、智能问答改进',
  13. },
  14. ];
  15. /**
  16. * 获取当前版本号
  17. */
  18. export const getCurrentVersion = (): string => {
  19. return CURRENT_VERSION;
  20. };
  21. /**
  22. * 比较版本号
  23. * @param v1
  24. * @param v2
  25. * @returns
  26. */
  27. export const compareVersions = (v1: string, v2: string): number => {
  28. const parts1 = v1.split('.').map(Number);
  29. const parts2 = v2.split('.').map(Number);
  30. for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
  31. const num1 = parts1[i] || 0;
  32. const num2 = parts2[i] || 0;
  33. if (num1 > num2) return 1;
  34. if (num1 < num2) return -1;
  35. }
  36. return 0;
  37. };
  38. /**
  39. *
  40. * @param lastViewedVersion
  41. * @returns true: 需要显示, false: 不需要显示
  42. */
  43. export const shouldShowUpdate = (lastViewedVersion: string | null): boolean => {
  44. if (!lastViewedVersion) return true;
  45. return compareVersions(CURRENT_VERSION, lastViewedVersion) > 0;
  46. };
  47. /**
  48. * 获取版本历史
  49. */
  50. export const getVersionHistory = () => {
  51. return VERSION_HISTORY;
  52. };
  53. /**
  54. * 重置查看记录
  55. */
  56. export const resetViewedVersion = (): void => {
  57. localStorage.removeItem('lastViewedUpdateVersion');
  58. };
  59. /**
  60. * 强制禁用更新通知
  61. */
  62. export const disableUpdateNotification = (): void => {
  63. localStorage.setItem('disableUpdateNotification', 'true');
  64. };
  65. /**
  66. * 启用更新通知
  67. */
  68. export const enableUpdateNotification = (): void => {
  69. localStorage.removeItem('disableUpdateNotification');
  70. };
  71. /**
  72. * 检查更新通知是否被禁用
  73. */
  74. export const isUpdateNotificationDisabled = (): boolean => {
  75. return localStorage.getItem('disableUpdateNotification') === 'true';
  76. };