| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /**
- * 版本管理工具
- * 用于管理更新通知的版本号
- */
- // 当前版本号
- export const CURRENT_VERSION = '1.2';
- // 版本历史记录
- export const VERSION_HISTORY = [
- {
- version: '1.2',
- date: '2025-12-11',
- description: '本次更新涉及知识库中的一些功能改进,解决了使用过程中的一些体验问题。',
- },
- {
- version: '1.1',
- date: '2025-11-04',
- description: '应用广场优化、知识库增强、智能问答改进',
- },
- ];
- /**
- * 获取当前版本号
- */
- export const getCurrentVersion = (): string => {
- return CURRENT_VERSION;
- };
- /**
- * 比较版本号
- * @param v1
- * @param v2
- * @returns
- */
- export const compareVersions = (v1: string, v2: string): number => {
- const parts1 = v1.split('.').map(Number);
- const parts2 = v2.split('.').map(Number);
-
- for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
- const num1 = parts1[i] || 0;
- const num2 = parts2[i] || 0;
-
- if (num1 > num2) return 1;
- if (num1 < num2) return -1;
- }
-
- return 0;
- };
- /**
- *
- * @param lastViewedVersion
- * @returns true: 需要显示, false: 不需要显示
- */
- export const shouldShowUpdate = (lastViewedVersion: string | null): boolean => {
- if (!lastViewedVersion) return true;
- // 三重保险:严格相等 + 字符串比较 + 版本号比较
- const isStrictEqual = CURRENT_VERSION === lastViewedVersion;
- const isStringEqual = String(CURRENT_VERSION) === String(lastViewedVersion);
- const isVersionEqual = compareVersions(CURRENT_VERSION, lastViewedVersion) === 0;
- // 只有三个条件都满足时才不显示,否则都要弹
- return !(isStrictEqual && isStringEqual && isVersionEqual);
- };
- /**
- * 获取版本历史
- */
- export const getVersionHistory = () => {
- return VERSION_HISTORY;
- };
- /**
- * 重置查看记录
- */
- export const resetViewedVersion = (): void => {
- localStorage.removeItem('lastViewedUpdateVersion');
- };
- /**
- * 强制禁用更新通知
- */
- export const disableUpdateNotification = (): void => {
- localStorage.setItem('disableUpdateNotification', 'true');
- };
- /**
- * 启用更新通知
- */
- export const enableUpdateNotification = (): void => {
- localStorage.removeItem('disableUpdateNotification');
- };
- /**
- * 检查更新通知是否被禁用
- */
- export const isUpdateNotificationDisabled = (): boolean => {
- return localStorage.getItem('disableUpdateNotification') === 'true';
- };
|