YTDiaLogBuild.ets 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import { BasicType, IBestToast } from 'basic'
  2. import { DiaLogPageEnum, DiaLogParam } from 'basic/src/main/ets/models/YTDiaLogModel'
  3. import { NumberKeyBoard, NumberKeyBoardStyle } from './NumberKeyboard'
  4. import { YtDatePicker } from './YtDatePicker'
  5. import { _YtHeader } from './_YtHeader'
  6. @Builder
  7. export function getBuilder(param: DiaLogParam, onBack: (ans?: string) => void){
  8. if(param.pageEnum == DiaLogPageEnum.BottomMenu) BottomMenu(onBack, param.params)
  9. else if (param.pageEnum == DiaLogPageEnum.DatePicker) DatePickerBuilder(onBack, param.param)
  10. else if (param.pageEnum == DiaLogPageEnum.NumBerInput) NumberInputBuilder({onBack: onBack, param: param.param})
  11. else if (param.pageEnum == DiaLogPageEnum.Confirm) DoubleConfirm(onBack, param.param)
  12. else if (param.pageEnum == DiaLogPageEnum.TextInput) InputComp({onBack: onBack, param: param.param})
  13. /******** 额外的 ***********/
  14. }
  15. // 底部菜单
  16. @Builder
  17. function BottomMenu(onBack: (ans:string) => void, params?: Array<BasicType>) {
  18. Column(){
  19. ForEach(params, (item: BasicType, index) => {
  20. Row(){
  21. Text(item.text)
  22. .fontSize(16)
  23. .textAlign(TextAlign.Center)
  24. }
  25. .width("100%")
  26. .alignItems(VerticalAlign.Center)
  27. .justifyContent(FlexAlign.Center)
  28. .padding({ top: 24, bottom: 24 })
  29. .onClick(() => {
  30. let ans = item.message ?? item.text ?? `${index}`
  31. onBack(ans)
  32. })
  33. Divider().width("80%").height(1).backgroundColor('#000000F2')
  34. })
  35. }
  36. .width("100%")
  37. .padding({ bottom: 30 })
  38. .backgroundColor(Color.White)
  39. .justifyContent(FlexAlign.Center)
  40. .alignItems(HorizontalAlign.Center)
  41. .borderRadius({ topLeft: 8, topRight: 8 })
  42. }
  43. // 时间选择器
  44. @Builder
  45. function DatePickerBuilder(onBack: (ans?:string) => void, param?: BasicType){
  46. YtDatePicker({
  47. selectDateBack: (date?: Date) => {
  48. if(!date) return onBack()
  49. // 转换为 YY-MM-DD HH:mm:ss 格式
  50. const year = date.getFullYear().toString();
  51. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  52. const day = date.getDate().toString().padStart(2, '0');
  53. const result = `${year}-${month}-${day}`;
  54. onBack(result)
  55. },
  56. selectedDate: param?.date ? new Date(param.date) : new Date(),
  57. linearInfo: { colors: [['#95C50A', 1]] },
  58. needCancel: true
  59. })
  60. }
  61. // 对话框
  62. @Builder
  63. function DoubleConfirm(onBack: (ans?:string) => void, param?: BasicType) {
  64. Column() {
  65. if(param?.text)
  66. Text(param.text)
  67. .fontColor(Color.Black)
  68. .lineHeight(18)
  69. .fontSize(18)
  70. .textAlign(TextAlign.Center)
  71. .margin({ bottom: 18 })
  72. Row() {
  73. Text('取消')
  74. .fontSize(16)
  75. .fontWeight(400)
  76. .borderRadius(param?.number ?? 36)
  77. .fontColor(Color.Black)
  78. .backgroundColor('#F5F5F7')
  79. .padding({ left: 36, top: 9, right: 36, bottom: 9})
  80. .onClick(() => {
  81. onBack()
  82. })
  83. Text('确定')
  84. .fontSize(16)
  85. .fontWeight(400)
  86. .borderRadius(param?.number ?? 36)
  87. .fontColor(Color.Black)
  88. .padding({ left: 36, top: 9, right: 36, bottom: 9})
  89. .linearGradient({
  90. colors: [ param?.color ? [param.color, 1 ] : ['#30E3CE', 0.4], ['#91F1FF', 0.8] ],
  91. angle: 200
  92. })
  93. .onClick(() => {
  94. onBack('true')
  95. })
  96. }
  97. .justifyContent(FlexAlign.SpaceBetween)
  98. .width('100%')
  99. }
  100. // .height(160)
  101. .width(280)
  102. .padding({ top: 28, left: 32, right: 32, bottom: 20 })
  103. .backgroundColor(Color.White)
  104. .borderRadius(8)
  105. }
  106. // 数字输入框
  107. @ComponentV2
  108. struct NumberInputBuilder{
  109. @Event onBack: (ans:string) => void
  110. @Param @Require param: BasicType
  111. @Local ans: string = ''
  112. aboutToAppear(): void {
  113. this.ans = this.param.text ?? ''
  114. }
  115. build() {
  116. Column(){
  117. // 标题
  118. RelativeContainer(){
  119. _YtHeader({ title: this.param?.text ?? '', isShowBackComp: false, })
  120. .height(44)
  121. .id('_title')
  122. .width("100%")
  123. .alignRules({
  124. top: { anchor: "__container__", align: VerticalAlign.Top},
  125. left: { anchor: "__container__", align: HorizontalAlign.Start}
  126. })
  127. Text(this.ans)
  128. .fontSize(32)
  129. .fontWeight(500)
  130. .fontColor('#30E3CE')
  131. .id('weight')
  132. .padding({left: 58, right: 58, bottom: 10, top: 60})
  133. .alignRules({
  134. top: { anchor: "_title", align: VerticalAlign.Bottom},
  135. middle: { anchor: "__container__", align: HorizontalAlign.Center}
  136. })
  137. Row()
  138. .width(151)
  139. .height(3)
  140. .backgroundColor('#30E3CE')
  141. .borderRadius(8)
  142. .alignRules({
  143. top: { anchor: "weight", align: VerticalAlign.Bottom},
  144. middle: { anchor: "__container__", align: HorizontalAlign.Center}
  145. })
  146. Text(this.param?.message ?? '')
  147. .fontSize(20)
  148. .fontWeight(500)
  149. .padding({ bottom: 10 })
  150. .fontColor('rgba(0, 0, 0, 0.5)')
  151. .alignRules({
  152. bottom: { anchor: "weight", align: VerticalAlign.Bottom},
  153. right: { anchor: "weight", align: HorizontalAlign.End}
  154. })
  155. }
  156. .height(210)
  157. .backgroundColor(Color.White)
  158. // 数字键盘
  159. Column(){
  160. NumberKeyBoard({
  161. textInputValue: this.ans,
  162. maxInputNum: 3,
  163. keyBoardStyle: new NumberKeyBoardStyle()
  164. .setFinishBackGround('#30E3CE')
  165. .setZeroBackGround(Color.White)
  166. .setBorder({ width: 0 })
  167. .setDeleteIcon($r('app.media.icon_delback')),
  168. onTextInputValueChange: (textInputValue: string) => {
  169. this.ans = textInputValue
  170. },
  171. onFinishClick: (text: string) => {
  172. if(!text || text == '0' || text == '0.') return
  173. if(text.charAt(text.length-1) === '.') this.ans += '0'
  174. this.onBack(this.ans!)
  175. }
  176. })
  177. }
  178. .height(260)
  179. .width("100%")
  180. .backgroundColor('#F5F6FA')
  181. .padding({ top: 10, bottom: 35, left: 10, right: 10})
  182. }
  183. // .height(470)
  184. .width("100%")
  185. .backgroundColor(Color.White)
  186. .padding({
  187. top: 24,
  188. })
  189. }
  190. }
  191. // 输入框
  192. @ComponentV2
  193. struct InputComp{
  194. @Event onBack: (ans?:string) => void
  195. @Param @Require param: BasicType
  196. @Local ans: string = ''
  197. aboutToAppear(): void {
  198. this.ans = this.param.text ?? ''
  199. }
  200. build() {
  201. Column({space: 10}){
  202. Row(){
  203. Text("取消")
  204. .fontSize(12)
  205. .fontWeight(400)
  206. .borderRadius(45)
  207. // .backgroundColor('#C1EDE9')
  208. .padding({ left: 20,top: 8, right: 20, bottom: 8})
  209. .onClick(() => {
  210. this.onBack()
  211. })
  212. // Text(this.param.text ?? '')
  213. // .fontSize(18)
  214. // .fontWeight(500)
  215. Text("确定")
  216. .fontSize(12)
  217. .fontWeight(400)
  218. .borderRadius(45)
  219. .fontColor(Color.Black)
  220. // .backgroundColor('#30E3CE')
  221. .padding({ left: 20,top: 8, right: 20, bottom: 8})
  222. .onClick(() => {
  223. this.onBack(this.ans)
  224. })
  225. }
  226. .width("100%")
  227. .alignItems(VerticalAlign.Center)
  228. .justifyContent(FlexAlign.SpaceBetween)
  229. TextInput({text: $$this.ans, placeholder: this.param.message})
  230. .height('48')
  231. .borderRadius(8)
  232. .defaultFocus(true)
  233. .maxLength(13)
  234. .backgroundColor('#F6F6F6')
  235. .onSubmit(() => {
  236. this.onBack(this.ans)
  237. })
  238. }
  239. .width("100%")
  240. .borderRadius({ topLeft: 10, topRight: 10 })
  241. .backgroundColor(this.param.color ?? '#ffff')
  242. .padding({ bottom: 42, left: 16, right: 16, top: 24 })
  243. }
  244. }