From 23fa268f56dcd99c8dcd46f50f3ffcaa4cdcbc49 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期五, 10 十月 2025 17:25:53 +0800
Subject: [PATCH] 功能完善

---
 entry/src/main/ets/pages/account/UserInfoPage.ets |   97 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/entry/src/main/ets/pages/account/UserInfoPage.ets b/entry/src/main/ets/pages/account/UserInfoPage.ets
index fe4f735..275f0bb 100644
--- a/entry/src/main/ets/pages/account/UserInfoPage.ets
+++ b/entry/src/main/ets/pages/account/UserInfoPage.ets
@@ -1,12 +1,87 @@
+import { promptAction, router } from "@kit.ArkUI"
+import { http } from "@kit.NetworkKit"
+import { HttpResponseResult } from "../../data/HttpResponse"
+import { ROMAIN } from "../../utils/config"
+import { UserInfo } from "./AccountPage"
+
 @Entry
 @Component
-export struct UserInfo {
+struct UserInfoPage {
   @State nickName: string = ''
   @State gender: string = ''
   @State age: string = ''
   @State preferJob: string = ''
   @State job: string = ''
   @State introduce: string = ''
+  @State userInfo: UserInfo = {
+    nickName: '',
+    mobilePhone: '',
+    age: '',
+    gender: '',
+    job: '',
+    preferJob: '',
+    introduce: '',
+  }
+
+  aboutToAppear(): void {
+    this.getUserInfo()
+  }
+
+  getUserInfo() {
+    let httpRequest = http.createHttp();
+    httpRequest.request(
+      `${ROMAIN}/quiz-community/public/v1.0/users/userinfo`,
+      {
+        method: http.RequestMethod.GET,
+        header: { 'Content-Type': 'application/json', 'x-jwt-token': `Bearer ${AppStorage.get('x-jwt-token')}` },
+      },
+      (err, data) => {
+        console.log('response', '/users/userinfo')
+        console.log(JSON.stringify(data.result))
+        if (data.responseCode == 200) {
+          const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<UserInfo>
+          if (resData.code == 200) {
+            this.userInfo = resData.data as UserInfo
+          } else {
+            promptAction.showToast({ message: resData.msg })
+          }
+        }
+      }
+    )
+  }
+
+  saveInfo() {
+    let httpRequest = http.createHttp();
+    let postData: UserInfo = {
+      nickName: this.userInfo.nickName,
+      mobilePhone: '',
+      age: this.userInfo.age,
+      gender: this.userInfo.gender,
+      job: this.userInfo.job,
+      preferJob: this.userInfo.preferJob,
+      introduce: this.userInfo.introduce
+    }
+    httpRequest.request(
+      `${ROMAIN}/quiz-community/public/v1.0/users/userinfo`,
+      {
+        method: http.RequestMethod.PUT,
+        header: { 'Content-Type': 'application/json' },
+        extraData: postData
+      },
+      (err, data) => {
+        console.log('response', '/users/userinfo')
+        console.log(JSON.stringify(data.result))
+        if (data.responseCode == 200) {
+          const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<string>
+          if (resData.code == 200) {
+            promptAction.showToast({ message: '淇濆瓨鎴愬姛' })
+          } else {
+            promptAction.showToast({ message: resData.msg })
+          }
+        }
+      }
+    )
+  }
 
   build() {
     Column() {
@@ -14,6 +89,9 @@
         Image($r('app.media.left_icon'))
           .width(20)
           .height(20)
+          .onClick(() => {
+            router.back()
+          })
         Text('涓汉淇℃伅')
           .fontSize(18)
           .fontWeight(700)
@@ -31,7 +109,7 @@
             .fontSize(14)
             .fontColor('#666666')
             .width('100%')
-          TextInput({ placeholder: '璇疯緭鍏�', text: this.nickName })
+          TextInput({ placeholder: '璇疯緭鍏�', text: $$this.userInfo.nickName })
             .placeholderFont({ size: 14 })
             .showUnderline(true)
             .margin({ top: -6 })
@@ -42,7 +120,7 @@
             .fontSize(14)
             .fontColor('#666666')
             .width('100%')
-          TextInput({ placeholder: '璇疯緭鍏�', text: this.gender })
+          TextInput({ placeholder: '璇疯緭鍏�', text: $$this.userInfo.gender })
             .placeholderFont({ size: 14 })
             .showUnderline(true)
             .margin({ top: -6 })
@@ -53,7 +131,7 @@
             .fontSize(14)
             .fontColor('#666666')
             .width('100%')
-          TextInput({ placeholder: '璇疯緭鍏�', text: this.age })
+          TextInput({ placeholder: '璇疯緭鍏�', text: $$this.userInfo.age })
             .placeholderFont({ size: 14 })
             .showUnderline(true)
             .margin({ top: -6 })
@@ -64,7 +142,7 @@
             .fontSize(14)
             .fontColor('#666666')
             .width('100%')
-          TextInput({ placeholder: '璇疯緭鍏�', text: this.job })
+          TextInput({ placeholder: '璇疯緭鍏�', text: $$this.userInfo.job })
             .placeholderFont({ size: 14 })
             .showUnderline(true)
             .margin({ top: -6 })
@@ -75,7 +153,7 @@
             .fontSize(14)
             .fontColor('#666666')
             .width('100%')
-          TextInput({ placeholder: '璇疯緭鍏�', text: this.preferJob })
+          TextInput({ placeholder: '璇疯緭鍏�', text: $$this.userInfo.preferJob })
             .placeholderFont({ size: 14 })
             .showUnderline(true)
             .margin({ top: -6 })
@@ -86,13 +164,13 @@
             .fontColor('#666666')
             .fontSize(14)
             .width('100%')
-          TextArea({ placeholder: '浠嬬粛涓�涓嬩綘鑷繁鍚', text: this.job })
+          TextArea({ placeholder: '浠嬬粛涓�涓嬩綘鑷繁鍚', text: this.userInfo.introduce })
             .placeholderFont({ size: 14 })
             .backgroundColor('#fff')
             .border({ width: 1, color: '#666666' })
             .borderRadius(5)
-            .minLines(10)
             .maxLength(200)
+            .constraintSize({ minHeight: 200 })
             .showCounter(true)
             .margin({ top: 10 })
         }
@@ -105,6 +183,9 @@
           .width('100%')
           .fontColor(Color.White)
           .backgroundColor('#1761f4')
+          .onClick(() => {
+            this.saveInfo()
+          })
 
       }
       .height('100%')

--
Gitblit v1.8.0