CzRger 5 months ago
parent
commit
631b2a6dcc
7 changed files with 19 additions and 11 deletions
  1. 4 1
      .env.development
  2. 4 1
      .env.production
  3. 3 1
      src/api/interceptors.ts
  4. 3 3
      src/router/index.ts
  5. 1 1
      src/stores/app.ts
  6. 1 1
      src/utils/permissions.ts
  7. 3 3
      vite.config.ts

+ 4 - 1
.env.development

@@ -2,4 +2,7 @@
 NODE_ENV = development
 
 # 标题
-VITE_TITLE = 智慧搜索平台
+VITE_TITLE = 智慧搜索平台
+
+# 基础路径
+VITE_BASE = 'smart-search-web'

+ 4 - 1
.env.production

@@ -2,4 +2,7 @@
 NODE_ENV = production
 
 # 标题
-VITE_TITLE = 智慧搜索平台
+VITE_TITLE = 智慧搜索平台
+
+# 基础路径
+VITE_BASE = 'smart-search-web'

+ 3 - 1
src/api/interceptors.ts

@@ -5,7 +5,9 @@ export class Interceptors {
   public instance: any
 
   constructor() {
-    this.instance = axios.create({timeout: 1000 * 300})
+    this.instance = axios.create({
+      baseURL: '/ssw-api', // api base_url
+      timeout: 1000 * 300})
     this.initInterceptors()
   }
 

+ 3 - 3
src/router/index.ts

@@ -18,7 +18,7 @@ const routes = [
 ]
 
 const router = createRouter({
-    history: createWebHistory(),
+    history: createWebHistory(import.meta.env.BASE_URL),
     routes,
 });
 
@@ -39,7 +39,7 @@ router.beforeEach((to, from , next) => {
         }
         document.title = to.meta?.title || ThemeStore.title || import.meta.env.VITE_TITLE
         next()
-    } else if (to.path === '/login') {
+    } else if (to.path === `/login`) {
         next()
     } else {
         ElMessage.error('用户信息获取失败!')
@@ -67,7 +67,7 @@ export const initMainRouter = async () => {
             themeConfig = theme.data.themeStyle ? JSON.parse(theme.data.themeStyle) : {}
             loading.close()
         })
-    } else if (location.pathname !== '/login') {
+    } else if (location.pathname !== `/${import.meta.env.VITE_BASE}/login`) {
         toLogin()
     }
 }

+ 1 - 1
src/stores/app.ts

@@ -19,7 +19,7 @@ export const useAppStore = defineStore('app', {
     setToken(token) {
       ElMessage.success('登录成功!')
       localStorage.setItem('ss_token', token)
-      location.replace('/')
+      window.location.replace(`/${import.meta.env.VITE_BASE}/`);
     },
     setTheme(config) {
       this.theme.init = true

+ 1 - 1
src/utils/permissions.ts

@@ -4,5 +4,5 @@ export const has = (value: any) => {
 
 export const toLogin = () => {
   localStorage.clear();
-  window.location.replace("/login");
+  window.location.replace(`/${import.meta.env.VITE_BASE}/login`);
 };

+ 3 - 3
vite.config.ts

@@ -40,7 +40,7 @@ export default defineConfig({
       promiseImportName: i => `__tla_${i}`
     })
   ],
-  // base: '/',
+  base: '/smart-search-web/',
   resolve: {
     alias: {
       '@': resolve(__dirname, 'src'),
@@ -59,8 +59,8 @@ export default defineConfig({
           return path.replace(/^\/mock-api/, 'mock-api')
         }
       },
-      '/api': {
-        target: 'http://10.110.45.26:18069/api/',
+      '/ssw-api': {
+        target: 'http://10.110.45.26:18069/',
         // target: 'http://8.130.72.63:18068/',
         changeOrigin: true,
         rewrite: (path) => {