tangjunhao преди 3 месеца
родител
ревизия
a400c60cfa
променени са 3 файла, в които са добавени 82 реда и са изтрити 90 реда
  1. 23 11
      src/router/index.js
  2. 1 1
      src/views/project/index.vue
  3. 58 78
      vite.config.ts

+ 23 - 11
src/router/index.js

@@ -46,18 +46,30 @@ const router = createRouter({
     ]
 })
 //修改动态网页标题 beforeEach 导航钩子,路由改变前触发
-router.beforeEach((to,from,next) =>{
-    //window.document.title = to.meta.title;
-    let token = getToken2();
-    if(!token && to.name !== 'login'){
-      next({ name: 'login' });
-    }
-    window.document.title = to.name;
+router.beforeEach((to, from, next) => {
+  const token = getToken2(); // 获取 token
+  
+  // 定义不需要登录的白名单路由
+  const whiteList = ['login', 'register'];
+  
+  // 如果用户有 token,直接放行
+  if (token) {
+    document.title = to.name || '默认标题'; // 设置页面标题
     next();
-})
-router.afterEach((to,from,next) =>{
-    window.scrollTo(0,0);
-})
+  } 
+  // 如果没有 token,并且目标页面不在白名单里,跳转到登录页
+  else if (!whiteList.includes(to.name)) {
+    next({ name: 'login' });
+  }
+  else {
+    document.title = to.name || '默认标题';
+    next();
+  }
+});
+// afterEach 不需要 next 参数
+router.afterEach(() => {
+  window.scrollTo(0, 0); // 页面滚动到顶部
+});
 export default router;
 
 

+ 1 - 1
src/views/project/index.vue

@@ -178,7 +178,7 @@ const addProject = () => {
   const params = {
     transCode: 'ES0002',
     name: newproject.value.name,
-    description: newproject.value.description
+    remark: newproject.value.description
   };
   request(params)
     .then((res) => {

+ 58 - 78
vite.config.ts

@@ -17,85 +17,65 @@ import VueSetupExtend from 'vite-plugin-vue-setup-extend'
 
 // https://vitejs.dev/config/
 export default defineConfig(({ mode }) => {
-    
-    const config = loadEnv(mode, './');
-    console.log(config);
-    return {
-        base: "./",
-        plugins: [
-            vue(), 
-            removeConsole(),
-            compression(),
-            monacoEditorPlugin({}), // 启用 Monaco Editor 插件
-            AutoImport({
-                //安装两行后你会发现在组件中不用再导入ref,reactive等
-                imports: ['vue', 'vue-router'],
-                //存放的位置
-                dts: "src/auto-import.d.ts",
-            }),
-            Components({
-                // 引入组件的,包括自定义组件,存放的位置
-                dts: "src/components.d.ts",
-            }),
-            VueSetupExtend(),
-        ],
+  const config = loadEnv(mode, './');
+  if (mode === 'development') console.debug('Loaded env:', config);
 
-        //1、 ↓解析配置
-        resolve: {
-            // ↓路径别名
-            alias: {
-                '@': resolve('src'),
-                 '@views': resolve('src/views')
-            }
+  return {
+    base: "./",
+    plugins: [
+      vue(),
+      removeConsole(),
+      compression(),
+      monacoEditorPlugin({}),
+      AutoImport({
+        imports: ['vue', 'vue-router'],
+        dts: "src/auto-import.d.ts",
+      }),
+      Components({
+        dts: "src/components.d.ts",
+      }),
+      VueSetupExtend(),
+    ],
+    resolve: {
+      alias: {
+        '@': resolve('src'),
+        '@views': resolve('src/views')
+      }
+    },
+    server: {
+      proxy: {
+        '/api': {
+          target: 'https://www.adicn.com/eps',
+          secure: false,
+          changeOrigin: true,
+          rewrite: (path) => path.replace(/^\/api/, '')
         },
-
-        //代理
-        server: {
-            proxy: {
-                '/api': {
-                    // target: 'http://192.168.0.131:8188/TransServlet',//配置文件获取地址
-                   target: 'https://www.adicn.com/eps',
-                    secure: false, //接受使用https
-                    changeOrigin: true, //允许跨域
-                    ws: false, //使用websocket
-                    rewrite: (path) => path.replace(/^\/api/, '')
-                },
-                '/eps': {
-                    // target: 'http://192.168.0.131:8188/TransServlet',//配置文件获取地址
-                   target: 'https://www.adicn.com/eps',
-                    secure: false, //接受使用https
-                    changeOrigin: true, //允许跨域
-                    ws: false, //使用websocket
-                    rewrite: (path) => path.replace(/^\/eps/, '')
-                },
-
-                '/file': {
-                    // target: 'http://192.168.0.15:8081/', // 后端接口地址
-                    target: 'http://192.168.0.43:2201/',
-                    secure: false, //接受使用https
-                    changeOrigin: true, //允许跨域
-                    ws: false, //使用websocket
-                    pathRewrite: { // 路径重写
-                        '^/file': ''
-                    }
-                }, '/websokct': {
-                    target: 'http://192.168.0.104:8188',
-                    // target: 'http://192.168.0.43:8081/',
-                    // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
-                    secure: false, //接受使用https
-                },
-
-            }
+        '/eps': {
+          target: 'https://www.adicn.com/eps',
+          secure: false,
+          changeOrigin: true,
+          rewrite: (path) => path.replace(/^\/eps/, '')
         },
-      renderer: {
-            css: {
-              preprocessorOptions: {
-                scss: {
-                  silenceDeprecations: ['legacy-js-api']
-                }
-              }
-            }
-        }  
+        '/file': {
+          target: 'http://192.168.0.43:2201/',
+          secure: false,
+          changeOrigin: true,
+          rewrite: path => path.replace(/^\/file/, '')
+        },
+        '/websocket': { // 原为 websockt,修正拼写
+          target: 'http://192.168.0.104:8188',
+          secure: false,
+          changeOrigin: true
+        },
+      }
+    },
+    css: {
+      preprocessorOptions: {
+        scss: {
+          // optional: global SCSS variables/mixins
+          // additionalData: `@import "@/styles/variables.scss";`
+        }
+      }
     }
-
-})
+  };
+});