mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
feat(kaak): add trusted server switcher and channel tree
This commit is contained in:
1 parent
17fb27b89a
commit
b13bdf1eb2
24 files changed
+733
-514
No files matched your search
@@ -66,7 +66,8 @@
|
||||
<path v-else-if="name === 'share'" d="M4 12v7a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7M16 6l-4-4-4 4m4-4v13" />
|
||||
<path v-else-if="name === 'copy'" d="M8 8V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-3M6 8h7a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z" />
|
||||
<path v-else-if="name === 'close'" d="m6 6 12 12M18 6 6 18" />
|
||||
<path v-else-if="name === 'more'" d="M5 12h.01M12 12h.01M19 12h.01" stroke-width="3" />
|
||||
<path v-else-if="name === 'more'" d="M5 12h.01M12 12h.01M19 12h.01" stroke-width="3" />
|
||||
<path v-else-if="name === 'menu'" d="M4 6h16M4 12h16M4 18h16" />
|
||||
<path v-else-if="name === 'refresh'" d="M20 11a8 8 0 0 0-14-4L4 9m0-4v4h4M4 13a8 8 0 0 0 14 4l2-2m0 4v-4h-4" />
|
||||
<path v-else-if="name === 'lock'" d="M6 10h12v10H6zM8 10V7a4 4 0 0 1 8 0v3" />
|
||||
<path v-else-if="name === 'users'" d="M16 21v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2m6-10a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm6-7a4 4 0 0 1 0 7m2 5h1a4 4 0 0 1 4 4v1" />
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<template>
|
||||
<ul
|
||||
v-if="tree.length"
|
||||
class="ws-voice-channel-tree"
|
||||
data-ws-part="voice.channel-tree.list"
|
||||
role="tree"
|
||||
aria-label="语音频道 / Voice channels"
|
||||
>
|
||||
<VoiceChannelTreeItem
|
||||
v-for="node in tree"
|
||||
:key="node.channel.id"
|
||||
:node="node"
|
||||
:depth="0"
|
||||
:current-channel-id="currentChannelId"
|
||||
:selected-channel-id="selectedChannelId"
|
||||
:expanded-ids="expandedIds"
|
||||
:avatar-style="avatarStyle"
|
||||
:avatar-initial="avatarInitial"
|
||||
:is-speaking="isSpeaking"
|
||||
:t="t"
|
||||
@toggle="toggleExpanded"
|
||||
@select="selectedChannelId = $event"
|
||||
@join="joinChannel"
|
||||
/>
|
||||
</ul>
|
||||
<div
|
||||
v-else
|
||||
class="ws-voice-channel-tree-empty"
|
||||
data-ws-part="voice.channel-tree.empty"
|
||||
role="status"
|
||||
>无可用语音频道 / No voice channels</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch, type CSSProperties } from "vue";
|
||||
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
|
||||
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
|
||||
import { buildVoiceChannelTree } from "../../services/voice-channel-tree.js";
|
||||
import VoiceChannelTreeItem from "./VoiceChannelTreeItem.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
channels: readonly TreeChannel[];
|
||||
currentChannelId?: string;
|
||||
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
|
||||
avatarInitial: (name: string) => string;
|
||||
isSpeaking: (member: ChannelMember) => boolean;
|
||||
t: (key: string) => string;
|
||||
}>();
|
||||
|
||||
const tree = computed(() => buildVoiceChannelTree(props.channels));
|
||||
const selectedChannelId = ref(props.currentChannelId ?? "");
|
||||
const expandedIds = ref(new Set<string>());
|
||||
|
||||
watch(() => props.currentChannelId, (channelId) => {
|
||||
if (channelId) selectedChannelId.value = channelId;
|
||||
}, { immediate: true });
|
||||
|
||||
watch(tree, (nodes) => {
|
||||
const availableIds = new Set<string>();
|
||||
const expanded = new Set(expandedIds.value);
|
||||
const pending = [...nodes];
|
||||
while (pending.length) {
|
||||
const node = pending.pop()!;
|
||||
availableIds.add(node.channel.id);
|
||||
if (node.children.length || node.channel.members.length) expanded.add(node.channel.id);
|
||||
pending.push(...node.children);
|
||||
}
|
||||
for (const id of expanded) if (!availableIds.has(id)) expanded.delete(id);
|
||||
expandedIds.value = expanded;
|
||||
}, { immediate: true });
|
||||
|
||||
function toggleExpanded(channelId: string): void {
|
||||
const next = new Set(expandedIds.value);
|
||||
if (next.has(channelId)) next.delete(channelId);
|
||||
else next.add(channelId);
|
||||
expandedIds.value = next;
|
||||
}
|
||||
|
||||
function joinChannel(channel: TreeChannel): void {
|
||||
if (channel.id === props.currentChannelId) return;
|
||||
selectedChannelId.value = channel.id;
|
||||
emit("join", channel);
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
join: [channel: TreeChannel];
|
||||
}>();
|
||||
</script>
|
||||
@@ -0,0 +1,143 @@
|
||||
<template>
|
||||
<li
|
||||
class="ws-voice-channel-node"
|
||||
data-ws-part="voice.channel-tree.node"
|
||||
role="treeitem"
|
||||
:aria-level="depth + 1"
|
||||
:aria-expanded="hasContents ? expanded : undefined"
|
||||
:aria-selected="selected"
|
||||
:aria-current="current ? 'location' : undefined"
|
||||
:data-current="current ? 'true' : 'false'"
|
||||
:data-selected="selected ? 'true' : 'false'"
|
||||
>
|
||||
<div class="ws-voice-channel-line" data-ws-part="voice.channel-tree.line">
|
||||
<button
|
||||
v-if="hasContents"
|
||||
type="button"
|
||||
class="ws-voice-channel-expander"
|
||||
data-ws-part="voice.channel-tree.expander"
|
||||
:aria-label="`${expanded ? '收起' : '展开'} ${node.channel.name} / ${expanded ? 'Collapse' : 'Expand'} channel`"
|
||||
:aria-expanded="expanded"
|
||||
@click.stop="emit('toggle', node.channel.id)"
|
||||
><Icon :name="expanded ? 'chevron-down' : 'chevron-right'" :size="13" /></button>
|
||||
<span v-else class="ws-voice-channel-expander-placeholder" aria-hidden="true"></span>
|
||||
<button
|
||||
type="button"
|
||||
class="ws-voice-channel-row"
|
||||
data-ws-part="voice.channel-tree.row"
|
||||
:title="`双击或按 Enter 加入 ${node.channel.name} / Double-click or press Enter to join`"
|
||||
@click="emit('select', node.channel.id)"
|
||||
@dblclick.stop.prevent="join"
|
||||
@keydown.enter.prevent.stop="join"
|
||||
>
|
||||
<Icon class="ws-voice-channel-type" data-ws-part="voice.channel-tree.icon" name="volume" :size="14" />
|
||||
<span class="ws-voice-channel-name" data-ws-part="voice.channel-tree.name">{{ node.channel.name }}</span>
|
||||
<span v-if="selected && !current" class="ws-voice-channel-join-hint" data-ws-part="voice.channel-tree.join-hint">双击加入</span>
|
||||
<span class="ws-voice-channel-count" data-ws-part="voice.channel-tree.count">
|
||||
{{ memberCount }}<template v-if="node.channel.maxClientsLimited && typeof node.channel.maxClients === 'number'">/{{ node.channel.maxClients }}</template>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="hasContents"
|
||||
class="ws-voice-channel-branch"
|
||||
data-ws-part="voice.channel-tree.branch"
|
||||
:data-expanded="expanded ? 'true' : 'false'"
|
||||
>
|
||||
<ul class="ws-voice-channel-branch-content" role="group">
|
||||
<li
|
||||
v-for="member in node.channel.members"
|
||||
:key="member.id"
|
||||
class="ws-voice-channel-member"
|
||||
data-ws-part="voice.channel-tree.member"
|
||||
role="treeitem"
|
||||
:aria-level="depth + 2"
|
||||
:aria-label="`${member.nickname}${member.isSelf ? `, ${t('you')}` : ''}${member.inputMuted ? `, ${t('inputMuted')}` : ''}${member.away ? ', away' : ''}`"
|
||||
:data-speaking="isSpeaking(member) ? 'true' : 'false'"
|
||||
:data-away="member.away ? 'true' : 'false'"
|
||||
>
|
||||
<span
|
||||
class="ws-voice-channel-member-avatar"
|
||||
data-ws-part="voice.channel-tree.avatar"
|
||||
:class="{ 'is-speaking': isSpeaking(member) }"
|
||||
:style="avatarStyle(member.nickname, member.isSelf, member.avatar)"
|
||||
aria-hidden="true"
|
||||
>{{ member.avatar ? '' : avatarInitial(member.nickname) }}</span>
|
||||
<span class="ws-voice-channel-member-name" data-ws-part="voice.channel-tree.member-name">
|
||||
{{ member.isSelf ? t('you') : member.nickname }}
|
||||
</span>
|
||||
<Icon
|
||||
v-if="member.inputMuted"
|
||||
class="ws-voice-channel-member-muted"
|
||||
data-ws-part="voice.channel-tree.member-muted"
|
||||
name="mic-off"
|
||||
:size="12"
|
||||
:title="t('inputMuted')"
|
||||
/>
|
||||
<span
|
||||
v-else-if="isSpeaking(member)"
|
||||
class="ws-voice-channel-member-speaking"
|
||||
data-ws-part="voice.channel-tree.member-speaking"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
<span v-if="member.away" class="ws-voice-channel-member-away" data-ws-part="voice.channel-tree.member-away" aria-hidden="true">·</span>
|
||||
</li>
|
||||
<VoiceChannelTreeItem
|
||||
v-for="child in node.children"
|
||||
:key="child.channel.id"
|
||||
:node="child"
|
||||
:depth="depth + 1"
|
||||
:current-channel-id="currentChannelId"
|
||||
:selected-channel-id="selectedChannelId"
|
||||
:expanded-ids="expandedIds"
|
||||
:avatar-style="avatarStyle"
|
||||
:avatar-initial="avatarInitial"
|
||||
:is-speaking="isSpeaking"
|
||||
:t="t"
|
||||
@toggle="emit('toggle', $event)"
|
||||
@select="emit('select', $event)"
|
||||
@join="emit('join', $event)"
|
||||
/>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, type CSSProperties } from "vue";
|
||||
import Icon from "../Icon.vue";
|
||||
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
|
||||
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
|
||||
import type { VoiceChannelTreeNode } from "../../services/voice-channel-tree.js";
|
||||
|
||||
defineOptions({ name: "VoiceChannelTreeItem" });
|
||||
|
||||
const props = defineProps<{
|
||||
node: VoiceChannelTreeNode<TreeChannel>;
|
||||
depth: number;
|
||||
currentChannelId?: string;
|
||||
selectedChannelId: string;
|
||||
expandedIds: ReadonlySet<string>;
|
||||
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
|
||||
avatarInitial: (name: string) => string;
|
||||
isSpeaking: (member: ChannelMember) => boolean;
|
||||
t: (key: string) => string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
toggle: [channelId: string];
|
||||
select: [channelId: string];
|
||||
join: [channel: TreeChannel];
|
||||
}>();
|
||||
|
||||
const expanded = computed(() => props.expandedIds.has(props.node.channel.id));
|
||||
const hasContents = computed(() => props.node.children.length > 0 || props.node.channel.members.length > 0);
|
||||
const current = computed(() => props.node.channel.id === props.currentChannelId);
|
||||
const selected = computed(() => props.node.channel.id === props.selectedChannelId);
|
||||
const memberCount = computed(() => String(props.node.channel.members.length).padStart(2, "0"));
|
||||
|
||||
function join(): void {
|
||||
if (props.node.channel.id !== props.currentChannelId) emit("join", props.node.channel);
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,84 @@
|
||||
<template>
|
||||
<div
|
||||
ref="rootElement"
|
||||
class="ws-voice-server-switcher"
|
||||
data-ws-part="voice.server-switcher"
|
||||
@keydown.esc.prevent.stop="closeMenu"
|
||||
>
|
||||
<button
|
||||
ref="triggerElement"
|
||||
type="button"
|
||||
class="ws-voice-server-switcher-trigger"
|
||||
data-ws-part="voice.server-switcher.trigger"
|
||||
aria-label="切换服务器 / Switch server"
|
||||
title="切换服务器 / Switch server"
|
||||
:aria-expanded="open"
|
||||
aria-haspopup="true"
|
||||
@click="open = !open"
|
||||
><Icon name="menu" :size="17" /></button>
|
||||
<div
|
||||
v-if="open"
|
||||
class="ws-voice-server-switcher-menu"
|
||||
data-ws-part="voice.server-switcher.menu"
|
||||
role="group"
|
||||
aria-label="快速切换服务器 / Quick server switch"
|
||||
>
|
||||
<button
|
||||
v-for="server in servers"
|
||||
:key="server.id"
|
||||
type="button"
|
||||
class="ws-voice-server-switcher-item"
|
||||
data-ws-part="voice.server-switcher.item"
|
||||
:class="{ 'is-current': server.current }"
|
||||
:aria-current="server.current ? 'true' : undefined"
|
||||
:disabled="server.current"
|
||||
@click="switchServer(server)"
|
||||
>
|
||||
<span class="ws-voice-server-switcher-icon" data-ws-part="voice.server-switcher.icon" :data-tone="server.tone">
|
||||
<img v-if="server.icon" :src="server.icon" alt="" />
|
||||
<span v-else>{{ server.monogram }}</span>
|
||||
</span>
|
||||
<span class="ws-voice-server-switcher-label" data-ws-part="voice.server-switcher.label">{{ server.label }}</span>
|
||||
<Icon v-if="server.current" class="ws-voice-server-switcher-current" data-ws-part="voice.server-switcher.current" name="check" :size="14" />
|
||||
</button>
|
||||
<p v-if="!otherServerCount" class="ws-voice-server-switcher-empty" data-ws-part="voice.server-switcher.empty">
|
||||
暂无其他收藏或最近连接的服务器。<br />Save or connect to another server to switch here.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import type { SkinPluginQuickServer } from "../../services/skin-plugin-context.js";
|
||||
import Icon from "../Icon.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
servers: readonly SkinPluginQuickServer[];
|
||||
onSwitchServer: (quickServerId: string) => void;
|
||||
}>();
|
||||
|
||||
const open = ref(false);
|
||||
const rootElement = ref<HTMLElement | null>(null);
|
||||
const triggerElement = ref<HTMLButtonElement | null>(null);
|
||||
const otherServerCount = computed(() => props.servers.filter((server) => !server.current).length);
|
||||
|
||||
function switchServer(server: SkinPluginQuickServer): void {
|
||||
if (server.current) return;
|
||||
props.onSwitchServer(server.id);
|
||||
closeMenu();
|
||||
}
|
||||
|
||||
function closeMenu(): void {
|
||||
if (!open.value) return;
|
||||
open.value = false;
|
||||
triggerElement.value?.focus();
|
||||
}
|
||||
|
||||
function onDocumentPointerDown(event: PointerEvent): void {
|
||||
if (event.target instanceof Node && !rootElement.value?.contains(event.target)) closeMenu();
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener("pointerdown", onDocumentPointerDown));
|
||||
onBeforeUnmount(() => document.removeEventListener("pointerdown", onDocumentPointerDown));
|
||||
</script>
|
||||
Reference in new issue
Block a user