Răsfoiți Sursa

feat: 删除开发和生产环境配置文件,优化登录表单和路由守卫逻辑

张涛 1 an în urmă
părinte
comite
1d55d9b7f0
5 a modificat fișierele cu 16 adăugiri și 38 ștergeri
  1. 0 7
      .env.development
  2. 0 5
      .env.production
  3. 10 20
      src/modules/login/FormItem.vue
  4. 3 4
      src/router/guard.js
  5. 3 2
      vite.config.mjs

+ 0 - 7
.env.development

@@ -1,7 +0,0 @@
-#开发环境
-NODE_ENV=development
-VITE_APP_MODE=development
-
-VITE_APP_API_URL= http://smartai.com:8191  # 外网地址
-# VITE_APP_API_URL= http://192.168.20.119:9301  # 内网地址
-

+ 0 - 5
.env.production

@@ -1,5 +0,0 @@
-#生产环境
-NODE_ENV=production
-VITE_APP_MODE=production
-
-VITE_APP_API_URL= http://smartai.com:8191  # 外网地址

+ 10 - 20
src/modules/login/FormItem.vue

@@ -2,14 +2,8 @@
   <div class="form-title">
     {{ form_type ? $t('login.registerModel') : $t('login.loginModel') }}
   </div>
-  <a-form
-    ref="ref_form"
-    :model="form"
-    :rules="rules"
-    :style="{ width: 'calc(100% - 40px)' }"
-    layout="validate"
-    @submit-success="handleSubmit"
-  >
+  <a-form ref="ref_form" :model="form" :rules="rules" :style="{ width: 'calc(100% - 40px)' }" layout="validate"
+    @submit-success="handleSubmit">
     <a-form-item field="username">
       <a-input v-model="form.username" :placeholder="$t('login.usernameTips')">
         <template #prefix> <icon-user /> </template>
@@ -21,23 +15,19 @@
       </a-input>
     </a-form-item>
     <a-form-item field="password">
-      <a-input-password
-        v-model="form.password"
-        :placeholder="$t('login.passwordTips')"
-        :defaultVisibility="true"
-        allow-clear
-      >
+      <a-input-password v-model="form.password" :placeholder="$t('login.passwordTips')" :defaultVisibility="true"
+        allow-clear>
         <template #prefix>
           <icon-user />
         </template>
       </a-input-password>
     </a-form-item>
     <a-form-item>
-      <a-button v-if="!form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading"
-        >{{ $t('login.loginBtn') }}
+      <a-button v-if="!form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading">{{
+        $t('login.loginBtn') }}
       </a-button>
-      <a-button v-if="form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading"
-        >{{ $t('login.registerBtn') }}
+      <a-button v-if="form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading">{{
+        $t('login.registerBtn') }}
       </a-button>
     </a-form-item>
   </a-form>
@@ -94,7 +84,7 @@ const handleSubmit = (data) => {
         await userStore.getRoutesList();
         // 登录成功后,获取用户权限
         await userStore.getUserInfo();
-        router.push({ path: '/knowledge' });
+        router.push({ path: '/' });
       })
       .catch((err) => {
         $message.error(err);
@@ -174,7 +164,7 @@ const changeFormType = (e) => {
   border-color: var(--color-neutral-3);
 }
 
-:deep .arco-form-item-label-col > .arco-form-item-label {
+:deep .arco-form-item-label-col>.arco-form-item-label {
   display: none;
 }
 </style>

+ 3 - 4
src/router/guard.js

@@ -9,17 +9,16 @@ const whiteList = ['/login', '/reg', '/noPer'];
 router.beforeEach((to, from, next) => {
   const isAuthorized = kuky_Authorization.get(); // 获取用户授权状态
   const isLoginPage = to.path === '/login'; // 判断目标路径是否为登录页
-  const firstLogin = from.path === '/login'; // 判断当前路径是否为登录页
   const isInWhiteList = whiteList.includes(to.path); // 检查目标路径是否在白名单中
   const hasAccess = accessFlatRoutes.some((route) => route.path == to.path);
 
   // 用户已授权的情况
   if (isAuthorized) {
-    if (firstLogin || isLoginPage) {
-      next(); // 如果是第一次登录,直接进入首页
+    if (isLoginPage) {
+      next(firstPage);
     } else if (!hasAccess && !isInWhiteList) {
       // 如果用户无访问权限且不在白名单中
-      next({ path: '/noPer' }); // 重定向到无权限页面
+      next('/noPer'); // 重定向到无权限页面
     } else {
       next(); // 其他情况,正常访问
     }

+ 3 - 2
vite.config.mjs

@@ -6,7 +6,7 @@ import vueDevTools from 'vite-plugin-vue-devtools';
 
 // https://vitejs.dev/config/
 export default defineConfig(({ mode }) => {
-  const env = loadEnv(mode, process.cwd());
+  // const env = loadEnv(mode, process.cwd());
   return {
     /**
      * 项目根目录
@@ -23,7 +23,8 @@ export default defineConfig(({ mode }) => {
       host: '0.0.0.0', // IP配置,支持从IP启动
       proxy: {
         '/api/': {
-          target: env.VITE_APP_API_URL,
+          target: 'http://smartai.com:8191',
+          // target: 'http://192.168.20.119:9301',
           changeOrigin: true,
           secure: false,
           ws: true,