提交网络请求
This commit is contained in:
@@ -9,7 +9,7 @@ import { OfficeSelectedSheet } from './OfficeSelectedSheet'
|
||||
import { PositionSelectedSheet } from './PositionSelectedSheet'
|
||||
import { SpecialitySelectedSheet } from './SpecialitySelectedSheet'
|
||||
import { http } from '@kit.NetworkKit';
|
||||
|
||||
import { rcp } from '@kit.RemoteCommunicationKit';
|
||||
interface extraData {
|
||||
uuid: string
|
||||
}
|
||||
@@ -146,26 +146,46 @@ export struct EditUserDataComp {
|
||||
onPhotoSelected: async (uri: string) => {
|
||||
this.photoPath = uri;
|
||||
console.info('Selected image URI:', uri);
|
||||
const base64String = await ChangeUtil.imageToBase64(uri);
|
||||
const base64String = await ChangeUtil.convertUriToBase64(uri);
|
||||
const updateDataUrl:string = BasicConstant.urlExpert + 'modify';
|
||||
hdHttp.post<string>(updateDataUrl, {
|
||||
uuid: authStore.getUser().uuid,
|
||||
userName: authStore.getUser().userName,
|
||||
photo: base64String,
|
||||
type:'2'
|
||||
} as updateExtraData).then(async (res: HdResponse<string>) => {
|
||||
let json:callBackData = JSON.parse(res+'') as callBackData;
|
||||
if(json.code == 1 && json.data && typeof json.data === 'object') {
|
||||
authStore.updateUser(json.data)
|
||||
console.log('更新图片成功:', authStore.getUser().email);
|
||||
promptAction.showToast({message:'头像修改成功', duration: 1000})
|
||||
} else {
|
||||
console.error('更新图片失败:'+json.message)
|
||||
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
console.error(`更新图片请求失败: ${err}`);
|
||||
// 定义content,请根据实际情况选择
|
||||
const postContent = new rcp.MultipartForm({
|
||||
'uuid': authStore.getUser().uuid,
|
||||
'userName': authStore.getUser().userName,
|
||||
'photo': base64String,
|
||||
'type':'2'
|
||||
})
|
||||
// 创建session
|
||||
const session = rcp.createSession();
|
||||
// 使用post发起请求,使用Promise进行异步回调;其中content以及destination为可选参数,可根据实际情况选择
|
||||
session.post(updateDataUrl, postContent)
|
||||
.then((response) => {
|
||||
// console.info(`Response succeeded: ${JSON.stringify(response.headers)}`);
|
||||
console.info(`Response succeeded: ${JSON.stringify(response.statusCode)}`);
|
||||
console.info(`Response succeeded22: ${JSON.stringify(response)}`);
|
||||
// console.info(`Response succeeded: ${JSON.stringify(postContent)}`);
|
||||
})
|
||||
.catch((err: BusinessError) => {
|
||||
console.error(`Response err: Code is ${JSON.stringify(err.code)}, message is ${JSON.stringify(err)}`);
|
||||
})
|
||||
// hdHttp.post<string>(updateDataUrl, {
|
||||
// uuid: authStore.getUser().uuid,
|
||||
// userName: authStore.getUser().userName,
|
||||
// photo: base64String,
|
||||
// type:'2'
|
||||
// } as updateExtraData).then(async (res: HdResponse<string>) => {
|
||||
// let json:callBackData = JSON.parse(res+'') as callBackData;
|
||||
// if(json.code == 1 && json.data && typeof json.data === 'object') {
|
||||
// authStore.updateUser(json.data)
|
||||
// console.log('更新图片成功:', authStore.getUser().email);
|
||||
// promptAction.showToast({message:'头像修改成功', duration: 1000})
|
||||
// } else {
|
||||
// console.error('更新图片失败:'+json.message)
|
||||
// promptAction.showToast({ message: json.message, duration: 1000 })
|
||||
// }
|
||||
// }).catch((err: BusinessError) => {
|
||||
// console.error(`更新图片请求失败: ${err}`);
|
||||
// })
|
||||
}
|
||||
}),
|
||||
alignment: DialogAlignment.Bottom,
|
||||
|
||||
Reference in New Issue
Block a user