"use client" import { getProjectDetailById } from "@/components/label/api/project" import { ProjectDetail } from "@/components/label/api/project/typing" import { useAllUserStore, useBackUrlStore } from "@/components/label/store/auth" import { Breadcrumbs, Flex, Group, Stack, Text, UnstyledButton, } from "@mantine/core" import { useRouter, useSearchParams } from "next/navigation" import { useEffect, useMemo, useState } from "react" import { SettingFilterPanel, SettingPage, } from "@/components/setting/PageSurface" import InfoSettingContainer from "./InfoSettingContainer" import OwnTaskTableContainer from "./OwnTaskTableContainer" import TaskBoardContainer from "./TaskBoardContainer" import TaskTableContainer from "./TaskTableContainer" type TabKey = "own" | "all" | "setting" | "board" export default function CollectionDetailPage() { const router = useRouter() const urlParams = useSearchParams() const type = urlParams.get("type") const id = urlParams.get("id") const projectId = typeof id === "string" && !isNaN(Number(id)) ? Number(id) : -1 const { backTitle, setBackProps } = useBackUrlStore() const { userOpts } = useAllUserStore() // const permissions = usePermissionStore((s) => s.detailInfo?.permissions) // const canConfig = useMemo(() => { // const v = permissions?.project?.config?.[0] // return typeof v === "boolean" ? v : true // }, [permissions]) const [selectKey, setSelectedKey] = useState( (backTitle as TabKey) || "all" ) const [info, setInfo] = useState() const [userEnums, setUserEnums] = useState<{ allEnum: Map labelEnum: Map review1Enum: Map review2Enum: Map }>({ allEnum: new Map(), labelEnum: new Map(), review1Enum: new Map(), review2Enum: new Map(), }) useEffect(() => { if (projectId === -1) return const getProjectInfo = async () => { const res = await getProjectDetailById(projectId) setInfo(res) } getProjectInfo() }, [projectId]) const updateProjectInfo = async () => { if (projectId === -1) return const res = await getProjectDetailById(projectId) setInfo(res) } useEffect(() => { if (!info?.label_process) return const { step_detail } = info.label_process let label: number[] = [] let review1: number[] = [] let review2: number[] = [] step_detail.forEach(({ action, user_list }: any) => { if (action === 1) label = user_list else if (action === 2) review1 = user_list else if (action === 3) review2 = user_list }) const all = Array.from(new Set([...label, ...review1, ...review2])) const toLabelMap = (uids: number[]) => new Map( uids.map((uid) => { const opt = userOpts.find((o) => o.value === uid) return [uid, opt?.label ?? String(uid)] }) ) queueMicrotask(() => { setUserEnums({ allEnum: toLabelMap(all), labelEnum: toLabelMap(label), review1Enum: toLabelMap(review1), review2Enum: toLabelMap(review2), }) }) }, [info, userOpts]) const breadcrumbsItems = useMemo(() => { return [ { title: type ? type === "collect" ? "我的收藏" : type === "dynamic" ? "动态项目" : "我的项目" : "我的项目", href: type ? type === "collect" ? `/person/collection` : "/project/dynamic" : "/project/own", }, { title: info?.name || "项目名称", href: "", }, ].map((item) => ( { if (!item.href) return router.push(item.href) }}> {item.title} )) }, [info?.name, router, type]) const menuItems = useMemo(() => { const arr: Array<{ label: string; key: TabKey }> = [ { label: "我的任务", key: "own" }, { label: "任务列表", key: "all" }, ] // if (canConfig) arr.push({ label: "任务配置", key: "setting" }) return arr }, []) useEffect(() => { if (menuItems.some((i) => i.key === selectKey)) return queueMicrotask(() => { setSelectedKey(menuItems[0]?.key ?? "own") }) }, [menuItems, selectKey]) const DetailMenuItems = () => { return ( {menuItems.map((item, index) => { const active = item.key === selectKey return ( { const next = item.key setSelectedKey(next) const backUrl = type ? `/project/detail?id=${projectId}&type=${type}` : `/project/detail?id=${projectId}` setBackProps(backUrl, next, "/image") }} style={{ paddingLeft: 14, paddingRight: 14, paddingTop: 6, paddingBottom: 6, borderTopLeftRadius: index === 0 ? 4 : 0, borderBottomLeftRadius: index === 0 ? 4 : 0, borderTopRightRadius: index === menuItems.length - 1 ? 4 : 0, borderBottomRightRadius: index === menuItems.length - 1 ? 4 : 0, background: active ? "var(--mantine-color-brand-filled)" : "rgba(0,0,0,0.04)", }}> {item.label} ) })} ) } return ( {breadcrumbsItems} {DetailMenuItems()} {selectKey === "own" ? ( ) : null} {selectKey === "all" ? ( ) : null} {selectKey === "board" ? : null} {selectKey === "setting" ? ( ) : null} ) }