mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 10:00:13 +01:00
This commit is contained in:
parent
6bfdaf35e4
commit
84819beaf7
2 changed files with 24 additions and 5 deletions
|
|
@ -80,7 +80,8 @@ export const newFile = (optios: {
|
|||
currentPath?: string,
|
||||
paths?: string[],
|
||||
useSavePath: boolean,
|
||||
name?: string
|
||||
name?: string,
|
||||
afterCB?: (id: string, title: string) => void
|
||||
}) => {
|
||||
if (getOpenNotebookCount() === 0) {
|
||||
showMessage(window.siyuan.languages.newFileTip);
|
||||
|
|
@ -97,12 +98,16 @@ export const newFile = (optios: {
|
|||
}
|
||||
if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) {
|
||||
if (data.data.path.startsWith("/") || optios.currentPath === "/") {
|
||||
const createPath = pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""))
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: data.data.box,
|
||||
path: pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")),
|
||||
path: createPath,
|
||||
// 根目录时无法确定 parentID
|
||||
markdown: ""
|
||||
}, response => {
|
||||
if (optios.afterCB) {
|
||||
optios.afterCB(response.data, pathPosix().basename(createPath));
|
||||
}
|
||||
/// #if !MOBILE
|
||||
openFileById({
|
||||
app: optios.app,
|
||||
|
|
@ -118,12 +123,16 @@ export const newFile = (optios: {
|
|||
notebook: data.data.box,
|
||||
path: optios.notebookId === data.data.box ? (optios.currentPath.endsWith(".sy") ? optios.currentPath : optios.currentPath + ".sy") : (data.data.path || "/")
|
||||
}, (responseHPath) => {
|
||||
const createPath = pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""))
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: data.data.box,
|
||||
path: pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")),
|
||||
path: createPath,
|
||||
parentID: getDisplayName(optios.currentPath, true, true),
|
||||
markdown: ""
|
||||
}, response => {
|
||||
if (optios.afterCB) {
|
||||
optios.afterCB(response.data, pathPosix().basename(createPath));
|
||||
}
|
||||
/// #if !MOBILE
|
||||
openFileById({
|
||||
app: optios.app,
|
||||
|
|
@ -142,11 +151,15 @@ export const newFile = (optios: {
|
|||
return;
|
||||
}
|
||||
if (optios.notebookId !== data.data.box) {
|
||||
const createPath = pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : ""))
|
||||
fetchPost("/api/filetree/createDocWithMd", {
|
||||
notebook: data.data.box,
|
||||
path: pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")),
|
||||
path: createPath,
|
||||
markdown: ""
|
||||
}, response => {
|
||||
if (optios.afterCB) {
|
||||
optios.afterCB(response.data, pathPosix().basename(createPath));
|
||||
}
|
||||
/// #if !MOBILE
|
||||
openFileById({
|
||||
app: optios.app,
|
||||
|
|
@ -172,6 +185,9 @@ export const newFile = (optios: {
|
|||
md: "",
|
||||
sorts: optios.paths
|
||||
}, () => {
|
||||
if (optios.afterCB) {
|
||||
optios.afterCB(id, title);
|
||||
}
|
||||
/// #if !MOBILE
|
||||
openFileById({app: optios.app, id, action: [Constants.CB_GET_CONTEXT, Constants.CB_GET_OPENNEW]});
|
||||
/// #else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue