Skip to content

Commit

Permalink
feat: 支持自定义跳转方式
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Jun 27, 2023
1 parent bc77be7 commit 3bcf50b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- 搜索完按回车会直接在新标签页打开第一个结果。
- 搜索完按一下对应卡片右上角的数字按钮 + Ctrl(mac 也可以用 command 键) ,也会直接打开对应结果。

另外可以设置跳转方式哦。

## 安装方法
### Docker

Expand Down Expand Up @@ -135,6 +137,8 @@ sudo systemctl daemon-reload && sudo systemctl enable --now VanNav.service
- [x] github 按钮可隐藏
- [x] 支持登录后才能查看的隐藏卡片
- [x] 搜索引擎集成功能
- [x] 增加一些搜索后快捷键直接打开卡片
- [x] 支持自定义跳转方式
- [ ] 自动主题切换
- [ ] 国际化
- [ ] 增加 ServiceWork ,离线可用,可安装
Expand Down
5 changes: 3 additions & 2 deletions ui/website/src/components/CardV2/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from "react";
import "./index.css";
import { getLogoUrl } from "../../utils/check";
import { getJumpTarget } from "../../utils/setting";
const Card = ({ title, url, des, logo, catelog, onClick, index, isSearching }) => {
const el = useMemo(() => {
if (url === "admin") {
Expand All @@ -16,11 +17,11 @@ const Card = ({ title, url, des, logo, catelog, onClick, index, isSearching }) =
const showNumIndex = index < 10 && isSearching;
return (
<a
href={url}
href={url == "toggleJumpTarget" ? undefined : url}
onClick={() => {
onClick();
}}
target="_blank"
target={getJumpTarget() === "blank" ? "_blank" : "_self"}
rel="noreferrer"
className="card-box"
>
Expand Down
6 changes: 5 additions & 1 deletion ui/website/src/components/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import GithubLink from "../GithubLink";
import DarkSwitch from "../DarkSwitch";
import { isLogin } from "../../utils/check";
import { generateSearchEngineCard } from "../../utils/serachEngine";
import { toggleJumpTarget } from "../../utils/setting";

const mutiSearch = (s, t) => {
const source = (s as string).toLowerCase();
Expand Down Expand Up @@ -39,7 +40,6 @@ const Content = (props: any) => {
setLoading(true);
const r = await FetchList();
setData(r);
console.log(r)
const tagInLocalStorage = window.localStorage.getItem("tag");
if (tagInLocalStorage && tagInLocalStorage !== "") {
if (r?.catelogs && r?.catelogs.includes(tagInLocalStorage)) {
Expand Down Expand Up @@ -145,6 +145,10 @@ const Content = (props: any) => {
isSearching={searchString.trim() !== ""}
onClick={() => {
resetSearch();
if (item.url == "toggleJumpTarget") {
toggleJumpTarget();
loadData();
}
}}
/>
);
Expand Down
16 changes: 15 additions & 1 deletion ui/website/src/utils/api.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import axios from "axios";
import { getJumpTarget } from "./setting";
const baseUrl = "/api/";
// const baseUrl = "https://tools.mereith.com/api/";

const selfJumpIcon = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAACg5JREFUeF7tnQFuGzcQRZWTpT1Z2pO1OVkKIhYgu5a1Q/J/kjNPQJEC5g45j/NMciWtv914QQACTwl8gw0EIPCcAIJQHRD4ggCCUB4QQBBqAAJ9BFhB+rhxVRECCFJkokmzjwCC9HHjqiIEEKTIRJNmHwEE6ePGVUUIIEiRiSbNPgII0seNq4oQQJCvJ/qPtx/f/y1SFsvT/PdhBI//bx8Ygvwf+V+32+377XZDCns5Pu2wSfL37Xazy4Igv+cEKfaR4dVIrLJUFwQxXpXjvj+3iFJZkCbHj33nn5FdJNBE+fNi23CzioIgRrhMtr9AtppUEwQ5tq/1oQG2lWTqQb6SIMgxVHvHXNzudrW5nvKqIghyTCmXY4JMk6SCIMhxTF1PHeiU7VZ2Qdqbff9MxU6wkwgM1/dwgI1pIcfGk2Ma2vAt4MyCtJWDj4uYKnHjbobOI1kFYfXYuGIXDK27zrsvXJBkpEtWjwit/G27V5GMgrB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JPaQDeS5h1FxZh7Ke9YI5LS2D9wkQE6cz+f24kwClVvFcwAAAAAElFTkSuQmCC`
export const FetchList = async () => {
const { data: raw } = await axios.get(baseUrl);
const { data } = raw;
Expand All @@ -16,7 +20,6 @@ export const FetchList = async () => {
}
});
if (!data.setting?.hideAdmin) {
catelogs.push("管理后台");
data.tools.push({
id: 999999999999,
catelog: "管理后台",
Expand All @@ -27,6 +30,17 @@ export const FetchList = async () => {
})
}

const jumpTarget = getJumpTarget();

data.tools.push({
id: 999099999978,
catelogs: "偏好设置",
name: jumpTarget == "blank" ? "新建窗口" : "原地跳转",
desc: `点击切换跳转方式`,
url: "toggleJumpTarget",
logo: jumpTarget == "blank" ? blankJumpIcon : selfJumpIcon
})

data.catelogs = catelogs;
return data;
};
Expand Down
22 changes: 22 additions & 0 deletions ui/website/src/utils/setting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type JumpTarget = 'blank' | 'self';

export const toggleJumpTarget = () => {
const thisTarget = getJumpTarget();
if (!thisTarget) {
setJumpTarget('blank');
}
if (thisTarget === 'blank') {
setJumpTarget('self');
} else {
setJumpTarget('blank');
}

}

const setJumpTarget = (target: JumpTarget) => {
window.localStorage.setItem('jumpTarget', target);
}

export const getJumpTarget = () => {
return window.localStorage.getItem('jumpTarget') as JumpTarget;
}
1 change: 1 addition & 0 deletions ui/website/src/utils/touch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const canTouch = 'ontouchstart' in document.documentElement;

0 comments on commit 3bcf50b

Please sign in to comment.