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