• 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 router from '@ohos.router'
17import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger'
18
19const TAG: string = 'Index'
20
21@Entry
22@Component
23struct Index {
24  @State mediaUris: Array<string> = []
25  @State stars: Array<boolean> = new Array(5).fill(false)
26  @State countStar: number = 0
27  @State isShowCamera: boolean = false
28  @State isShowComment: boolean = true
29
30  async onPageShow() {
31    Logger.info(TAG, 'enter onPageShow')
32    if (router.getParams()['isShowCamera'] !== undefined && router.getParams()['isShowCamera'] !== null) {
33      this.isShowCamera = router.getParams()['isShowCamera']
34      Logger.info(TAG, `this.isShowCamera = ${this.isShowCamera}`)
35    }
36
37    if (router.getParams()['mediaUris'] !== undefined && router.getParams()['mediaUris'] !== null) {
38      this.mediaUris = router.getParams()['mediaUris']
39      this.mediaUris.push('')
40    }
41    Logger.info(TAG, 'end onPageShow')
42  }
43
44  terminateSelf(context: any) {
45    context.terminateSelf()
46  }
47
48  build() {
49    Column() {
50      Row() {
51        Image($r('app.media.back'))
52          .width(46)
53          .height(26)
54          .objectFit(ImageFit.Contain)
55          .onClick(() => {
56            let context = getContext(this)
57            this.terminateSelf(context)
58          })
59
60        Text($r('app.string.publish_comments'))
61          .fontSize(22)
62          .margin({ left: 130 })
63          .textAlign(TextAlign.Center)
64
65        Blank()
66
67        Button($r('app.string.submit'))
68          .fontSize(20)
69          .height(32)
70          .width(80)
71          .backgroundColor('#E92F4F')
72          .borderRadius(20)
73          .margin({ right: 10 })
74      }
75      .width('100%')
76      .height(32)
77      .padding({ left: 14 })
78      .margin({ top: 20 })
79
80
81      Scroll() {
82        Column() {
83          Stack({ alignContent: Alignment.Top }) {
84            Column() {
85              Stack() {
86                TextArea({ placeholder: $r('app.string.tip') })
87                  .height(150)
88                  .backgroundColor('#fffffff')
89                  .onChange((value) => {
90                    if (value.length === 0) {
91                      this.isShowComment = true
92                    } else {
93                      this.isShowComment = false
94                    }
95                  })
96
97                if (this.isShowComment) {
98                  Image($r('app.media.comment'))
99                    .height(20)
100                    .width(20)
101                    .margin({ top: 8, left: 16 })
102                }
103              }
104              .alignContent(Alignment.TopStart)
105              .margin({ top: 40 })
106
107              if (this.isShowCamera) {
108                Grid() {
109                  ForEach(this.mediaUris, (item, index) => {
110                    GridItem() {
111                      if (index < this.mediaUris.length - 1) {
112                        Image(item)
113                          .width('100%')
114                          .height(100)
115                          .borderRadius(10)
116
117                      } else {
118                        Column() {
119                          Image($r('app.media.photo'))
120                            .height(40)
121                            .width(40)
122                            .onClick(() => {
123                              router.push({
124                                url: 'pages/ChoicePhoto',
125                                params: { 'mediaUris': this.mediaUris }
126                              })
127                            })
128                          Text($r('app.string.add_picture'))
129                            .fontSize(13)
130                        }
131                        .alignItems(HorizontalAlign.Center)
132                        .justifyContent(FlexAlign.Center)
133                        .width('100%')
134                        .height(100)
135                        .borderRadius(10)
136                        .backgroundColor('#F1F3F5')
137                      }
138                    }
139                  })
140                }
141                .columnsTemplate('1fr 1fr 1fr 1fr')
142                .columnsGap(8)
143                .rowsGap(8)
144                .margin({ top: 8 })
145                .width('94%')
146                .height(105 * (this.mediaUris.length > 4 ? 2 : 1))
147              } else {
148                Column() {
149                  Image($r('app.media.camera'))
150                    .width(40)
151                    .height(40)
152
153                  Text($r('app.string.add_picture'))
154                    .fontSize(16)
155                }
156                .onClick(() => {
157                  router.push({
158                    url: 'pages/ChoicePhoto'
159                  })
160                })
161                .width('94%')
162                .height(130)
163                .margin({ top: 10 })
164                .borderRadius(10)
165                .justifyContent(FlexAlign.Center)
166                .backgroundColor('#F1F3F5')
167              }
168              Text($r('app.string.anonymous_display'))
169                .fontSize(15)
170                .fontColor('#99182431')
171                .alignSelf(ItemAlign.Start)
172                .margin({ left: 16, top: 16 })
173            }
174            .width('100%')
175            .height('100%')
176            .margin({ top: 22 })
177            .borderRadius(20)
178            .backgroundColor('#fffffff')
179
180            Image($r('app.media.commodity'))
181              .width(44)
182              .height(44)
183          }
184          .backgroundColor('#f1f3f5')
185          .height('100%')
186          .width('94%')
187          .margin({ top: 10 })
188        }
189        .width('100%')
190        .height(this.isShowCamera === false ? 380 : 300 + (this.mediaUris.length / 4 > 1 ? 160 : 60))
191      }
192      .margin({ top: 20 })
193      .constraintSize({ maxHeight: '94%', minHeight: '94%' })
194      .backgroundColor('#f1f3f5')
195    }
196    .width('100%')
197    .height('100%')
198    .backgroundColor('#f1f3f5')
199  }
200}
201