Browse Source

Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
415b6eb630
8 changed files with 21 additions and 26 deletions
  1. 2 0
      .env.development
  2. 1 0
      .env.production
  3. 0 16
      admin.html
  4. 1 1
      index.html
  5. 1 1
      login.html
  6. 7 4
      src/utils/axios.ts
  7. 4 2
      src/utils/userdata.ts
  8. 5 2
      vite.config.ts

+ 2 - 0
.env.development

@@ -0,0 +1,2 @@
+#VITE_SERVER_URL=http://20.20.20.4:8762
+VITE_SERVER_URL=http://lqai.caner.top:9080

+ 1 - 0
.env.production

@@ -0,0 +1 @@
+VITE_SERVER_URL=https://srbg.jdjinsui.com:8765

+ 0 - 16
admin.html

@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
-  <meta charset="UTF-8" />
-  <link rel="icon" href="/favicon.ico" />
-  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-  <title>智慧隧道AI建造</title>
-</head>
-
-<body>
-  <div id="app"></div>
-  <script type="module" src="/src/pages/admin/main.ts"></script>
-</body>
-
-</html>

+ 1 - 1
index.html

@@ -3,7 +3,7 @@
   <head>
     <meta charset="UTF-8" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>智慧隧道AI建造</title>
+    <title>home</title>
   </head>
   <body>
     <div id="app"></div>

+ 1 - 1
login.html

@@ -5,7 +5,7 @@
   <meta charset="UTF-8" />
   <link rel="icon" href="/favicon.ico" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-  <title>智慧隧道AI建造</title>
+  <title>登录</title>
 </head>
 
 <body>

+ 7 - 4
src/utils/axios.ts

@@ -12,6 +12,7 @@ const resetLoaing = (type: boolean) => {
     const el = obj[key]
     if ('loading' in el) {
       el.loading = type
+      break
     }
   }
 
@@ -20,9 +21,11 @@ const resetLoaing = (type: boolean) => {
 // http request 拦截=>增加是否显示loading
 axios.interceptors.request.use(
   (config: any) => {
-    config.baseURL = import.meta.env.VITE_SERVER_URL
-    const headers = config.headers || {}
-    headers['Authorization'] = 'Bearer ' + userinfo.token
+    if (!config.url.includes('https://')) {
+      config.baseURL = import.meta.env.VITE_SERVER_URL
+      const headers = config.headers || {}
+      headers['Authorization'] = 'Bearer ' + userinfo.token
+    }
     const showLoading = config.showLoading || false
     if (showLoading) resetLoaing(true)
     return config
@@ -35,7 +38,7 @@ axios.interceptors.response.use(
   (response) => {
     const data = response.data
     if (data.code !== 200) {
-      if (data.code === 2002) {
+      if (data.code === 401) {
         // token 错误
         userData.clear()
         window.location.href = '/login.html'

+ 4 - 2
src/utils/userdata.ts

@@ -9,7 +9,9 @@ interface userDATA {
  * 用户加密操作
  */
 class Userservice {
-  constructor() { }
+  constructor() {
+    this.setTime()
+   }
   /**
    * 加密
    * @param {string} txt 密码
@@ -37,7 +39,7 @@ class Userservice {
    * 获取
    */
   getUserData() {
-    return JSON.parse(localStorage.getItem('userDATA') as string)
+    return JSON.parse(localStorage.getItem('userDATA') as string) || null
   }
   /**
    * 时间限制24小时

+ 5 - 2
vite.config.ts

@@ -2,6 +2,7 @@ import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import eslint from 'vite-plugin-eslint'
 import path from 'path'
+import viteCompression from 'vite-plugin-compression'
 
 // https://vitejs.dev/config/
 export default defineConfig({
@@ -15,7 +16,7 @@ export default defineConfig({
       '@': path.resolve(__dirname, './src')
     }
   },
-  plugins: [vue(), eslint({ fix: true, include: ['**/*.ts', '**/*.vue'] })],
+  plugins: [vue(), viteCompression(), eslint({ fix: true, include: ['**/*.ts', '**/*.vue'] })],
   server: {
     host: 'localhost',
     port: 6547,
@@ -34,7 +35,6 @@ export default defineConfig({
   build: {
     rollupOptions: {
       input: {
-        admin: path.resolve(__dirname, 'admin.html'),
         index: path.resolve(__dirname, 'index.html'),
         login: path.resolve(__dirname, 'login.html')
       },
@@ -51,4 +51,7 @@ export default defineConfig({
       }
     }
   },
+  define: {
+    __VUE_OPTIONS_API__: false
+  }  
 })