First Committ
This commit is contained in:
25
src/router/index.ts
Executable file
25
src/router/index.ts
Executable file
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
createMemoryHistory, createRouter, createWebHashHistory, createWebHistory,
|
||||
} from 'vue-router'
|
||||
|
||||
import { cfgrouter } from './route-config'
|
||||
|
||||
export default function (/* { store, ssrContext } */) {
|
||||
const routermode = process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory
|
||||
|
||||
const createHistory = process.env.SERVER
|
||||
? createMemoryHistory
|
||||
: routermode
|
||||
|
||||
return createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
routes: cfgrouter.getmenu(),
|
||||
|
||||
// Leave this as is and make changes in quasar.conf.js instead!
|
||||
// quasar.conf.js -> build -> vueRouterMode
|
||||
// quasar.conf.js -> build -> publicPath
|
||||
history: createHistory(
|
||||
process.env.MODE === 'ssr' ? void 0 : process.env.VUE_ROUTER_BASE,
|
||||
),
|
||||
})
|
||||
}
|
||||
164
src/router/permission.ts
Normal file
164
src/router/permission.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { static_data } from '@src/db/static_data'
|
||||
import { useProgressBar } from '@store/Modules/ProgressBar'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const progressBar = useProgressBar()
|
||||
|
||||
const getRouteData = async (to: any) => {
|
||||
if (!to.meta.transparent) {
|
||||
progressBar.start()
|
||||
}
|
||||
const titleToDisplay: any = await to.meta.asyncData(to)
|
||||
}
|
||||
|
||||
const $router = useRouter()
|
||||
|
||||
// router().beforeEach(async (to: IMyRoute, from: IMyRoute, next) => {
|
||||
$router.beforeEach(async (to, from, next) => {
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
try {
|
||||
if (globalStore) {
|
||||
if (!globalStore.finishLoading) {
|
||||
let eseguicheck = true
|
||||
|
||||
// Controlla se c'è nella lista allora non eseguire il controllo:
|
||||
for (const route of static_data.routes) {
|
||||
if (route.path === to.path) {
|
||||
eseguicheck = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (eseguicheck) {
|
||||
// Qui arrivano gli URL che non sono della lista ROUTE.
|
||||
// quindi ad esempio http://localhost:8085/signup/paoloar77
|
||||
|
||||
if (!globalStore.TIMER && to.path !== '/') {
|
||||
// console.log('TIMER')
|
||||
globalStore.TIMER = setInterval(() => {
|
||||
// console.log('SETINTERVAL')
|
||||
if (globalStore.finishLoading) {
|
||||
if (globalStore.TIMER) {
|
||||
// console.log('TIMER_STATE', TIMER_STATE, 'URL_RITORNA', URL_RITORNA)
|
||||
if (globalStore.TIMER_STATE === 2) {
|
||||
clearInterval(globalStore.TIMER)
|
||||
globalStore.TIMER = null
|
||||
// console.log('TERMINA INTERVALLO')
|
||||
// next('/prova')
|
||||
// return
|
||||
}
|
||||
// se mi ero salvato un url per doverci ritornare, allora puntalo a questo:
|
||||
if (globalStore.URL_RITORNA !== '') {
|
||||
// next(URL_RITORNA)
|
||||
globalStore.TIMER_STATE = 2
|
||||
} else if (globalStore.TIMER_STATE === 0) {
|
||||
globalStore.URL_RESTORE = to.path
|
||||
// next('/')
|
||||
globalStore.TIMER_STATE = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 200)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (globalStore.finishLoading) {
|
||||
if (globalStore.TIMER) {
|
||||
// console.log('TIMER_STATE', TIMER_STATE, 'to.path', to.path)
|
||||
if (globalStore.URL_RITORNA === '' && globalStore.URL_RESTORE !== '') {
|
||||
globalStore.URL_RITORNA = globalStore.URL_RESTORE
|
||||
// onsole.log('URL_RITORNA', URL_RITORNA)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// await tools.aspettansec(4000)
|
||||
}
|
||||
|
||||
if (from.name && from.matched[0].name === to.name && from.meta.isModal) {
|
||||
next()
|
||||
console.log('Route interceptor log: <1>')
|
||||
return
|
||||
}
|
||||
// else if (from.name === to.name && isEqual(from.params, to.params)) {
|
||||
if (from.name === to.name) {
|
||||
console.log('Route interceptor log: <2>')
|
||||
console.log('from e to: ', from, to)
|
||||
next()
|
||||
} else {
|
||||
if (!to.meta.transparent && !to.meta.isModal) {
|
||||
// console.log('Route interceptor log: <4>')
|
||||
progressBar.start()
|
||||
} else if (to.meta.transparent && !from.name) {
|
||||
console.log('Route interceptor log: <5>')
|
||||
progressBar.start()
|
||||
} else if (to.meta.transparent && !to.matched.some((m) => m.name === from.name)) {
|
||||
console.log('Route interceptor log: <6>')
|
||||
progressBar.start()
|
||||
}
|
||||
|
||||
// Check requires auth
|
||||
if (to.matched.some((m) => m.meta.requiresAuth)) {
|
||||
// await LoginStore.actions.refreshUserInfos()
|
||||
if (tools.isLoggedToSystem()) {
|
||||
if (to.meta.asyncData) {
|
||||
await getRouteData(to)
|
||||
}
|
||||
} else {
|
||||
// LoginStore.mutations.showLoginRoute(to.fullPath)
|
||||
if (from.name) {
|
||||
progressBar.hide()
|
||||
} else {
|
||||
// next('/')
|
||||
}
|
||||
|
||||
$router.push({ name: 'pages.SignIn' })
|
||||
return
|
||||
}
|
||||
} else if (to.matched.some((m) => m.meta.noAuth) && userStore.isLogged) {
|
||||
next('/')
|
||||
} else if (to.meta.asyncData) {
|
||||
await getRouteData(to)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// if (to.meta.middleware) {
|
||||
// const middleware = Array.isArray(to.meta.middleware)
|
||||
// ? to.meta.middleware
|
||||
// : [to.meta.middleware]
|
||||
//
|
||||
// const context = {
|
||||
// from,
|
||||
// next,
|
||||
// Router,
|
||||
// to
|
||||
// }
|
||||
//
|
||||
// const nextMiddleware = nextFactory(context, middleware, 1)
|
||||
//
|
||||
// return middleware[0]({ ...context, next: nextMiddleware })
|
||||
// }
|
||||
//
|
||||
return next()
|
||||
} catch
|
||||
(err) {
|
||||
console.log('Route error:', err)
|
||||
progressBar.fail()
|
||||
}
|
||||
})
|
||||
|
||||
// const getRouteData = async (to: IMyRoute | IMyRouteRecord) => {
|
||||
|
||||
/*
|
||||
router().afterEach(async (from: IMyRoute, next) => {
|
||||
progressBar.finish()
|
||||
// AlertsStore.mutations.hideAlert()
|
||||
// EventBus.$emit('closePopups')
|
||||
})
|
||||
*/
|
||||
42
src/router/route-config.ts
Executable file
42
src/router/route-config.ts
Executable file
@@ -0,0 +1,42 @@
|
||||
import { static_data } from '@src/db/static_data'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
|
||||
interface IMyMeta {
|
||||
title?: string,
|
||||
headerShadow?: boolean,
|
||||
contentProp?: boolean,
|
||||
transparent?: boolean,
|
||||
isModal?: boolean,
|
||||
requiresAuth?: boolean,
|
||||
isTab?: boolean,
|
||||
noAuth?: boolean,
|
||||
// asyncData?: (to?: IMyRoute | IMyRouteRecord) => Promise<{title?: string} | void>,
|
||||
asyncData?: (to?: any) => Promise<{ title?: string } | void>,
|
||||
isAuthorized?: (to?: any) => boolean
|
||||
middleware?: any[]
|
||||
}
|
||||
|
||||
/*
|
||||
export interface IMyRoute extends Route {
|
||||
meta: IMyMeta,
|
||||
matched: IMyRouteRecord[]
|
||||
}
|
||||
|
||||
export interface IMyRouteRecord extends RouteRecord {
|
||||
meta: IMyMeta,
|
||||
}
|
||||
*/
|
||||
|
||||
export const cfgrouter = {
|
||||
|
||||
getmenu(): RouteRecordRaw[] {
|
||||
const arrroutes: RouteRecordRaw[] = []
|
||||
|
||||
for (const route of static_data.routes) {
|
||||
tools.addRoute(arrroutes, route)
|
||||
}
|
||||
|
||||
return arrroutes
|
||||
},
|
||||
}
|
||||
12
src/router/route-names.ts
Executable file
12
src/router/route-names.ts
Executable file
@@ -0,0 +1,12 @@
|
||||
export const RouteNames = {
|
||||
home: 'home',
|
||||
login: 'login',
|
||||
projects: 'projects',
|
||||
projectsall: 'projall',
|
||||
projectsshared: 'projectsShared',
|
||||
myprojects: 'myprojects',
|
||||
favouriteprojects: 'favproj',
|
||||
listprojects: 'listproj',
|
||||
livelli: 'livelli',
|
||||
ecommerce: 'ecommerce',
|
||||
}
|
||||
Reference in New Issue
Block a user