mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(kaak): match channel sidebar and audio dock reference
This commit is contained in:
1 parent
b13bdf1eb2
commit
96d2ebae01
17 files changed
+847
-135
No files matched your search
@@ -1,19 +1,21 @@
|
||||
<template>
|
||||
<ul
|
||||
v-if="tree.length"
|
||||
v-if="visibleTree.length"
|
||||
class="ws-voice-channel-tree"
|
||||
data-ws-part="voice.channel-tree.list"
|
||||
:data-layout="layout"
|
||||
role="tree"
|
||||
aria-label="语音频道 / Voice channels"
|
||||
>
|
||||
<VoiceChannelTreeItem
|
||||
v-for="node in tree"
|
||||
v-for="node in visibleTree"
|
||||
:key="node.channel.id"
|
||||
:node="node"
|
||||
:depth="0"
|
||||
:layout="layout"
|
||||
:current-channel-id="currentChannelId"
|
||||
:selected-channel-id="selectedChannelId"
|
||||
:expanded-ids="expandedIds"
|
||||
:expanded-ids="effectiveExpandedIds"
|
||||
:avatar-style="avatarStyle"
|
||||
:avatar-initial="avatarInitial"
|
||||
:is-speaking="isSpeaking"
|
||||
@@ -28,19 +30,21 @@
|
||||
class="ws-voice-channel-tree-empty"
|
||||
data-ws-part="voice.channel-tree.empty"
|
||||
role="status"
|
||||
>无可用语音频道 / No voice channels</div>
|
||||
>{{ query.trim() ? "没有匹配的频道 / No matching channels" : "无可用语音频道 / 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 { buildVoiceChannelTree, filterVoiceChannelTree } from "../../services/voice-channel-tree.js";
|
||||
import VoiceChannelTreeItem from "./VoiceChannelTreeItem.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
channels: readonly TreeChannel[];
|
||||
currentChannelId?: string;
|
||||
query?: string;
|
||||
layout?: "default" | "server-sidebar";
|
||||
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
|
||||
avatarInitial: (name: string) => string;
|
||||
isSpeaking: (member: ChannelMember) => boolean;
|
||||
@@ -48,8 +52,22 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const tree = computed(() => buildVoiceChannelTree(props.channels));
|
||||
const layout = computed(() => props.layout ?? "default");
|
||||
const query = computed(() => props.query ?? "");
|
||||
const visibleTree = computed(() => filterVoiceChannelTree(tree.value, query.value));
|
||||
const selectedChannelId = ref(props.currentChannelId ?? "");
|
||||
const expandedIds = ref(new Set<string>());
|
||||
const effectiveExpandedIds = computed(() => {
|
||||
const result = new Set(expandedIds.value);
|
||||
if (!query.value.trim()) return result;
|
||||
const pending = [...visibleTree.value];
|
||||
while (pending.length) {
|
||||
const node = pending.pop()!;
|
||||
if (node.children.length) result.add(node.channel.id);
|
||||
pending.push(...node.children);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
watch(() => props.currentChannelId, (channelId) => {
|
||||
if (channelId) selectedChannelId.value = channelId;
|
||||
@@ -62,7 +80,7 @@ watch(tree, (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);
|
||||
if (node.children.length || (layout.value === "default" && 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);
|
||||
@@ -85,4 +103,5 @@ function joinChannel(channel: TreeChannel): void {
|
||||
const emit = defineEmits<{
|
||||
join: [channel: TreeChannel];
|
||||
}>();
|
||||
|
||||
</script>
|
||||
@@ -4,15 +4,15 @@
|
||||
data-ws-part="voice.channel-tree.node"
|
||||
role="treeitem"
|
||||
:aria-level="depth + 1"
|
||||
:aria-expanded="hasContents ? expanded : undefined"
|
||||
:aria-expanded="isExpandable ? 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">
|
||||
<div class="ws-voice-channel-line" data-ws-part="voice.channel-tree.line" :style="{ '--channel-depth': depth }">
|
||||
<button
|
||||
v-if="hasContents"
|
||||
v-if="isExpandable"
|
||||
type="button"
|
||||
class="ws-voice-channel-expander"
|
||||
data-ws-part="voice.channel-tree.expander"
|
||||
@@ -20,7 +20,6 @@
|
||||
: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"
|
||||
@@ -39,8 +38,72 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<template v-if="layout === 'server-sidebar'">
|
||||
<ul v-if="node.channel.members.length" class="ws-voice-channel-member-list" role="group" :style="{ '--channel-depth': depth }">
|
||||
<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')}` : ''}`"
|
||||
:data-self="member.isSelf ? 'true' : 'false'"
|
||||
>
|
||||
<span
|
||||
class="ws-voice-channel-member-avatar"
|
||||
data-ws-part="voice.channel-tree.avatar"
|
||||
: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.nickname }}</span>
|
||||
<span v-if="member.isSelf" class="ws-voice-channel-member-self">你</span>
|
||||
<Icon
|
||||
v-if="member.inputMuted"
|
||||
class="ws-voice-channel-member-muted"
|
||||
data-ws-part="voice.channel-tree.member-muted"
|
||||
name="mic-off"
|
||||
:size="13"
|
||||
:title="t('inputMuted')"
|
||||
/>
|
||||
<Icon
|
||||
v-else
|
||||
class="ws-voice-channel-member-mic"
|
||||
name="mic"
|
||||
:size="13"
|
||||
:title="t('microphoneActive')"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
<div
|
||||
v-if="hasChildren"
|
||||
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">
|
||||
<VoiceChannelTreeItem
|
||||
v-for="child in node.children"
|
||||
:key="child.channel.id"
|
||||
:node="child"
|
||||
:depth="depth + 1"
|
||||
:layout="layout"
|
||||
: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>
|
||||
</template>
|
||||
<div
|
||||
v-if="hasContents"
|
||||
v-else-if="hasContents"
|
||||
class="ws-voice-channel-branch"
|
||||
data-ws-part="voice.channel-tree.branch"
|
||||
:data-expanded="expanded ? 'true' : 'false'"
|
||||
@@ -88,6 +151,7 @@
|
||||
:key="child.channel.id"
|
||||
:node="child"
|
||||
:depth="depth + 1"
|
||||
:layout="layout"
|
||||
:current-channel-id="currentChannelId"
|
||||
:selected-channel-id="selectedChannelId"
|
||||
:expanded-ids="expandedIds"
|
||||
@@ -116,6 +180,7 @@ defineOptions({ name: "VoiceChannelTreeItem" });
|
||||
const props = defineProps<{
|
||||
node: VoiceChannelTreeNode<TreeChannel>;
|
||||
depth: number;
|
||||
layout: "default" | "server-sidebar";
|
||||
currentChannelId?: string;
|
||||
selectedChannelId: string;
|
||||
expandedIds: ReadonlySet<string>;
|
||||
@@ -132,7 +197,9 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
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 hasChildren = computed(() => props.node.children.length > 0);
|
||||
const hasContents = computed(() => hasChildren.value || props.node.channel.members.length > 0);
|
||||
const isExpandable = computed(() => props.layout === "server-sidebar" ? hasChildren.value : hasContents.value);
|
||||
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"));
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<template>
|
||||
<header class="ws-voice-server-header">
|
||||
<div class="ws-voice-server-title-line">
|
||||
<strong class="ws-voice-server-name">{{ serverLabel || "TeamSpeak" }}</strong>
|
||||
<VoiceServerSwitcher :servers="servers" :on-switch-server="onSwitchServer" />
|
||||
</div>
|
||||
<div class="ws-voice-server-meta-line">
|
||||
<div class="ws-voice-server-tags">
|
||||
<span class="ws-voice-server-tag">TeamSpeak</span>
|
||||
<span class="ws-voice-server-tag" :class="`is-${connectionState}`">
|
||||
<i v-if="connectionState === 'connected'" aria-hidden="true"></i>
|
||||
{{ connectionLabel }}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
ref="searchButton"
|
||||
class="ws-voice-server-search-toggle"
|
||||
type="button"
|
||||
:aria-expanded="searchOpen"
|
||||
aria-label="搜索频道 / Search channels"
|
||||
title="搜索频道 / Search channels"
|
||||
@click="toggleSearch"
|
||||
><Icon name="search" :size="18" /></button>
|
||||
</div>
|
||||
<label v-if="searchOpen" class="ws-voice-server-search-box">
|
||||
<span class="sr-only">搜索频道名称 / Search channel names</span>
|
||||
<Icon name="search" :size="16" />
|
||||
<input
|
||||
ref="searchInput"
|
||||
v-model="query"
|
||||
type="search"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
placeholder="搜索频道 / Search channels"
|
||||
@keydown.esc.prevent="closeSearch"
|
||||
/>
|
||||
<button v-if="query" type="button" aria-label="清除搜索 / Clear search" @click="query = ''; searchInput?.focus()">
|
||||
<Icon name="close" :size="15" />
|
||||
</button>
|
||||
</label>
|
||||
<div class="ws-voice-server-divider" aria-hidden="true"></div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from "vue";
|
||||
import type { SkinPluginQuickServer } from "../../services/skin-plugin-context.js";
|
||||
import Icon from "../Icon.vue";
|
||||
import VoiceServerSwitcher from "./VoiceServerSwitcher.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
serverLabel: string;
|
||||
connectionState: "connected" | "connecting" | "disconnected";
|
||||
servers: readonly SkinPluginQuickServer[];
|
||||
onSwitchServer: (quickServerId: string) => void;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{ "update:query": [value: string] }>();
|
||||
const searchOpen = ref(false);
|
||||
const query = ref("");
|
||||
const searchButton = ref<HTMLButtonElement | null>(null);
|
||||
const searchInput = ref<HTMLInputElement | null>(null);
|
||||
const connectionLabel = computed(() => ({
|
||||
connected: "已连接",
|
||||
connecting: "连接中",
|
||||
disconnected: "未连接",
|
||||
})[props.connectionState]);
|
||||
|
||||
watch(query, (value) => emit("update:query", value));
|
||||
|
||||
async function toggleSearch(): Promise<void> {
|
||||
if (searchOpen.value) {
|
||||
closeSearch();
|
||||
return;
|
||||
}
|
||||
searchOpen.value = true;
|
||||
await nextTick();
|
||||
searchInput.value?.focus();
|
||||
}
|
||||
|
||||
function closeSearch(): void {
|
||||
searchOpen.value = false;
|
||||
query.value = "";
|
||||
void nextTick(() => searchButton.value?.focus());
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user