只有笔记文件才有图层数据,其他文件没有图层数据。
复制
static modifyLayers(notePath: string, page: number, layers: Layer[]): Promise<APIResponse<boolean>>;
| 参数 | 类型 | 说明 |
|---|---|---|
notePath | string | 笔记文件路径 |
page | number | 页面索引(从 0 开始) |
layers | Layer[] | 已存在的图层数据数组 |
APIResponse<boolean>:result === true表示修改成功
示例
复制
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;
}