Ver Fonte

Merge remote-tracking branch 'origin/master'

YuJing há 2 meses atrás
pai
commit
f79dea9873

+ 1 - 0
commons/basic/Index.ets

@@ -16,6 +16,7 @@ export { YTUserRequest } from './src/main/ets/apis/YTUserRequest'
 
 
 export { ScanCodeUtil } from './src/main/ets/utils/ScanCodeUtil'
+export { YTBindSheet } from './src/main/ets/utils/YTBindSheet'
 
 export { YTDate } from './src/main/ets/utils/YTDate'
 

+ 84 - 0
commons/basic/src/main/ets/utils/YTBindSheet.ets

@@ -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()

+ 1 - 1
commons/basic/src/main/ets/utils/YTToast.ets

@@ -12,7 +12,7 @@ interface InitOption {
 }
 
 
-class Params<T> implements BasicType<T> {
+export class Params<T> implements BasicType<T> {
   src?: ResourceStr
   acSrc?: ResourceStr
   text?: string