first commit 根据url里的id打开特定块 (#7086)

This commit is contained in:
iamqiz 2023-01-16 20:42:28 +08:00 committed by GitHub
parent 1befd3fc47
commit 77560d6601
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -105,7 +105,16 @@ export const setProxy = () => {
}); });
/// #endif /// #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) => { export const onGetConfig = (isStart: boolean) => {
const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general"); const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general");
const matchKeymap2 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.general, "editor", "general"); const matchKeymap2 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.general, "editor", "general");
@ -179,6 +188,18 @@ export const onGetConfig = (isStart: boolean) => {
mountHelp(); mountHelp();
} }
addGA(); 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 = () => { const initBar = () => {