This commit is contained in:
Vladimir Voronin
2024-11-04 17:59:42 +03:00
parent 7ae38604d2
commit 77f00597ee

View File

@@ -7,6 +7,7 @@
<!-- Контентная часть заполняет оставшееся пространство --> <!-- Контентная часть заполняет оставшееся пространство -->
<div class="flex-grow "> <div class="flex-grow ">
{{ tg_id }}
<Button label="Sub" :class="checkNotif ? 'flex' : '!hidden'" @click="checkSubscribe"/> <Button label="Sub" :class="checkNotif ? 'flex' : '!hidden'" @click="checkSubscribe"/>
<router-view/> <router-view/>
</div> </div>
@@ -24,9 +25,19 @@ import {subscribeUserToPush} from "@/services/pushManager";
import apiClient from '@/services/axiosSetup'; import apiClient from '@/services/axiosSetup';
const checkNotif = computed(() => { const checkNotif = computed(() => {
return 'Notification' in window && Notification.permission === 'default'
return !!tg_id.value && 'Notification' in window && Notification.permission === 'default'
}) })
const tg_id = computed(() => {
if (window.Telegram?.WebApp) {
const tg = window.Telegram.WebApp;
tg.expand(); // Разворачиваем приложение на весь экран
return tg.initDataUnsafe.user?.id ?? null; // Если tg_id нет, возвращаем null
}
return null;
});
const checkSubscribe = async () => { const checkSubscribe = async () => {
if ("Notification" in window) { if ("Notification" in window) {
if (Notification.permission === 'default') { if (Notification.permission === 'default') {