mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
feat: 双击播放队列中的歌曲(不清空队列)
- 新增 POST /api/player/:botId/play-at 端点,跳转到队列指定索引 - 使用 queue.playAt(index) + resolveAndPlay,保留队列完整 - Queue.vue 添加 @dblclick 处理,双击即播放对应歌曲 - 添加 store.playAtIndex() action Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
17991b936a
commit
d8c0911593
3 files changed
+41
No files matched your search
@@ -142,6 +142,32 @@ export function createPlayerRouter(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Jump to a specific index in the queue (without clearing it)
|
||||||
|
router.post("/:botId/play-at", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const bot = (req as any).bot;
|
||||||
|
const { index } = req.body;
|
||||||
|
if (typeof index !== "number" || index < 0) {
|
||||||
|
res.status(400).json({ error: "index is required" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const queue = bot.getQueueManager();
|
||||||
|
const song = queue.playAt(index);
|
||||||
|
if (!song) {
|
||||||
|
res.status(400).json({ error: "Invalid queue index" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ok = await bot.resolveAndPlay(song);
|
||||||
|
if (!ok) {
|
||||||
|
res.json({ message: `Cannot play: ${song.name}` });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.json({ message: `Now playing: ${song.name} - ${song.artist}` });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: (err as Error).message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.post("/:botId/playlist", async (req, res) => {
|
router.post("/:botId/playlist", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const bot = (req as any).bot;
|
const bot = (req as any).bot;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
:key="`${song.id}-${i}`"
|
:key="`${song.id}-${i}`"
|
||||||
class="queue-item"
|
class="queue-item"
|
||||||
:class="{ active: store.currentSong?.id === song.id }"
|
:class="{ active: store.currentSong?.id === song.id }"
|
||||||
|
@dblclick="playAtIndex(i)"
|
||||||
>
|
>
|
||||||
<CoverArt :url="song.coverUrl" :size="32" :radius="4" />
|
<CoverArt :url="song.coverUrl" :size="32" :radius="4" />
|
||||||
<div class="queue-song-info">
|
<div class="queue-song-info">
|
||||||
@@ -54,6 +55,11 @@ watch(() => props.open, (isOpen) => {
|
|||||||
if (isOpen) store.fetchQueue();
|
if (isOpen) store.fetchQueue();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function playAtIndex(index: number) {
|
||||||
|
await store.playAtIndex(index);
|
||||||
|
await store.fetchQueue();
|
||||||
|
}
|
||||||
|
|
||||||
async function removeSong(index: number) {
|
async function removeSong(index: number) {
|
||||||
if (!store.activeBotId) return;
|
if (!store.activeBotId) return;
|
||||||
try {
|
try {
|
||||||
@@ -130,6 +136,8 @@ async function removeSong(index: number) {
|
|||||||
padding: 8px;
|
padding: 8px;
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
transition: background var(--transition-fast);
|
transition: background var(--transition-fast);
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: var(--hover-bg);
|
background: var(--hover-bg);
|
||||||
|
|||||||
@@ -172,6 +172,13 @@ export const usePlayerStore = defineStore('player', {
|
|||||||
setTimeout(() => this.syncElapsed(), 500);
|
setTimeout(() => this.syncElapsed(), 500);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async playAtIndex(index: number) {
|
||||||
|
if (!this.activeBotId) return;
|
||||||
|
await axios.post(`/api/player/${this.activeBotId}/play-at`, { index });
|
||||||
|
this.serverElapsed = 0;
|
||||||
|
this._syncAfterAction();
|
||||||
|
},
|
||||||
|
|
||||||
async play(query: string, platform = 'netease') {
|
async play(query: string, platform = 'netease') {
|
||||||
if (!this.activeBotId) return;
|
if (!this.activeBotId) return;
|
||||||
await axios.post(`/api/player/${this.activeBotId}/play`, { query, platform });
|
await axios.post(`/api/player/${this.activeBotId}/play`, { query, platform });
|
||||||
|
|||||||
Reference in new issue
Block a user