fix(daily): opt

This commit is contained in:
zhangheng
2026-04-11 17:37:09 +08:00
parent 35b6849a64
commit 6baeae111e
6 changed files with 332 additions and 24 deletions

View File

@@ -0,0 +1,112 @@
"use client"
import { usePathname } from "next/navigation"
import { useEffect } from "react"
import { getProjectAdminList } from "./api/project"
import { getUserAll, getUserGroupTree } from "./api/user"
import {
useAllTaskStore,
useAllUserStore,
usePermissionStore,
} from "./store/auth"
export function OptStore() {
// const detectEnvironment = async () => {
// try {
// const result = await getName()
// console.log("Running in Tauri environment", result)
// return true
// } catch {
// console.log("Not running in Tauri environment")
// return false
// }
// }
const user_id = usePermissionStore.getState().user_id
const { needUpdate, setUserOpts, setTreeData, setAdminOpts, setFlag } =
useAllUserStore()
const pathname = usePathname()
useEffect(() => {
if (user_id) {
const getData = async () => {
const res = await getUserAll()
setUserOpts(res)
const gRes = await getUserGroupTree()
const getTreeData = (data: any, parentHasDisabledChild = false) => {
let hasDisabledChild = parentHasDisabledChild
const newData: any = {
title: data.name,
value: data.id,
key: data.id,
children: [],
disabled: false,
}
if (data.members && data.members.length) {
data.members.forEach((member: any) => {
newData.children.push({
title: member.name,
value: member.id,
key: member.id,
})
})
}
if (data.children && data.children.length) {
data.children.forEach((child: any) => {
const childData = getTreeData(child, hasDisabledChild)
newData.children.push(childData)
if (childData.disabled) {
hasDisabledChild = true
}
})
}
if (
data.id.includes("-") &&
(!data.members || !data.members.length) &&
(!data.children || !data.children.length || hasDisabledChild)
) {
newData.disabled = true
}
return newData
}
let arr: any[] = []
gRes.forEach((g: any) => {
arr.push(getTreeData(g))
})
const aRes = await getProjectAdminList()
setAdminOpts(aRes)
setTreeData(arr)
setFlag(false)
}
if (needUpdate) getData()
}
}, [user_id, setTreeData, setUserOpts, needUpdate, setFlag, setAdminOpts])
// 全局监听 重置项目详情中任务列表搜索缓存
useEffect(() => {
if (pathname !== "/project/info/detail" && pathname !== "/label") {
useAllTaskStore.getState().resetParams()
}
}, [pathname])
// // tauri://close-requested
// useEffect(() => {
// ;(async () => {
// if (await detectEnvironment()) {
// const window = getCurrentWindow()
// const unlisten = await window.onCloseRequested(async (_event) => {
// usePermissionStore.getState().logout()
// // event.preventDefault();
// })
// return () => {
// unlisten()
// }
// }
// })()
// }, [])
return <></>
}

View File

@@ -0,0 +1,98 @@
import httpFetch from "@/api/fetch"
import { BASE_LABEL_API } from "../const"
import { Organization, User } from "./typing"
// 获取用户列表
export const getUserList = (data: User.ListRequest) => {
return httpFetch<User.ListResponse>({
url: BASE_LABEL_API + "/api/v1/label_server/user/list",
method: "POST",
body: JSON.stringify({ ...data, tenant: "cowarobot" }),
})
}
// 新增用户
export const userAdd = (data: User.CreateProps) => {
return httpFetch({
url: BASE_LABEL_API + "/api/v1/label_server/user/add",
method: "POST",
body: JSON.stringify(data),
})
}
// 批量导入用户
export const userImport = (data: { user_infos: any[] }) => {
return httpFetch<string[]>({
url: BASE_LABEL_API + "/api/v1/label_server/user/batch_add",
method: "POST",
body: JSON.stringify(data),
})
}
// 编辑用户
export const userEditById = (data: User.EditProps, id: number) => {
return httpFetch({
url: BASE_LABEL_API + `/api/v1/label_server/user/edit/${id}`,
method: "PUT",
body: JSON.stringify(data),
})
}
// 编辑用户组织
export const userUpdateGroup = (data: User.UpdateGroupProps) => {
return httpFetch({
url: BASE_LABEL_API + `/api/v1/label_server/user/update/group`,
method: "POST",
body: JSON.stringify(data),
})
}
// 获取用户组织树
export const getUserGroupTree = () => {
return httpFetch<Organization.Response[]>({
url: BASE_LABEL_API + "/api/v1/label_server/user/group/tree",
method: "GET",
})
}
// 新增用户组
export const userGroupAdd = (data: Organization.CreateProps) => {
return httpFetch({
url: BASE_LABEL_API + "/api/v1/label_server/user/group/add",
method: "POST",
body: JSON.stringify(data),
})
}
// 修改用户密码
export const modifyUserPassword = (data: {
old_password: string
new_password: string
}) => {
return httpFetch({
url: BASE_LABEL_API + "/api/v1/label_server/user/modify_password",
method: "PUT",
body: JSON.stringify(data),
})
}
/* ****************************** Options ****************************** */
interface Option {
label: string
value: string
}
// 获取所有用户组
export const getUserGroupAll = () => {
return httpFetch<Array<Option>>({
url: BASE_LABEL_API + `/api/v1/label_server/user/group/all`,
method: "GET",
})
}
// 获取所有用户
export const getUserAll = () => {
return httpFetch<Array<Option>>({
url: BASE_LABEL_API + "/api/v1/label_server/user/all",
method: "GET",
})
}

View File

@@ -0,0 +1,76 @@
export namespace User {
export interface UserInfo {
uid: number
name: string
all_projects: { [x: number]: number[] }
collect_projects: number[]
group_name: string
group_uuid: string
work_status: number
base_city: string
}
export interface LoginInfo extends UserInfo {
token: string
refresh_token: string
}
export interface ListRequest {
name?: string
page_number?: number
page_size?: number
}
export interface ListResponse {
user_list: UserInfo[]
total_pages: number
total_items: number
}
export interface CreateProps {
user_name: string
group_uuid: string
base_city: string
}
export interface EditProps {
user_name?: string
password?: string
group_uuid?: string
base_city?: string
work_status?: number
}
export interface UpdateGroupProps {
user_id: number
group_uuid: string
}
}
export namespace Organization {
export interface CreateProps {
group_name: string
leader_uid: number
parent_group_uuid: string
}
interface Member {
base_city: string
id: number
name: string
work_status: number
}
export interface Response {
children?: Response[]
create_at?: string
create_user?: string
group_uuid: string
leader_uid?: number
leader_name?: string
members?: Member[]
name: string
parent_group_uuid: string
[key: string]: boolean | string | number | Response[] | Member[] | undefined
}
}

View File

@@ -70,17 +70,17 @@ const currentComponentList: MenuItem[] = [
{
title: "个人中心",
url: "person",
icon: "PersonalMenuIcon",
icon: "PersonalCenterIcon",
items: [
{
title: "个人看板",
url: "dashboard",
icon: "TaskMenuIcon",
icon: "DashboardIcon",
},
{
title: "个人日报",
url: "report",
icon: "AuthMenuIcon",
icon: "ReportIcon",
},
],
},
@@ -91,22 +91,22 @@ export const componentList: MenuItem[] = [
{
title: "图片标注",
url: "image",
icon: "SystemIcon",
icon: "ImageAnnotationIcon",
},
{
title: "视频标注",
url: "video",
icon: "SystemIcon",
icon: "VideoAnnotationIcon",
},
{
title: "点云标注",
url: "lidar",
icon: "LidarAnnotationIcon",
},
// {
// title: "点云标注",
// url: "pointcloud",
// icon: "SystemIcon",
// },
{
title: "管理中心",
url: "mgt",
icon: "SystemIcon",
icon: "ManagementCenterIcon",
},
]

View File

@@ -1,14 +1,39 @@
// import { type LucideIcon } from "lucide-react";
import {
AuthMenuIcon,
PersonalMenuIcon,
SystemIcon,
TaskMenuIcon,
} from "./icons/custom"
IconCategory2,
IconCube3dSphere,
IconFileText,
IconFolder,
IconFolders,
IconHierarchy3,
IconLayoutDashboard,
IconPhoto,
IconSettings,
IconUserCircle,
IconUsersGroup,
IconVideo,
} from "@tabler/icons-react"
import React from "react"
const iconMap = {
DashboardIcon: IconLayoutDashboard,
EmployeeManagementIcon: IconUsersGroup,
ImageAnnotationIcon: IconPhoto,
LidarAnnotationIcon: IconCube3dSphere,
ManagementCenterIcon: IconSettings,
MyProjectsIcon: IconFolder,
PersonalCenterIcon: IconUserCircle,
ProjectCategoryIcon: IconCategory2,
ProjectManagementIcon: IconFolders,
ReportIcon: IconFileText,
TeamManagementIcon: IconHierarchy3,
VideoAnnotationIcon: IconVideo,
SystemIcon: IconSettings,
PersonalMenuIcon: IconUserCircle,
TaskMenuIcon: IconLayoutDashboard,
AuthMenuIcon: IconFileText,
} as const
export const ClientIcon = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"button"> & {
@@ -16,12 +41,7 @@ export const ClientIcon = React.forwardRef<
}
>(({ icon, ...props }, _ref) => {
if (icon) {
const IconComponent = {
SystemIcon,
PersonalMenuIcon,
TaskMenuIcon,
AuthMenuIcon,
}[icon]
const IconComponent = iconMap[icon as keyof typeof iconMap]
return IconComponent ? <IconComponent style={{ ...props.style }} /> : null
} else {
return null