From f7c6e451e73666bedbd5351349af41aac2ef2a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Wed, 23 Oct 2024 16:17:48 +0800 Subject: [PATCH] init --- .gitmodules | 3 + HarmonyOSBaseLibs | 1 + app/oh-package-lock.json5 | 18 +++++ app/oh-package.json5 | 4 +- app/src/main/ets/appability/AppAbility.ets | 2 + app/src/main/ets/pages/Index.ets | 78 +++++++++++++++++++--- app/src/main/ets/pages/RouterBuilder.ets | 13 ++++ app/src/main/ets/pages/login/LoginView.ets | 34 ++++++++++ build-profile.json5 | 4 ++ 9 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 160000 HarmonyOSBaseLibs create mode 100644 app/oh-package-lock.json5 create mode 100644 app/src/main/ets/pages/RouterBuilder.ets create mode 100644 app/src/main/ets/pages/login/LoginView.ets diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ad98cc2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "HarmonyOSBaseLibs"] + path = HarmonyOSBaseLibs + url = https://xuqinmin.com/xuqinmin12/HarmonyOSBaseLibs.git diff --git a/HarmonyOSBaseLibs b/HarmonyOSBaseLibs new file mode 160000 index 0000000..c76be01 --- /dev/null +++ b/HarmonyOSBaseLibs @@ -0,0 +1 @@ +Subproject commit c76be010962baf3e318d1cc3e76eb3128bdcc8de diff --git a/app/oh-package-lock.json5 b/app/oh-package-lock.json5 new file mode 100644 index 0000000..6618223 --- /dev/null +++ b/app/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@szyx/sdk_base@../HarmonyOSBaseLibs": "@szyx/sdk_base@../HarmonyOSBaseLibs" + }, + "packages": { + "@szyx/sdk_base@../HarmonyOSBaseLibs": { + "name": "@szyx/sdk_base", + "version": "1.0.4", + "resolved": "../HarmonyOSBaseLibs", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/app/oh-package.json5 b/app/oh-package.json5 index f660669..a3206ff 100644 --- a/app/oh-package.json5 +++ b/app/oh-package.json5 @@ -5,6 +5,8 @@ "main": "", "author": "", "license": "", - "dependencies": {} + "dependencies": { + "@szyx/sdk_base": "file:../HarmonyOSBaseLibs" + } } diff --git a/app/src/main/ets/appability/AppAbility.ets b/app/src/main/ets/appability/AppAbility.ets index 5e2a2e8..7abb3de 100644 --- a/app/src/main/ets/appability/AppAbility.ets +++ b/app/src/main/ets/appability/AppAbility.ets @@ -1,6 +1,7 @@ import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; +import { GlobalContext } from '@szyx/sdk_base'; export default class AppAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { @@ -22,6 +23,7 @@ export default class AppAbility extends UIAbility { } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); }); + GlobalContext.setContext(this.context) } onWindowStageDestroy(): void { diff --git a/app/src/main/ets/pages/Index.ets b/app/src/main/ets/pages/Index.ets index 9393e00..6beeeb8 100644 --- a/app/src/main/ets/pages/Index.ets +++ b/app/src/main/ets/pages/Index.ets @@ -1,20 +1,76 @@ -@Entry +import { SZYXLocalStorageHelper, SZYXLocalStorageKeys, WindowHelper } from '@szyx/sdk_base'; +import { RouterBuilder, RouterKeys } from './RouterBuilder'; + +@Entry(SZYXLocalStorageHelper.storage) @Component struct Index { + @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack() @State message: string = 'Hello World'; + @State isLoading: boolean = false + @State isOut: boolean = false + @LocalStorageLink(SZYXLocalStorageKeys.HttpHandlerListLength) @Watch('loadingChange') handlerLength: number = 0 + + loadingChange() { + if (this.handlerLength > 0 && !this.isLoading && !this.isOut) { + this.isOut = true + setTimeout(() => { + this.isOut = false + if (this.handlerLength > 0) { + this.isLoading = true + } + }, 300) + } else if (this.handlerLength == 0) { + this.isLoading = false + this.isOut = false + } + } + + aboutToAppear(): void { + WindowHelper.setWindowLayoutFullScreen(true) + WindowHelper.hideStatusBar() + } build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } + Stack() { + Navigation(this.pageInfos) { + Column() { + + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.pageInfos.pushPathByName(RouterKeys.Login, undefined) + }) + + }.width('100%').height('100%') + .linearGradient({ + // 0点方向顺时针旋转为正向角度,线性渐变起始角度的默认值为180° + colors: [ + [0xC1E7FC, 0], // 颜色断点1的颜色和比重,对应组件在180°方向上的起始位置 + [0xffffff, 1.0],// 颜色断点2的颜色和比重,对应组件在180°方向上的终点位置 + ] }) + + }.navDestination(RouterBuilder).hideTitleBar(true) + + Column() { + LoadingProgress() + .color(Color.White) + .width(80).height(80) + Text('努力加载中..') + .fontSize(16) + .fontColor(Color.White) + } + .visibility(this.isLoading ? Visibility.Visible : Visibility.None) + .width('100%') + .height('100%') + .backgroundColor('#40000000') + .justifyContent(FlexAlign.Center) } - .height('100%') - .width('100%') } } \ No newline at end of file diff --git a/app/src/main/ets/pages/RouterBuilder.ets b/app/src/main/ets/pages/RouterBuilder.ets new file mode 100644 index 0000000..7737583 --- /dev/null +++ b/app/src/main/ets/pages/RouterBuilder.ets @@ -0,0 +1,13 @@ +import { LoginView } from './login/LoginView' + + +export class RouterKeys { + public static Login = 'Login' +} + +@Builder +export function RouterBuilder(name: string, param: ESObject) { + if (name === RouterKeys.Login) { + LoginView() + } +} \ No newline at end of file diff --git a/app/src/main/ets/pages/login/LoginView.ets b/app/src/main/ets/pages/login/LoginView.ets new file mode 100644 index 0000000..8b80828 --- /dev/null +++ b/app/src/main/ets/pages/login/LoginView.ets @@ -0,0 +1,34 @@ +import { SafeView, WindowHelper } from '@szyx/sdk_base' + +@Component +@Preview +export struct LoginView { + @Consume('pageInfos') pageInfos: NavPathStack + // 手机号 + @State phone: string | undefined = undefined + // 密码 + @State pwd: string | undefined = undefined + // 是否勾选协议 + @State checkAgreement: boolean = false + // 是不是验证码登录 + @State isCode: boolean = true + + aboutToAppear(): void { + WindowHelper.showStatusBar() + } + + build() { + SafeView({ + pageInfos: this.pageInfos ?? undefined + }) { + Text('登录') + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + } + } +} \ No newline at end of file diff --git a/build-profile.json5 b/build-profile.json5 index 63f3fbe..d5148cf 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -36,6 +36,10 @@ ] } ] + }, + { + "name": "basic", + "srcPath": "./HarmonyOSBaseLibs" } ] } \ No newline at end of file