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