Explorar o código

地灾项目中使用的免登录

sujunling hai 1 ano
pai
achega
c6e1ab28e7

+ 6 - 1
.env.development

@@ -11,7 +11,12 @@ VITE_GLOB_PUBLIC_PATH = /
 # VITE_PROXY = [["/api","http://192.168.2.225/api"]]
 
 # 线上演示环境
-VITE_PROXY = [["/api","http://117.174.10.73:19200"],["/agent","http://117.174.10.73:31895"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"],["/mapTools","http://106.12.170.138:10090"]]
+# VITE_PROXY = [["/api","http://117.174.10.73:19200"],["/agent","http://117.174.10.73:31895"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"],["/mapTools","http://106.12.170.138:10090"]]
+# VITE_PROXY = [["/api","http://192.168.49.163:20043"],["/agent","http://192.168.49.163:20043"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"],["/mapTools","http://106.12.170.138:10090"]]
+# VITE_PROXY = [["/api","http://127.0.0.1:20043"],["/agent","http://127.0.0.1:20043"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"],["/mapTools","http://106.12.170.138:10090"]]
+VITE_PROXY = [["/api","http://192.168.49.163:20043"],["/agent","http://192.168.49.163:20043"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"],["/mapTools","http://106.12.170.138:10090"]]
+# VITE_PROXY = [["/api","http://127.0.0.1:8008"],["/agent","http://127.0.0.1:8008"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"],["/mapTools","http://106.12.170.138:10090"]]
+# VITE_PROXY = [["/api","http://127.0.0.1:8008"],["/agent","http://127.0.0.1:8008"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"],["/mapTools","http://106.12.170.138:10090"]]
 # VITE_PROXY = [["/api","http://192.168.119.143:9200"],["/agent","http://192.168.119.143:31895"],["/iserver","http://221.182.8.141:15000/iserver"],["/onlineIde","http://106.12.170.138:4001/examples"],["/tfDemo","http://106.12.170.138:4001/demo"]]                                                            
 # 线上测试环境
 # VITE_PROXY = [["/api","http://localhost:8080/api"],["/thingskit-drawio","http://localhost:3000/"]]

+ 1 - 0
build/vite/proxy.ts

@@ -25,6 +25,7 @@ export function createProxy(list: ProxyList = []) {
       target: target,
       changeOrigin: true,
       ws: true,
+      // logLevel: 'debug', // 打印转发日志
       rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
       // https is require secure=false
       ...(isHttps ? { secure: false } : {}),

+ 21 - 3
src/router/guard/permissionGuard.ts

@@ -1,7 +1,7 @@
 import type { Router, RouteRecordRaw } from 'vue-router';
 import { usePermissionStoreWithOut } from '/@/store/modules/permission';
 import { PageEnum } from '/@/enums/pageEnum';
-import { useUserStoreWithOut } from '/@/store/modules/user';
+import { useUserStore, useUserStoreWithOut } from '/@/store/modules/user';
 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
 import { RootRoute } from '/@/router/routes';
 import { getMenuList } from '/@/api/sys/menu';
@@ -15,9 +15,25 @@ const DEVICE_LIST = PageEnum.DEVICE_LIST;
 const ROOT_PATH = RootRoute.path;
 const whitePathList: string[] = [LOGIN_PATH, DEVICE_LIST];
 
-export function createPermissionGuard(router: Router) {
+export async function createPermissionGuard(router: Router) {
   const userStore = useUserStoreWithOut();
   const permissionStore = usePermissionStoreWithOut();
+  const userStore2 = useUserStore();
+
+  if (location.href.indexOf('refreshToken') > -1) {
+    await userStore2.login({
+      password: 'Tofly@028',
+      username: 'ADMIN2',
+      mode: 'modal', //不要默认的错误提示
+    })
+      .catch((data) => {
+        console.log("自动登录:", data);
+      });
+    //修改地址栏链接
+    window.history.pushState('', '', location.href.split('?')[0]);
+  }
+
+
   router.beforeEach(async (to, from, next) => {
     const userInfo = await getAuthCache(USER_INFO_KEY);
     if (
@@ -116,7 +132,9 @@ export function createPermissionGuard(router: Router) {
     const routes = await permissionStore.buildRoutesAction();
 
     routes?.forEach((route) => {
-      router.addRoute(route as unknown as RouteRecordRaw);
+      if (route.path.indexOf('/') > -1) {
+        router.addRoute(route as unknown as RouteRecordRaw);
+      }
     });
 
     router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);

+ 0 - 1
src/utils/http/axios/index.ts

@@ -45,7 +45,6 @@ const transform: AxiosTransform = {
     if (joinPrefix) {
       config.url = `${urlPrefix}${config.url}`;
     }
-
     if (apiUrl && isString(apiUrl)) {
       if (config.apiUrl2) {
         config.url = `${apiUrl2}${config.url}`;

+ 3 - 1
src/views/sys/login/Login.vue

@@ -1,5 +1,5 @@
 <template>
-  <div :class="prefixCls" class="relative w-full h-full px-4">
+  <div v-if="loginShow" :class="prefixCls" class="relative w-full h-full px-4">
     <!-- <AppLocalePicker
       class="absolute text-white top-4 right-4 enter-x xl:text-gray-600"
       :showText="false"
@@ -191,8 +191,10 @@ const localeStore = useLocaleStore();
 const showLocale = localeStore.getShowPicker;
 // const title = computed(() => globSetting?.title ?? '');
 
+var loginShow = ref(false);
 onMounted(() => {
   useTitle('空间数据管理平台');
+  loginShow.value = !(location.href.indexOf('refreshToken') > -1);
 });
 </script>
 <style lang="less">