diff --git "a/public/asset/\346\227\245\347\250\213.sy.zip" "b/public/asset/\346\227\245\347\250\213.sy.zip" new file mode 100644 index 0000000..0365861 Binary files /dev/null and "b/public/asset/\346\227\245\347\250\213.sy.zip" differ diff --git a/src/api.ts b/src/api.ts index eac3944..bf0501e 100644 --- a/src/api.ts +++ b/src/api.ts @@ -569,4 +569,36 @@ export async function testSync(myurl: string, token: string) { return true; } return false; -} \ No newline at end of file +} + +//导入思源文件.zip +export async function importSY(notebookId: string, file: Blob) { + const formData = new FormData(); + formData.append('file', file, '日程.sy.zip'); + formData.append('notebook', notebookId); + formData.append('toPath', '/'); + + const response = await fetch('/api/import/importSY', { + method: 'POST', + body: formData + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + return data.code === 0; +} + +//触发网络下载 +export const downloadFile = (file: Blob) => { + const url = URL.createObjectURL(file); + const link = document.createElement('a'); + link.href = url; + link.download = '日程.sy.zip'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); +}; \ No newline at end of file diff --git a/src/calendar/module-calendar.ts b/src/calendar/module-calendar.ts index cb57354..4a1e125 100644 --- a/src/calendar/module-calendar.ts +++ b/src/calendar/module-calendar.ts @@ -536,9 +536,31 @@ export class M_calendar { } } + async importMoBan() { + let notebookId = getSTCalendarNotebookId((await api.lsNotebooks()).notebooks); + console.log("ceshi1", notebookId); + if (!notebookId) { + showMessage("已创建名为“ST日程管理”的笔记本", 3000, "info"); + await api.createNotebook("ST日程管理"); + notebookId = getSTCalendarNotebookId((await api.lsNotebooks()).notebooks); + } + //获取模板zip文件 + try{ + const file = await api.getFileBlob("/data/plugins/siyuan-steve-tools/asset/日程.sy.zip"); + await api.importSY(notebookId, file); + }catch(e){ + console.log(e); + } + showMessage("已导入日程模板", 3000, "info"); + } + } +function getSTCalendarNotebookId(notebooks): string | null { + const stCalendarNotebook = notebooks.find(notebook => notebook.name === "ST日程管理"); + return stCalendarNotebook ? stCalendarNotebook.id : null; +} function extractDataAvId(markdown: string): string | null { const regex = /data-av-id="([^"]+)"/; @@ -560,16 +582,16 @@ function convertTimestampToArray(timestamp: number): [number, number, number, nu ]; } -type FrequencyType = 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY'; -const mapFrequency = (chinese: string): FrequencyType => { - const frequencyMap: Record = { - '每天': 'DAILY', - '每周': 'WEEKLY', - '每月': 'MONTHLY', - '每年': 'YEARLY' - }; - return frequencyMap[chinese] || 'WEEKLY'; -}; +// type FrequencyType = 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY'; +// const mapFrequency = (chinese: string): FrequencyType => { +// const frequencyMap: Record = { +// '每天': 'DAILY', +// '每周': 'WEEKLY', +// '每月': 'MONTHLY', +// '每年': 'YEARLY' +// }; +// return frequencyMap[chinese] || 'WEEKLY'; +// }; // const targetElement = document.querySelector('div[contenteditable="false"][data-av-id="20241213113357-m9b143e"][data-av-type="table"][data-node-id="20241003141312-30yk3cr"][data-type="NodeAttributeView"][class="av"][custom-sy-av-view="20241213113357-tuugpcw"][name="日程"]'); diff --git a/src/setting-example.svelte b/src/setting-example.svelte index c8fb8db..5a547dc 100644 --- a/src/setting-example.svelte +++ b/src/setting-example.svelte @@ -77,19 +77,19 @@ key: "cal-show-view", value: settings["cal-show-view"], }, - // { - // type: "button", - // title: "日程周期规则说明", - // description: "日程周期规则说明", - // key: "cal-rule", - // value: settings["cal-rule"], - // button: { - // label: "查看", - // callback: () => { - // moduleInstances['M_calendar'].showhelp(); - // }, - // }, - // }, + { + type: "button", + title: "日程周期模板", + description: "生成日程周期模板(注意:会创建一个笔记本)", + key: "cal-rule", + value: settings["cal-rule"], + button: { + label: "生成", + callback: () => { + moduleInstances['M_calendar'].importMoBan(); + }, + }, + }, { type: "button", title: "恢复默认配置",