This commit is contained in:
2026-10-10 13:35:08 +07:00
parent 84341a5e27
commit 927aa81dda
4 changed files with 168 additions and 103 deletions
@@ -184,6 +184,8 @@ export type GetPermissionsReq = {
export type GetPermissionsRsp = {
permissions: string[] | undefined;
// Actual server environment: prod or venue.
environment: string | undefined;
};
export type UploadFileReq = {
+40 -25
View File
@@ -1,35 +1,41 @@
<script setup lang="ts">
import { MenuOutlined } from '@vicons/material'
import { Icon } from '@vicons/utils'
import { useMessage } from 'naive-ui'
import { ref, watch } from 'vue'
import { NTag, useMessage } from 'naive-ui'
import { storeToRefs } from 'pinia'
import { computed, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { getAuthClient } from '@/api/auth_client'
import { useAuthStore } from '@/stores/auth'
import { useUIStore } from '@/stores/ui'
const props = defineProps<{ active?: string }>()
const authStore = useAuthStore()
const router = useRouter()
const client = getAuthClient()
const uiStore = useUIStore()
const message = useMessage()
const permissions = ref<string[]>([])
const { permissions, environment, isLoadingEnvironment } = storeToRefs(uiStore)
const environmentLabel = computed(() => {
if (isLoadingEnvironment.value) return 'Среда: …'
if (environment.value === 'prod') return 'Сервер'
if (environment.value === 'venue') return 'Локальная сеть'
return 'Среда: ?'
})
async function getPermissions() {
permissions.value = []
if (!authStore.user) return
const token = authStore.getToken()
try {
const res = await client.GetPermissions({})
if (token === authStore.getToken()) permissions.value = res.permissions || []
} catch (err) {
message.error('Не удалось загрузить права доступа')
console.error('Failed to load permissions:', err)
}
}
watch(() => authStore.user, getPermissions, { immediate: true })
watch(
() => authStore.user,
async () => {
try {
await uiStore.load()
} catch (err) {
message.error('Не удалось загрузить сведения сервера')
console.error('Failed to load server information:', err)
}
},
{ immediate: true },
)
function hasPermission(permission: string): boolean {
return permissions.value.includes(permission)
@@ -90,13 +96,7 @@ const openMenu = ref(false)
>
Игры
</button>
<button
type="button"
class="menu-item-block"
@click="router.push('/screen')"
>
Экран
</button>
<button type="button" class="menu-item-block" @click="router.push('/screen')">Экран</button>
<button
type="button"
class="menu-item-block"
@@ -144,6 +144,14 @@ const openMenu = ref(false)
</div>
<div class="right-group">
<NTag
size="small"
:type="environment === 'venue' ? 'warning' : 'default'"
:title="environment ? 'Среда подключённого сервера' : 'Среда сервера не определена'"
role="status"
>
{{ environmentLabel }}
</NTag>
<button
v-if="!authStore.isAuthenticated"
type="button"
@@ -196,6 +204,13 @@ const openMenu = ref(false)
opacity: 0.8;
}
.right-group {
align-items: center;
display: flex;
flex-shrink: 0;
gap: 10px;
}
.right {
margin-left: auto;
}
+35
View File
@@ -0,0 +1,35 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getAuthClient } from '@/api/auth_client'
import { useAuthStore } from '@/stores/auth'
export const useUIStore = defineStore('ui', () => {
const permissions = ref<string[]>([])
const environment = ref<'prod' | 'venue' | null>(null)
const isLoadingEnvironment = ref(true)
let requestId = 0
async function load() {
const authStore = useAuthStore()
const token = authStore.getToken()
const currentRequest = ++requestId
permissions.value = []
environment.value = null
isLoadingEnvironment.value = true
try {
const res = await getAuthClient().GetPermissions({})
if (currentRequest !== requestId) return
if (token === authStore.getToken()) permissions.value = res.permissions || []
if (res.environment === 'prod' || res.environment === 'venue') {
environment.value = res.environment
}
} catch (err) {
if (currentRequest === requestId) throw err
} finally {
if (currentRequest === requestId) isLoadingEnvironment.value = false
}
}
return { permissions, environment, isLoadingEnvironment, load }
})