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
|
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() {
|
Row() {
|
Image($r('app.media.left_icon'))
|
.width(20)
|
.height(20)
|
.onClick(() => {
|
router.back()
|
})
|
Text('个人信息')
|
.fontSize(18)
|
.fontWeight(700)
|
Row()
|
}
|
.width('100%')
|
.padding(10)
|
.justifyContent(FlexAlign.SpaceBetween)
|
|
Divider()
|
|
Column({ space: 14 }) {
|
Column() {
|
Text(`昵称`)
|
.fontSize(14)
|
.fontColor('#666666')
|
.width('100%')
|
TextInput({ placeholder: '请输入', text: $$this.userInfo.nickName })
|
.placeholderFont({ size: 14 })
|
.showUnderline(true)
|
.margin({ top: -6 })
|
}
|
|
Column() {
|
Text(`性别`)
|
.fontSize(14)
|
.fontColor('#666666')
|
.width('100%')
|
TextInput({ placeholder: '请输入', text: $$this.userInfo.gender })
|
.placeholderFont({ size: 14 })
|
.showUnderline(true)
|
.margin({ top: -6 })
|
}
|
|
Column() {
|
Text(`年龄`)
|
.fontSize(14)
|
.fontColor('#666666')
|
.width('100%')
|
TextInput({ placeholder: '请输入', text: $$this.userInfo.age })
|
.placeholderFont({ size: 14 })
|
.showUnderline(true)
|
.margin({ top: -6 })
|
}
|
|
Column() {
|
Text(`职业`)
|
.fontSize(14)
|
.fontColor('#666666')
|
.width('100%')
|
TextInput({ placeholder: '请输入', text: $$this.userInfo.job })
|
.placeholderFont({ size: 14 })
|
.showUnderline(true)
|
.margin({ top: -6 })
|
}
|
|
Column() {
|
Text(`心仪职业`)
|
.fontSize(14)
|
.fontColor('#666666')
|
.width('100%')
|
TextInput({ placeholder: '请输入', text: $$this.userInfo.preferJob })
|
.placeholderFont({ size: 14 })
|
.showUnderline(true)
|
.margin({ top: -6 })
|
}
|
|
Column() {
|
Text(`个人简介`)
|
.fontColor('#666666')
|
.fontSize(14)
|
.width('100%')
|
TextArea({ placeholder: '介绍一下你自己吧~', text: this.userInfo.introduce })
|
.placeholderFont({ size: 14 })
|
.backgroundColor('#fff')
|
.border({ width: 1, color: '#666666' })
|
.borderRadius(5)
|
.maxLength(200)
|
.constraintSize({ minHeight: 200 })
|
.showCounter(true)
|
.margin({ top: 10 })
|
}
|
|
Button('保存')
|
.fontSize(14)
|
.height(36)
|
.type(ButtonType.Normal)
|
.borderRadius(6)
|
.width('100%')
|
.fontColor(Color.White)
|
.backgroundColor('#1761f4')
|
.onClick(() => {
|
this.saveInfo()
|
})
|
|
}
|
.height('100%')
|
.width('100%')
|
.padding(16)
|
}
|
}
|
}
|