mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-12-03 03:12:51 +08:00
Merge pull request #186 from jiayuLian/feat/per-user-music-accounts
feat(music): 每用户音乐账号 + 管理员账号池(个人优先、分配次之、共享兜底)
This commit is contained in:
27 files changed
+3565
-390
No files matched your search
@@ -0,0 +1,553 @@
|
||||
<template>
|
||||
<!-- Admin console for the music-account pool (#164 follow-up).
|
||||
One row per login the admin owns; each row can be handed to members (or
|
||||
to another admin). See src/web/api/music-accounts.ts for the rules. -->
|
||||
<div class="pool">
|
||||
<p class="hint">
|
||||
这里存放管理员拥有的音乐账号,可以逐个分配给成员。成员自己扫码绑定的账号优先级更高,
|
||||
管理员分配的账号只在他们没绑定自己的账号时生效。播放地址、搜索、歌单都会按被分配的账号获取。
|
||||
</p>
|
||||
|
||||
<!-- Create -->
|
||||
<div class="create-row">
|
||||
<select v-model="draft.platform" class="field">
|
||||
<option v-for="p in platforms" :key="p.platform" :value="p.platform">
|
||||
{{ PLATFORM_LABEL[p.platform] ?? p.platform }}
|
||||
{{ p.playbackSupported ? '' : '(暂不支持按账号播放)' }}
|
||||
</option>
|
||||
</select>
|
||||
<input v-model="draft.label" class="field" placeholder="名称,如 网易云-主号" maxlength="64" />
|
||||
<input
|
||||
v-model.number="draft.capacity"
|
||||
class="field field-narrow"
|
||||
type="number"
|
||||
min="0"
|
||||
title="0 = 可分配给多人;1 = 独占,只能给一个人"
|
||||
placeholder="人数上限"
|
||||
/>
|
||||
<button class="btn primary" :disabled="creating" @click="create">
|
||||
<Icon icon="mdi:plus" /> 添加账号
|
||||
</button>
|
||||
<button class="btn" :disabled="creating" @click="importShared">
|
||||
<Icon icon="mdi:download" /> 从共享账号导入
|
||||
</button>
|
||||
</div>
|
||||
<textarea
|
||||
v-model="draft.cookie"
|
||||
class="field cookie-input"
|
||||
rows="2"
|
||||
placeholder="粘贴该账号的 Cookie(仅保存在服务器,列表里只显示掩码)"
|
||||
></textarea>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
|
||||
<!-- List -->
|
||||
<div v-if="accounts.length === 0" class="empty">还没有添加任何账号</div>
|
||||
|
||||
<div v-for="a in accounts" :key="a.id" class="account" :class="{ disabled: !a.enabled }">
|
||||
<div class="account-head">
|
||||
<div class="account-title">
|
||||
<span class="badge">{{ PLATFORM_LABEL[a.platform] ?? a.platform }}</span>
|
||||
<span class="label">{{ a.label }}</span>
|
||||
<span v-if="a.capacity === 1" class="tag exclusive">独占</span>
|
||||
<span v-else-if="a.capacity > 1" class="tag">最多 {{ a.capacity }} 人</span>
|
||||
<span v-else class="tag">不限人数</span>
|
||||
<span v-if="!a.playbackSupported" class="tag warn">该平台暂不支持按账号播放</span>
|
||||
</div>
|
||||
<div class="account-actions">
|
||||
<button class="btn tiny" @click="probe(a)">
|
||||
<Icon icon="mdi:shield-check" /> 检测
|
||||
</button>
|
||||
<label class="switch" :title="a.enabled ? '已启用' : '已停用'">
|
||||
<input type="checkbox" :checked="a.enabled" @change="toggleEnabled(a)" />
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
<button class="btn tiny danger" @click="remove(a)">
|
||||
<Icon icon="mdi:trash-can-outline" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="account-meta">
|
||||
<span class="mono">{{ a.cookiePreview }}</span>
|
||||
<span v-if="probeResult[a.id]" class="probe" :class="{ ok: probeResult[a.id]!.loggedIn }">
|
||||
{{ probeResult[a.id]!.loggedIn ? `登录有效${probeResult[a.id]!.nickname ? ':' + probeResult[a.id]!.nickname : ''}` : '登录已失效' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="grantees">
|
||||
<span class="grantees-label">已分配:</span>
|
||||
<span v-if="a.grantees.length === 0" class="muted">无</span>
|
||||
<span v-for="g in a.grantees" :key="g.userId" class="chip">
|
||||
{{ g.username }}
|
||||
<button class="chip-x" title="收回" @click="revoke(a, g.userId)">×</button>
|
||||
</span>
|
||||
<select
|
||||
class="field field-narrow assign-select"
|
||||
:value="''"
|
||||
:disabled="assignable(a).length === 0"
|
||||
@change="onAssign(a, $event)"
|
||||
>
|
||||
<option value="">{{ assignable(a).length === 0 ? '已满额' : '+ 分配给…' }}</option>
|
||||
<option v-for="u in assignable(a)" :key="u.id" :value="u.id">
|
||||
{{ u.username }}{{ u.role === 'admin' ? '(管理员)' : '' }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="cookie-edit">
|
||||
<input
|
||||
v-model="cookieDraft[a.id]"
|
||||
class="field"
|
||||
type="password"
|
||||
placeholder="更新 Cookie(登录失效时用)"
|
||||
/>
|
||||
<button class="btn tiny" :disabled="!cookieDraft[a.id]" @click="updateCookie(a)">
|
||||
保存
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { Icon } from '@iconify/vue';
|
||||
import axios from 'axios';
|
||||
|
||||
interface Grantee { userId: string; username: string; grantedAt: string }
|
||||
interface PoolAccount {
|
||||
id: string;
|
||||
platform: string;
|
||||
label: string;
|
||||
cookiePreview: string;
|
||||
capacity: number;
|
||||
enabled: boolean;
|
||||
playbackSupported: boolean;
|
||||
granteeCount: number;
|
||||
grantees: Grantee[];
|
||||
}
|
||||
interface AssignableUser { id: string; username: string; role: string }
|
||||
|
||||
const PLATFORM_LABEL: Record<string, string> = {
|
||||
netease: '网易云',
|
||||
qq: 'QQ音乐',
|
||||
kugou: '酷狗',
|
||||
bilibili: 'B站',
|
||||
};
|
||||
|
||||
const accounts = ref<PoolAccount[]>([]);
|
||||
const users = ref<AssignableUser[]>([]);
|
||||
const platforms = ref<Array<{ platform: string; playbackSupported: boolean }>>([]);
|
||||
const creating = ref(false);
|
||||
const error = ref('');
|
||||
// Default to exclusive: sharing one login between members mixes their
|
||||
// playback history and recommendations, which is almost never intended.
|
||||
const draft = reactive({ platform: 'netease', label: '', cookie: '', capacity: 1 });
|
||||
const cookieDraft = reactive<Record<string, string>>({});
|
||||
const probeResult = ref<Record<string, { loggedIn: boolean; nickname?: string } | undefined>>({});
|
||||
|
||||
const assignable = (a: PoolAccount) => {
|
||||
const held = new Set(a.grantees.map((g) => g.userId));
|
||||
// An exclusive account that already has a holder offers nobody: the API would
|
||||
// answer 409 anyway, so don't dangle options that cannot work.
|
||||
if (a.capacity === 1 && a.granteeCount >= 1) return [];
|
||||
if (a.capacity > 1 && a.granteeCount >= a.capacity) return [];
|
||||
return users.value.filter((u) => !held.has(u.id));
|
||||
};
|
||||
|
||||
const errText = (err: any, fallback: string) => {
|
||||
const e = err?.response?.data?.error;
|
||||
if (e === 'account_exclusive') return '该账号是独占的,请先收回其他成员';
|
||||
if (e === 'account_full') return '该账号已分配满额';
|
||||
if (e === 'account_disabled') return '该账号已停用';
|
||||
if (e === 'no_shared_login') return '机器人还没有登录该平台的共享账号';
|
||||
return e ?? fallback;
|
||||
};
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const res = await axios.get('/api/music-accounts');
|
||||
accounts.value = res.data.accounts ?? [];
|
||||
users.value = res.data.users ?? [];
|
||||
platforms.value = res.data.platforms ?? [];
|
||||
if (!platforms.value.some((p) => p.platform === draft.platform)) {
|
||||
draft.platform = platforms.value[0]?.platform ?? 'netease';
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = errText(err, '加载失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function create() {
|
||||
error.value = '';
|
||||
if (!draft.label.trim() || !draft.cookie.trim()) {
|
||||
error.value = '名称和 Cookie 都要填';
|
||||
return;
|
||||
}
|
||||
creating.value = true;
|
||||
try {
|
||||
await axios.post('/api/music-accounts', {
|
||||
platform: draft.platform,
|
||||
label: draft.label.trim(),
|
||||
cookie: draft.cookie.trim(),
|
||||
capacity: Number(draft.capacity) || 0,
|
||||
});
|
||||
draft.label = '';
|
||||
draft.cookie = '';
|
||||
draft.capacity = 1;
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = errText(err, '添加失败');
|
||||
} finally {
|
||||
creating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function importShared() {
|
||||
error.value = '';
|
||||
creating.value = true;
|
||||
try {
|
||||
await axios.post('/api/music-accounts/import-shared', {
|
||||
platform: draft.platform,
|
||||
label: `${PLATFORM_LABEL[draft.platform] ?? draft.platform} 共享账号`,
|
||||
capacity: Number(draft.capacity) || 0,
|
||||
});
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = errText(err, '导入失败');
|
||||
} finally {
|
||||
creating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleEnabled(a: PoolAccount) {
|
||||
error.value = '';
|
||||
try {
|
||||
await axios.patch(`/api/music-accounts/${a.id}`, { enabled: !a.enabled });
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = errText(err, '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function updateCookie(a: PoolAccount) {
|
||||
error.value = '';
|
||||
try {
|
||||
await axios.patch(`/api/music-accounts/${a.id}`, { cookie: cookieDraft[a.id] });
|
||||
cookieDraft[a.id] = '';
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = errText(err, '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(a: PoolAccount) {
|
||||
if (!confirm(`删除「${a.label}」?已分配给成员的记录会一起收回。`)) return;
|
||||
error.value = '';
|
||||
try {
|
||||
await axios.delete(`/api/music-accounts/${a.id}`);
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = errText(err, '删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function onAssign(a: PoolAccount, ev: Event) {
|
||||
const select = ev.target as HTMLSelectElement;
|
||||
const userId = select.value;
|
||||
select.value = '';
|
||||
if (!userId) return;
|
||||
error.value = '';
|
||||
try {
|
||||
await axios.post(`/api/music-accounts/${a.id}/assign`, { userId });
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = errText(err, '分配失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function revoke(a: PoolAccount, userId: string) {
|
||||
error.value = '';
|
||||
try {
|
||||
await axios.delete(`/api/music-accounts/${a.id}/assign/${userId}`);
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = errText(err, '收回失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function probe(a: PoolAccount) {
|
||||
error.value = '';
|
||||
try {
|
||||
const res = await axios.post(`/api/music-accounts/${a.id}/probe`);
|
||||
probeResult.value[a.id] = { loggedIn: Boolean(res.data.loggedIn), nickname: res.data.nickname };
|
||||
} catch (err) {
|
||||
probeResult.value[a.id] = { loggedIn: false };
|
||||
error.value = errText(err, '检测失败');
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.pool {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
line-height: 1.6;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.create-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.field {
|
||||
padding: 7px 10px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
color: inherit;
|
||||
font-size: 13px;
|
||||
min-width: 0;
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.field-narrow {
|
||||
width: 96px;
|
||||
}
|
||||
|
||||
.cookie-input {
|
||||
width: 100%;
|
||||
resize: vertical;
|
||||
font-family: var(--font-mono, monospace);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 7px 14px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 13px;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
&:hover:not(:disabled) {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
&:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: default;
|
||||
}
|
||||
&.primary {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
&.tiny {
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
&.danger:hover {
|
||||
border-color: #e26a6a;
|
||||
color: #e26a6a;
|
||||
}
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 16px;
|
||||
font-size: 13px;
|
||||
color: var(--text-tertiary);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.account {
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
margin-bottom: 10px;
|
||||
background: var(--hover-bg);
|
||||
&.disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.account-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.account-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 11px;
|
||||
padding: 2px 7px;
|
||||
border-radius: 10px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 11px;
|
||||
color: var(--text-tertiary);
|
||||
&.exclusive {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
&.warn {
|
||||
color: #d19a3a;
|
||||
}
|
||||
}
|
||||
|
||||
.account-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.account-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: var(--font-mono, monospace);
|
||||
}
|
||||
|
||||
.probe {
|
||||
color: #e26a6a;
|
||||
&.ok {
|
||||
color: var(--color-online);
|
||||
}
|
||||
}
|
||||
|
||||
.grantees {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.grantees-label {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.muted {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 2px 8px;
|
||||
font-size: 12px;
|
||||
border-radius: 10px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.chip-x {
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--text-tertiary);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
padding: 0 0 0 2px;
|
||||
&:hover {
|
||||
color: #e26a6a;
|
||||
}
|
||||
}
|
||||
|
||||
.assign-select {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.cookie-edit {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
.field {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 34px;
|
||||
height: 18px;
|
||||
input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
.slider {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: var(--border-color);
|
||||
border-radius: 9px;
|
||||
cursor: pointer;
|
||||
transition: background var(--transition-fast);
|
||||
}
|
||||
.slider::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
left: 2px;
|
||||
top: 2px;
|
||||
background: #fff;
|
||||
border-radius: 50%;
|
||||
transition: transform var(--transition-fast);
|
||||
}
|
||||
input:checked + .slider {
|
||||
background: var(--color-primary);
|
||||
}
|
||||
input:checked + .slider::before {
|
||||
transform: translateX(16px);
|
||||
}
|
||||
}
|
||||
|
||||
.error {
|
||||
margin: 6px 0;
|
||||
font-size: 12px;
|
||||
color: #e26a6a;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,552 @@
|
||||
<template>
|
||||
<!-- The signed-in user's own music accounts (#164 + #164 follow-up).
|
||||
Two ways an account can apply to this user:
|
||||
- 自己扫码绑定 (source = personal) → they may unlink it
|
||||
- 管理员分配 (source = granted) → only the admin can revoke it
|
||||
Everything is read from /api/me/music/<platform>/status; the cookie never
|
||||
reaches the browser. -->
|
||||
<div class="account-card">
|
||||
<div class="account-header">
|
||||
<Icon icon="mdi:account-music" class="account-icon" />
|
||||
<div class="account-info">
|
||||
<div class="account-name">我的音乐账号</div>
|
||||
<div class="account-status" :class="{ logged: status.loggedIn, granted: status.source === 'granted' }">
|
||||
<template v-if="status.source === 'granted'">
|
||||
由管理员分配:{{ status.label || '已分配的账号' }}
|
||||
<template v-if="status.loggedIn && status.nickname">({{ status.nickname }})</template>
|
||||
<template v-else-if="!status.loggedIn">,但登录已失效,请联系管理员</template>
|
||||
</template>
|
||||
<template v-else-if="status.loggedIn">已绑定:{{ status.nickname }}</template>
|
||||
<template v-else-if="status.linked">已绑定,但登录已失效,请重新扫码</template>
|
||||
<template v-else>未绑定 — 使用机器人的共享账号</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Platform switch: only the sources this instance has enabled. -->
|
||||
<div v-if="platforms.length > 1" class="platform-tabs">
|
||||
<button
|
||||
v-for="p in platforms"
|
||||
:key="p"
|
||||
class="platform-tab"
|
||||
:class="{ active: p === current }"
|
||||
@click="selectPlatform(p)"
|
||||
>
|
||||
{{ PLATFORM_LABEL[p] ?? p }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p class="hint">
|
||||
<template v-if="status.source === 'granted'">
|
||||
网页搜索、歌单和每日推荐默认使用管理员分配的账号。自己的绑定优先。
|
||||
</template>
|
||||
<template v-else-if="status.supportsQrLogin">
|
||||
管理员开启每用户独立账号后,可使用你绑定的{{ PLATFORM_LABEL[current] ?? current }}账号查看网页搜索、歌单和推荐。登录凭据保存在服务器。
|
||||
</template>
|
||||
<template v-else>
|
||||
该平台暂不支持在网页端自助绑定,需要账号请联系管理员分配。
|
||||
</template>
|
||||
</p>
|
||||
|
||||
<!-- 网页用哪个账号。只有真的持有个人/分配账号、且管理员开了这个功能时
|
||||
才有得选;否则本来就走共享账号。 -->
|
||||
<div
|
||||
v-if="status.featureEnabled && status.linked"
|
||||
class="account-choice"
|
||||
role="radiogroup"
|
||||
aria-label="网页端使用哪个账号"
|
||||
>
|
||||
<div class="account-choice-title">网页端使用哪个账号</div>
|
||||
|
||||
<div
|
||||
class="account-choice-option"
|
||||
:class="{ active: !status.preferShared }"
|
||||
role="radio"
|
||||
:aria-checked="!status.preferShared"
|
||||
tabindex="0"
|
||||
@click="setPreference(false)"
|
||||
@keydown.enter.prevent="setPreference(false)"
|
||||
@keydown.space.prevent="setPreference(false)"
|
||||
>
|
||||
<span class="account-choice-dot" :class="{ on: !status.preferShared }" />
|
||||
<span class="account-choice-text">
|
||||
<strong>我的账号</strong>
|
||||
<em>
|
||||
{{ status.source === 'granted' ? '管理员分配的账号' : '我扫码绑定的账号' }}
|
||||
</em>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="account-choice-option"
|
||||
:class="{ active: status.preferShared }"
|
||||
role="radio"
|
||||
:aria-checked="status.preferShared"
|
||||
tabindex="0"
|
||||
@click="setPreference(true)"
|
||||
@keydown.enter.prevent="setPreference(true)"
|
||||
@keydown.space.prevent="setPreference(true)"
|
||||
>
|
||||
<span class="account-choice-dot" :class="{ on: status.preferShared }" />
|
||||
<span class="account-choice-text">
|
||||
<strong>共享账号(管理员的)</strong>
|
||||
<em>查看共享账号的歌单和推荐</em>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="account-choice-note">
|
||||
这个选择影响网页端的搜索、歌单和推荐。房间播歌使用机器人共享账号。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="login-methods">
|
||||
<button
|
||||
v-if="status.supportsQrLogin"
|
||||
class="login-btn"
|
||||
:disabled="qr.loading"
|
||||
@click="startQrLogin"
|
||||
>
|
||||
<Icon icon="mdi:qrcode" />
|
||||
{{ status.linked ? '重新扫码绑定' : '扫码绑定' }}
|
||||
</button>
|
||||
<!-- Only the user's OWN login can be removed here; an admin-granted one
|
||||
is managed from Settings → 音乐账号分配. -->
|
||||
<button v-if="status.canUnlink" class="login-btn" @click="unlink">
|
||||
<Icon icon="mdi:link-off" />
|
||||
解除绑定
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="qr.loading" class="qr-loading">
|
||||
<Icon icon="mdi:loading" class="spin" />
|
||||
生成二维码中...
|
||||
</div>
|
||||
<div v-else-if="qr.dataUrl" class="qr-wrap">
|
||||
<img :src="qr.dataUrl" class="qr-image" alt="QR Code" />
|
||||
<div class="qr-status" :class="qr.status">
|
||||
<template v-if="qr.status === 'waiting'">
|
||||
<Icon icon="mdi:cellphone" /> 请使用{{ PLATFORM_LABEL[current] ?? '' }}APP扫码
|
||||
</template>
|
||||
<template v-else-if="qr.status === 'scanned'">
|
||||
<Icon icon="mdi:check" /> 已扫码,请在手机上确认
|
||||
</template>
|
||||
<template v-else-if="qr.status === 'confirmed'">
|
||||
<Icon icon="mdi:check-circle" /> 绑定成功!
|
||||
</template>
|
||||
<template v-else-if="qr.status === 'expired'">
|
||||
<Icon icon="mdi:refresh" /> 二维码已过期
|
||||
<button class="btn-link" @click="startQrLogin">重新生成</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
||||
import { Icon } from '@iconify/vue';
|
||||
import axios from 'axios';
|
||||
import QRCode from 'qrcode';
|
||||
|
||||
const props = withDefaults(defineProps<{ platforms?: string[] }>(), {
|
||||
platforms: () => ['netease'],
|
||||
});
|
||||
|
||||
const PLATFORM_LABEL: Record<string, string> = {
|
||||
netease: '网易云',
|
||||
qq: 'QQ音乐',
|
||||
kugou: '酷狗',
|
||||
bilibili: 'B站',
|
||||
};
|
||||
|
||||
const current = ref(props.platforms[0] ?? 'netease');
|
||||
const status = reactive({
|
||||
linked: false,
|
||||
loggedIn: false,
|
||||
nickname: '',
|
||||
label: '',
|
||||
source: 'none' as 'none' | 'personal' | 'granted',
|
||||
canUnlink: false,
|
||||
supportsQrLogin: false,
|
||||
preferShared: false,
|
||||
featureEnabled: false,
|
||||
});
|
||||
const qr = reactive({
|
||||
loading: false,
|
||||
dataUrl: '',
|
||||
key: '',
|
||||
status: 'waiting' as 'waiting' | 'scanned' | 'confirmed' | 'expired',
|
||||
});
|
||||
const error = ref('');
|
||||
let pollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const base = () => `/api/me/music/${current.value}`;
|
||||
|
||||
function stopPolling() {
|
||||
if (pollTimer) clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const res = await axios.get(`${base()}/status`);
|
||||
status.linked = Boolean(res.data?.linked);
|
||||
status.loggedIn = Boolean(res.data?.loggedIn);
|
||||
status.nickname = res.data?.nickname ?? '';
|
||||
status.label = res.data?.label ?? '';
|
||||
status.source = res.data?.source ?? 'none';
|
||||
status.canUnlink = Boolean(res.data?.canUnlink);
|
||||
status.supportsQrLogin = Boolean(res.data?.supportsQrLogin);
|
||||
status.preferShared = Boolean(res.data?.preferShared);
|
||||
status.featureEnabled = Boolean(res.data?.featureEnabled);
|
||||
} catch {
|
||||
// Leave the last known state
|
||||
}
|
||||
}
|
||||
|
||||
function resetQr() {
|
||||
stopPolling();
|
||||
qr.dataUrl = '';
|
||||
qr.key = '';
|
||||
qr.status = 'waiting';
|
||||
}
|
||||
|
||||
function selectPlatform(p: string) {
|
||||
if (p === current.value) return;
|
||||
current.value = p;
|
||||
error.value = '';
|
||||
resetQr();
|
||||
void refreshStatus();
|
||||
}
|
||||
|
||||
async function startQrLogin() {
|
||||
stopPolling();
|
||||
error.value = '';
|
||||
qr.loading = true;
|
||||
qr.dataUrl = '';
|
||||
qr.status = 'waiting';
|
||||
try {
|
||||
const res = await axios.post(`${base()}/qrcode`);
|
||||
const { qrUrl, qrImg, key } = res.data;
|
||||
qr.key = key;
|
||||
// Dark-on-light only: many in-app scanners can't read an inverted code.
|
||||
qr.dataUrl = qrImg || (await QRCode.toDataURL(qrUrl, {
|
||||
width: 200,
|
||||
margin: 2,
|
||||
color: { dark: '#000000', light: '#ffffff' },
|
||||
}));
|
||||
pollTimer = setInterval(pollQrStatus, 2000);
|
||||
} catch (err: any) {
|
||||
const code = err?.response?.status;
|
||||
error.value = code === 501
|
||||
? '该平台暂不支持自助绑定,请联系管理员分配账号'
|
||||
: (err?.response?.data?.error ?? '二维码生成失败');
|
||||
} finally {
|
||||
qr.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function pollQrStatus() {
|
||||
if (!qr.key) return;
|
||||
try {
|
||||
const res = await axios.get(`${base()}/qrcode/status`, { params: { key: qr.key } });
|
||||
qr.status = res.data.status;
|
||||
if (qr.status === 'confirmed') {
|
||||
stopPolling();
|
||||
await refreshStatus();
|
||||
} else if (qr.status === 'expired') {
|
||||
stopPolling();
|
||||
}
|
||||
} catch {
|
||||
// Ignore poll errors
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch which login playback uses.
|
||||
*
|
||||
* `true` = the bot's shared account (usually the admin's, usually the one with
|
||||
* a membership), `false` = my own / the assigned one. Nothing is unlinked, so
|
||||
* switching back restores the personal account exactly as it was.
|
||||
*/
|
||||
async function setPreference(preferShared: boolean) {
|
||||
if (preferShared === status.preferShared) return;
|
||||
error.value = '';
|
||||
const previous = status.preferShared;
|
||||
status.preferShared = preferShared; // optimistic — the radio must feel instant
|
||||
try {
|
||||
await axios.put(`${base()}/preference`, { preferShared });
|
||||
} catch (err: any) {
|
||||
status.preferShared = previous;
|
||||
const code = err?.response?.status;
|
||||
error.value =
|
||||
code === 409
|
||||
? '管理员未开启「每用户独立账号」,暂时无法切换'
|
||||
: (err?.response?.data?.error ?? '切换失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function unlink() {
|
||||
error.value = '';
|
||||
try {
|
||||
await axios.delete(base());
|
||||
resetQr();
|
||||
await refreshStatus();
|
||||
} catch (err: any) {
|
||||
error.value = err?.response?.data?.error ?? '解除绑定失败';
|
||||
}
|
||||
}
|
||||
|
||||
// Settings can render before the provider list is known; follow it if it changes.
|
||||
watch(
|
||||
() => props.platforms,
|
||||
(list) => {
|
||||
if (list.length > 0 && !list.includes(current.value)) {
|
||||
current.value = list[0];
|
||||
void refreshStatus();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(refreshStatus);
|
||||
onUnmounted(stopPolling);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.account-card {
|
||||
margin-top: 16px;
|
||||
padding: 20px;
|
||||
background: var(--hover-bg);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.account-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.account-icon {
|
||||
font-size: 28px;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.account-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.account-status {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
&.logged { color: var(--color-online); }
|
||||
&.granted { color: var(--text-secondary); }
|
||||
}
|
||||
|
||||
.platform-tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.platform-tab {
|
||||
padding: 5px 12px;
|
||||
font-size: 12px;
|
||||
border-radius: 14px;
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-card);
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
&.active {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
margin: 0 0 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.account-choice {
|
||||
margin: 12px 0 16px;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--border-color, rgba(128, 128, 128, 0.2));
|
||||
border-radius: var(--radius-sm, 8px);
|
||||
}
|
||||
|
||||
.account-choice-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.account-choice-option {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 8px 10px;
|
||||
border-radius: var(--radius-sm, 8px);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease;
|
||||
|
||||
& + & {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--hover-bg-strong, rgba(128, 128, 128, 0.08));
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: var(--hover-bg-strong, rgba(128, 128, 128, 0.1));
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.account-choice-dot {
|
||||
flex: 0 0 auto;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-top: 2px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid var(--text-secondary, #888);
|
||||
position: relative;
|
||||
|
||||
&.on {
|
||||
border-color: var(--color-primary);
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 2px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.account-choice-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
|
||||
strong {
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
em {
|
||||
font-style: normal;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scope disclaimer: the radio above governs the web player only. Members were
|
||||
reading "共享账号" as "房间里也用这个" — which is true, but for the opposite
|
||||
reason, so it needs saying. */
|
||||
.account-choice-note {
|
||||
margin-top: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px dashed var(--border-color, rgba(128, 128, 128, 0.2));
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--text-secondary);
|
||||
|
||||
code {
|
||||
font-size: 11px;
|
||||
padding: 1px 4px;
|
||||
border-radius: 3px;
|
||||
background: var(--hover-bg-strong, rgba(128, 128, 128, 0.12));
|
||||
}
|
||||
}
|
||||
|
||||
.login-methods {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
&:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); }
|
||||
&:disabled { opacity: 0.6; cursor: default; }
|
||||
}
|
||||
|
||||
.qr-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.qr-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.qr-image {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
border-radius: var(--radius-md);
|
||||
border: 2px solid var(--border-color);
|
||||
}
|
||||
|
||||
.qr-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
&.confirmed { color: var(--color-online); }
|
||||
}
|
||||
|
||||
.btn-link {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-primary);
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #e26a6a;
|
||||
}
|
||||
|
||||
.spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
@@ -1,261 +0,0 @@
|
||||
<template>
|
||||
<!-- The signed-in user's own NetEase account, used for THEIR 私人FM instead
|
||||
of the bot's shared login (#164). -->
|
||||
<div class="account-card">
|
||||
<div class="account-header">
|
||||
<Icon icon="mdi:radio" class="account-icon" />
|
||||
<div class="account-info">
|
||||
<div class="account-name">我的网易云账号(私人FM)</div>
|
||||
<div class="account-status" :class="{ logged: status.loggedIn }">
|
||||
<template v-if="status.loggedIn">已绑定: {{ status.nickname }}</template>
|
||||
<template v-else-if="status.linked">已绑定,但登录已失效,请重新扫码</template>
|
||||
<template v-else>未绑定 — 私人FM使用机器人的共享账号</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="hint">
|
||||
绑定后,你在网页端开启的网易云私人FM会按你自己的口味推荐;其他人不受影响。
|
||||
仅保存在服务器上,不会显示给任何人。
|
||||
</p>
|
||||
|
||||
<div class="login-methods">
|
||||
<button class="login-btn" :disabled="qr.loading" @click="startQrLogin">
|
||||
<Icon icon="mdi:qrcode" />
|
||||
{{ status.linked ? '重新扫码绑定' : '扫码绑定' }}
|
||||
</button>
|
||||
<button v-if="status.linked" class="login-btn" @click="unlink">
|
||||
<Icon icon="mdi:link-off" />
|
||||
解除绑定
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="qr.loading" class="qr-loading">
|
||||
<Icon icon="mdi:loading" class="spin" />
|
||||
生成二维码中...
|
||||
</div>
|
||||
<div v-else-if="qr.dataUrl" class="qr-wrap">
|
||||
<img :src="qr.dataUrl" class="qr-image" alt="QR Code" />
|
||||
<div class="qr-status" :class="qr.status">
|
||||
<template v-if="qr.status === 'waiting'">
|
||||
<Icon icon="mdi:cellphone" /> 请使用网易云音乐APP扫码
|
||||
</template>
|
||||
<template v-else-if="qr.status === 'scanned'">
|
||||
<Icon icon="mdi:check" /> 已扫码,请在手机上确认
|
||||
</template>
|
||||
<template v-else-if="qr.status === 'confirmed'">
|
||||
<Icon icon="mdi:check-circle" /> 绑定成功!
|
||||
</template>
|
||||
<template v-else-if="qr.status === 'expired'">
|
||||
<Icon icon="mdi:refresh" /> 二维码已过期
|
||||
<button class="btn-link" @click="startQrLogin">重新生成</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref } from 'vue';
|
||||
import { Icon } from '@iconify/vue';
|
||||
import axios from 'axios';
|
||||
import QRCode from 'qrcode';
|
||||
|
||||
const BASE = '/api/me/music/netease';
|
||||
|
||||
const status = reactive({ linked: false, loggedIn: false, nickname: '' });
|
||||
const qr = reactive({
|
||||
loading: false,
|
||||
dataUrl: '',
|
||||
key: '',
|
||||
status: 'waiting' as 'waiting' | 'scanned' | 'confirmed' | 'expired',
|
||||
});
|
||||
const error = ref('');
|
||||
let pollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function stopPolling() {
|
||||
if (pollTimer) clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const res = await axios.get(`${BASE}/status`);
|
||||
status.linked = Boolean(res.data?.linked);
|
||||
status.loggedIn = Boolean(res.data?.loggedIn);
|
||||
status.nickname = res.data?.nickname ?? '';
|
||||
} catch {
|
||||
// Leave the last known state
|
||||
}
|
||||
}
|
||||
|
||||
async function startQrLogin() {
|
||||
stopPolling();
|
||||
error.value = '';
|
||||
qr.loading = true;
|
||||
qr.dataUrl = '';
|
||||
qr.status = 'waiting';
|
||||
try {
|
||||
const res = await axios.post(`${BASE}/qrcode`);
|
||||
const { qrUrl, qrImg, key } = res.data;
|
||||
qr.key = key;
|
||||
// Dark-on-light only: many in-app scanners can't read an inverted code.
|
||||
qr.dataUrl = qrImg || (await QRCode.toDataURL(qrUrl, {
|
||||
width: 200,
|
||||
margin: 2,
|
||||
color: { dark: '#000000', light: '#ffffff' },
|
||||
}));
|
||||
pollTimer = setInterval(pollQrStatus, 2000);
|
||||
} catch (err: any) {
|
||||
error.value = err?.response?.data?.error ?? '二维码生成失败';
|
||||
} finally {
|
||||
qr.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function pollQrStatus() {
|
||||
if (!qr.key) return;
|
||||
try {
|
||||
const res = await axios.get(`${BASE}/qrcode/status`, { params: { key: qr.key } });
|
||||
qr.status = res.data.status;
|
||||
if (qr.status === 'confirmed') {
|
||||
stopPolling();
|
||||
await refreshStatus();
|
||||
} else if (qr.status === 'expired') {
|
||||
stopPolling();
|
||||
}
|
||||
} catch {
|
||||
// Ignore poll errors
|
||||
}
|
||||
}
|
||||
|
||||
async function unlink() {
|
||||
error.value = '';
|
||||
try {
|
||||
await axios.delete(BASE);
|
||||
stopPolling();
|
||||
qr.dataUrl = '';
|
||||
await refreshStatus();
|
||||
} catch (err: any) {
|
||||
error.value = err?.response?.data?.error ?? '解除绑定失败';
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(refreshStatus);
|
||||
onUnmounted(stopPolling);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.account-card {
|
||||
margin-top: 16px;
|
||||
padding: 20px;
|
||||
background: var(--hover-bg);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.account-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.account-icon {
|
||||
font-size: 28px;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.account-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.account-status {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
&.logged { color: var(--color-online); }
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
margin: 0 0 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.login-methods {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
&:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); }
|
||||
&:disabled { opacity: 0.6; cursor: default; }
|
||||
}
|
||||
|
||||
.qr-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.qr-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.qr-image {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
border-radius: var(--radius-md);
|
||||
border: 2px solid var(--border-color);
|
||||
}
|
||||
|
||||
.qr-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
&.confirmed { color: var(--color-online); }
|
||||
}
|
||||
|
||||
.btn-link {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-primary);
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #e26a6a;
|
||||
}
|
||||
|
||||
.spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
@@ -116,7 +116,10 @@
|
||||
</form>
|
||||
<p v-if="ownPwError" class="user-error">{{ ownPwError }}</p>
|
||||
<p v-if="ownPwSuccess" class="user-success">{{ ownPwSuccess }}</p>
|
||||
<PersonalNeteaseAccount v-if="providerOn('netease') && !session.isGuest.value" />
|
||||
<PersonalMusicAccount
|
||||
v-if="!session.isGuest.value && personalPlatforms.length > 0"
|
||||
:platforms="personalPlatforms"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<!-- Bot Management (create/edit/delete/start-stop) requires bot.manage -->
|
||||
@@ -973,6 +976,29 @@
|
||||
@change="savePlayKeepsQueue"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<!-- Admin-only: per-user music accounts. Off by default so an existing
|
||||
deployment keeps sharing one login with everyone. -->
|
||||
<label v-if="session.isAdmin.value" class="profile-toggle behavior-toggle">
|
||||
<div class="profile-toggle-text">
|
||||
<div class="profile-toggle-label">每个成员使用自己的音乐账号</div>
|
||||
<div class="profile-toggle-hint">开启后,成员可用自己绑定或管理员分配的账号访问网页搜索、歌单和推荐。仅网易云支持成员扫码绑定。没有专属账号时使用机器人共享账号。房间播歌始终使用共享账号。</div>
|
||||
</div>
|
||||
<input
|
||||
v-model="perUserMusicAccounts"
|
||||
type="checkbox"
|
||||
class="profile-toggle-switch"
|
||||
@change="savePerUserMusicAccounts"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<!-- Admin-only: the pool of logins that can be handed to members. Only
|
||||
meaningful while the toggle above is on. -->
|
||||
<div v-if="session.isAdmin.value && perUserMusicAccounts" class="pool-wrap">
|
||||
<div class="pool-title">音乐账号分配</div>
|
||||
<div class="pool-hint">添加管理员拥有的账号,分配给指定成员(也可以分配给其他管理员)。成员自己绑定的账号优先;未绑定的人使用分配给自己的账号;都没有时回到机器人的共享账号。这些账号同样只作用于<strong>网页端</strong>,房间里的播放始终用共享账号。</div>
|
||||
<MusicAccountPool />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Guest Mode (admin only) -->
|
||||
@@ -1311,7 +1337,8 @@ import axios from 'axios';
|
||||
import AvatarUpload from '../components/AvatarUpload.vue';
|
||||
import CustomAvatarRow from '../components/CustomAvatarRow.vue';
|
||||
import AccentColorPicker from '../components/AccentColorPicker.vue';
|
||||
import PersonalNeteaseAccount from '../components/PersonalNeteaseAccount.vue';
|
||||
import PersonalMusicAccount from '../components/PersonalMusicAccount.vue';
|
||||
import MusicAccountPool from '../components/MusicAccountPool.vue';
|
||||
import QRCode from 'qrcode';
|
||||
import { usePlayerStore } from '../stores/player.js';
|
||||
import { useSession } from '../composables/useSession.js';
|
||||
@@ -1452,6 +1479,11 @@ function providerOn(p: string): boolean {
|
||||
return enabledProviders.value.length === 0 || enabledProviders.value.includes(p);
|
||||
}
|
||||
|
||||
// Sources the member can hold a personal account for. Only enabled ones are
|
||||
// offered — /api/me/music serves a fixed set regardless of config.
|
||||
const PERSONAL_PLATFORMS = ['netease', 'qq', 'kugou', 'bilibili'] as const;
|
||||
const personalPlatforms = computed(() => PERSONAL_PLATFORMS.filter((p) => providerOn(p)));
|
||||
|
||||
// --- Default music source (issue #126) ---
|
||||
// Chinese labels for the gateable providers, shown in the default-source select.
|
||||
const PROVIDER_LABELS: Record<string, string> = {
|
||||
@@ -1846,6 +1878,8 @@ const localAudioEnabled = ref(true);
|
||||
// Saved-queues + play-keeps-queue toggles (#119), both default OFF.
|
||||
const savedQueuesEnabled = ref(false);
|
||||
const playKeepsQueue = ref(false);
|
||||
// Per-user music accounts (#164 follow-up). Admin toggle, default OFF.
|
||||
const perUserMusicAccounts = ref(false);
|
||||
|
||||
function normalizeVoiceDuckingVolume(): number {
|
||||
const raw = voiceDuckingVolumePercent.value as number | string;
|
||||
@@ -1886,6 +1920,7 @@ async function loadIdleTimeout() {
|
||||
localAudioEnabled.value = res.data.localAudioEnabled ?? true;
|
||||
savedQueuesEnabled.value = res.data.savedQueuesEnabled ?? false;
|
||||
playKeepsQueue.value = res.data.playKeepsQueue ?? false;
|
||||
perUserMusicAccounts.value = res.data.perUserMusicAccounts ?? false;
|
||||
store.savedQueuesEnabled = savedQueuesEnabled.value;
|
||||
applyGuestModeFromServer(res.data.guestMode);
|
||||
applyAdminGroupsFromServer(res.data.adminGroups);
|
||||
@@ -1964,6 +1999,15 @@ async function savePlayKeepsQueue() {
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
async function savePerUserMusicAccounts() {
|
||||
try {
|
||||
const res = await axios.post('/api/bot/settings', {
|
||||
perUserMusicAccounts: perUserMusicAccounts.value,
|
||||
});
|
||||
perUserMusicAccounts.value = res.data.perUserMusicAccounts ?? perUserMusicAccounts.value;
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
// --- Spotify (Connect) settings (§8) ---
|
||||
// NOTE: This card's status comes ONLY from /api/spotify/status (playback OAuth
|
||||
// `authorized`). It is deliberately NOT wired to the player store's
|
||||
@@ -3404,6 +3448,26 @@ onUnmounted(() => {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
// --- Music account pool (admin) ---
|
||||
.pool-wrap {
|
||||
margin-top: 8px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px dashed var(--border-color);
|
||||
}
|
||||
|
||||
.pool-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.pool-hint {
|
||||
font-size: 12px;
|
||||
color: var(--text-tertiary);
|
||||
line-height: 1.5;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
font-size: 13px;
|
||||
color: var(--text-tertiary);
|
||||
|
||||
Reference in new issue
Block a user