diff --git a/app/(main)/page.tsx b/app/(main)/page.tsx index dd5d0d1..c7a847a 100644 --- a/app/(main)/page.tsx +++ b/app/(main)/page.tsx @@ -2,7 +2,7 @@ import SiderNav from "../_ui/SiderNav"; import Search from "../_ui/Search"; import LinkListBox from "../_ui/LinkListBox"; import { getLinkTypeList } from "../_lib/data/linkType"; -import { getLinkList, getLinkListAll } from "../_lib/data/link"; +import { getLinkList } from "../_lib/data/link"; import Footer from "../_ui/footer"; export default async function Page() { diff --git a/app/_lib/data/link.ts b/app/_lib/data/link.ts index aafedd4..23b7142 100644 --- a/app/_lib/data/link.ts +++ b/app/_lib/data/link.ts @@ -14,6 +14,7 @@ export type Link = { logoLink: string; isHot?: boolean; addTime: number; + subLinkType?: string[]; } diff --git a/app/_lib/data/linkType.ts b/app/_lib/data/linkType.ts index 3b9ddf7..91d44aa 100644 --- a/app/_lib/data/linkType.ts +++ b/app/_lib/data/linkType.ts @@ -11,7 +11,7 @@ export type LinkType = { _id: string; href?: string; priority?: number; - subLinkType?: string[]; + subCategory?: string[]; location?: string; } diff --git a/app/_ui/LinkListBox.tsx b/app/_ui/LinkListBox.tsx index 1ac4a1f..f49f597 100644 --- a/app/_ui/LinkListBox.tsx +++ b/app/_ui/LinkListBox.tsx @@ -2,15 +2,16 @@ import Link from "next/link"; import { LinkType } from "../_lib/data/linkType"; import { Link as _Link } from "../_lib/data/link"; -import { useEffect, useMemo } from "react"; +import { useEffect, useMemo, useState } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faArrowRight, faClock, faFire, faRightFromBracket, faRightLong, faTimeline, faTimesCircle, faTimesRectangle, faVolumeTimes } from "@fortawesome/free-solid-svg-icons"; import { useAtom } from "jotai"; import { linkTypeAtom } from "../_lib/atom"; import Image from "next/image"; +import clsx from "clsx"; const PICTURE_PREFIX = 'https://newuitab.oss-cn-hangzhou.aliyuncs.com/ai_upload/downloads/' export const LinkBlock = ({ val }: { val: _Link }) => { - return
@@ -19,10 +20,25 @@ export const LinkBlock = ({ val }: { val: _Link }) => {
} + export default function LinkListBox({ linkTypeList, linkList, showHot, showRecent }: { linkTypeList: LinkType[]; linkList: _Link[]; showHot: boolean; showRecent: boolean }) { const hotList = useMemo(() => linkList.filter((val, index) => val.isHot && index < 12), [linkList]) const recentList = useMemo(() => linkList.map(val => val).sort((a, b) => b.addTime - a.addTime).filter((_, idx) => idx < 12), [linkList]) const [currentId] = useAtom(linkTypeAtom) + const [selectSubType, setSelectSubType] = useState>(new Map()) + useEffect(() => { + if (linkTypeList.length === 0) return + for (let i = 0; i < linkTypeList.length; i++) { + const item = linkTypeList[i]; + console.log(item); + + if (item.subCategory?.length) { + setSelectSubType(pre => { + return new Map(pre.set(item._id, item.subCategory?.length ? item.subCategory[0] : '')); + }) + } + } + }, [linkTypeList, setSelectSubType]) useEffect(() => { console.log(currentId); @@ -77,7 +93,6 @@ export default function LinkListBox({ linkTypeList, linkList, showHot, showRecen {item.label} { linkList.filter(val => val.type === item._id).length >= 42 && - @@ -86,12 +101,40 @@ export default function LinkListBox({ linkTypeList, linkList, showHot, showRecen } + { + item.subCategory && item.subCategory.length > 0 && +
+ { + item.subCategory.map(subItem => ( +
{ + setSelectSubType(pre => { + return new Map(pre.set(item._id, subItem)) + }) + }} + className={clsx(" px-3 py-1 rounded-lg ", + selectSubType.get(item._id) === subItem ? + "text-white bg-orange-300" + : "bg-[#f5f5f5] shadow hover:bg-orange-300/30 cursor-pointer" + )}> + {subItem} +
+ )) + } +
+ }
{ - linkList.filter(val => val.type === item._id).filter((_, idx) => idx < 42).map(val => ( - + item.subCategory ? + linkList.filter(val => val.type === item._id && val.subLinkType?.includes(selectSubType.get(item._id) || '-1')).filter((_, idx) => idx < 42).map(val => ( + - )) + )) + : + linkList.filter(val => val.type === item._id).filter((_, idx) => idx < 42).map(val => ( + + + )) }
diff --git a/app/_ui/MarkdownView.tsx b/app/_ui/MarkdownView.tsx index aa8577f..28041be 100644 --- a/app/_ui/MarkdownView.tsx +++ b/app/_ui/MarkdownView.tsx @@ -1,8 +1,11 @@ -"use client"; -import { MdPreview} from 'md-editor-rt'; +import { Editor } from "@bytemd/react"; -export default function MarkdownView({ value = '' }: { value?: string }) { +export default function MyMarkdownEdit({ value = '', onChange }: { value?: string; onChange?: (val: string) => void }) { return ( - + ) } \ No newline at end of file diff --git a/app/_ui/footer.tsx b/app/_ui/footer.tsx index a15ed9c..adee806 100644 --- a/app/_ui/footer.tsx +++ b/app/_ui/footer.tsx @@ -1,5 +1,5 @@ export default function Footer() { - return
+ return
} \ No newline at end of file diff --git a/app/admin/(default)/dashboard/article/detail/AddOrEdit.tsx b/app/admin/(default)/dashboard/article/detail/AddOrEdit.tsx index 6d5663c..4035fa5 100644 --- a/app/admin/(default)/dashboard/article/detail/AddOrEdit.tsx +++ b/app/admin/(default)/dashboard/article/detail/AddOrEdit.tsx @@ -8,16 +8,13 @@ import { Button, Card, Col, DatePicker, Form, Input, InputNumber, message, Row, import { useRouter } from 'next/navigation' import 'md-editor-rt/lib/style.css'; import '@ant-design/v5-patch-for-react-19'; -import { mRequest } from '@/app/_lib/request'; import dayjs from 'dayjs'; -import { Editor } from "@bytemd/react"; import gfm from '@bytemd/plugin-gfm' import { useEffect, useMemo, useRef, useState } from 'react'; -import { valueType } from 'antd/es/statistic/utils'; import { getLinkList, updateLink } from '@/app/_lib/data/link'; import { debounce } from '@/app/_lib/utils'; import { useRequest } from 'ahooks'; -import { updateUser } from '@/app/_lib/data/user'; +import MyMarkdownEdit from '@/app/_ui/MarkdownView'; const plugins = [ gfm(), // Add more plugins here @@ -27,12 +24,13 @@ const plugins = [ export default function AddOrEdit({ editData }: { editData?: ArticleType | null }) { const router = useRouter() const fetchRef = useRef(0) - const formRef = useRef(null) + const [form] = Form.useForm(); const [fetching, setFetching] = useState(false); const [options, setOptions] = useState([]); - const { data: linkList = [] } = useRequest(() => getLinkList({ filter: { articleId: editData?._id } }).then(res => res.list)) + const { data: linkList = [] } = useRequest(() => getLinkList({ filter: { articleId: editData?._id || '-1' } }).then(res => res.list)) useEffect(() => { - if (linkList.length === 0) { + if (linkList.length !== 0) { + form.setFieldValue('linkId', linkList.map(item => ({ key: item._id, value: item._id, label: item.name }))) return } @@ -78,7 +76,7 @@ export default function AddOrEdit({ editData }: { editData?: ArticleType | null - ref={formRef} + form={form} onFinish={async (res: any) => { const linkIdList = res.linkId const addTime = res.addTime.unix() @@ -100,8 +98,13 @@ export default function AddOrEdit({ editData }: { editData?: ArticleType | null addTime: dayjs().unix() }).then(id => { - console.log(id); - + linkIdList.map((item: any) => { + updateLink( + item.value, + { + articleId: id + }) + }) }) } @@ -206,10 +209,7 @@ export default function AddOrEdit({ editData }: { editData?: ArticleType | null message: '请输入内容' } ]}> - {/* */} - + diff --git a/app/admin/(default)/layout.tsx b/app/admin/(default)/layout.tsx index 90e8076..1b0a84c 100644 --- a/app/admin/(default)/layout.tsx +++ b/app/admin/(default)/layout.tsx @@ -28,6 +28,12 @@ export default function Layout({ href: '/admin/dashboard/article' }, + { + label: '营销文章管理', + iconElement: , + _id: 'adArticleMenagement', + href: '/admin/dashboard/adArticle' + }, { label: '搜索管理', iconElement: ,