فهرست منبع

统一认证平台逻辑调整

lingmin_package@163.com 4 هفته پیش
والد
کامیت
79df545645
4فایلهای تغییر یافته به همراه30 افزوده شده و 5 حذف شده
  1. 5 0
      src/api/auth.ts
  2. 1 1
      src/router/index.ts
  3. 24 4
      src/views/dashboard/Index.vue
  4. 0 0
      tsconfig.tsbuildinfo

+ 5 - 0
src/api/auth.ts

@@ -43,5 +43,10 @@ export const authApi = {
       token,
       new_password: newPassword
     })
+  },
+
+  // 获取SSO免登跳转URL(预签发OAuth2授权码)
+  getSSORedirectUrl(appId: string): Promise<ApiResponse<{ redirect_url: string }>> {
+    return request.post('/api/v1/auth/sso-redirect', { app_id: appId })
   }
 }

+ 1 - 1
src/router/index.ts

@@ -163,7 +163,7 @@ router.beforeEach(async (to, from, next) => {
 
   // 检查是否需要访客权限(已登录用户不能访问登录/注册页)
   if (to.meta.requiresGuest && authStore.isAuthenticated) {
-    next({ name: 'Dashboard' })
+    next({ name: 'MyApps' })
     return
   }
 

+ 24 - 4
src/views/dashboard/Index.vue

@@ -82,6 +82,7 @@
 import { ref, onMounted } from 'vue'
 import { useAuthStore } from '@/stores/auth'
 import { appApi } from '@/api/apps'
+import { authApi } from '@/api/auth'
 import { ElMessage } from 'element-plus'
 import {
   OfficeBuilding,
@@ -165,13 +166,32 @@ const loadApps = async () => {
   }
 }
 
-const handleAppClick = (app: any) => {
+const handleAppClick = async (app: any) => {
   const url = app.home_url || app.redirect_uri
-  if (url) {
-    window.open(url, '_blank')
-  } else {
+  if (!url) {
     ElMessage.warning('该应用未配置访问地址')
+    return
   }
+
+  // 优先尝试 SSO 免登跳转(后端预签发 OAuth2 授权码)
+  try {
+    const response = await authApi.getSSORedirectUrl(app.id)
+    if (response.code === '000000' || response.code === 0) {
+      const redirectUrl = response.data?.redirect_url
+      if (redirectUrl) {
+        window.open(redirectUrl, '_blank')
+        return
+      }
+    }
+    // 接口返回业务错误,降级到直接打开
+    console.warn('SSO 免登接口返回错误:', response.message)
+  } catch (error: any) {
+    // 网络异常等,降级到直接打开
+    console.warn('SSO 免登请求失败,降级到直接打开:', error)
+  }
+
+  // 降级方案:直接打开应用首页
+  window.open(url, '_blank')
 }
 
 onMounted(() => {

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
tsconfig.tsbuildinfo


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است