• 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 Constants from '../../common/constant';
17import { AuthAccount, PermissionType } from '../../common/FileUtils/utils';
18
19const TAG = 'Select';
20
21@Extend(MenuItem)
22function timeTextStyle() {
23  .labelFont({ size: $r('sys.float.ohos_id_text_size_body1'), weight: FontWeight.Regular })
24  .margin({
25    left: Constants.ENCRYPTION_PROTECTION_TIME_MENU_MARGIN_LEFT,
26    right: Constants.ENCRYPTION_PROTECTION_TIME_MENU_MARGIN_RIGHT
27  })
28  .padding({
29    left: Constants.ENCRYPTION_PROTECTION_TIME_MENU_PADDING_LEFT,
30    right: Constants.ENCRYPTION_PROTECTION_TIME_MENU_PADDING_RIGHT,
31  })
32  .borderRadius($r('sys.float.ohos_id_corner_radius_default_m'))
33}
34
35@Component
36struct permissionTypeSelect {
37  @State index: number = 0;
38  @Prop isReadType: boolean = false;
39  @State permissionTypes: PermissionType[] = [
40    { value: $r('app.string.PERMISSION_TYPE_SELECT_TARGET'), data: 'target', index: 0 },
41    { value: $r('app.string.PERMISSION_TYPE_SELECT_ALL'), data: 'all', index: 1 },
42    { value: $r('app.string.PERMISSION_TYPE_SELECT_SELF'), data: 'self', index: 2 }
43  ];
44  @Link @Watch('selectedItemUpdated') selectedItem: PermissionType;
45  @Link staffArray: AuthAccount[];
46  @Prop @Watch('onCountUpdated') isDisable: boolean = false;
47
48  onCountUpdated(isDisable: boolean): void {
49    if (this.isReadType) {
50      if (this.isDisable) {
51        this.selectedItem = this.permissionTypes[Constants.ENCRYPTION_TYPE_SELECT];
52        this.index = Constants.ENCRYPTION_TYPE_SELECT;
53      } else {
54        this.selectedItem = this.permissionTypes[Constants.ENCRYPTION_TYPE_SELECT_INDEX];
55        this.index = Constants.ENCRYPTION_TYPE_SELECT_INDEX;
56      }
57    }
58  }
59
60  selectedItemUpdated(selectedItem: object): void {
61    this.index = this.selectedItem.index;
62  }
63
64  aboutToAppear() {
65    if (this.isReadType) {
66      this.permissionTypes = this.permissionTypes.filter(item => {
67        return item.data !== 'self';
68      })
69    }
70    setTimeout(() => {
71      let selectIndex = this.selectedItem.index === -1 ? 0 : this.selectedItem.index;
72      this.selectedItem = this.permissionTypes[selectIndex];
73    }, Constants.ENCRYPTION_SET_TIMEOUT_TIME)
74  }
75
76  @Builder
77  PermissionTypeMenu() {
78    Menu() {
79      ForEach(this.permissionTypes, (item: PermissionType) => {
80        MenuItem({ content: item.value })
81          .selected(this.index === item.index)
82          .selectIcon(true)
83          .onChange(() => {
84            this.index = item.index;
85            this.selectedItem = this.permissionTypes[item.index];
86          });
87      })
88    }
89  }
90
91  build() {
92    Row() {
93      Text() {
94        Span(this.permissionTypes[this.index].value)
95        Span(`${this.selectedItem?.data === 'target' && this.staffArray.length > 0 ?
96          ` (${this.staffArray.length})` : ''}`)
97      }
98      .fontSize($r('sys.float.ohos_id_text_size_body2'))
99      .fontWeight(FontWeight.Medium)
100      .fontColor($r('sys.color.ohos_id_color_text_secondary'));
101
102      SymbolGlyph($r('sys.symbol.arrowtriangle_down_fill'))
103        .fontSize(`${Constants.VALIDITY_IMAGE_WIDTH}vp`)
104        .fontColor([$r('sys.color.ohos_id_color_tertiary')])
105        .margin({
106          left: Constants.VALIDITY_IMAGE_PADDING_LEFT,
107          right: Constants.VALIDITY_IMAGE_PADDING_RIGHT
108        });
109    }
110    .opacity(this.isDisable ? Constants.DU_LINE_WIDTH : Constants.FOOTER_OPACITY_ONE)
111    .enabled(this.isDisable ? false : true)
112    .bindMenu(this.PermissionTypeMenu, { placement: Placement.BottomRight, showInSubWindow: false });
113  }
114}
115
116@Component
117struct validDateTypeMenuItem {
118  @Link selectedIndex: number;
119  @State perMissionTypes: PermissionType[] = [
120    { value: $r('app.string.permanently'), data: 'permanently', index: 0 },
121    { value: $r('app.string.Appointed_day'), data: 'Appointed_day', index: 1 }
122  ];
123
124  build() {
125    Menu() {
126      ForEach(this.perMissionTypes, (item: PermissionType) => {
127        MenuItem({ content: item.value })
128          .selected(this.selectedIndex === item.index)
129          .selectIcon(true)
130          .timeTextStyle()
131          .onChange(() => {
132            this.selectedIndex = item.index;
133          });
134      })
135    }
136  }
137}
138
139@Component
140struct validDateTypeMenu {
141  @Link selectedIndex: number;
142  @Prop isDisable: boolean = false;
143  @State validDateTypes: PermissionType[] = [
144    { value: $r('app.string.permanently'), data: 'permanently', index: 0 },
145    { value: $r('app.string.Appointed_day'), data: 'Appointed_day', index: 1 }
146  ];
147
148  @Builder
149  ValidDateMenuItem() {
150    validDateTypeMenuItem({ selectedIndex: $selectedIndex });
151  }
152
153  build() {
154    Row() {
155      Text(this.validDateTypes[this.selectedIndex].value)
156        .fontSize($r('sys.float.ohos_id_text_size_body2'))
157        .fontWeight(FontWeight.Medium)
158        .fontColor($r('sys.color.ohos_id_color_text_secondary'));
159
160      SymbolGlyph($r('sys.symbol.arrowtriangle_down_fill'))
161        .fontSize(`${Constants.VALIDITY_IMAGE_WIDTH}vp`)
162        .fontColor([$r('sys.color.ohos_id_color_tertiary')])
163        .margin({
164          left: Constants.VALIDITY_IMAGE_PADDING_LEFT,
165          right: Constants.VALIDITY_IMAGE_PADDING_RIGHT
166        });
167    }
168    .opacity(this.isDisable ? Constants.DU_LINE_WIDTH : Constants.FOOTER_OPACITY_ONE)
169    .enabled(this.isDisable ? false : true)
170    .bindMenu(this.ValidDateMenuItem(), { placement: Placement.BottomRight, showInSubWindow: false });
171  }
172}
173
174export { permissionTypeSelect, validDateTypeMenuItem, validDateTypeMenu };