-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
目前距离1.0版本还需要对sider页面的tag选择修改、大屏下tag栏展示布局修改、添加次高级搜索等
- Loading branch information
master1lan
committed
Feb 25, 2023
1 parent
f3b31d1
commit c4f8e4e
Showing
7 changed files
with
183 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { videoOrderType } from "@utils/fetch/fetchtype"; | ||
| import { nanoid } from "nanoid"; | ||
| import { FC } from "react"; | ||
| import { useNavigate } from "react-router-dom"; | ||
| import { OrderArr, returnReplacedParmasURl } from "./tool"; | ||
| import { useURLParams } from "@utils/hooks/url"; | ||
|
|
||
| export default function SelectNav() { | ||
| const navigate = useNavigate(), | ||
| handlerCilck = (queryString: videoOrderType) => { | ||
| const replacedUrl = returnReplacedParmasURl([ | ||
| { parmas: "order", replace: queryString }, | ||
| ]), | ||
| newQuerySrting = new URL(replacedUrl).search; | ||
| navigate(`/search${newQuerySrting}`); | ||
| }; | ||
| return ( | ||
| <div className='flex gap-4 my-6 pl-1 text-gray-500 text-sm max-sm:justify-evenly max-sm:gap-0 max-[400px]:my-3'> | ||
| {Search_Nav.map((item) => ( | ||
| <SearchNavItem | ||
| onClick={handlerCilck.bind(null, item.queryString)} | ||
| {...item} | ||
| key={item.id} | ||
| /> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const SearchNavItem: FC<{ | ||
| onClick: () => void; | ||
| label: string; | ||
| queryString: videoOrderType; | ||
| }> = ({ label, onClick, queryString }) => { | ||
| const [order] = useURLParams(["order"]), | ||
| isCurOrder = OrderArr.includes(order as videoOrderType) | ||
| ? order === queryString | ||
| : queryString === "score"; | ||
| return ( | ||
| <div | ||
| onClick={onClick} | ||
| className={`px-4 py-2 rounded-md cursor-pointer hover:text-sky-500 flex-shrink max-[400px]:px-2 max-[400px]:py-1 ${ | ||
| isCurOrder ? `bg-sky-100 text-sky-500` : "" | ||
| }`} | ||
| > | ||
| {label} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| type searchNavType = { | ||
| id: string; | ||
| label: "综合排序" | "最多播放" | "最新发表"; | ||
| queryString: videoOrderType; | ||
| }; | ||
| const Search_Nav: searchNavType[] = [ | ||
| { | ||
| id: nanoid(4), | ||
| label: "综合排序", | ||
| queryString: "score", | ||
| }, | ||
| { | ||
| id: nanoid(4), | ||
| label: "最多播放", | ||
| queryString: "view", | ||
| }, | ||
| { | ||
| id: nanoid(4), | ||
| label: "最新发表", | ||
| queryString: "pubdate", | ||
| }, | ||
| ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { videoOrderType } from "@utils/fetch/fetchtype"; | ||
|
|
||
| function ParseQueryString(queryString: string) { | ||
| const regExp = /([^&=]+)=([\w\W]*?)(&|$)/g; | ||
| let result = null, | ||
| ret: { [key: string]: string } = {}; | ||
| while ((result = regExp.exec(queryString)) != null) { | ||
| ret[result[1]] = result[2]; | ||
| } | ||
| return ret; | ||
| } | ||
| export const parseURL = (url = window.location.href) => { | ||
| const objUrl = new URL(url), | ||
| params = objUrl.search.slice(1); | ||
| return ParseQueryString(params); | ||
| }; | ||
|
|
||
| export const returnReplacedParmasURl = ( | ||
| input: { parmas: string; replace: string }[] | ||
| ) => { | ||
| const originUrl = window.location.href, | ||
| paramsObj = parseURL(originUrl); | ||
| input.forEach(({ parmas, replace }) => (paramsObj[parmas] = replace)); | ||
| return originUrl.replace( | ||
| window.location.search, | ||
| `?${Object.entries(paramsObj) | ||
| .map(([key, value]) => `${key}=${value}`) | ||
| .join("&")}` | ||
| ); | ||
| }; | ||
| export const OrderArr: videoOrderType[] = ["pubdate", "score", "view"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const useURLParams = (searchList: string[]) => { | ||
| const originURl = window.location.href; | ||
| const url = new URL(originURl); | ||
| return searchList.map((item) => url.searchParams.get(item) || ""); | ||
| }; |