import { BasicType } from '../models'; import { ComponentContent } from '@kit.ArkUI'; import { Params } from './YTToast'; import { BusinessError } from '@ohos.base'; interface InitOption { context: UIContext; options: SheetOptions } export class YTBindSheet { private static declare instance: YTBindSheet private declare ctx: UIContext; private declare contentNode: ComponentContent | null; private declare options: SheetOptions private maskColor: string = '#80000000' static getInstance() { if (!YTBindSheet.instance) { YTBindSheet.instance = new YTBindSheet() } return YTBindSheet.instance } init(initOption: InitOption) { this.ctx = initOption.context; if (!initOption.options.maskColor) { initOption.options.maskColor = this.maskColor } this.options = initOption.options; } setContext(context: UIContext) { this.ctx = context; } setContentNode(node: ComponentContent) { this.contentNode = node; } setOptions(options: SheetOptions) { const keys = Object.keys(options) keys.forEach((key) => { if (options[key]) { this.options[key] = options[key] } }) } openBindSheet(builder: WrappedBuilder<[ BasicType ]>, item: BasicType) { this.contentNode = new ComponentContent(this.ctx, builder, new Params(item)); this.ctx.openBindSheet(this.contentNode, this.options) .then(() => { console.info('openBindSheet success'); }) .catch((err: BusinessError) => { console.error('openBindSheet error: ' + err.code + ' ' + err.message); }) } hide() { this.ctx.closeBindSheet(this.contentNode) .then(() => { console.info('closeBindSheet success'); }) .catch((err: BusinessError) => { console.error('closeBindSheet error: ' + err.code + ' ' + err.message); }) } //刷新数据 updateBindSheet(item: BasicType) { if (this.contentNode !== null) { this.contentNode.update(item) } } } export const yTBindSheet = YTBindSheet.getInstance()