83 lines
3.4 KiB
Vue
83 lines
3.4 KiB
Vue
<script setup lang="ts">
|
|
import { onBeforeUnmount, ref, watch } from 'vue'
|
|
import { useRoute } from 'vue-router'
|
|
import { useSession } from '../session'
|
|
|
|
const session = useSession()
|
|
const route = useRoute()
|
|
const error = ref('')
|
|
const busy = ref(false)
|
|
const browser = window.xhchat?.openBrowser
|
|
const notice = ref<string>()
|
|
let noticeTimer: ReturnType<typeof setTimeout> | undefined
|
|
|
|
function dismissNotice() {
|
|
clearTimeout(noticeTimer)
|
|
notice.value = undefined
|
|
}
|
|
|
|
watch(() => session.groupChange, (event) => {
|
|
if (!event?.notify || route.params.id === event.groupId) return
|
|
dismissNotice()
|
|
notice.value = event.groupId
|
|
noticeTimer = setTimeout(dismissNotice, 8000)
|
|
})
|
|
watch(() => route.params.id, (id) => { if (id === notice.value) dismissNotice() })
|
|
onBeforeUnmount(dismissNotice)
|
|
|
|
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"><img src="/brand/xhchat.png" alt=""></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 />
|
|
<div v-if="notice" class="group-notice" role="status">
|
|
<RouterLink :to="'/groups/' + notice" @click="dismissNotice">有新的群消息</RouterLink>
|
|
<button type="button" class="plain" aria-label="关闭群消息提醒" @click="dismissNotice">关闭</button>
|
|
</div>
|
|
</main>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.group-notice {
|
|
position: fixed; inset-inline-end: 1rem; inset-block-end: 1rem; z-index: 6;
|
|
display: flex; align-items: center; gap: .7rem; padding: .6rem .85rem;
|
|
background: var(--surface); border: 1px solid var(--line); border-radius: .5rem;
|
|
}
|
|
</style>
|