From 50374e173e5effb8a09528f20496c45ad5c329be Mon Sep 17 00:00:00 2001 From: imsyy Date: Fri, 27 Sep 2024 09:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E6=89=98=E7=9B=98?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA=20#260?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/tray.ts | 10 +++--- package.json | 2 +- src/api/other.ts | 2 +- src/components/Setting/AboutSetting.vue | 48 ++++++++++++++++++++----- src/utils/helper.ts | 22 +++++++----- src/utils/time.ts | 15 ++++++-- 6 files changed, 74 insertions(+), 25 deletions(-) diff --git a/electron/main/tray.ts b/electron/main/tray.ts index d6e23331..cdeba189 100644 --- a/electron/main/tray.ts +++ b/electron/main/tray.ts @@ -36,11 +36,11 @@ export interface MainTray { // 托盘图标 const trayIcon = (filename: string) => { - const rootPath = isDev - ? join(__dirname, "../../public/icons/tray") - : join(app.getAppPath(), "../../public/icons/tray"); - return nativeImage.createFromPath(join(rootPath, filename)); - // return nativeImage.createFromPath(join(__dirname, `../../public/icons/tray/${filename}`)); + // const rootPath = isDev + // ? join(__dirname, "../../public/icons/tray") + // : join(app.getAppPath(), "../../public/icons/tray"); + // return nativeImage.createFromPath(join(rootPath, filename)); + return nativeImage.createFromPath(join(__dirname, `../../public/icons/tray/${filename}`)); }; // 托盘菜单 diff --git a/package.json b/package.json index 1eeae1f5..289bb126 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "splayer", "productName": "SPlayer", - "version": "3.0.0-alpha.1", + "version": "3.0.0-alpha.2", "description": "A minimalist music player", "main": "./out/main/index.js", "author": "imsyy", diff --git a/src/api/other.ts b/src/api/other.ts index b515cdd5..c3eae1e7 100644 --- a/src/api/other.ts +++ b/src/api/other.ts @@ -5,7 +5,7 @@ export const updateLog = () => { return request({ baseURL: "https://api.github.com", withCredentials: false, - url: "/repos/imsyy/SPlayer/releases/latest", + url: "/repos/imsyy/SPlayer/releases", params: { noCookie: true }, }); }; diff --git a/src/components/Setting/AboutSetting.vue b/src/components/Setting/AboutSetting.vue index 93d6571c..aff431d5 100644 --- a/src/components/Setting/AboutSetting.vue +++ b/src/components/Setting/AboutSetting.vue @@ -13,18 +13,41 @@ 检查更新 - + 最新版本 - {{ updateData?.version || "v0.0.0" }} + {{ newVersion?.version || "v0.0.0" }} - {{ updateData?.time }} + {{ newVersion?.time }} -
+
+
+ 历史版本 + + + + + + + {{ item?.version || "v0.0.0" }} + + {{ item?.time }} + +
+ + + + +
社区与资讯 @@ -64,7 +87,16 @@ const communityData = [ ]; // 更新日志数据 -const updateData = ref(null); +const updateData = ref(null); + +// 最新版本 +const newVersion = computed(() => updateData.value?.[0]); + +// 历史版本 +const oldVersion = computed(() => { + const oldData = updateData.value?.slice(1); + return oldData ? oldData : []; +}); // 检查更新 const checkUpdate = debounce(() => { @@ -95,10 +127,10 @@ onMounted(getUpdateData); border-radius: 6px; } } -#update-data { +.update-data { :deep(.n-card__content) { - flex-direction: column; - align-items: normal; + flex-direction: column !important; + align-items: normal !important; } .version { padding-left: 4px; diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 0db8b9bf..ca11a78f 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -4,6 +4,8 @@ import { h, VNode } from "vue"; import { useClipboard } from "@vueuse/core"; import { getCacheData } from "./cache"; import { updateLog } from "@/api/other"; +import { isEmpty } from "lodash-es"; +import { convertToLocalTime } from "./time"; import { marked } from "marked"; import SvgIcon from "@/components/Global/SvgIcon.vue"; @@ -266,12 +268,16 @@ export const formatForGlobalShortcut = (shortcut: string): string => { }; // 获取更新日志 -export const getUpdateLog = async (): Promise => { - const result = await getCacheData(updateLog, { key: "updateLog", time: 60 }); - return { - version: result.tag_name, - changelog: await marked(result.body), - time: result.published_at, - url: result.html_url, - }; +export const getUpdateLog = async (): Promise => { + const result = await getCacheData(updateLog, { key: "updateLog", time: 10 }); + if (!result || isEmpty(result)) return []; + const updateLogs = await Promise.all( + result.map(async (v: any) => ({ + version: v.tag_name, + changelog: await marked(v.body), + time: convertToLocalTime(v.published_at), + url: v.html_url, + })), + ); + return updateLogs; }; diff --git a/src/utils/time.ts b/src/utils/time.ts index cbec5d29..6a92e246 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -1,9 +1,11 @@ import dayjs from "dayjs"; import duration from "dayjs/plugin/duration"; import relativeTime from "dayjs/plugin/relativeTime"; +import localizedFormat from "dayjs/plugin/localizedFormat"; dayjs.extend(duration); dayjs.extend(relativeTime); +dayjs.extend(localizedFormat); // 秒转为时间 export const secondsToTime = (seconds: number) => { @@ -120,10 +122,19 @@ export const getGreeting = () => { * 是否为当天的6点之前 * @param timestamp 当前时间戳 */ -export const isBeforeSixAM = (timestamp: number) => { +export const isBeforeSixAM = (timestamp: number) => { // 当天的早上 6 点 - const sixAM = dayjs().startOf('day').add(6, 'hour'); + const sixAM = dayjs().startOf("day").add(6, "hour"); // 判断输入时间是否在六点之前 const inputTime = dayjs(timestamp); return inputTime.isBefore(sixAM); }; + +/** + * 将 ISO 8601 格式的时间字符串转换为本地时间 + * @param isoString - ISO 8601 格式的时间字符串 + * @returns + */ +export const convertToLocalTime = (isoString: string): string => { + return dayjs(isoString).format("YYYY-MM-DD HH:mm:ss"); +};