|
@@ -1,4 +1,4 @@
|
|
|
-import { Menu, type MenuProps } from "antd";
|
|
|
|
|
|
|
+import { Menu, Tooltip, type MenuProps } from "antd";
|
|
|
import {
|
|
import {
|
|
|
SearchOutlined,
|
|
SearchOutlined,
|
|
|
HomeOutlined,
|
|
HomeOutlined,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
ToolOutlined,
|
|
ToolOutlined,
|
|
|
TeamOutlined,
|
|
TeamOutlined,
|
|
|
} from "@ant-design/icons";
|
|
} from "@ant-design/icons";
|
|
|
-import { useNavigate, useMatches, type UIMatch } from "react-router";
|
|
|
|
|
|
|
+import { useNavigate, type UIMatch } from "react-router";
|
|
|
import {
|
|
import {
|
|
|
ChannelIcon,
|
|
ChannelIcon,
|
|
|
CourseOutLinedIcon,
|
|
CourseOutLinedIcon,
|
|
@@ -24,6 +24,12 @@ import RecentModal from "../recent/RecentModal.tsx";
|
|
|
import SettingModal from "../setting/SettingModal.tsx";
|
|
import SettingModal from "../setting/SettingModal.tsx";
|
|
|
import { useIntl } from "react-intl";
|
|
import { useIntl } from "react-intl";
|
|
|
import { fullUrl } from "../../utils";
|
|
import { fullUrl } from "../../utils";
|
|
|
|
|
+import { useActiveStudio } from "../../hooks/useActiveStudio";
|
|
|
|
|
+import { useCurrentRouteId } from "../../hooks/useCurrentRouteId";
|
|
|
|
|
+import {
|
|
|
|
|
+ TEAMSPACE_HINT,
|
|
|
|
|
+ teamspaceAvailability,
|
|
|
|
|
+} from "../../features/teamspace/scope";
|
|
|
|
|
|
|
|
/* ================= 类型 ================= */
|
|
/* ================= 类型 ================= */
|
|
|
|
|
|
|
@@ -38,18 +44,17 @@ interface MenuItem {
|
|
|
|
|
|
|
|
/** ⭐ 用于高亮匹配 */
|
|
/** ⭐ 用于高亮匹配 */
|
|
|
activeId?: string | string[];
|
|
activeId?: string | string[];
|
|
|
|
|
+
|
|
|
|
|
+ /** 判断团队空间下是否可用的路由 id;不写则取 activeId(打开弹窗、没有路由的菜单要写) */
|
|
|
|
|
+ scopeId?: string;
|
|
|
|
|
+
|
|
|
|
|
+ disabled?: boolean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface RouteHandle {
|
|
export interface RouteHandle {
|
|
|
id?: string;
|
|
id?: string;
|
|
|
crumb?: string | ((match: UIMatch) => string);
|
|
crumb?: string | ((match: UIMatch) => string);
|
|
|
}
|
|
}
|
|
|
-/* ================= 当前路由ID ================= */
|
|
|
|
|
-
|
|
|
|
|
-function useCurrentRouteId(): string | undefined {
|
|
|
|
|
- const matches = useMatches() as UIMatch<number, RouteHandle>[];
|
|
|
|
|
- return [...matches].reverse().find((match) => match.handle?.id)?.handle?.id;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
/* ================= 匹配算法 ================= */
|
|
/* ================= 匹配算法 ================= */
|
|
|
|
|
|
|
@@ -114,6 +119,44 @@ function findOpenKeys(
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* ================= 团队空间置灰 ================= */
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 团队空间下把不可用的菜单置灰并给出原因;有子菜单的,子项全灰才灰。
|
|
|
|
|
+ */
|
|
|
|
|
+function applyTeamspace(
|
|
|
|
|
+ items: MenuItem[],
|
|
|
|
|
+ hint: (id: string) => string
|
|
|
|
|
+): MenuItem[] {
|
|
|
|
|
+ return items.map((item) => {
|
|
|
|
|
+ if (item.children) {
|
|
|
|
|
+ const children = applyTeamspace(item.children, hint);
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...item,
|
|
|
|
|
+ children,
|
|
|
|
|
+ disabled: children.every((child) => child.disabled),
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ const scopeId =
|
|
|
|
|
+ item.scopeId ??
|
|
|
|
|
+ (typeof item.activeId === "string" ? item.activeId : undefined);
|
|
|
|
|
+ const availability = teamspaceAvailability(scopeId);
|
|
|
|
|
+ if (item.type === "divider" || availability === "available") {
|
|
|
|
|
+ return item;
|
|
|
|
|
+ }
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...item,
|
|
|
|
|
+ disabled: true,
|
|
|
|
|
+ extra: undefined,
|
|
|
|
|
+ label: (
|
|
|
|
|
+ <Tooltip title={hint(TEAMSPACE_HINT[availability])} placement="right">
|
|
|
|
|
+ <span>{item.label}</span>
|
|
|
|
|
+ </Tooltip>
|
|
|
|
|
+ ),
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* ================= 组件 ================= */
|
|
/* ================= 组件 ================= */
|
|
|
interface Props {
|
|
interface Props {
|
|
|
onSearch?: () => void;
|
|
onSearch?: () => void;
|
|
@@ -123,13 +166,14 @@ const Widget = ({ onSearch }: Props) => {
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
|
const navigate = useNavigate();
|
|
|
const routeId = useCurrentRouteId();
|
|
const routeId = useCurrentRouteId();
|
|
|
|
|
+ const { isTeamspace } = useActiveStudio();
|
|
|
|
|
|
|
|
const [recentOpen, setRecentOpen] = useState(false);
|
|
const [recentOpen, setRecentOpen] = useState(false);
|
|
|
const [openSetting, setOpenSetting] = useState(false);
|
|
const [openSetting, setOpenSetting] = useState(false);
|
|
|
|
|
|
|
|
/* ================= 菜单配置 ================= */
|
|
/* ================= 菜单配置 ================= */
|
|
|
|
|
|
|
|
- const items: MenuItem[] = [
|
|
|
|
|
|
|
+ const allItems: MenuItem[] = [
|
|
|
{
|
|
{
|
|
|
key: "search",
|
|
key: "search",
|
|
|
icon: <SearchOutlined />,
|
|
icon: <SearchOutlined />,
|
|
@@ -173,6 +217,7 @@ const Widget = ({ onSearch }: Props) => {
|
|
|
id: "columns.studio.setting.title",
|
|
id: "columns.studio.setting.title",
|
|
|
}),
|
|
}),
|
|
|
activeId: "workspace.setting",
|
|
activeId: "workspace.setting",
|
|
|
|
|
+ scopeId: "workspace.settings",
|
|
|
},
|
|
},
|
|
|
{ type: "divider", key: "d1" },
|
|
{ type: "divider", key: "d1" },
|
|
|
|
|
|
|
@@ -182,6 +227,7 @@ const Widget = ({ onSearch }: Props) => {
|
|
|
label: intl.formatMessage({
|
|
label: intl.formatMessage({
|
|
|
id: "columns.studio.recent.title",
|
|
id: "columns.studio.recent.title",
|
|
|
}),
|
|
}),
|
|
|
|
|
+ scopeId: "workspace.recent",
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
{
|
|
{
|
|
@@ -232,6 +278,7 @@ const Widget = ({ onSearch }: Props) => {
|
|
|
label: intl.formatMessage({
|
|
label: intl.formatMessage({
|
|
|
id: "columns.library.course.title",
|
|
id: "columns.library.course.title",
|
|
|
}),
|
|
}),
|
|
|
|
|
+ scopeId: "workspace.course",
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
key: "/workspace/task",
|
|
key: "/workspace/task",
|
|
@@ -324,7 +371,7 @@ const Widget = ({ onSearch }: Props) => {
|
|
|
{
|
|
{
|
|
|
key: "/workspace/team",
|
|
key: "/workspace/team",
|
|
|
label: intl.formatMessage({
|
|
label: intl.formatMessage({
|
|
|
- id: "columns.studio.group.title",
|
|
|
|
|
|
|
+ id: "labels.teamspace",
|
|
|
}),
|
|
}),
|
|
|
activeId: "workspace.team",
|
|
activeId: "workspace.team",
|
|
|
},
|
|
},
|
|
@@ -345,6 +392,10 @@ const Widget = ({ onSearch }: Props) => {
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
];
|
|
];
|
|
|
|
|
+ const items = isTeamspace
|
|
|
|
|
+ ? applyTeamspace(allItems, (id) => intl.formatMessage({ id }))
|
|
|
|
|
+ : allItems;
|
|
|
|
|
+
|
|
|
/** 当前选中 */
|
|
/** 当前选中 */
|
|
|
const selectedKey = findSelectedKey(items, routeId);
|
|
const selectedKey = findSelectedKey(items, routeId);
|
|
|
|
|
|