|
|
@@ -29,11 +29,18 @@ import { ref, onMounted } from 'vue';
|
|
|
import axios from 'axios';
|
|
|
import client from "@/stores/modules/client";
|
|
|
import icpList from '@/utils/ipc';
|
|
|
+import packageJson from '@/../../package.json';
|
|
|
+import { getRouterUrl } from '@/utils/appfun';
|
|
|
|
|
|
const configInfoStore = configInfo();
|
|
|
const router = useRouter();
|
|
|
const loading = ref(true);
|
|
|
|
|
|
+// 版本检查相关
|
|
|
+const currentVersion = ref(packageJson.version);
|
|
|
+const latestVersion = ref('');
|
|
|
+const isLatest = ref(true);
|
|
|
+
|
|
|
|
|
|
import socket from "@/stores/modules/socket";
|
|
|
// 初始化 WebSocket 状态管理
|
|
|
@@ -101,13 +108,88 @@ function openResourceDirectory() {
|
|
|
clientStore.ipc.send(icpList.utils.shellFun, params);
|
|
|
}
|
|
|
|
|
|
+// 版本号比较函数
|
|
|
+const compareVersions = (v1, v2) => {
|
|
|
+ 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;
|
|
|
+};
|
|
|
|
|
|
+// 打开OTA窗口
|
|
|
+const openOTA = () => {
|
|
|
+ const { href } = router.resolve({
|
|
|
+ name: 'ota'
|
|
|
+ });
|
|
|
+
|
|
|
+ clientStore.ipc.removeAllListeners(icpList.utils.openMain);
|
|
|
+ let params = {
|
|
|
+ title: '版本更新',
|
|
|
+ width: 900,
|
|
|
+ height: 700,
|
|
|
+ frame: true,
|
|
|
+ id: 'ota',
|
|
|
+ url: getRouterUrl(href)
|
|
|
+ };
|
|
|
+ clientStore.ipc.send(icpList.utils.openMain, params);
|
|
|
+};
|
|
|
+
|
|
|
+// 获取版本信息并检查更新
|
|
|
+const checkForUpdates = async () => {
|
|
|
+ try {
|
|
|
+ // 添加时间戳避免缓存问题
|
|
|
+ const timestamp = new Date().getTime();
|
|
|
+ const response = await axios.get('https://ossimg.valimart.net/frontend/html/zhihuiyin/version.json', {
|
|
|
+ params: {
|
|
|
+ _t: timestamp
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 确保 response.data 是 JSON 数据
|
|
|
+ let data;
|
|
|
+ if (typeof response.data === 'string') {
|
|
|
+ data = JSON.parse(response.data);
|
|
|
+ } else {
|
|
|
+ data = response.data;
|
|
|
+ }
|
|
|
|
|
|
-// 在组件挂载时执行健康检查
|
|
|
+ if (data.length > 0) {
|
|
|
+ const latest = data[data.length - 1];
|
|
|
+ latestVersion.value = latest.version;
|
|
|
+
|
|
|
+ // 比较版本号
|
|
|
+ isLatest.value = compareVersions(currentVersion.value, latest.version) >= 0;
|
|
|
+
|
|
|
+ // 如果发现新版本,自动打开OTA窗口
|
|
|
+ if (!isLatest.value) {
|
|
|
+ openOTA();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('检查版本更新失败:', error);
|
|
|
+ // 静默处理错误,不影响用户体验
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// 在组件挂载时执行健康检查和版本检查
|
|
|
onMounted(() => {
|
|
|
checkHealth();
|
|
|
+ // 延迟执行版本检查,避免影响健康检查
|
|
|
+ setTimeout(() => {
|
|
|
+ checkForUpdates();
|
|
|
+ }, 1000);
|
|
|
});
|
|
|
</script>
|
|
|
|