diff --git a/admin/src/router/index.js b/admin/src/router/index.js index 6623078..c60a765 100644 --- a/admin/src/router/index.js +++ b/admin/src/router/index.js @@ -5,69 +5,69 @@ import {ConfigGetAction, $response, AdminStatusAction} from "~/api" import {reGetAdmin} from "~/tool/info" import {$favicon} from "~/tool/favicon" import { - useStore, useSaveTokenType, useSessionToken, useToken, useRouterActive + useStore, useSaveTokenType, useSessionToken, useToken, useRouterActive } from '~/store' const no_login_list = ['login', '404']; const $router_active = useRouterActive() const router = createRouter({ - history: createWebHashHistory(import.meta.env.BASE_URL), routes: setupLayouts(generatedRoutes) + history: createWebHashHistory(import.meta.env.BASE_URL), routes: setupLayouts(generatedRoutes) }) const updateRouterActive = (matched) => { - matched.shift() - const last = matched[matched.length - 1] - if (no_login_list.indexOf(last.name) !== -1) return - setTimeout(() => { - $router_active.value = matched.map((item) => { - return { - title: 'title' in item.meta ? item.meta.title : item.name, - key: item.name - } - }) + matched.shift() + const last = matched[matched.length - 1] + if (no_login_list.indexOf(last.name) !== -1) return + setTimeout(() => { + $router_active.value = matched.map((item) => { + return { + title: 'title' in item.meta ? item.meta.title : item.name, + key: item.name + } }) + }) } router.beforeEach(async (to, from, next) => { - window.$loading.start() - const $store = useStore() - if (!$store.config) { - const response = await ConfigGetAction(['Logo', 'Favicon', 'Login欢迎图片', '网站名称']) - $response(response, () => { - $store.config = response.data - }) - $favicon($store.config['Favicon']) + window.$loading.start() + const $store = useStore() + if (!$store.config) { + const response = await ConfigGetAction(['Logo', 'Favicon', 'Login欢迎图片', '网站名称']) + $response(response, () => { + $store.config = response.data + }) + $favicon($store.config['Favicon']) + } + document.title = ('title' in to.meta && to.meta.title !== '首页') ? `${to.meta.title} ${$store.config['网站名称']}` : $store.config['网站名称'] + if (no_login_list.indexOf(to.name) === -1) { + const $save_token_type = useSaveTokenType() + let $token; + if ($save_token_type.value === 'local') { + $token = useToken() + } else { + $token = useSessionToken() } - document.title = ('title' in to.meta && to.meta.title !== '首页') ? `${to.meta.title} ${$store.config['网站名称']}` : $store.config['网站名称'] - if (no_login_list.indexOf(to.name) === -1) { - const $save_token_type = useSaveTokenType() - let $token; - if ($save_token_type.value === 'local') { - $token = useToken() - } else { - $token = useSessionToken() - } - if ($token.value === '') { - next('/login?f=' + encodeURIComponent(to.fullPath)) - setTimeout(() => { - window.$loading.finish() - }) - } else { - const response = await AdminStatusAction() - $response(response, () => { - if (!$store.admin_info) reGetAdmin() - updateRouterActive(to.matched.map(item => item)) - next() - }, next) - setTimeout(() => { - window.$loading.finish() - }) - } + if ($token.value === '') { + next('/login?f=' + encodeURIComponent(to.fullPath)) + setTimeout(() => { + window.$loading.finish() + }) } else { + const response = await AdminStatusAction() + $response(response, () => { + if (!$store.admin_info) reGetAdmin() + updateRouterActive(to.matched.map(item => item)) next() - setTimeout(() => { - window.$loading.finish() - }) + }, next) + setTimeout(() => { + window.$loading.finish() + }) } + } else { + next() + setTimeout(() => { + window.$loading.finish() + }) + } }) export default router diff --git a/normal/.gitignore b/normal/.gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/normal/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/normal/README.md b/normal/README.md new file mode 100644 index 0000000..05ad1aa --- /dev/null +++ b/normal/README.md @@ -0,0 +1,14 @@ +# Vue 3 + Vite + +```bash +pnpm i +# If you don't have pnpm installed, run: npm install -g pnpm +pnpm dev +pnpm build +``` + +This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 ` + +
+ + + + +