简体中文
list.previewImage.before
约 389 字大约 1 分钟
2025-12-16
该钩子在列表图片字段预览前调用。
用途
预览图片前执行额外的业务逻辑:
- 阻止预览
- 使用其他方式进行预览
参数
functional用于注册Hook回调函数。执行该Hook时,宿主会向回调函数传入以下参数。图片预览参数和列表通用参数均位于context中。
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| context | 图片预览事件上下文 | Object | — | — |
| plugin | 当前插件运行信息,业务逻辑通常不需要使用 | Object | — | — |
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| objectApiname | 对象apiName | String | — | — |
| fieldName | 字段apiName | String | — | — |
| data | 当前图片字段值;可能是以|分隔的字符串或图片对象数组 | String | Object[] | — | — |
| trData | 当前行完整数据 | Object | — | — |
| startIndex | 本次点击图片在data中的索引,从0开始 | Number | — | — |
| field | 当前图片字段描述 | Object | — | — |
返回结果
Hook可以返回结果对象,也可以返回Promise<Object>。宿主会在Promise resolve后判断是否继续默认预览。
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| stopPreView | 是否阻止默认预览(示例) | Boolean | — | false |
返回{stopPreView: true}时阻止宿主的默认图片预览;未返回结果、未返回stopPreView或该值为false时,继续执行默认预览。
示例
基础用法
export default class Plugin {
apply() {
return [{
event: "list.previewImage.before",
functional: this.previewBefore.bind(this)
}];
}
previewBefore(context, plugin) {
console.log(context.fieldName);
console.log(context.data);
}
}阻止预览
export default class Plugin {
apply() {
return [{
event: "list.previewImage.before",
functional: this.previewBefore.bind(this)
}];
}
previewBefore(context, plugin) {
return Promise.resolve({
stopPreView: true
})
}
}