This commit is contained in:
Rao 2025-02-25 22:19:39 +08:00
commit ec049f01bc
3 changed files with 63 additions and 47 deletions

View File

@ -36,7 +36,7 @@ export class AppConfigRouter {
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
return await this.appConfigService.deleteMany(input); return await this.appConfigService.deleteMany(input);
}), }),
findFirst: this.trpc.protectProcedure findFirst: this.trpc.procedure
.input(AppConfigFindFirstArgsSchema) .input(AppConfigFindFirstArgsSchema)
.query(async ({ input }) => { .query(async ({ input }) => {
return await this.appConfigService.findFirst(input); return await this.appConfigService.findFirst(input);

View File

@ -1,28 +1,34 @@
import { Menu } from 'antd'; import { Menu } from "antd";
import { useNavigate, useLocation } from 'react-router-dom'; import { useNavigate, useLocation } from "react-router-dom";
const menuItems = [ const menuItems = [
{ key: 'home', path: '/', label: '首页' }, { key: "home", path: "/", label: "首页" },
{ key: 'courses', path: '/courses', label: '全部课程' }, { key: "courses", path: "/courses", label: "全部课程" },
{ key: 'paths', path: '/paths', label: '学习路径' } { key: "paths", path: "/paths", label: "学习路径" },
]; ];
export const NavigationMenu = () => { export const NavigationMenu = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const { pathname } = useLocation(); const { pathname } = useLocation();
const selectedKey = menuItems.find(item => item.path === pathname)?.key || ''; const selectedKey =
menuItems.find((item) => item.path === pathname)?.key || "";
return ( return (
<Menu <Menu
mode="horizontal" mode="horizontal"
className="border-none font-medium" className="border-none font-medium"
selectedKeys={[selectedKey]} selectedKeys={[selectedKey]}
onClick={({ key }) => { onClick={({ key }) => {
const selectedItem = menuItems.find(item => item.key === key); const selectedItem = menuItems.find((item) => item.key === key);
if (selectedItem) navigate(selectedItem.path); if (selectedItem) navigate(selectedItem.path);
}} window.scrollTo({
> top: 0,
behavior: "smooth",
});
}}>
{menuItems.map(({ key, label }) => ( {menuItems.map(({ key, label }) => (
<Menu.Item key={key} className="text-gray-600 hover:text-blue-600"> <Menu.Item
key={key}
className="text-gray-600 hover:text-blue-600">
{label} {label}
</Menu.Item> </Menu.Item>
))} ))}

View File

@ -72,7 +72,7 @@ export default function TermSelect({
throw error; throw error;
} }
}, },
[utils] [utils, value]
); );
const fetchTerms = useCallback(async () => { const fetchTerms = useCallback(async () => {
@ -139,15 +139,18 @@ export default function TermSelect({
} }
}; };
const handleExpand = async (keys: React.Key[]) => { const handleExpand = useCallback(
async (keys: React.Key[]) => {
try { try {
const allKeyIds = const allKeyIds =
keys.map((key) => key.toString()).filter(Boolean) || []; keys.map((key) => key.toString()).filter(Boolean) || [];
const expandedNodes = await utils.term.getChildSimpleTree.fetch({ const expandedNodes = await utils.term.getChildSimpleTree.fetch(
{
termIds: allKeyIds, termIds: allKeyIds,
taxonomyId, taxonomyId,
domainId, domainId,
}); }
);
const flattenedNodes = expandedNodes.flat(); const flattenedNodes = expandedNodes.flat();
const newItems = getUniqueItems( const newItems = getUniqueItems(
[...listTreeData, ...flattenedNodes], [...listTreeData, ...flattenedNodes],
@ -155,9 +158,16 @@ export default function TermSelect({
); );
setListTreeData(newItems); setListTreeData(newItems);
} catch (error) { } catch (error) {
console.error("Error expanding nodes with keys", keys, ":", error); console.error(
"Error expanding nodes with keys",
keys,
":",
error
);
} }
}; },
[value]
);
const handleDropdownVisibleChange = async (open: boolean) => { const handleDropdownVisibleChange = async (open: boolean) => {
if (open) { if (open) {
// This will attempt to expand all nodes and fetch their children when the dropdown opens // This will attempt to expand all nodes and fetch their children when the dropdown opens