chenritian 1 сар өмнө
parent
commit
7b9d7ae335

+ 104 - 0
commons/basic/src/main/ets/components/ToastBuilders/AlertToastComp.ets

@@ -0,0 +1,104 @@
+import { BasicType } from '../../models'
+import { yTToast } from '../../utils/YTToast'
+import { YTButton } from '../generalComp/YTButton'
+
+
+@Builder
+export function AlertToastBuilder(item: BasicType<undefined>) {
+  AlertToastComp({
+    message: item.message,
+    onConfirm: item.onConfirm,
+    onCancel: item.onCancel,
+    messageAlignSelf: item.messageAlignSelf,
+    confirmMessage: item.confirmMessage,
+    cancelMessage: item.cancelMessage,
+    isShowClose: item.isShowClose
+  })
+}
+
+@Component
+struct AlertToastComp {
+  message: string = ''
+  confirmMessage: string = '保存并退出'
+  cancelMessage: string = '取消并退出'
+  isShowClose: boolean = true
+  onConfirm: (index: string) => void = (index: string) => {
+  }
+  onCancel: () => void = () => {
+  }
+  messageAlignSelf: ItemAlign = ItemAlign.Center
+
+  build() {
+
+    Column({ space: 24 }) {
+      Stack() {
+        Row() {
+          Text(this.message)
+            .fontSize(16)
+            .fontWeight(400)
+            .fontColor('#FF353C46')
+            .alignSelf(this.messageAlignSelf)
+        }
+        .width('100%')
+        .justifyContent(FlexAlign.Center)
+
+        Row() {
+          Image($r('app.media.icon_cancel_blue'))
+            .width(16)
+        }
+        .width('100%')
+        .justifyContent(FlexAlign.End)
+        .onClick(() => {
+          yTToast.hide()
+        })
+        .visibility(this.isShowClose ? Visibility.Visible : Visibility.Hidden)
+      }
+      .width('100%')
+
+      Row() {
+        YTButton({
+          btContent: this.confirmMessage,
+          btWidth: 104,
+          btHeight: 42,
+          btFontSize: 16,
+          bgc: '#FF6E645E',
+          btPadding: 0,
+          btFontColor: '#FFF',
+          click: () => {
+            // yTToast.hide()
+            // yTRouter.routerBack()
+
+            this.onConfirm?.('0')
+          }
+        })
+        YTButton({
+          btContent: this.cancelMessage,
+          btWidth: 104,
+          btHeight: 42,
+          btFontSize: 16,
+          bgc: '#FFF5F5F7',
+          btPadding: 0,
+          btFontColor: '#FF353C46',
+          click: () => {
+            // console.log('你好')
+            this.onCancel?.()
+          }
+        })
+      }
+      .width('100%')
+      .justifyContent(FlexAlign.SpaceBetween)
+    }
+    .width(343)
+    // .height(138)
+    .padding({
+      left: 48,
+      right: 48,
+      top: 28,
+      bottom: 20
+    })
+    .backgroundColor('#FFF')
+    .borderRadius(16)
+
+    // .margin({ left: 16, right: 16 })
+  }
+}

+ 7 - 0
commons/basic/src/main/ets/models/index.ets

@@ -14,6 +14,13 @@ export interface BasicType<T = undefined> {
   index?: number,
   loginType?: LoginCollect
   finally?: () => void
+  onConfirm?: (text: string) => void
+  onCancel?: () => void
+  messageAlignSelf?: ItemAlign
+  confirmMessage?: string
+  cancelMessage?: string
+  isShowClose?: boolean
+
 }
 
 export type ReqString = Record<string, string>

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

@@ -6,6 +6,7 @@ import { yTDoubleConfirm } from '../components/ToastBuilders/YtDoubleConfirm';
 import { agreePrivacy } from '../components/ToastBuilders/AgreePrivacy';
 import { LoginCollect } from '../models/LoginCollect';
 import { loginToUse } from '../components/ToastBuilders/LoginToUse';
+import { AlertToastBuilder } from '../components/ToastBuilders/AlertToastComp';
 
 interface InitOption {
   context?: UIContext;
@@ -23,6 +24,12 @@ export class Params<T> implements BasicType<T> {
   message?: string
   loginType?: LoginCollect
   click?: () => void
+  onConfirm?: (text: string) => void
+  onCancel?: () => void
+  messageAlignSelf?: ItemAlign
+  confirmMessage?: string
+  cancelMessage?: string
+  isShowClose?: boolean
 
   constructor(item: BasicType = {}) {
     this.src = item.src;
@@ -33,6 +40,12 @@ export class Params<T> implements BasicType<T> {
     this.message = item.message;
     this.acSrc = item.acSrc;
     this.loginType = item.loginType;
+    this.onConfirm = item.onConfirm
+    this.onCancel = item.onCancel
+    this.messageAlignSelf = item.messageAlignSelf
+    this.confirmMessage = item.confirmMessage
+    this.cancelMessage = item.cancelMessage
+    this.isShowClose = item.isShowClose
   }
 }
 
@@ -101,7 +114,9 @@ export class YTToast {
   loginToUse(item: BasicType = {}) {
     this.openToast(wrapBuilder(loginToUse), item)
   }
-
+  alertToast(item: BasicType<undefined>) {
+    this.openToast(wrapBuilder(AlertToastBuilder), item)
+  }
 
   hide() {
     try {

BIN
commons/basic/src/main/resources/base/media/icon_cancel_blue.png