fix(bug): fix router
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { getPersonProjectDashBoard } from "@/components/label/api/project"
|
import { getPersonProjectDashBoard } from "@/components/label/api/project"
|
||||||
import { Project } from "@/components/label/api/project/typing"
|
import { Project } from "@/components/label/api/project/typing"
|
||||||
import { Button, Group, Text, UnstyledButton } from "@mantine/core"
|
import { Button, Group, Text } from "@mantine/core"
|
||||||
|
|
||||||
import { IconRefresh } from "@tabler/icons-react"
|
import { IconRefresh } from "@tabler/icons-react"
|
||||||
import dayjs from "dayjs"
|
import dayjs from "dayjs"
|
||||||
@@ -76,15 +76,16 @@ export default function PersonalProjectTable() {
|
|||||||
width: 150,
|
width: 150,
|
||||||
render: (record: Project.PersonProjectDashboardResponseItem) => {
|
render: (record: Project.PersonProjectDashboardResponseItem) => {
|
||||||
return (
|
return (
|
||||||
<UnstyledButton
|
<Text
|
||||||
px={6}
|
px={6}
|
||||||
variant="transparent"
|
variant="transparent"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setCurrentRowId(record.project_id)
|
false && setCurrentRowId(record.project_id)
|
||||||
router.push(`/project/info/detail?id=${record.project_id}`)
|
false &&
|
||||||
|
router.push(`/project/info/detail?id=${record.project_id}`)
|
||||||
}}
|
}}
|
||||||
title={record.project_id.toString()}
|
title={record.project_id.toString()}
|
||||||
c={"brand"}
|
// c={"brand"}
|
||||||
style={{
|
style={{
|
||||||
fontSize: "14px",
|
fontSize: "14px",
|
||||||
maxWidth: "100%",
|
maxWidth: "100%",
|
||||||
@@ -93,7 +94,7 @@ export default function PersonalProjectTable() {
|
|||||||
textOverflow: "ellipsis",
|
textOverflow: "ellipsis",
|
||||||
}}>
|
}}>
|
||||||
{record.project_id}
|
{record.project_id}
|
||||||
</UnstyledButton>
|
</Text>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -247,7 +247,10 @@ export default function PersonDashboardPage() {
|
|||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<SimpleGrid cols={{ base: 1, lg: 2 }} spacing="md" style={{ flex: 1 }}>
|
<SimpleGrid
|
||||||
|
cols={{ base: 1, lg: 2 }}
|
||||||
|
spacing="md"
|
||||||
|
style={{ flex: 1, maxHeight: "calc(100% - 194px)" }}>
|
||||||
<Paper
|
<Paper
|
||||||
shadow="xs"
|
shadow="xs"
|
||||||
withBorder
|
withBorder
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ import AppLayout from "@/components/layout/AppLayout"
|
|||||||
import { PathnameRecorder } from "@/components/layout/PathnameRecorder"
|
import { PathnameRecorder } from "@/components/layout/PathnameRecorder"
|
||||||
import { componentList, showList } from "@/components/layout/common"
|
import { componentList, showList } from "@/components/layout/common"
|
||||||
|
|
||||||
async function getMenu() {
|
// async function getMenu() {
|
||||||
return [...componentList, ...showList]
|
// return [...componentList, ...showList]
|
||||||
}
|
// }
|
||||||
|
|
||||||
export default async function Layout({
|
export default async function Layout({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
const menu = await getMenu()
|
const menu = [...componentList, ...showList]
|
||||||
return (
|
return (
|
||||||
<AppLayout menu={menu}>
|
<AppLayout menu={menu}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
10
build.sh
10
build.sh
@@ -51,11 +51,11 @@ FLAG_PROD="${ENV}_latest"
|
|||||||
|
|
||||||
cd $SHELL_FOLDER
|
cd $SHELL_FOLDER
|
||||||
|
|
||||||
# 检查git状态
|
# # 检查git状态
|
||||||
echo -e "${GREEN}Checking git status...${NC}"
|
# echo -e "${GREEN}Checking git status...${NC}"
|
||||||
git fetch
|
# git fetch
|
||||||
git merge
|
# git merge
|
||||||
if [[ $? != 0 ]]; then echo -e "${RED}git pull error${NC}"; exit 100; fi
|
# if [[ $? != 0 ]]; then echo -e "${RED}git pull error${NC}"; exit 100; fi
|
||||||
|
|
||||||
BRANCH_NAME=`git branch | grep "*"`
|
BRANCH_NAME=`git branch | grep "*"`
|
||||||
echo -e "${GREEN}Current branch: ${BRANCH_NAME/* /}${NC}"
|
echo -e "${GREEN}Current branch: ${BRANCH_NAME/* /}${NC}"
|
||||||
|
|||||||
121
components/label/hooks/useAuth.ts
Normal file
121
components/label/hooks/useAuth.ts
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { usePermissionStore } from "@/components/label/store/auth"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
|
||||||
|
interface PermissionItem {
|
||||||
|
[x: string]: [boolean, null, string]
|
||||||
|
}
|
||||||
|
|
||||||
|
type PermissionMap = {
|
||||||
|
[x: string]: PermissionItem
|
||||||
|
}
|
||||||
|
|
||||||
|
const mappingList: { [x: string]: [string, string] } = {
|
||||||
|
"/project/own": ["project", "config"],
|
||||||
|
"/management/team/employee": ["user", "view"],
|
||||||
|
"/management/team/organization": ["user", "group_view"],
|
||||||
|
"/management/team/dailypaper": ["daily_work", "team_view"],
|
||||||
|
"/management/team/cost": ["settlement_form", "view"],
|
||||||
|
"/management/team/workload": ["workload", "view"],
|
||||||
|
"/management/team/sync_server": ["data_sync", "server_view"],
|
||||||
|
"/management/team/sync_task": ["data_sync", "task_view"],
|
||||||
|
"/management/team/board": ["user", "view"],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const headerBarCheckItems = (data: PermissionMap) => {
|
||||||
|
const projectTitle = [
|
||||||
|
["daily_work", "self_view"],
|
||||||
|
["label_schema", "view"],
|
||||||
|
["project", "view"],
|
||||||
|
["task", "view"],
|
||||||
|
] as const
|
||||||
|
|
||||||
|
let projectVisible = false
|
||||||
|
projectTitle.forEach(([prop, subProp]) => {
|
||||||
|
if (data[prop] && data[prop][subProp] && data[prop][subProp][0]) {
|
||||||
|
projectVisible = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const staffTitle = [
|
||||||
|
["daily_work", "team_view"],
|
||||||
|
["user", "view"],
|
||||||
|
["user", "group_view"],
|
||||||
|
] as const
|
||||||
|
|
||||||
|
let staffVisible = false
|
||||||
|
staffTitle.forEach(([prop, subProp]) => {
|
||||||
|
if (data[prop] && data[prop][subProp] && data[prop][subProp][0]) {
|
||||||
|
staffVisible = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return [projectVisible, staffVisible]
|
||||||
|
}
|
||||||
|
|
||||||
|
const useAuth = () => {
|
||||||
|
const pathname = usePathname()
|
||||||
|
const detailInfo = usePermissionStore((s) => s.detailInfo)
|
||||||
|
const permission = detailInfo?.permissions as PermissionMap | undefined
|
||||||
|
const roleName: string[] = detailInfo?.role_name ?? []
|
||||||
|
|
||||||
|
return {
|
||||||
|
hasPermission: () => {
|
||||||
|
if (
|
||||||
|
[
|
||||||
|
"/",
|
||||||
|
"/login",
|
||||||
|
"/management",
|
||||||
|
"/management/person/dashboard",
|
||||||
|
"/management/team",
|
||||||
|
].includes(pathname)
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!permission) return false
|
||||||
|
if (mappingList[pathname]) {
|
||||||
|
const [prop, subProp] = mappingList[pathname]
|
||||||
|
return (
|
||||||
|
!!permission[prop] &&
|
||||||
|
!!permission[prop][subProp] &&
|
||||||
|
!!permission[prop][subProp][0]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
// path 跳转是否可见
|
||||||
|
canNv: (path: string, type = "view") => {
|
||||||
|
if (!permission) return false
|
||||||
|
if (mappingList[path]) {
|
||||||
|
const [prop] = mappingList[path]
|
||||||
|
return (
|
||||||
|
!!permission[prop] &&
|
||||||
|
!!permission[prop][type] &&
|
||||||
|
!!permission[prop][type][0]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
// 当前页面是否可见某个操作
|
||||||
|
isShow: (type = "view") => {
|
||||||
|
if (!permission) return false
|
||||||
|
if (mappingList[pathname]) {
|
||||||
|
const [prop] = mappingList[pathname]
|
||||||
|
return (
|
||||||
|
!!permission[prop] &&
|
||||||
|
!!permission[prop][type] &&
|
||||||
|
!!permission[prop][type][0]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
checkRole: (name: string) => {
|
||||||
|
if (!name) return false
|
||||||
|
return roleName.includes(name)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useAuth
|
||||||
@@ -263,8 +263,13 @@ export const useBackUrlStore = create(
|
|||||||
(set) => ({
|
(set) => ({
|
||||||
backUrl: null,
|
backUrl: null,
|
||||||
backTitle: null,
|
backTitle: null,
|
||||||
setBackProps: (url: string, title?: string) =>
|
basePath: "",
|
||||||
set({ backUrl: url, backTitle: title || null }),
|
setBackProps: (url: string, title?: string, basePath?: string) =>
|
||||||
|
set({
|
||||||
|
backUrl: url,
|
||||||
|
backTitle: title || null,
|
||||||
|
basePath: basePath || "",
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: "back_url",
|
name: "back_url",
|
||||||
|
|||||||
@@ -81,11 +81,11 @@ export const componentList: MenuItem[] = [
|
|||||||
url: "video",
|
url: "video",
|
||||||
icon: "SystemIcon",
|
icon: "SystemIcon",
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
title: "点云标注",
|
// title: "点云标注",
|
||||||
url: "pointcloud",
|
// url: "pointcloud",
|
||||||
icon: "SystemIcon",
|
// icon: "SystemIcon",
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
title: "管理中心",
|
title: "管理中心",
|
||||||
url: "mgt",
|
url: "mgt",
|
||||||
|
|||||||
Reference in New Issue
Block a user