1/*
2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 */
15import router from '@ohos.router';
16import Logger from '../utils/Logger'
17import MessagePage from '../component/MessageComponent'
18import VideoComponent from '../component/VideoComponent'
19import emitter from '@ohos.events.emitter';
20import Constant from '../utils/Constant';
21
22const TAG: string = '[Index]'
23
24@Entry
25@Component
26struct Index {
27  @State selectDownIndex: number = 0; // 底部选择索引
28
29  /**
30   * 登录验证
31   */
32  loginVerification(): boolean {
33    // 验证是否登录
34    if (AppStorage.get("userInfo") == null || AppStorage.get("userInfo") == undefined) {
35      return false;
36    }
37    return true;
38  }
39
40  pageTransition() {
41    // 禁止首页页面转场效果
42    PageTransitionEnter({ type: RouteType.None, duration: 0 })
43    PageTransitionExit({ type: RouteType.None, duration: 0 })
44  }
45
46  onPageShow() {
47    router.clear();
48  }
49
50  build() {
51    Column() {
52
53      Column() {
54        if (this.selectDownIndex === 0) {
55          VideoComponent()
56        } else if (this.selectDownIndex === 1) {
57
58        } else if (this.selectDownIndex === 2 && this.loginVerification()) {
59          MessagePage()
60        } else if (this.selectDownIndex === 3) {
61
62        }
63      }
64      .width('100%')
65      .height('92%')
66
67      // 底部操作栏
68      Row() {
69        Text($r('app.string.Home_page'))
70          .height('100%')
71          .fontColor(this.selectDownIndex === 0 ? $r('app.color.COLOR_FFFFFF') : $r('app.color.COLOR_CCF1F3F5'))
72          .fontSize(22)
73          .fontFamily($r('app.string.Font_family_medium'))
74          .margin({ left: 10 })
75          .onClick(e => {
76            this.selectDownIndex = 0;
77            Logger.info(TAG, `onClick this is ${this.selectDownIndex}`)
78          })
79        Text($r('app.string.Friend'))
80          .height('100%')
81          .fontColor(this.selectDownIndex === 1 ? $r('app.color.COLOR_FFFFFF') : $r('app.color.COLOR_CCF1F3F5'))
82          .fontSize(22)
83          .fontFamily($r('app.string.Font_family_medium'))
84          .margin({ left: 10 })
85          .onClick(e => {
86            this.selectDownIndex = 1;
87            Logger.info(TAG, `onClick this is ${this.selectDownIndex}`)
88          })
89        Image($r('app.media.app_icon'))
90          .id('index_main')
91          .width(80)
92          .height(40)
93          .objectFit(ImageFit.Contain)
94          .onClick(e => {
95            Logger.info(TAG, `onClick this is ${this.selectDownIndex}`)
96            // 跳转页面前暂停本地视频
97            emitter.emit({ eventId: Constant.EVENT_PAUSED_INDEX });
98            // 验证是否登录
99            if (!this.loginVerification()) {
100              router.pushUrl({ url: 'appsampled/pages/Login' })
101              return;
102            }
103            router.pushUrl({ url: 'appsampled/pages/CameraPage' })
104          })
105        Text($r('app.string.Message'))
106          .id('index_message')
107          .height('100%')
108          .fontColor(this.selectDownIndex === 2 ? $r('app.color.COLOR_FFFFFF') : $r('app.color.COLOR_CCF1F3F5'))
109          .fontSize(22)
110          .fontFamily($r('app.string.Font_family_medium'))
111          .margin({ right: 10 })
112          .onClick(e => {
113            this.selectDownIndex = 2;
114            Logger.info(TAG, `onClick this is ${this.selectDownIndex}`)
115            // 跳转页面前暂停本地视频
116            emitter.emit({ eventId: Constant.EVENT_PAUSED_INDEX });
117            // 验证是否登录
118            if (!this.loginVerification()) {
119              router.pushUrl({ url: 'appsampled/pages/Login' })
120            }
121          })
122        Text($r('app.string.Me'))
123          .height('100%')
124          .fontColor(this.selectDownIndex === 3 ? $r('app.color.COLOR_FFFFFF') : $r('app.color.COLOR_CCF1F3F5'))
125          .fontSize(22)
126          .fontFamily($r('app.string.Font_family_medium'))
127          .margin({ left: 10 })
128          .onClick(e => {
129            this.selectDownIndex = 3;
130            Logger.info(TAG, `onClick this is ${this.selectDownIndex}`)
131          })
132
133      }
134      .width('100%')
135      .height('8%')
136      .justifyContent(FlexAlign.SpaceAround)
137    }
138    .width('100%')
139    .height('100%')
140    .backgroundColor($r('app.color.COLOR_000000'))
141  }
142}
143
144
145