From 9be594f9dc83716114e7c4279bc96ec5f3d9e4a1 Mon Sep 17 00:00:00 2001 From: 0xJacky Date: Tue, 2 Aug 2022 14:03:35 +0800 Subject: [PATCH] [frontend-next] Refactored install and 404 pages --- frontend/src/api/index.ts | 12 ++ .../StdDataDisplay/StdPagination.vue | 1 - frontend/src/lib/http/index.ts | 10 +- frontend/src/routes/index.ts | 33 +--- frontend/src/views/other/Error.vue | 20 +- frontend/src/views/other/Install.vue | 186 ++++++++++-------- frontend/src/views/other/Login.vue | 15 +- server/api/install.go | 105 +++++----- 8 files changed, 199 insertions(+), 183 deletions(-) create mode 100644 frontend/src/api/index.ts diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts new file mode 100644 index 00000000..4f15603f --- /dev/null +++ b/frontend/src/api/index.ts @@ -0,0 +1,12 @@ +import http from '@/lib/http' + +const install = { + get_lock() { + return http.get('/install') + }, + install_nginx_ui(data: any) { + return http.post('/install', data) + } +} + +export default install diff --git a/frontend/src/components/StdDataDisplay/StdPagination.vue b/frontend/src/components/StdDataDisplay/StdPagination.vue index 1b5c124a..7ae71be3 100644 --- a/frontend/src/components/StdDataDisplay/StdPagination.vue +++ b/frontend/src/components/StdDataDisplay/StdPagination.vue @@ -17,7 +17,6 @@ function changePage(num: number) { :pageSize="pagination.per_page" :size="size" :total="pagination.total" - :show-total="(total, range) => `当前显示${range[0]}-${range[1]}条数据,共${total}条数据`" class="pagination" @change="changePage" /> diff --git a/frontend/src/lib/http/index.ts b/frontend/src/lib/http/index.ts index 9338e512..f1b2cb09 100644 --- a/frontend/src/lib/http/index.ts +++ b/frontend/src/lib/http/index.ts @@ -2,15 +2,12 @@ import axios, {AxiosRequestConfig} from 'axios' import {useUserStore} from '@/pinia' import {storeToRefs} from 'pinia' +import router from '@/routes' + const user = useUserStore() const {token} = storeToRefs(user) -declare module 'axios' { - export interface AxiosResponse extends Promise { - } -} - let instance = axios.create({ baseURL: import.meta.env.VITE_API_ROOT, timeout: 50000, @@ -38,7 +35,6 @@ instance.interceptors.request.use( } ) - instance.interceptors.response.use( response => { return Promise.resolve(response.data) @@ -47,6 +43,8 @@ instance.interceptors.response.use( switch (error.response.status) { case 401: case 403: + user.logout() + await router.push('/login') break } return Promise.reject(error.response.data) diff --git a/frontend/src/routes/index.ts b/frontend/src/routes/index.ts index 6d6ebac2..9506f40e 100644 --- a/frontend/src/routes/index.ts +++ b/frontend/src/routes/index.ts @@ -100,7 +100,7 @@ export const routes = [ { path: '/install', name: () => $gettext('Install'), - // component: () => import('@/views/other/Install.vue'), + component: () => import('@/views/other/Install.vue'), meta: {noAuth: true} }, { @@ -110,16 +110,10 @@ export const routes = [ meta: {noAuth: true} }, { - path: '/404', - name: () => $gettext('404 Not Found'), - component: () => import('@/views/other/Error.vue'), - meta: {noAuth: true, status_code: 404, error: 'Not Found'} - }, - { - path: '/*', + path: '/:pathMatch(.*)*', name: () => $gettext('Not Found'), - redirect: '/404', - meta: {noAuth: true} + component: () => import('@/views/other/Error.vue'), + meta: {noAuth: true, status_code: 404, error: () => $gettext('Not Found')} } ] @@ -130,25 +124,8 @@ const router = createRouter({ }) router.beforeEach((to, from, next) => { - // @ts-ignore - document.title = to.name() + ' | Nginx UI' - - if (import.meta.env.MODE === 'production') { - // axios.get('/version.json?' + Date.now()).then(r => { - // if (!(process.env.VUE_APP_VERSION === r.data.version - // && Number(process.env.VUE_APP_BUILD_ID) === r.data.build_id)) { - // Vue.prototype.$info({ - // title: $gettext('System message'), - // content: $gettext('Detected version update, this page will refresh.'), - // onOk() { - // location.reload() - // }, - // okText: $gettext('OK') - // }) - // } - // }) - } + document.title = to.name?.() + ' | Nginx UI' const user = useUserStore() const {is_login} = user diff --git a/frontend/src/views/other/Error.vue b/frontend/src/views/other/Error.vue index dce22d36..fea174f7 100644 --- a/frontend/src/views/other/Error.vue +++ b/frontend/src/views/other/Error.vue @@ -1,16 +1,17 @@ + + - -