| | |
| | | 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() { |
| | |
| | | Image($r('app.media.left_icon')) |
| | | .width(20) |
| | | .height(20) |
| | | .onClick(() => { |
| | | router.back() |
| | | }) |
| | | Text('个人信息') |
| | | .fontSize(18) |
| | | .fontWeight(700) |
| | |
| | | .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 }) |
| | |
| | | .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 }) |
| | |
| | | .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 }) |
| | |
| | | .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 }) |
| | |
| | | .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 }) |
| | |
| | | .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 }) |
| | | } |
| | |
| | | .width('100%') |
| | | .fontColor(Color.White) |
| | | .backgroundColor('#1761f4') |
| | | .onClick(() => { |
| | | this.saveInfo() |
| | | }) |
| | | |
| | | } |
| | | .height('100%') |