This commit is contained in:
Vanessa 2023-01-16 21:33:20 +08:00
parent 77560d6601
commit c5f35969eb
7 changed files with 52 additions and 62 deletions

View file

@ -0,0 +1,33 @@
import {Dialog} from "../dialog";
import {fetchPost} from "./fetch";
import {isMobile} from "./functions";
// 需独立出来,否则移动端引用的时候会引入 pc 端大量无用代码
export const renameTag = (labelName: string) => {
const dialog = new Dialog({
title: window.siyuan.languages.rename,
content: `<div class="b3-dialog__content"><input class="b3-text-field fn__block" value="${labelName}"></div>
<div class="b3-dialog__action">
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
</div>`,
width: isMobile() ? "80vw": "520px",
});
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
});
const inputElement = dialog.element.querySelector("input");
dialog.bindInput(inputElement, () => {
(btnsElement[1] as HTMLButtonElement).click();
});
inputElement.focus();
inputElement.select();
btnsElement[1].addEventListener("click", () => {
fetchPost("/api/tag/renameTag", {oldLabel: labelName, newLabel: inputElement.value});
});
};
export const getWorkspaceName = () => {
return window.siyuan.config.system.workspaceDir.replace(/^.*[\\\/]/, "");
};

View file

@ -27,10 +27,11 @@ import {showMessage} from "../dialog/message";
import {editor} from "../config/editor";
import {goBack, goForward} from "./backForward";
import {replaceLocalPath} from "../editor/rename";
import {getWorkspaceName, workspaceMenu} from "../menus/workspace";
import {workspaceMenu} from "../menus/workspace";
import {Tab} from "../layout/Tab";
import {Editor} from "../editor";
import {zoomOut} from "../menus/protyle";
import { getWorkspaceName } from "./noRelyPCFunction";
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
if (key1 === "general") {
@ -105,16 +106,7 @@ export const setProxy = () => {
});
/// #endif
};
// 获取 location.search 里特定参数,失败返回false
function getUrlArg(arg_name: string) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == arg_name){return pair[1];}
}
return false;
}
export const onGetConfig = (isStart: boolean) => {
const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general");
const matchKeymap2 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.general, "editor", "general");
@ -188,18 +180,6 @@ export const onGetConfig = (isStart: boolean) => {
mountHelp();
}
addGA();
//根据url里的id参数打开相应的块,用于浏览器访问
let url_doc_id=getUrlArg("id")
if (url_doc_id) {
fetchPost("/api/block/getBlockInfo", {id: url_doc_id}, response => {
if (response.code === 0 && typeof url_doc_id === "string") {
openFileById({
id: url_doc_id,
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT,]
})
}
})
}
};
const initBar = () => {