Documentation Index
Fetch the complete documentation index at: https://docs.supernote.com/llms.txt
Use this file to discover all available pages before exploring further.
主图层和背景图层不支持修改图层名称。即使传入新的 name,也不会生效,界面中仍会显示默认名称。
static modifyLayers(notePath: string, page: number, layers: Layer[]): Promise<APIResponse<boolean>>;
参数
| 参数 | 类型 | 说明 |
|---|
notePath | string | 笔记文件路径 |
page | number | 页面索引(从 0 开始) |
layers | Layer[] | 已存在的图层数据数组。主图层和背景图层的 name 不支持修改 |
返回
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;
}