From c2bc25bac71fb29c2943dea89c327cac73ec3c59 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 12 Aug 2023 23:51:14 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/8874 --- app/src/constants.ts | 1 + app/src/protyle/util/compatibility.ts | 17 +++++- app/src/search/assets.ts | 83 ++++++++++++++++++++++++++- app/src/search/util.ts | 5 +- 4 files changed, 100 insertions(+), 6 deletions(-) diff --git a/app/src/constants.ts b/app/src/constants.ts index 29b3f1308..a0adeaa06 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -70,6 +70,7 @@ export abstract class Constants { public static readonly LOCAL_ZOOM = "local-zoom"; public static readonly LOCAL_SEARCHDATA = "local-searchdata"; public static readonly LOCAL_SEARCHKEYS = "local-searchkeys"; + public static readonly LOCAL_SEARCHASSET = "local-searchasset"; public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index 05702a0b2..021658c42 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -148,6 +148,16 @@ export const getLocalStorage = (cb: () => void) => { window.siyuan.storage = response.data; // 历史数据迁移 const defaultStorage: any = {}; + defaultStorage[Constants.LOCAL_SEARCHASSET] = { + keys: [], + col: "", + row: "", + layout: 0, + method: 0, + types: [".txt", ".md", ".docx", ".xlsx", ".pptx"], + sort: 0, + k: "", + }; defaultStorage[Constants.LOCAL_SEARCHKEYS] = { keys: [], replaceKeys: [], @@ -216,9 +226,10 @@ export const getLocalStorage = (cb: () => void) => { }; defaultStorage[Constants.LOCAL_ZOOM] = 1; - [Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD, - Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHDATA, - Constants.LOCAL_ZOOM, Constants.LOCAL_LAYOUTS, Constants.LOCAL_AI, Constants.LOCAL_PLUGINTOPUNPIN].forEach((key) => { + [Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, + Constants.LOCAL_EXPORTWORD, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, + Constants.LOCAL_SEARCHDATA, Constants.LOCAL_ZOOM, Constants.LOCAL_LAYOUTS, Constants.LOCAL_AI, + Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET].forEach((key) => { if (typeof response.data[key] === "string") { try { const parseData = JSON.parse(response.data[key]); diff --git a/app/src/search/assets.ts b/app/src/search/assets.ts index b350d17be..efd7bd36f 100644 --- a/app/src/search/assets.ts +++ b/app/src/search/assets.ts @@ -1,3 +1,84 @@ -export const openSearchAsset = () => { +import {Constants} from "../constants"; +import {fetchPost} from "../util/fetch"; +export const openSearchAsset = (element: HTMLElement, isStick: boolean) => { + const localSearch = window.siyuan.storage[Constants.LOCAL_SEARCHASSET] + let methodText = window.siyuan.languages.keyword; + if (localSearch.method === 1) { + methodText = window.siyuan.languages.querySyntax; + } else if (localSearch.method === 2) { + methodText = "SQL"; + } else if (localSearch.method === 3) { + methodText = window.siyuan.languages.regex; + } + const loadingElement = element.nextElementSibling; + loadingElement.classList.remove("fn__none"); + element.innerHTML = `
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + +
+
+
+
+
+
+
+ ↑/↓ ${window.siyuan.languages.searchTip1} + Enter/Double Click ${window.siyuan.languages.searchTip2} + Esc ${window.siyuan.languages.searchTip5} +
` + element.previousElementSibling.classList.add("fn__none"); + element.classList.remove("fn__none") + if (element.querySelector("#searchList").innerHTML !== "") { + return + } + + fetchPost("/api/search/fullTextSearchAssetContent", { + page: 1, + query: localSearch.k, + types: localSearch.types, + method: localSearch.method, + orderBy: localSearch.sort + }, (response) => { + loadingElement.classList.remove("fn__none") + console.log(response) + }) } diff --git a/app/src/search/util.ts b/app/src/search/util.ts index c21a072a8..12f1ca36e 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -216,7 +216,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
-
+
↑/↓ ${window.siyuan.languages.searchTip1} ${updateHotkeyTip(window.siyuan.config.keymap.general.newFile.custom)} ${window.siyuan.languages.new} Enter/Double Click ${window.siyuan.languages.searchTip2} @@ -225,6 +225,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo Esc ${window.siyuan.languages.searchTip5}
+
`; const criteriaData: ISearchOption[] = []; @@ -495,7 +496,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo event.preventDefault(); break; } else if (target.id === "searchAsset") { - openSearchAsset(); + openSearchAsset(element.querySelector(".search__assets"), !!closeCB); event.stopPropagation(); event.preventDefault(); break;