Vanessa 2024-04-28 19:18:02 +08:00
parent b6cae8cf8e
commit a77f998e16
3 changed files with 49 additions and 32 deletions

View file

@ -102,7 +102,7 @@ export abstract class Constants {
public static readonly LOCAL_SEARCHUNREF = "local-searchunref";
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
public static readonly LOCAL_HISTORY = "local-history";
public static readonly LOCAL_CODELANG = "local-codelang"; // string
public static readonly LOCAL_FONTSTYLES = "local-fontstyles";
public static readonly LOCAL_EXPORTPDF = "local-exportpdf";

View file

@ -30,22 +30,44 @@ const renderDoc = (element: HTMLElement, currentPage: number) => {
const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement;
const typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement;
const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement;
window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] = notebookElement.value;
setStorageVal(Constants.LOCAL_HISTORYNOTEID, window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID]);
const docElement = element.querySelector('.history__text[data-type="docPanel"]');
const assetElement = element.querySelector('.history__text[data-type="assetPanel"]');
const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;
docElement.classList.add("fn__none");
mdElement.classList.add("fn__none");
if (typeElement.value === "0" || typeElement.value === "1") {
opElement.removeAttribute("disabled");
notebookElement.removeAttribute("disabled");
assetElement.classList.add("fn__none");
} else {
opElement.setAttribute("disabled", "disabled");
if (typeElement.value === "2") {
notebookElement.setAttribute("disabled", "disabled");
assetElement.classList.remove("fn__none");
if (window.siyuan.storage[Constants.LOCAL_HISTORY].type !== 2) {
opElement.value = "all";
}
opElement.querySelector('option[value="clean"]').classList.remove("fn__none")
opElement.querySelector('option[value="update"]').classList.remove("fn__none")
opElement.querySelector('option[value="delete"]').classList.add("fn__none")
opElement.querySelector('option[value="format"]').classList.add("fn__none")
opElement.querySelector('option[value="sync"]').classList.remove("fn__none")
opElement.querySelector('option[value="replace"]').classList.add("fn__none")
opElement.querySelector('option[value="outline"]').classList.add("fn__none")
} else {
notebookElement.removeAttribute("disabled");
assetElement.classList.add("fn__none");
if (window.siyuan.storage[Constants.LOCAL_HISTORY].type === 2) {
opElement.value = "all";
}
opElement.querySelector('option[value="clean"]').classList.add("fn__none")
opElement.querySelector('option[value="update"]').classList.remove("fn__none")
opElement.querySelector('option[value="delete"]').classList.remove("fn__none")
opElement.querySelector('option[value="format"]').classList.remove("fn__none")
opElement.querySelector('option[value="sync"]').classList.remove("fn__none")
opElement.querySelector('option[value="replace"]').classList.remove("fn__none")
opElement.querySelector('option[value="outline"]').classList.remove("fn__none")
}
window.siyuan.storage[Constants.LOCAL_HISTORY] = {
notebookId: notebookElement.value,
type: parseInt(typeElement.value),
operation: opElement.value
};
setStorageVal(Constants.LOCAL_HISTORY, window.siyuan.storage[Constants.LOCAL_HISTORY]);
fetchPost("/api/history/searchHistory", {
notebook: notebookElement.value,
query: inputElement.value,
@ -303,19 +325,11 @@ export const openHistory = (app: App) => {
return;
}
let existLocalHistoryNoteID = false;
const localHistory = window.siyuan.storage[Constants.LOCAL_HISTORY];
let notebookSelectHTML = `<option value='%' ${localHistory.notebookId === "%" ? "selected" : ""}>${window.siyuan.languages.allNotebooks}</option>`;
window.siyuan.notebooks.forEach((item) => {
if (!item.closed) {
if (item.id === window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID]) {
existLocalHistoryNoteID = true;
}
}
});
let notebookSelectHTML = `<option value='%' ${!existLocalHistoryNoteID ? "selected" : ""}>${window.siyuan.languages.allNotebooks}</option>`;
window.siyuan.notebooks.forEach((item) => {
if (!item.closed) {
notebookSelectHTML += ` <option value="${item.id}"${item.id === window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] ? " selected" : ""}>${escapeHtml(item.name)}</option>`;
notebookSelectHTML += ` <option value="${item.id}"${item.id === localHistory.notebookId ? " selected" : ""}>${escapeHtml(item.name)}</option>`;
}
});
@ -342,20 +356,20 @@ export const openHistory = (app: App) => {
</div>
<span class="fn__space"></span>
<select data-type="typeselect" class="b3-select ${isMobile() ? "fn__size96" : "fn__size200"}">
<option value="0" selected>${window.siyuan.languages.docName}</option>
<option value="1">${window.siyuan.languages.docNameAndContent}</option>
<option value="2">${window.siyuan.languages.assets}</option>
<option value="0" ${localHistory.type === 0 ? "selected" : ""}>${window.siyuan.languages.docName}</option>
<option value="1" ${localHistory.type === 1 ? "selected" : ""}>${window.siyuan.languages.docNameAndContent}</option>
<option value="2" ${localHistory.type === 2 ? "selected" : ""}>${window.siyuan.languages.assets}</option>
</select>
<span class="fn__space"></span>
<select data-type="opselect" class="b3-select${isMobile() ? " fn__size96" : ""}">
<option value="all" selected>${window.siyuan.languages.allOp}</option>
<option value="clean">${window.siyuan.languages.historyClean}</option>
<option value="update">${window.siyuan.languages.historyUpdate}</option>
<option value="delete">${window.siyuan.languages.historyDelete}</option>
<option value="format">${window.siyuan.languages.historyFormat}</option>
<option value="sync">${window.siyuan.languages.historySync}</option>
<option value="replace">${window.siyuan.languages.historyReplace}</option>
<option value="outline">${window.siyuan.languages.historyOutline}</option>
<option value="all" ${localHistory.operation === "all" ? "selected" : ""}>${window.siyuan.languages.allOp}</option>
<option value="clean" ${localHistory.operation === "clean" ? "selected" : ""}>${window.siyuan.languages.historyClean}</option>
<option value="update" ${localHistory.operation === "update" ? "selected" : ""}>${window.siyuan.languages.historyUpdate}</option>
<option value="delete" ${localHistory.operation === "delete" ? "selected" : ""}>${window.siyuan.languages.historyDelete}</option>
<option value="format" ${localHistory.operation === "format" ? "selected" : ""}>${window.siyuan.languages.historyFormat}</option>
<option value="sync" ${localHistory.operation === "sync" ? "selected" : ""}>${window.siyuan.languages.historySync}</option>
<option value="replace" ${localHistory.operation === "replace" ? "selected" : ""}>${window.siyuan.languages.historyReplace}</option>
<option value="outline" ${localHistory.operation === "outline" ? "selected" : ""}>${window.siyuan.languages.historyOutline}</option>
</select>
<span class="fn__space"></span>
<select data-type="notebookselect" class="b3-select ${isMobile() ? "fn__size96" : "fn__size200"}">

View file

@ -195,6 +195,9 @@ export const getLocalStorage = (cb: () => void) => {
defaultStorage[Constants.LOCAL_OUTLINE] = {keepExpand: true};
defaultStorage[Constants.LOCAL_FILEPOSITION] = {}; // {id: IScrollAttr}
defaultStorage[Constants.LOCAL_DIALOGPOSITION] = {}; // {id: IPosition}
defaultStorage[Constants.LOCAL_HISTORY] = {
notebookId: "%", type: 0, operation: "all"
};
defaultStorage[Constants.LOCAL_FLASHCARD] = {
fullscreen: false
};
@ -256,7 +259,7 @@ export const getLocalStorage = (cb: () => void) => {
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, Constants.LOCAL_FLASHCARD,
Constants.LOCAL_DIALOGPOSITION, Constants.LOCAL_SEARCHUNREF,
Constants.LOCAL_DIALOGPOSITION, Constants.LOCAL_SEARCHUNREF, Constants.LOCAL_HISTORY,
Constants.LOCAL_OUTLINE, Constants.LOCAL_FILEPOSITION].forEach((key) => {
if (typeof response.data[key] === "string") {
try {