53 lines
2.2 KiB
Vue
53 lines
2.2 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from 'vue'
|
|
import { useSession } from '../session'
|
|
|
|
const session = useSession()
|
|
const error = ref('')
|
|
const busy = ref(false)
|
|
const browser = window.xhchat?.openBrowser
|
|
|
|
async function act(action: () => Promise<void>) {
|
|
busy.value = true
|
|
error.value = ''
|
|
try {
|
|
await action()
|
|
} catch (cause) {
|
|
error.value = cause instanceof Error ? cause.message : '操作失败,请稍后重试'
|
|
} finally {
|
|
busy.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<main v-if="session.identity" class="workspace">
|
|
<nav class="rail" aria-label="主导航">
|
|
<RouterLink class="mark" to="/devices" aria-label="XHChat">X</RouterLink>
|
|
<RouterLink class="rail-link" to="/chat" title="消息" aria-label="消息">◇</RouterLink>
|
|
<RouterLink class="rail-link" to="/contacts" title="联系人" aria-label="联系人">人</RouterLink>
|
|
<RouterLink class="rail-link" to="/devices" title="设备管理" aria-label="设备管理">▣</RouterLink>
|
|
<button v-if="browser" type="button" class="rail-link browser-button" title="浏览器" aria-label="浏览器" @click="act(browser)">◎</button>
|
|
</nav>
|
|
<aside class="account-panel">
|
|
<div class="account-summary">
|
|
<span class="avatar" aria-hidden="true">{{ session.identity.user.username[0]?.toUpperCase() }}</span>
|
|
<div><strong>{{ session.identity.user.username }}</strong><small>我的账号</small></div>
|
|
</div>
|
|
<nav class="panel-links" aria-label="工作区">
|
|
<RouterLink to="/chat">消息</RouterLink>
|
|
<RouterLink to="/contacts">联系人</RouterLink>
|
|
<RouterLink to="/groups">群组</RouterLink>
|
|
<RouterLink to="/devices">设备管理</RouterLink>
|
|
<button v-if="browser" class="plain mobile-browser" @click="act(browser)">浏览器</button>
|
|
</nav>
|
|
<div class="account-footer">
|
|
<p aria-live="polite"><span class="dot" :class="{ online: session.connection === '实时连接已建立' }"></span>{{ session.connection }}</p>
|
|
<p v-if="error" class="error" role="alert">{{ error }}</p>
|
|
<button class="plain" :disabled="busy" @click="act(session.logout)">退出登录</button>
|
|
</div>
|
|
</aside>
|
|
<RouterView />
|
|
</main>
|
|
</template>
|