跳转到主要内容
static createNote(params: {
  notePath: string;
  template: string;
  mode: number;
  isPortrait: boolean;
}): Promise<APIResponse<boolean>>;
参数
参数类型说明
params.notePathstring笔记路径
params.templatestring模版来源:
- 系统模版:通过 getNoteSystemTemplates 获取,传递其中的模版名称(Templatename)即可创建;
- 自定义模版:传递自定义模版的图片路径,根据图片文件创建笔记。
params.modenumber创建模式:0 普通笔记文件,1 识别笔记文件
params.isPortraitboolean是否是竖屏笔记
返回

示例

import { PluginFileAPI, PluginCommAPI } from 'sn-plugin-lib';

/**
 * 创建笔记的示例(使用系统模版)。
 */
export async function exampleCreateNote() {
  const notePath = '/storage/emulated/0/Note/new.note';

  // 获取系统模版列表并选择一个模版名称(Template.name)
  const tplRes = await PluginCommAPI.getNoteSystemTemplates();
  if (!tplRes.success) {
    throw new Error(tplRes.error?.message ?? 'getNoteSystemTemplates 调用失败');
  }
  const templates = (tplRes.result ?? []) as any[];
  const templateName = templates[0]?.name;
  if (!templateName) {
    throw new Error('未获取到系统模版名称');
  }

  const res = await PluginFileAPI.createNote({
    notePath,
    template: templateName,
    mode: 0,
    isPortrait: true,
  });
  if (!res.success) {
    throw new Error(res.error?.message ?? 'createNote 调用失败');
  }
  return res.result;
}