跳转到主要内容
只有笔记文件才有图层数据,其他文件没有图层数据。
static modifyLayers(notePath: string, page: number, layers: Layer[]): Promise<APIResponse<boolean>>;
参数
参数类型说明
notePathstring笔记文件路径
pagenumber页面索引(从 0 开始)
layersLayer[]已存在的图层数据数组
返回

示例

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

/**
 * 修改页面图层数据的示例。
 */
export async function exampleModifyLayers() {
  const notePath = '/storage/emulated/0/Note/demo.note';
  const page = 0;

  const listRes = await PluginFileAPI.getLayers(notePath, page);
  if (!listRes.success) {
    throw new Error(listRes.error?.message ?? 'getLayers 调用失败');
  }

  const layers = (listRes.result ?? []) as Layer[];
  const customs = layers.filter((l) => l.layerId >= 1 && l.layerId <= 3);
  const custom = customs[0];
  if (custom) {
    custom.name = '工作图层';
    custom.isVisible = true;
    custom.isCurrentLayer = true;
  }
  layers.forEach((l) => {
    if (l !== custom) {
      l.isCurrentLayer = false;
    }
  });
  const res = await PluginFileAPI.modifyLayers(notePath, page, layers);
  if (!res.success) {
    throw new Error(res.error?.message ?? 'modifyLayers 调用失败');
  }
  return res.result;
}