diff --git a/README.md b/README.md index 240bdb2..4bf9d2f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,12 @@ - [x] 网站背景自定义 - [x] 数据备份及恢复 - [x] 移动端适配 -* [ ] 还没想好呢 +* [ ] 切换搜索引擎 +* [ ] 设置 +* [ ] 备份 +* [ ] 一言 +* [ ] 书签 +* [ ] 备忘 ### 部署 diff --git a/package.json b/package.json index 281870a..c87ff03 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "snavigation", "private": true, - "version": "0.0.0", + "version": "2.0.0 beta 1", "type": "module", "scripts": { "dev": "vite", @@ -10,7 +10,7 @@ }, "dependencies": { "axios": "^1.4.0", - "axios-jsonp": "^1.0.4", + "fetch-jsonp": "^1.3.0", "pinia": "^2.1.4", "pinia-plugin-persistedstate": "^3.2.0", "sass": "^1.64.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e939caf..85b4dd2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,9 @@ dependencies: axios: specifier: ^1.4.0 version: 1.4.0 - axios-jsonp: - specifier: ^1.0.4 - version: 1.0.4 + fetch-jsonp: + specifier: ^1.3.0 + version: 1.3.0 pinia: specifier: ^2.1.4 version: 2.1.4(vue@3.3.4) @@ -403,10 +403,6 @@ packages: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} dev: false - /axios-jsonp@1.0.4: - resolution: {integrity: sha512-KI5Fc4ery6DR+oneXG09hPZfGuNUW8Lblhe750h53Z0Eh5MRsrHn49YitDU4RsMk0HV+12zcvL2Q51QkOLGdIQ==} - dev: false - /axios@1.4.0: resolution: {integrity: sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==} dependencies: @@ -497,6 +493,10 @@ packages: /estree-walker@2.0.2: resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + /fetch-jsonp@1.3.0: + resolution: {integrity: sha512-hxCYGvmANEmpkHpeWY8Kawfa5Z1t2csTpIClIDG/0S92eALWHRU1RnGaj86Tf5Cc0QF+afSa4SQ4pFB2rFM5QA==} + dev: false + /fill-range@7.0.1: resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} engines: {node: '>=8'} diff --git a/src/App.vue b/src/App.vue index c2c3187..9a4b24f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,7 @@ @@ -56,14 +62,48 @@ const searchSuggestionsRef = ref(null); // 关闭搜索框 const closeSearchInput = () => { status.setSiteStatus("normal"); + searchInputRef.value?.blur(); inputValue.value = ""; }; // 前往搜索 -const toSearch = () => { - const keywords = inputValue.value?.trim(); - if (keywords) { - console.log("前往搜索:" + keywords); +const toSearch = (val, type = 1) => { + const searchValue = val?.trim(); + // 定义跳转方法 + const jumpLink = (url) => { + if (set.urlJumpType === "open") { + window.location.href = url; + } else if (set.urlJumpType === "href") { + window.open(url, "_blank"); + } + }; + // 是否为空 + if (searchValue) { + console.log("前往搜索:" + searchValue, type); + // type + // 1 默认 / 2 快捷翻译 / 3 电子邮件 / 4 直接访问 + // 切换搜索引擎还没写,先这样 + switch (type) { + case 1: + jumpLink(`https://www.bing.com/search?q=${searchValue}`); + break; + case 2: + jumpLink(`https://fanyi.baidu.com/#en/zh/${searchValue}`); + break; + case 3: + jumpLink(`mailto:${searchValue}`); + break; + case 4: + const urlRegex = /^(https?:\/\/)/i; + const url = urlRegex.test(searchValue) + ? searchValue + : `//${searchValue}`; + jumpLink(url); + break; + default: + break; + } + closeSearchInput(); } else { status.setSiteStatus("focus"); searchInputRef.value?.focus(); @@ -95,7 +135,7 @@ const pressKeyboard = (event) => { // 13 回车 if (keyCode === 13) toSearch(); // 子组件事件 - searchSuggestionsRef.value?.keyboardEvents(keyCode); + searchSuggestionsRef.value?.keyboardEvents(keyCode, event); }; onMounted(() => { diff --git a/src/components/SearchSuggestions.vue b/src/components/SearchSuggestions.vue index 46780ea..4589cce 100644 --- a/src/components/SearchSuggestions.vue +++ b/src/components/SearchSuggestions.vue @@ -1,54 +1,113 @@