| 类名 | 类描述 |
|---|---|
| VHDoc | 文档控制器 |
| VHDocView | 文档展示组件 |
| 属性 | 属性描述 |
|---|---|
| VHWatermarkConfig | 文档水印 |
| VHDocCallbackInterface | 文档回调类 |
| 方法 | 方法描述 |
|---|---|
| VHDoc.init | 文档初始化 |
| VHDocView | 构建文档组件 |
| VHDoc.zoomReset | 文档还原 |
| VHDoc.zoomIn | 文档放大 |
| VHDoc.zoomOut | 文档缩小 |
public init(webinar: VHWebinarData, water: VHWatermarkConfig, listener: VHDocCallbackInterface): number| 参数名称 | 是否必须 | 示例 | 备注 |
|---|---|---|---|
| webinar | 是 | VHWebinarData活动基础配置 | |
| water | 是 | xxx | VHWatermarkConfig 文档水印配置 |
| listener | 是 | xxx | 文档回调事件 |
在组件生命周期aboutToAppear内进行初始化,设 置活动信息、水印信息、回调类
@Component
export struct VHDocPageComponent {
@Require webinars: VHWebinarData;
@Require playConfig: VHPlayerConfig;
//文档id集合
@State documentViews: Array<string> = new Array();
//选择文档id
@State selectCid: string = '';
private docController: VHDoc = new VHDoc();
private controller: TabsController = new TabsController()
@State showDoc: boolean = true;
private selectDocument: number = 0;
private contentWidth: number = 0;
private contentHeight: number = 0;
aboutToAppear(): void {
this.docController.init(this.webinars, this.playConfig?.water!, this);
}
}@Component
export struct VHDocView {
/**
* @description 文档控制器
* */
@Require docController:VHDoc;
/**
* @description 文档id
* */
@Require docId:string;
}在布局文件中添加,通过Tabs加载VHDocView。
build() {
Stack({alignContent:Alignment.Bottom}) {
Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
ForEach(this.documentViews, (doc: string, index: number) => {
TabContent() {
VHDocView({ docController: this.docController, docId: doc, isDocPaint: false })
.width('100%')
.height('100%')
.onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
//重置文档视图大小。
this.contentWidth = newValue.width as number;
this.contentHeight = newValue.height as number;
//******** 重要:需要重置文档画布大小 ********/
this.docController.setDocumentViewSize(doc, this.contentWidth, this.contentHeight);
})
}
.tabBar(this.tabBuilder(doc, index))
.width('100%')
.height('100%')
}, (doc: string, index: number) => {
if (this.selectCid == doc) {
if (this.selectDocument != 0) {
clearInterval(this.selectDocument);
this.selectDocument = 0;
}
this.selectDocument = setInterval(() => {
this.controller.changeIndex(index);
if (this.selectDocument != 0) {
clearInterval(this.selectDocument);
this.selectDocument = 0;
}
}, 100);
}
return doc;
})
}
.barHeight(0) //可通过设置此参数隐藏tab
.opacity(this.showDoc == true ? 100 : 0) //通过设置透明度来显示和隐藏,避免重新加载docview导致的画笔不全问题
.animationDuration(0)
.width('100%')
.height('100%')
.scrollable(false)
.zIndex(0)
}
.width('100%')
.height('100%')
}public zoomReset()通过按键触发放大
Image($r("app.media.reset"))
.width("30vp")
.height("30vp")
.onClick(()=>{
this.docController.zoomReset();
})public zoomIn()通过按键触发放大
Image($r("app.media.big"))
.width("30vp")
.height("30vp")
.onClick(()=>{
this.docController.zoomIn();
})public zoomOut()通过按键触发缩小
Image($r("app.media.small"))
.width("30vp")
.height("30vp")
.onClick(()=>{
this.docController.zoomOut();
})播放器水印主要通过在播放器层级上增加图片并控制位置显示实现。参考防录屏
通过回调监听文档添加和移除。通过documentViews存储文档id,通过VHDocView进行加载
文档类型
| VHDocType | 类型 | 备注 |
|---|---|---|
| VHDocType_Doc | 0 | 文档 |
| VHDocType_Board | 0 | 白板 |