app
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import { goLogin } from '../utils/navigate'
|
||||
|
||||
const http = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL ?? '/api',
|
||||
@@ -17,7 +18,7 @@ http.interceptors.response.use(
|
||||
if (error.response?.status === 401 && !error.config?.url?.endsWith('/auth/login')) {
|
||||
localStorage.removeItem('jiaowu_token')
|
||||
localStorage.removeItem('jiaowu_user')
|
||||
window.location.assign(`/login?redirect=${encodeURIComponent(location.pathname)}`)
|
||||
goLogin(location.pathname + location.search + location.hash)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
},
|
||||
|
||||
+6
-4
@@ -3,8 +3,10 @@ import { createPinia } from 'pinia'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import { setRouter } from './utils/navigate'
|
||||
|
||||
createApp(App)
|
||||
.use(createPinia())
|
||||
.use(router)
|
||||
.mount('#app')
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
setRouter(router)
|
||||
app.mount('#app')
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import AdminLayout from '../layouts/AdminLayout.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
history: import.meta.env.VITE_ROUTER_MODE === 'hash'
|
||||
? createWebHashHistory()
|
||||
: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { Router } from 'vue-router'
|
||||
|
||||
let router: Router | null = null
|
||||
|
||||
export function setRouter(r: Router): void {
|
||||
router = r
|
||||
}
|
||||
|
||||
export function goLogin(redirect: string): void {
|
||||
if (router) {
|
||||
router.push({ name: 'login', query: { redirect } })
|
||||
} else {
|
||||
window.location.assign(
|
||||
`/?redirect=${encodeURIComponent(redirect)}#/login`,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -314,8 +314,9 @@ async function showQrCode() {
|
||||
ElMessage.warning('未取得签到码,请刷新考勤表后重试。')
|
||||
return
|
||||
}
|
||||
const publicBase = import.meta.env.VITE_PUBLIC_BASE_URL ?? window.location.origin
|
||||
qrCheckInUrl.value =
|
||||
`${window.location.origin}/my-attendance?token=${encodeURIComponent(sheet.checkInToken)}`
|
||||
`${publicBase}/my-attendance?token=${encodeURIComponent(sheet.checkInToken)}`
|
||||
try {
|
||||
qrDataUrl.value = await QRCode.toDataURL(qrCheckInUrl.value, {
|
||||
width: 360,
|
||||
|
||||
@@ -610,9 +610,10 @@ function openCalendarClient() {
|
||||
function normalizeCalendarSubscription(value: any) {
|
||||
if (!value?.feedPath) return value
|
||||
const configuredBase = String(http.defaults.baseURL ?? '/api')
|
||||
const publicBase = import.meta.env.VITE_PUBLIC_BASE_URL ?? window.location.origin
|
||||
const apiBase = new URL(
|
||||
configuredBase.endsWith('/') ? configuredBase : `${configuredBase}/`,
|
||||
window.location.origin,
|
||||
publicBase,
|
||||
)
|
||||
const feedUrl = new URL(value.feedPath, apiBase).toString()
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user