before_redesign
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
||||
import routes from './routes'
|
||||
import { useAuthStore } from 'stores/auth'
|
||||
import { useProjectsStore } from 'stores/projects'
|
||||
import { computed } from 'vue'
|
||||
const tg = window.Telegram?.WebApp
|
||||
|
||||
declare module 'vue-router' {
|
||||
@@ -35,6 +34,9 @@ export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
|
||||
const publicPath = ['404', 'terms', 'privacy', 'consent', 'settings']
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const projectsStore = useProjectsStore()
|
||||
|
||||
Router.beforeEach(async (to) => {
|
||||
if (to.name !== 'telegram_only' && sessionStorage.getItem('isTelegram') === 'false') {
|
||||
return { name: 'telegram_only', replace: true }
|
||||
@@ -42,9 +44,6 @@ export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
|
||||
if (to.name === 'telegram_only') return true
|
||||
if (typeof to.name === 'string' && publicPath.includes(to.name)) return true
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const projectsStore = useProjectsStore()
|
||||
|
||||
if (to.name === 'login')
|
||||
return authStore.isAuth ? { name: 'projects', replace: true } : true
|
||||
@@ -58,13 +57,9 @@ export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
|
||||
if (to.params.id) {
|
||||
if (!projectsStore.isInit) await projectsStore.init()
|
||||
|
||||
const currentProjectId = computed(() => projectsStore.currentProjectId)
|
||||
|
||||
if (to.params.id) {
|
||||
if (currentProjectId.value !== Number(to.params.id)) {
|
||||
if (!projectsStore.projectById(Number(to.params.id)))
|
||||
projectsStore.setCurrentProjectId(Number(to.params.id))
|
||||
if (to.params.id && projectsStore.projectById(Number(to.params.id))) {
|
||||
if (projectsStore.currentProjectId !== Number(to.params.id)) {
|
||||
projectsStore.setCurrentProjectId(Number(to.params.id))
|
||||
}
|
||||
} else {
|
||||
projectsStore.setCurrentProjectId(null)
|
||||
@@ -93,7 +88,9 @@ export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
}
|
||||
}
|
||||
|
||||
useProjectsStore().setCurrentProjectId(to.params.id ? Number(to.params.id) : null)
|
||||
if (to.params.id) projectsStore.setLastProjectId(Number(to.params.id))
|
||||
if (to.name === 'projects') projectsStore.setLastProjectId(null)
|
||||
projectsStore.setCurrentProjectId(to.params.id ? Number(to.params.id) : null)
|
||||
})
|
||||
|
||||
return Router
|
||||
|
||||
Reference in New Issue
Block a user