From c4c6178b9e896bb455a8be74d22dc42904701ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=95=E5=B1=82=E7=94=A8=E6=88=B7?= Date: Tue, 28 Oct 2025 14:51:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=88=20style:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=8C=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/server/control/index.ts | 187 ++++++++++++++++++++++++ electron/server/index.ts | 6 +- electron/server/netease/index.ts | 4 +- electron/server/unblock/index.ts | 4 +- src/components/Player/FullPlayer.vue | 5 +- src/components/Player/PlayerComment.vue | 4 +- src/components/Player/PlayerData.vue | 2 +- src/utils/player.ts | 136 +++++++++++++---- 8 files changed, 306 insertions(+), 42 deletions(-) create mode 100644 electron/server/control/index.ts diff --git a/electron/server/control/index.ts b/electron/server/control/index.ts new file mode 100644 index 0000000..04babab --- /dev/null +++ b/electron/server/control/index.ts @@ -0,0 +1,187 @@ +import { FastifyInstance } from "fastify"; +import mainWindow from "../../main/windows/main-window"; + +/** + * 播放控制接口 + * @param fastify Fastify 实例 + */ +export const initControlAPI = async (fastify: FastifyInstance) => { + // 播放控制路由前缀 + await fastify.register( + async (fastify) => { + // 播放 + fastify.get("/play", async (_request, reply) => { + try { + const mainWin = mainWindow.getWin(); + if (!mainWin) { + return reply.code(500).send({ + code: 500, + message: "主窗口未找到", + data: null, + }); + } + + mainWin.webContents.send("play"); + + return reply.send({ + code: 200, + message: "播放命令已发送", + data: null, + }); + } catch (error) { + return reply.code(500).send({ + code: 500, + message: "播放失败", + data: error, + }); + } + }); + + // 暂停 + fastify.get("/pause", async (_request, reply) => { + try { + const mainWin = mainWindow.getWin(); + if (!mainWin) { + return reply.code(500).send({ + code: 500, + message: "主窗口未找到", + data: null, + }); + } + + mainWin.webContents.send("pause"); + + return reply.send({ + code: 200, + message: "暂停命令已发送", + data: null, + }); + } catch (error) { + return reply.code(500).send({ + code: 500, + message: "暂停失败", + data: error, + }); + } + }); + + // 播放/暂停切换 + fastify.get("/toggle", async (_request, reply) => { + try { + const mainWin = mainWindow.getWin(); + if (!mainWin) { + return reply.code(500).send({ + code: 500, + message: "主窗口未找到", + data: null, + }); + } + + // 这里可以根据当前播放状态来决定发送 play 还是 pause + // 暂时先发送 toggle 事件,如果渲染进程支持的话 + mainWin.webContents.send("toggle"); + + return reply.send({ + code: 200, + message: "播放/暂停切换命令已发送", + data: null, + }); + } catch (error) { + return reply.code(500).send({ + code: 500, + message: "播放/暂停切换失败", + data: error, + }); + } + }); + + // 下一曲 + fastify.get("/next", async (_request, reply) => { + try { + const mainWin = mainWindow.getWin(); + if (!mainWin) { + return reply.code(500).send({ + code: 500, + message: "主窗口未找到", + data: null, + }); + } + + mainWin.webContents.send("playNext"); + + return reply.send({ + code: 200, + message: "下一曲命令已发送", + data: null, + }); + } catch (error) { + return reply.code(500).send({ + code: 500, + message: "下一曲失败", + data: error, + }); + } + }); + + // 上一曲 + fastify.get("/prev", async (_request, reply) => { + try { + const mainWin = mainWindow.getWin(); + if (!mainWin) { + return reply.code(500).send({ + code: 500, + message: "主窗口未找到", + data: null, + }); + } + + mainWin.webContents.send("playPrev"); + + return reply.send({ + code: 200, + message: "上一曲命令已发送", + data: null, + }); + } catch (error) { + return reply.code(500).send({ + code: 500, + message: "上一曲失败", + data: error, + }); + } + }); + + // 获取播放状态(可选功能) + fastify.get("/status", async (_request, reply) => { + try { + const mainWin = mainWindow.getWin(); + if (!mainWin) { + return reply.code(500).send({ + code: 500, + message: "主窗口未找到", + data: null, + }); + } + + // 这里可以通过 IPC 获取当前播放状态 + // 暂时返回基本信息 + return reply.send({ + code: 200, + message: "获取状态成功", + data: { + connected: true, + window: "available", + }, + }); + } catch (error) { + return reply.code(500).send({ + code: 500, + message: "获取状态失败", + data: error, + }); + } + }); + }, + { prefix: "/control" }, + ); +}; diff --git a/electron/server/index.ts b/electron/server/index.ts index 9fe6d58..fe81d9a 100644 --- a/electron/server/index.ts +++ b/electron/server/index.ts @@ -1,8 +1,9 @@ import { join } from "path"; import { isDev } from "../main/utils/config"; import { serverLog } from "../main/logger"; -import initNcmAPI from "./netease"; -import initUnblockAPI from "./unblock"; +import { initNcmAPI } from "./netease"; +import { initUnblockAPI } from "./unblock"; +import { initControlAPI } from "./control"; import fastifyCookie from "@fastify/cookie"; import fastifyMultipart from "@fastify/multipart"; import fastifyStatic from "@fastify/static"; @@ -47,6 +48,7 @@ const initAppServer = async () => { // 注册接口 server.register(initNcmAPI, { prefix: "/api" }); server.register(initUnblockAPI, { prefix: "/api" }); + server.register(initControlAPI, { prefix: "/api" }); // 启动端口 const port = Number(process.env["VITE_SERVER_PORT"] || 25884); await server.listen({ port }); diff --git a/electron/server/netease/index.ts b/electron/server/netease/index.ts index 04c121e..113c32b 100644 --- a/electron/server/netease/index.ts +++ b/electron/server/netease/index.ts @@ -29,7 +29,7 @@ const getHandler = (name: string, neteaseApi: (params: any) => any) => { }; // 初始化 NcmAPI -const initNcmAPI = async (fastify: FastifyInstance) => { +export const initNcmAPI = async (fastify: FastifyInstance) => { // 主信息 fastify.get("/netease", (_, reply) => { reply.send({ @@ -62,5 +62,3 @@ const initNcmAPI = async (fastify: FastifyInstance) => { serverLog.info("🌐 Register NcmAPI successfully"); }; - -export default initNcmAPI; diff --git a/electron/server/unblock/index.ts b/electron/server/unblock/index.ts index 9df3f58..d04b17f 100644 --- a/electron/server/unblock/index.ts +++ b/electron/server/unblock/index.ts @@ -26,7 +26,7 @@ const getNeteaseSongUrl = async (id: number | string): Promise => }; // 初始化 UnblockAPI -const UnblockAPI = async (fastify: FastifyInstance) => { +export const initUnblockAPI = async (fastify: FastifyInstance) => { // 主信息 fastify.get("/unblock", (_, reply) => { reply.send({ @@ -64,5 +64,3 @@ const UnblockAPI = async (fastify: FastifyInstance) => { serverLog.info("🌐 Register UnblockAPI successfully"); }; - -export default UnblockAPI; diff --git a/src/components/Player/FullPlayer.vue b/src/components/Player/FullPlayer.vue index 7aa14f9..96f525b 100644 --- a/src/components/Player/FullPlayer.vue +++ b/src/components/Player/FullPlayer.vue @@ -246,9 +246,8 @@ onBeforeUnmount(() => { } &.show-comment { .content-left { - position: static; - min-width: 40vw; - max-width: 50vh; + min-width: 40%; + width: 40%; padding: 0 60px; .player-cover, .player-data { diff --git a/src/components/Player/PlayerComment.vue b/src/components/Player/PlayerComment.vue index aa0f0d4..51a585f 100644 --- a/src/components/Player/PlayerComment.vue +++ b/src/components/Player/PlayerComment.vue @@ -118,9 +118,11 @@ onMounted(() => {