|
@@ -0,0 +1,84 @@
|
|
|
|
|
+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<Object> | 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<Object>) {
|
|
|
|
|
+ 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<undefined>(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()
|