فهرست منبع

feat: LDAP用户新增和修改

tuonian 4 ماه پیش
والد
کامیت
16dfd1d7d3
3فایلهای تغییر یافته به همراه37 افزوده شده و 5 حذف شده
  1. 3 2
      frontend/src/routes/index.tsx
  2. 33 2
      frontend/src/routes/routes.tsx
  3. 1 1
      server/modules/ldap/user_service.go

+ 3 - 2
frontend/src/routes/index.tsx

@@ -16,7 +16,7 @@ import {NginxLayout} from "../pages/nginx/layout.tsx";
 import {ldapRoutes} from '../pages/ldap/layout.tsx'
 import {ErrorBoundary} from "../components/error/ErrorBoundary.tsx";
 import {UserList} from "../pages/user/list";
-import {DirectPage} from "./routes.tsx";
+import {DirectPage, useMatchNav} from "./routes.tsx";
 /**
  * @author tuonian
  * @date 2023/6/26
@@ -38,6 +38,8 @@ export const RouteWrapper = ({Component, ...props}: RouteWrapperProps) => {
     const location = useLocation()
     const dispatch = useAppDispatch()
 
+    const matchNav = useMatchNav(true)
+
 
     useEffect(() => {
         if (!isLogin){
@@ -69,7 +71,6 @@ export const RouteWrapper = ({Component, ...props}: RouteWrapperProps) => {
             <div className="hint-msg">加载中,请稍等...</div>
         </div>)
     }
-
     return <Component {...props} />
 }
 

+ 33 - 2
frontend/src/routes/routes.tsx

@@ -1,6 +1,7 @@
 import {LoadingText} from "../components/loading";
-import {useEffect} from "react";
-import {useNavigate} from "react-router";
+import {useEffect, useMemo} from "react";
+import {useMatches, useNavigate} from "react-router";
+import {useAppSelector} from "../store";
 
 /**
  * 顶部的菜单
@@ -23,6 +24,36 @@ export const NavList = [
   }
 ]
 
+/**
+ * 是否有菜单全新
+ */
+export const useMatchNav = (checkPermission = false) => {
+  const matches = useMatches()
+  const user = useAppSelector(state => state.user.user)
+  const navigate = useNavigate()
+
+  return useMemo(()=>{
+    let nav = null
+    for (const match of matches) {
+      nav = NavList.find(item=>item.key == match.pathname)
+      if (nav){
+       break
+      }
+    }
+    if (!nav || nav.roles.length == 0 || !checkPermission){
+      return true
+    }
+    const roles = user?.roles?.split(",") || []
+    for (const r of nav.roles){
+      if (roles.includes(r)){
+        return nav
+      }
+    }
+    navigate('/')
+    return false;
+  },[matches, user, checkPermission])
+}
+
 type IProps = {
   to: string
 }

+ 1 - 1
server/modules/ldap/user_service.go

@@ -129,7 +129,7 @@ func (c *UserService) SyncUser(server *models.LdapServer, current *models.LdapUs
 	user.Uid = current.Uid
 	user.Remark = current.Remark
 
-	_, err = o.Update(&user)
+	_, err = o.Update(user)
 	if err != nil {
 		return err
 	}