1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import deviceInfo from '@ohos.deviceInfo' 17 18import { Action } from '../../../redux/actions/Action' 19import { Log } from '../../../utils/Log' 20import { OhCombinedState } from '../../../redux/store' 21import { getStore } from '../../../redux/store' 22import EntryComponent from './EntryComponent' 23import { Dispatch } from '../../../redux/core/redux/types/store' 24 25@Observed 26export class CustomDialogDetails { 27 confirmCallback: Function = () => { 28 }; 29 confirmItem: boolean = false; 30 height: number = 0; 31 width: number = 0; 32 setAlias: string = ''; 33 childrenList: ChildrenItemStruct[] = []; 34 settingTitle: string = ''; 35} 36 37class StateStruct { 38} 39 40class CustomDialogViewDispatcher { 41 private mDispatch: Dispatch = (data) => data; 42 43 public setDispatch(dispatch: Dispatch) { 44 this.mDispatch = dispatch; 45 } 46 47 public closeDialog(isCloseFlag: boolean): void { 48 this.mDispatch(Action.closeDialog(isCloseFlag)); 49 } 50} 51 52class ChildrenItemStruct { 53 itemValue: Resource = $r('app.string.photo_ratio_4_3'); 54} 55 56class StyleStruct { 57 columns: number = 0; 58 offset: number = 0; 59} 60 61@CustomDialog 62export struct CustomDialogView { 63 private TAG: string = '[CustomDialogView]:' 64 localStyle: StyleStruct = { columns: 4, offset: 0 }; 65 controller?: CustomDialogController; 66 cancel: () => void = () => { 67 }; 68 confirm: () => void = () => { 69 }; 70 @Consume customDialogDetails: CustomDialogDetails; 71 @State settingAlias: string = ""; 72 @State getValue: string = ""; 73 @State childrenList: Array<ChildrenItemStruct> = []; 74 @State state: StateStruct = new StateStruct(); 75 private mAction: CustomDialogViewDispatcher = new CustomDialogViewDispatcher(); 76 77 async aboutToAppear() { 78 Log.info(`${this.TAG} aboutToAppear start`) 79 this.childrenList = this.customDialogDetails.childrenList 80 Log.info(`${this.TAG} childrenList ${JSON.stringify(this.childrenList)}`) 81 getStore().subscribe((state: OhCombinedState) => { 82 this.state = {}; 83 }, (dispatch: Dispatch) => { 84 this.mAction.setDispatch(dispatch); 85 }); 86 87 this.settingAlias = this.customDialogDetails.setAlias 88 Log.info(`${this.TAG} aboutToAppear end`) 89 } 90 91 public onChange(): void { 92 Log.info(`${this.TAG} onChange start`) 93 this.mAction.closeDialog(false) 94 if (this.controller) { 95 this.controller.close() 96 } 97 this.cancel() 98 Log.info(`${this.TAG} onChange end`) 99 } 100 101 build() { 102 if (deviceInfo.deviceType == 'PAD' || deviceInfo.deviceType == 'tablet') { 103 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 104 Column() { 105 Row() { 106 Text(this.customDialogDetails.settingTitle) 107 .fontSize($r("sys.float.ohos_id_text_size_dialog_tittle")) 108 .fontColor('#E6000000') 109 .opacity(0.9) 110 .fontWeight(FontWeight.Medium) 111 .opacity($r("sys.float.ohos_id_alpha_content_primary")) 112 } 113 .width('100%') 114 .height(56) 115 116 List() { 117 ForEach(this.customDialogDetails.childrenList, (item: ChildrenItemStruct) => { 118 ListItem() { 119 EntryComponent({ 120 itemValue: item.itemValue, 121 checkedValue: this.getValue, 122 settingAlias: this.settingAlias, 123 onChange: () => this.onChange() 124 }) 125 } 126 .height(48) 127 .width('100%') 128 }) 129 } 130 .listDirection(Axis.Vertical) 131 .divider({ strokeWidth: 0.5, color: '#33000000', startMargin: 0, endMargin: 12 }) // 每行之间的分界线 132 Column() { 133 Button({ type: ButtonType.Capsule, stateEffect: true }) { 134 Text($r('app.string.cancel')) 135 .fontSize($r("sys.float.ohos_id_text_size_sub_title2")) 136 .fontColor('#1095E8') 137 .fontWeight(FontWeight.Medium) 138 .height('100%') 139 .height('100%') 140 } 141 .width('100%') 142 .height('100%') 143 .backgroundColor('#00ffffff') 144 .onClick(() => { 145 this.mAction.closeDialog(false) 146 if (this.controller) { 147 this.controller?.close() 148 } 149 }) 150 } 151 .height(56) 152 .width('100%') 153 .margin({ top: 8 }).padding({ bottom: '16vp' }) 154 } 155 .width(394) 156 .margin({ left: '12vp', right: '12vp', bottom: '16vp' }) 157 .backgroundColor(Color.White) 158 .padding({ left: '24vp', right: '24vp' }) 159 .borderRadius($r("sys.float.ohos_id_corner_radius_default_xl")) 160 } 161 } else { 162 Flex({ justifyContent: FlexAlign.Center }) { 163 Column() { 164 Row() { 165 Text(this.customDialogDetails.settingTitle) 166 .fontSize($r("sys.float.ohos_id_text_size_dialog_tittle")) 167 .fontColor('#E6000000') 168 .opacity(0.9) 169 .fontWeight(FontWeight.Medium) 170 .opacity($r("sys.float.ohos_id_alpha_content_primary")) 171 } 172 .width('100%') 173 .height(56) 174 175 GridContainer({ columns: this.localStyle.columns, gutter: 12, margin: 12 }) { 176 177 List() { 178 ForEach(this.customDialogDetails.childrenList, (item: ChildrenItemStruct) => { 179 ListItem() { 180 EntryComponent({ 181 itemValue: item.itemValue, 182 checkedValue: this.getValue, 183 settingAlias: this.settingAlias, 184 onChange: () => this.onChange() 185 }) 186 } 187 .height(48) 188 .width('100%') 189 }) 190 } 191 .listDirection(Axis.Vertical) 192 .divider({ strokeWidth: 0.5, color: '#33000000', startMargin: 0, endMargin: 12 }) // 每行之间的分界线 193 Column() { 194 Button({ type: ButtonType.Capsule, stateEffect: true }) { 195 Text($r('app.string.cancel')) 196 .fontSize($r("sys.float.ohos_id_text_size_sub_title2")) 197 .fontColor('#1095E8') 198 .fontWeight(FontWeight.Medium) 199 .height('100%') 200 .height('100%') 201 } 202 .width('100%') 203 .height('100%') 204 .backgroundColor('#00ffffff') 205 .onClick(() => { 206 this.mAction.closeDialog(false) 207 if (this.controller) { 208 this.controller?.close() 209 } 210 }) 211 } 212 .height(56) 213 .width('100%') 214 .margin({ top: 8 }).padding({ bottom: '16vp' }) 215 } 216 .width('96%') 217 } 218 .margin({ left: '12vp', right: '12vp', bottom: '16vp' }) 219 .backgroundColor(Color.White) 220 .padding({ left: '24vp', right: '24vp' }) 221 .borderRadius($r("sys.float.ohos_id_corner_radius_default_xl")) 222 .useSizeType({ 223 xs: { span: 4, offset: this.localStyle.offset }, 224 sm: { span: 4, offset: this.localStyle.offset }, 225 md: { span: 4, offset: this.localStyle.offset }, 226 lg: { span: 4, offset: this.localStyle.offset } 227 }) 228 } 229 } 230 } 231}