From 1ce875be27d9011c3944c6b975d9f817947ecdf8 Mon Sep 17 00:00:00 2001 From: wwf <1971391498@qq.com> Date: 星期三, 01 十月 2025 16:22:24 +0800 Subject: [PATCH] 登录、注册 --- entry/src/main/ets/pages/login/SignInPage.ets | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 254 insertions(+), 0 deletions(-) diff --git a/entry/src/main/ets/pages/login/SignInPage.ets b/entry/src/main/ets/pages/login/SignInPage.ets new file mode 100644 index 0000000..011d93c --- /dev/null +++ b/entry/src/main/ets/pages/login/SignInPage.ets @@ -0,0 +1,254 @@ +import { promptAction } from '@kit.ArkUI' +import http from '@ohos.net.http'; +import { HttpResponseResult } from '../../data/HttpResponse'; +import { ComponentContent } from '@kit.ArkUI'; +import { PromptActionClass } from '../../utils/PromptActionClass'; + +class DialogParams { + text: string = ""; + + constructor(text: string) { + this.text = text; + } +} +@Builder +function buildText(params: DialogParams) { + Column({ space: 10 }) { + Image($r('app.media.signIn_page_check')) + .width(80) + .height(80) + Text(params.text) + .fontSize(20) + .fontWeight(FontWeight.Bold) + Text() + .fontSize(16) + .fontColor('#666666') + Button('杩斿洖鐧诲綍椤�') + .type(ButtonType.Normal) + .borderRadius(8) + .width('100%') + .onClick(() => { + PromptActionClass.closeDialog(); + PromptActionClass.ctx.getRouter().replaceUrl({ + url: 'pages/login/LoginPage' + }) + }) + } + .width(300) + .padding({ top: 40, bottom: 40, left: 20, right: 20 }) + .borderRadius(14) + .backgroundColor(Color.White) +} + +/** + * @Description : 娉ㄥ唽椤� + */ +@Entry +@Component +struct SignInPage { + @State account: string = '' + @State password: string = '' + @State confirmPassword: string = '' + @State accountErrorFlag: boolean = false + @State passwordErrorFlag: boolean = false + @State confirmPasswordErrorFlag: boolean = false + @State dialogMessage: string = '娉ㄥ唽鎴愬姛'; + private ctx: UIContext = this.getUIContext(); + private contentNode: ComponentContent<Object> = + new ComponentContent(this.ctx, wrapBuilder(buildText), new DialogParams((this.dialogMessage))); + params: DialogParams = new DialogParams('娉ㄥ唽鎴愬姛') + + aboutToAppear(): void { + PromptActionClass.setContext(this.ctx); + PromptActionClass.setContentNode(this.contentNode); + PromptActionClass.setOptions({ alignment: DialogAlignment.Center, offset: { dx: 0, dy: 0 } }); + } + + submitRegister() { + if (!this.account) { + this.accountErrorFlag = true + return + } + if (!this.password || this.password.length !== 8) { + this.passwordErrorFlag = true + return + } + if (this.confirmPassword !== this.password) { + this.confirmPasswordErrorFlag = true + return + } + let httpRequest = http.createHttp(); + + // 鍑嗗瑕佹彁浜ょ殑鏁版嵁浣� + interface PostData { + mobilePhone: string, + password: string + } + let postData: PostData = { + mobilePhone: this.account, + password: this.password + } + + httpRequest.request( + "http://192.168.20.70:8080/quiz-community/public/v1.0/users/register", + { + method: http.RequestMethod.POST, + header: { 'Content-Type': 'application/json' }, + extraData: postData + }, + (err, data) => { + console.log('response', '/users/register') + console.log(JSON.stringify(data.result)) + if (data.responseCode == 200) { + const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<null> + if (resData.code == 200) { + PromptActionClass.openDialog() + } else { + promptAction.showToast({ message: resData.msg }) + } + } else { + promptAction.showToast({ message: err.message }) + } + } + ) + } + + build() { + Column({space: 10}){ + Text('鎮ㄥソ锛�') + .width('100%') + .fontSize(22) + .fontWeight(800) + .fontColor(Color.White) + .onClick(() => { + PromptActionClass.openDialog() + }) + Text('娆㈣繋浣跨敤瀛﹁仒鍚岃') + .width('100%') + .fontSize(22) + .fontWeight(800) + .fontColor(Color.White) + Column({ space: 20 }) { + Text('璐﹀彿娉ㄥ唽') + .width('100%') + .textAlign(TextAlign.Center) + .fontSize(20) + .fontWeight(800) + + Row() { + Image($r('app.media.icon_username')) + .width(16) + .height(16) + TextInput({ placeholder: '璇疯緭鍏ヨ处鍙�', text: $$this.account }) + .type(InputType.USER_NAME) + .backgroundColor('#f3f7fe') + .onChange(() => { + this.accountErrorFlag = false + }) + } + .width('100%') + .backgroundColor('#f3f7fe') + .border(this.accountErrorFlag ? { width: 1, color: Color.Red } : { width: 'none' }) + .borderRadius(10) + .padding({ left: 10, right: 10 }) + + if(this.accountErrorFlag) { + Text('璐﹀彿涓嶈兘绌�') + .width('100%') + .fontSize(12) + .fontColor(Color.Red) + .margin({ top: -16, bottom: -16, left: 20 }) + } + + Row() { + Image($r('app.media.icon_password')) + .width(16) + .height(16) + TextInput({ placeholder: '璇疯緭鍏�8浣嶅瘑鐮�', text: $$this.password }) + .type(InputType.Password) + .backgroundColor('#f3f7fe') + .onChange(() =>{ + this.passwordErrorFlag = false + }) + } + .width('100%') + .backgroundColor('#f3f7fe') + .border(this.passwordErrorFlag ? { width: 1, color: Color.Red } : { width: 'none' }) + .borderRadius(10) + .padding({ left: 10, right: 10 }) + + if(this.passwordErrorFlag) { + Text('璇疯緭鍏�8浣嶆暟鐨勫瘑鐮�') + .width('100%') + .fontSize(12) + .fontColor(Color.Red) + .margin({ top: -16, bottom: -16, left: 20 }) + } + + Row() { + Image($r('app.media.icon_password')) + .width(16) + .height(16) + TextInput({ placeholder: '璇峰啀娆¤緭鍏ュ瘑鐮�', text: $$this.confirmPassword }) + .type(InputType.Password) + .backgroundColor('#f3f7fe') + .onChange(() =>{ + this.confirmPasswordErrorFlag = false + }) + } + .width('100%') + .backgroundColor('#f3f7fe') + .border(this.confirmPasswordErrorFlag ? { width: 1, color: Color.Red } : { width: 'none' }) + .borderRadius(10) + .padding({ left: 10, right: 10 }) + + if(this.confirmPasswordErrorFlag) { + Text('涓ゆ瀵嗙爜杈撳叆涓嶄竴鑷�') + .width('100%') + .fontSize(12) + .fontColor(Color.Red) + .margin({ top: -16, bottom: -16, left: 20 }) + } + + Button('娉� 鍐�') + .type(ButtonType.Normal) + .width('100%') + .borderRadius(10) + .onClick(() => { + this.submitRegister() + }) + + } + .width('100%') + .margin({ top: 20 }) + .padding({ top: 30, bottom: 30, left: 20, right: 20 }) + .borderRadius(6) + .backgroundColor(Color.White) + + Row() { + Text() { + Span('宸叉湁璐﹀彿锛�') + Span('绔嬪嵆鐧诲綍>') + .fontColor('#1756f4') + .decoration({ type: TextDecorationType.Underline, color: '#1756f4' }) + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ + url: 'pages/login/LoginPage' + }) + }) + } + .fontSize(14) + .fontWeight(500) + .margin({ top: 10 }) + } + } + .width('100%') + .height('100%') + .padding({ top: 100, left: 20, right: 20 }) + .backgroundImage($r('app.media.login_page_bg')) + .backgroundImageSize({width: '100%',height:'100%'}) + + } +} + + -- Gitblit v1.8.0