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 { getStore } from '../../../redux/store' 21import EntryComponent from './EntryComponent' 22 23@Observed 24export class CustomDialogDetails { 25 confirmCallback: Function 26 confirmItem: boolean 27 height: number 28 width: number 29 setAlias: string 30 childrenList: any[] 31 settingTitle: string 32} 33 34let localState = (state) => { 35 return {} 36} 37 38let localDispatcher = (dispatch) => { 39 return { 40 closeDialog: (isCloseFlag: boolean) => { 41 dispatch(Action.closeDialog(isCloseFlag)) 42 } 43 } 44} 45 46class StateStruct { 47 closeDialog : Function 48} 49 50@CustomDialog 51export struct CustomDialogView { 52 private TAG: string = '[CustomDialogView]:' 53 // @StorageLink('settingsDetailList') settingsDetailList: any[]= []; 54 localStyle = { "columns": 4, "offset": 0 } 55 controller: CustomDialogController 56 cancel: () => void 57 confirm: () => void 58 @Consume customDialogDetails: CustomDialogDetails 59 @State settingAlias: string= "" 60 @State getValue: string= "" 61 @StorageLink('settingsList') settingsList: any[]= [] 62 @State childrenList: Array<any> = [] 63 64 @State state: StateStruct = new StateStruct() 65 66 async aboutToAppear() { 67 Log.info(`${this.TAG} aboutToAppear start`) 68 this.childrenList = this.customDialogDetails.childrenList 69 Log.info(`${this.TAG} childrenList ${JSON.stringify(this.childrenList)}`) 70 getStore().connect(localState, localDispatcher)(this.state) 71 this.settingAlias = this.customDialogDetails.setAlias 72 Log.info(`${this.TAG} aboutToAppear end`) 73 } 74 75 public onChange(): void { 76 Log.info(`${this.TAG} onChange start`) 77 this.state.closeDialog(false) 78 this.controller.close() 79 this.cancel() 80 Log.info(`${this.TAG} onChange end`) 81 } 82 83 build() { 84 if (deviceInfo.deviceType == 'PAD' || deviceInfo.deviceType == 'tablet') { 85 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 86 Column() { 87 Row() { 88 Text(this.customDialogDetails.settingTitle) 89 .fontSize($r("sys.float.ohos_id_text_size_dialog_tittle")) 90 .fontColor('#E6000000') 91 .opacity(0.9) 92 .fontWeight(FontWeight.Medium) 93 .opacity($r("sys.float.ohos_id_alpha_content_primary")) 94 } 95 .width('100%') 96 .height(56) 97 98 List() { 99 ForEach(this.customDialogDetails.childrenList, (item) => { 100 ListItem() { 101 EntryComponent({ 102 itemValue: item.itemValue, 103 checkedValue: this.getValue, 104 settingAlias: this.settingAlias, 105 onChange: () => this.onChange() 106 }) 107 } 108 .height(48) 109 .width('100%') 110 }) 111 } 112 .listDirection(Axis.Vertical) 113 .divider({ strokeWidth: 0.5, color: '#33000000', startMargin: 0, endMargin: 12 }) // 每行之间的分界线 114 Column() { 115 Button({ type: ButtonType.Capsule, stateEffect: true }) { 116 Text($r('app.string.cancel')) 117 .fontSize($r("sys.float.ohos_id_text_size_sub_title2")) 118 .fontColor('#1095E8') 119 .fontWeight(FontWeight.Medium) 120 .height('100%') 121 .height('100%') 122 } 123 .width('100%') 124 .height('100%') 125 .backgroundColor('#00ffffff') 126 .onClick(() => { 127 this.state.closeDialog(false) 128 this.controller.close() 129 }) 130 } 131 .height(56) 132 .width('100%') 133 .margin({ top: 8 }).padding({ bottom: '16vp' }) 134 } 135 .width(394) 136 .margin({ left: '12vp', right: '12vp', bottom: '16vp' }) 137 .backgroundColor(Color.White) 138 .padding({ left: '24vp', right: '24vp' }) 139 .borderRadius($r("sys.float.ohos_id_corner_radius_default_xl")) 140 } 141 } else { 142 Flex({ justifyContent: FlexAlign.Center }) { 143 Column() { 144 Row() { 145 Text(this.customDialogDetails.settingTitle) 146 .fontSize($r("sys.float.ohos_id_text_size_dialog_tittle")) 147 .fontColor('#E6000000') 148 .opacity(0.9) 149 .fontWeight(FontWeight.Medium) 150 .opacity($r("sys.float.ohos_id_alpha_content_primary")) 151 } 152 .width('100%') 153 .height(56) 154 155 GridContainer({ columns: this.localStyle.columns, gutter: 12, margin: 12 }) { 156 157 List() { 158 ForEach(this.customDialogDetails.childrenList, (item) => { 159 ListItem() { 160 EntryComponent({ 161 itemValue: item.itemValue, 162 checkedValue: this.getValue, 163 settingAlias: this.settingAlias, 164 onChange: () => this.onChange() 165 }) 166 } 167 .height(48) 168 .width('100%') 169 }) 170 } 171 .listDirection(Axis.Vertical) 172 .divider({ strokeWidth: 0.5, color: '#33000000', startMargin: 0, endMargin: 12 }) // 每行之间的分界线 173 Column() { 174 Button({ type: ButtonType.Capsule, stateEffect: true }) { 175 Text($r('app.string.cancel')) 176 .fontSize($r("sys.float.ohos_id_text_size_sub_title2")) 177 .fontColor('#1095E8') 178 .fontWeight(FontWeight.Medium) 179 .height('100%') 180 .height('100%') 181 } 182 .width('100%') 183 .height('100%') 184 .backgroundColor('#00ffffff') 185 .onClick(() => { 186 this.state.closeDialog(false) 187 this.controller.close() 188 }) 189 } 190 .height(56) 191 .width('100%') 192 .margin({ top: 8 }).padding({ bottom: '16vp' }) 193 } 194 .width('96%') 195 } 196 .margin({ left: '12vp', right: '12vp', bottom: '16vp' }) 197 .backgroundColor(Color.White) 198 .padding({ left: '24vp', right: '24vp' }) 199 .borderRadius($r("sys.float.ohos_id_corner_radius_default_xl")) 200 .useSizeType({ 201 xs: { span: 4, offset: this.localStyle.offset }, 202 sm: { span: 4, offset: this.localStyle.offset }, 203 md: { span: 4, offset: this.localStyle.offset }, 204 lg: { span: 4, offset: this.localStyle.offset } 205 }) 206 } 207 } 208 } 209}