fix: correct back button work
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
<FullscreenViewport/>
|
<FullscreenViewport/>
|
||||||
<router-view />
|
<router-view />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {onMounted, ref} from "vue";
|
import {onMounted, ref, watch} from "vue";
|
||||||
import { useWebAppViewport } from 'vue-tg';
|
import { useWebAppViewport, useBackButton } from 'vue-tg';
|
||||||
import { useMiniApp, FullscreenViewport } from 'vue-tg';
|
import { useMiniApp, FullscreenViewport } from 'vue-tg';
|
||||||
|
import {useRoute, useRouter} from "vue-router";
|
||||||
|
|
||||||
const tg = useMiniApp();
|
const tg = useMiniApp();
|
||||||
const platform = ref();
|
const platform = ref();
|
||||||
@@ -14,4 +17,28 @@ platform.value = tg.platform;
|
|||||||
|
|
||||||
const { disableVerticalSwipes } = useWebAppViewport();
|
const { disableVerticalSwipes } = useWebAppViewport();
|
||||||
disableVerticalSwipes();
|
disableVerticalSwipes();
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
const backButton = useBackButton();
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => route.fullPath,
|
||||||
|
() => {
|
||||||
|
if (route.name === 'home') {
|
||||||
|
if (typeof backButton.hide === 'function') {
|
||||||
|
backButton.hide();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (typeof backButton.show === 'function') {
|
||||||
|
backButton.show();
|
||||||
|
backButton.onClick(() => {
|
||||||
|
router.back();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import CategoriesList from "./views/CategoriesList.vue";
|
|||||||
import ProductsList from "./views/ProductsList.vue";
|
import ProductsList from "./views/ProductsList.vue";
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{path: '/', component: Home},
|
{path: '/', name: 'home', component: Home},
|
||||||
{path: '/product/:id', component: Product},
|
{path: '/product/:id', component: Product},
|
||||||
{path: '/categories', component: CategoriesList},
|
{path: '/categories', component: CategoriesList},
|
||||||
{path: '/category/:id', component: ProductsList},
|
{path: '/category/:id', component: ProductsList},
|
||||||
|
|||||||
@@ -10,8 +10,15 @@ html, body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
padding-top: env(--tg-content-safe-area-inset-top);
|
padding-top: var(--tg-content-safe-area-inset-top);
|
||||||
padding-bottom: env(--tg-content-safe-area-inset-bottom);
|
padding-bottom: var(--tg-content-safe-area-inset-bottom);
|
||||||
padding-left: env(--tg-content-safe-area-inset-left);
|
padding-left: var(--tg-content-safe-area-inset-left);
|
||||||
padding-right: env(--tg-content-safe-area-inset-right);
|
padding-right: var(--tg-content-safe-area-inset-right);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-container {
|
||||||
|
padding-top: var(--tg-safe-area-inset-top);
|
||||||
|
padding-bottom: var(--tg-safe-area-inset-bottom);
|
||||||
|
padding-left: var(--tg-safe-area-inset-left);
|
||||||
|
padding-right: var(--tg-safe-area-inset-right);
|
||||||
}
|
}
|
||||||
@@ -6,21 +6,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {onMounted, ref} from "vue";
|
import {ref} from "vue";
|
||||||
|
|
||||||
const goodsRef = ref();
|
const goodsRef = ref();
|
||||||
function scrollToProducts() {
|
function scrollToProducts() {
|
||||||
goodsRef.value?.scrollIntoView({ behavior: 'smooth' });
|
goodsRef.value?.scrollIntoView({ behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
|
|
||||||
import { useBackButton } from 'vue-tg';
|
|
||||||
import ProductsList from "./ProductsList.vue";
|
import ProductsList from "./ProductsList.vue";
|
||||||
import CategoriesInline from "../components/CategoriesInline.vue";
|
import CategoriesInline from "../components/CategoriesInline.vue";
|
||||||
const backButton = useBackButton();
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
if (backButton.isVisible.value) {
|
|
||||||
backButton.hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -46,14 +46,12 @@ import {onMounted, ref} from "vue";
|
|||||||
import {$fetch} from "ofetch";
|
import {$fetch} from "ofetch";
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import {useBackButton, useHapticFeedback} from 'vue-tg';
|
import {useHapticFeedback} from 'vue-tg';
|
||||||
const hapticFeedback = useHapticFeedback();
|
const hapticFeedback = useHapticFeedback();
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const productId = route.params.id
|
const productId = route.params.id
|
||||||
|
|
||||||
const id = 28;
|
|
||||||
const product = ref([]);
|
const product = ref([]);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -61,14 +59,6 @@ onMounted(async () => {
|
|||||||
product.value = data;
|
product.value = data;
|
||||||
});
|
});
|
||||||
|
|
||||||
const backButton = useBackButton();
|
|
||||||
if (typeof backButton.show === 'function') {
|
|
||||||
backButton.show();
|
|
||||||
backButton.onClick(() => {
|
|
||||||
router.back()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const carouselRef = ref();
|
const carouselRef = ref();
|
||||||
let lastScrollLeft = 0;
|
let lastScrollLeft = 0;
|
||||||
function onScroll(e) {
|
function onScroll(e) {
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mx-auto max-w-2xl px-4 py-4 sm:px-6 sm:py-6 lg:max-w-7xl lg:px-8">
|
<div class="mx-auto max-w-2xl px-4 py-4 sm:px-6 sm:py-6 lg:max-w-7xl lg:px-8">
|
||||||
|
|
||||||
|
<div v-if="isLoading" class="grid grid-cols-2 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
|
||||||
|
<div v-for="n in 8" :key="n" class="animate-pulse space-y-2">
|
||||||
|
<div class="aspect-square bg-gray-200 rounded-md"></div>
|
||||||
|
<div class="h-4 bg-gray-200 rounded w-3/4"></div>
|
||||||
|
<div class="h-4 bg-gray-200 rounded w-1/2"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
<h2 class="text-lg font-bold mb-5 text-center">{{ productsMeta.currentCategoryName }}</h2>
|
<h2 class="text-lg font-bold mb-5 text-center">{{ productsMeta.currentCategoryName }}</h2>
|
||||||
|
|
||||||
<div v-if="products.length > 0" class="grid grid-cols-2 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
|
<div v-if="products.length > 0" class="grid grid-cols-2 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
|
||||||
@@ -16,12 +26,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<NoProducts v-else/>
|
<NoProducts v-else/>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {onMounted, ref} from "vue";
|
import {onMounted, ref} from "vue";
|
||||||
import {useBackButton, useHapticFeedback, useMiniApp} from 'vue-tg';
|
import {useHapticFeedback} from 'vue-tg';
|
||||||
import { useRouter, useRoute } from 'vue-router';
|
import { useRouter, useRoute } from 'vue-router';
|
||||||
import ftch from "../utils/ftch.js";
|
import ftch from "../utils/ftch.js";
|
||||||
import NoProducts from "../components/NoProducts.vue";
|
import NoProducts from "../components/NoProducts.vue";
|
||||||
@@ -31,6 +42,7 @@ const router = useRouter();
|
|||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const categoryId = route.params.id;
|
const categoryId = route.params.id;
|
||||||
|
|
||||||
|
const isLoading = ref(true);
|
||||||
const products = ref([]);
|
const products = ref([]);
|
||||||
const productsMeta = ref([]);
|
const productsMeta = ref([]);
|
||||||
|
|
||||||
@@ -46,19 +58,12 @@ function onScroll(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const backButton = useBackButton();
|
|
||||||
if (typeof backButton.show === 'function') {
|
|
||||||
backButton.show();
|
|
||||||
backButton.onClick(() => {
|
|
||||||
router.back()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const {data, meta} = await ftch('products', {
|
const {data, meta} = await ftch('products', {
|
||||||
categoryId: categoryId,
|
categoryId: categoryId,
|
||||||
});
|
});
|
||||||
productsMeta.value = meta;
|
productsMeta.value = meta;
|
||||||
products.value = data;
|
products.value = data;
|
||||||
|
isLoading.value = false;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user