• 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 utils from '../../common/utils'
18import doubleButtonComponent from '../component/autoManager/doubleButtonComponent'
19import logger from '../../common/logger'
20
21const TAG = 'ManagerStart';
22
23@Entry
24@Component
25struct ManagerStart {
26  @State textContext: Resource = $r('app.string.unitManageDevice');
27  @State textManager: Resource = $r('app.string.unitManage');
28  @State textManagerBefore: Resource = $r('app.string.textManagerBefore');
29  @State textManagerAfter: Resource = $r('app.string.textManagerAfter');
30  @State textTerms: Resource = $r('app.string.textTerms');
31  @State textTermsBefore: Resource = $r('app.string.textTermsBefore');
32
33  build() {
34    Column() {
35      GridContainer({
36        columns: utils.isLargeDevice(),
37        sizeType: SizeType.Auto,
38        gutter: '12vp',
39        margin: '12vp'
40      }) {
41        Column() {
42          Image($r('app.media.ic_start'))
43            .width($r('app.float.wh_value_40'))
44            .height($r('app.float.wh_value_40'))
45            .margin({ top: '72vp', bottom: '16vp' })
46            .objectFit(ImageFit.Contain)
47
48          Text(this.textContext)
49            .height('40vp')
50            .textAlign(TextAlign.Center)
51            .fontWeight(FontWeight.Medium)
52            .lineHeight($r('app.float.lineHeight_vp_41'))
53            .fontSize($r('app.float.font_vp_30'))
54            .fontFamily('HarmonyHeiTi')
55        }
56        .useSizeType({
57          xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 },
58          md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 }
59        })
60        .width('100%')
61        .align(Alignment.Center)
62
63        Column() {
64          Row() {
65            Text() {
66              Span(this.textTermsBefore)
67                .fontWeight(FontWeight.Regular)
68                .fontSize($r('app.float.font_vp_16'))
69                .fontFamily('HarmonyHeiTi')
70
71              Span(this.textTerms)
72                .decoration({ type: TextDecorationType.None })
73                .fontColor(0x007DFF)
74                .fontSize($r('app.float.font_vp_16'))
75                .fontFamily('HarmonyHeiTi')
76                .fontWeight(FontWeight.Regular)
77                .onClick(() => {
78                  router.pushUrl({ url: 'pages/autoManager/termsShowPage' })
79                })
80
81              Span(this.textManagerBefore)
82                .fontWeight(FontWeight.Regular)
83                .fontSize($r('app.float.font_vp_16'))
84                .fontFamily('HarmonyHeiTi')
85
86              Span(this.textManager)
87                .decoration({ type: TextDecorationType.None })
88                .fontColor(0x007DFF)
89                .fontSize($r('app.float.font_vp_16'))
90                .fontFamily('HarmonyHeiTi')
91                .fontWeight(FontWeight.Regular)
92                .onClick(() => {
93                  router.pushUrl({ url: 'pages/autoManager/unitManagerShowPage' })
94                })
95
96              Span(this.textManagerAfter)
97                .fontWeight(FontWeight.Regular)
98                .fontSize($r('app.float.font_vp_16'))
99                .fontFamily('HarmonyHeiTi')
100            }
101            .lineHeight($r('app.float.lineHeight_vp_21_5'))
102          }
103          .useSizeType({
104            xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 },
105            md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 }
106          })
107          .width('100%')
108          .margin({ top: '48vp' })
109          .justifyContent(FlexAlign.Center)
110        }
111        .width('100%')
112      }
113
114      Blank()
115
116      GridContainer({
117        columns: utils.isLargeDevice(),
118        sizeType: SizeType.Auto,
119        gutter: '12vp',
120        margin: '12vp'
121      }) {
122        Column() {
123          Button() {
124            Text($r('app.string.buttonAcceptAndContinue'))
125              .fontSize($r('app.float.font_vp_16'))
126              .fontFamily('HarmonyHeiTi')
127              .fontWeight(FontWeight.Medium)
128              .fontColor(0xFFFFFF)
129              .lineHeight($r('app.float.lineHeight_vp_22'))
130          }
131          .backgroundColor(0x007DFF)
132          .onClick(() => {
133            router.pushUrl({ url: 'pages/autoManager/loadingInfo' })
134          })
135          .width('100%')
136          .height('40vp')
137          .useSizeType({
138            xs: { span: 2, offset: 3 }, sm: { span: 2, offset: 3 },
139            md: { span: 2, offset: 3 }, lg: { span: 2, offset: 3 }
140          })
141        }
142        .width('100%')
143        .useSizeType({
144          xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 },
145          md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 }
146        })
147        .margin({ bottom: '100vp' })
148      }
149
150      GridContainer({
151        columns: utils.isLargeDevice(),
152        sizeType: SizeType.Auto,
153        gutter: '12vp',
154        margin: '12vp'
155      }) {
156        Column() {
157          doubleButtonComponent({ nextFlag: true, returnDialogFlag: false })
158        }
159        .useSizeType({
160          xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 },
161          md: { span: 8, offset: 0 }, lg: { span: 12, offset: 0 }
162        })
163        .width('100%')
164        .margin({ bottom: '16vp' })
165      }
166    }
167    .backgroundColor(0xF1F3F5)
168    .width('100%')
169    .height('100%')
170  }
171
172  aboutToAppear() {
173    this.parseManageParameter();
174  }
175
176  parseManageParameter() {
177    let data = globalThis.autoManagerAbilityWant;
178
179    if (!utils.checkObjPropertyValid(data, 'parameters.elementName.abilityName')
180      || !utils.checkObjPropertyValid(data, 'parameters.enterprise.name')
181      || !utils.isValid(data.parameters.elementName.bundleName)
182      || !utils.isValid(data.parameters.url)
183      || !utils.isValid(data.parameters.termsName)
184      || (!utils.isValid(data.parameters.termsContent) || !Array.isArray(data.parameters.termsContent))
185      || !utils.isValid(data.parameters.enterprise.description)) {
186      logger.error(TAG, 'parseManageParameter fail! parameters is not valid')
187      return;
188    }
189
190    let mapVal = new Map([
191      ['manageAbilityName', data.parameters.elementName.abilityName],
192      ['manageBundleName', data.parameters.elementName.bundleName],
193      ['manageUrl', data.parameters.url],
194      ['manageTermsName', data.parameters.termsName],
195      ['manageTermsContent', data.parameters.termsContent],
196      ['manageEnterpriseName', data.parameters.enterprise.name],
197      ['manageEnterpriseDescription', data.parameters.enterprise.description]
198    ]);
199
200    for (let [key, value] of mapVal) {
201      AppStorage.SetOrCreate(key, value);
202    }
203  }
204}