ソースを参照

feat(mini): 优化小程序登录流程,未登录直接进入登录页

- 用人端:将登录页设为小程序首页
- 两个登录页添加已登录自动跳转逻辑
- 未登录用户直接看到登录页,不再先进入首页再跳转

🤖 Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 週間 前
コミット
d8054e7bbd

+ 8 - 1
mini-ui-packages/mini-enterprise-auth-ui/src/pages/login/Login.tsx

@@ -25,7 +25,14 @@ type LoginFormData = z.infer<typeof loginSchema>
 
 export default function Login() {
   const [showPassword, setShowPassword] = useState(false)
-  const { login, isLoading } = useAuth()
+  const { login, isLoading, isLoggedIn } = useAuth()
+
+  // 如果已登录,直接跳转到 dashboard
+  useEffect(() => {
+    if (isLoggedIn) {
+      Taro.switchTab({ url: '/pages/yongren/dashboard/index' })
+    }
+  }, [isLoggedIn])
 
   const form = useForm<LoginFormData>({
     resolver: zodResolver(loginSchema as any),

+ 9 - 2
mini-ui-packages/rencai-auth-ui/src/pages/LoginPage/LoginPage.tsx

@@ -1,4 +1,4 @@
-import React, { useState } from 'react'
+import React, { useState, useEffect } from 'react'
 import { View, Text, Input, Button } from '@tarojs/components'
 import { useAuth } from '../../hooks'
 import { Navbar } from '@d8d/mini-shared-ui-components/components/navbar'
@@ -13,7 +13,14 @@ export const LoginPage: React.FC = () => {
   const [identifier, setIdentifier] = useState('')
   const [password, setPassword] = useState('')
   const [loading, setLoading] = useState(false)
-  const { login } = useAuth()
+  const { login, isLoggedIn } = useAuth()
+
+  // 如果已登录,直接跳转到首页
+  useEffect(() => {
+    if (isLoggedIn) {
+      Taro.switchTab({ url: '/pages/index/index' })
+    }
+  }, [isLoggedIn])
 
   const handleLogin = async () => {
     // 表单验证

+ 1 - 0
mini/src/app.config.ts

@@ -1,5 +1,6 @@
 export default defineAppConfig({
   pages: [
+    'pages/login/index',
     'pages/yongren/dashboard/index',
     'pages/yongren/talent/list/index',
     'pages/yongren/talent/detail/index',