图片上传
This commit is contained in:
parent
3d1c988435
commit
ab1f72ba6c
File diff suppressed because one or more lines are too long
@ -8,6 +8,7 @@ import { CryptoJS } from '@ohos/crypto-js'
|
|||||||
import { Base64Util } from './Base64Util';
|
import { Base64Util } from './Base64Util';
|
||||||
import { ChangeUtil } from './ChangeUtil'
|
import { ChangeUtil } from './ChangeUtil'
|
||||||
import { BasicConstant } from '../constants/BasicConstant'
|
import { BasicConstant } from '../constants/BasicConstant'
|
||||||
|
import image from '@ohos.multimedia.image';
|
||||||
|
|
||||||
interface HdRequestOptions {
|
interface HdRequestOptions {
|
||||||
baseURL?: string
|
baseURL?: string
|
||||||
@ -175,7 +176,6 @@ class HdHttp {
|
|||||||
return this.request<T>(url, http.RequestMethod.POST, data)
|
return this.request<T>(url, http.RequestMethod.POST, data)
|
||||||
}
|
}
|
||||||
httpReq<T>(url: string, datas: HashMap<string, string>): Promise<HdResponse<T>> {
|
httpReq<T>(url: string, datas: HashMap<string, string>): Promise<HdResponse<T>> {
|
||||||
|
|
||||||
// 创建httpRequest对象。
|
// 创建httpRequest对象。
|
||||||
let httpRequest = http.createHttp();
|
let httpRequest = http.createHttp();
|
||||||
let url1 = "https://dev-app.igandan.com/app/manager/getSystemTimeStamp";
|
let url1 = "https://dev-app.igandan.com/app/manager/getSystemTimeStamp";
|
||||||
@ -204,29 +204,22 @@ class HdHttp {
|
|||||||
datas.set("client_type", 'A');
|
datas.set("client_type", 'A');
|
||||||
datas.set("version",'4.0.0' );
|
datas.set("version",'4.0.0' );
|
||||||
datas.set('timestamp',tp+'');
|
datas.set('timestamp',tp+'');
|
||||||
|
|
||||||
return this.posts<T>(url, datas);
|
return this.posts<T>(url, datas);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return this.posts<T>(url, datas);
|
return this.posts<T>(url, datas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
).catch((err:BusinessError) => {
|
).catch((err:BusinessError) => {
|
||||||
logger.info('Response httpReq error:' + JSON.stringify(err));
|
logger.info('Response httpReq error:' + JSON.stringify(err));
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
|
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
httpRequest.destroy()
|
httpRequest.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
httpReqSimply<T>(url: string) {
|
|
||||||
|
|
||||||
|
httpReqSimply<T>(url: string) {
|
||||||
// 创建httpRequest对象。
|
// 创建httpRequest对象。
|
||||||
let httpRequest = http.createHttp();
|
let httpRequest = http.createHttp();
|
||||||
|
|
||||||
let promise = httpRequest.request(
|
let promise = httpRequest.request(
|
||||||
// 请求url地址
|
// 请求url地址
|
||||||
url,
|
url,
|
||||||
@ -248,16 +241,14 @@ class HdHttp {
|
|||||||
const result = data.result as HdResponse<T>
|
const result = data.result as HdResponse<T>
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
).catch((err:BusinessError) => {
|
).catch((err:BusinessError) => {
|
||||||
logger.info('Response httpReq error:' + JSON.stringify(err));
|
logger.info('Response httpReq error:' + JSON.stringify(err));
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
|
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
httpRequest.destroy()
|
httpRequest.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSign(extraDatas1:HashMap<string, string>): string {
|
getSign(extraDatas1:HashMap<string, string>): string {
|
||||||
let secret= extraDatas1.get("timestamp")
|
let secret= extraDatas1.get("timestamp")
|
||||||
if(secret!=null) {
|
if(secret!=null) {
|
||||||
@ -275,14 +266,125 @@ class HdHttp {
|
|||||||
let Md5keyValueStr: string = CryptoJS.MD5(keyValueStr).toString();
|
let Md5keyValueStr: string = CryptoJS.MD5(keyValueStr).toString();
|
||||||
let base64Str:string=Base64Util.encodeToStrSync(Md5keyValueStr);
|
let base64Str:string=Base64Util.encodeToStrSync(Md5keyValueStr);
|
||||||
return base64Str;
|
return base64Str;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传图片方法
|
||||||
|
* @param url 上传地址
|
||||||
|
* @param imageUri 图片URI
|
||||||
|
* @param params 其他参数
|
||||||
|
* @returns Promise<HdResponse<T>>
|
||||||
|
*/
|
||||||
|
async uploadImage<T>(url: string, imageUrl: string): Promise<HdResponse<T>> {
|
||||||
|
try {
|
||||||
|
// 1. 读取图片文件并转换为base64
|
||||||
|
const imageBase64 = await this.imageToBase64(imageUrl);
|
||||||
|
|
||||||
|
// 2. 准备上传参数
|
||||||
|
const uploadParams: UploadImageParams = {
|
||||||
|
uuid: authStore.getUser().uuid || '',
|
||||||
|
userName: authStore.getUser().userName || '',
|
||||||
|
photo: imageBase64,
|
||||||
|
type: '2' // 根据业务需求设置类型
|
||||||
|
};
|
||||||
|
|
||||||
|
// 3. 转换为HashMap格式 - 使用类型安全的方式
|
||||||
|
const hashMap = new HashMap<string, string>();
|
||||||
|
hashMap.set('uuid', uploadParams.uuid);
|
||||||
|
hashMap.set('userName', uploadParams.userName);
|
||||||
|
hashMap.set('photo', uploadParams.photo);
|
||||||
|
hashMap.set('type', uploadParams.type);
|
||||||
|
|
||||||
|
// 4. 调用posts方法上传
|
||||||
|
return this.posts<T>(url, hashMap);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('uploadImage error:' + JSON.stringify(error));
|
||||||
|
promptAction.showToast({ message: '图片上传失败' });
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将图片转换为base64字符串
|
||||||
|
* @param imageUri 图片URI
|
||||||
|
* @returns Promise<string> base64字符串
|
||||||
|
*/
|
||||||
|
private async imageToBase64(imageUrl: string): Promise<string> {
|
||||||
|
// 1. 验证URI有效性
|
||||||
|
if (!imageUrl || !imageUrl.startsWith('file://')) {
|
||||||
|
throw new Error('无效的图片URI,必须以file://开头');
|
||||||
|
}
|
||||||
|
let imageSource: image.ImageSource | undefined;
|
||||||
|
let pixelMap: image.PixelMap | undefined;
|
||||||
|
let imagePacker: image.ImagePacker | undefined;
|
||||||
|
try {
|
||||||
|
// 2. 创建ImageSource(添加错误处理)
|
||||||
|
imageSource = image.createImageSource(imageUrl);
|
||||||
|
if (!imageSource) {
|
||||||
|
throw new Error('创建ImageSource失败,请检查图片路径');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 获取图片信息(添加详细日志)
|
||||||
|
logger.info('正在获取图片信息...');
|
||||||
|
const imageInfo = await imageSource.getImageInfo();
|
||||||
|
logger.info(`图片尺寸: ${imageInfo.size.width}x${imageInfo.size.height}`);
|
||||||
|
|
||||||
|
// 4. 创建PixelMap
|
||||||
|
pixelMap = await imageSource.createPixelMap({
|
||||||
|
desiredSize: {
|
||||||
|
width: imageInfo.size.width,
|
||||||
|
height: imageInfo.size.height
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!pixelMap) {
|
||||||
|
throw new Error('创建PixelMap失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 压缩图片
|
||||||
|
imagePacker = image.createImagePacker();
|
||||||
|
const packOpts: image.PackingOption = {
|
||||||
|
format: "image/jpeg",
|
||||||
|
quality: 80 // 适当提高质量保证清晰度
|
||||||
|
};
|
||||||
|
|
||||||
|
logger.info('正在压缩图片...');
|
||||||
|
const arrayBuffer = await imagePacker.packing(pixelMap, packOpts);
|
||||||
|
|
||||||
|
// 6. 转换为base64
|
||||||
|
const unit8Array = new Uint8Array(arrayBuffer);
|
||||||
|
let binary = '';
|
||||||
|
unit8Array.forEach(byte => {
|
||||||
|
binary += String.fromCharCode(byte);
|
||||||
|
});
|
||||||
|
|
||||||
|
const base64String = Base64Util.encodeToStrSync(binary);
|
||||||
|
logger.info(`图片转换成功,大小: ${Math.round(base64String.length / 1024)}KB`);
|
||||||
|
return base64String;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('图片处理失败: ' + JSON.stringify(error));
|
||||||
|
throw new Error(`图片处理失败: ${error.message}`);
|
||||||
|
} finally {
|
||||||
|
// 7. 确保释放资源
|
||||||
|
try {
|
||||||
|
pixelMap?.release();
|
||||||
|
imageSource?.release();
|
||||||
|
imagePacker?.release();
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('资源释放异常: ' + JSON.stringify(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UploadImageParams {
|
||||||
|
uuid:string,
|
||||||
|
userName:string,
|
||||||
|
photo:string,
|
||||||
|
type:string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const hdHttp = new HdHttp({ baseURL: '' })
|
export const hdHttp = new HdHttp({ baseURL: '' })
|
||||||
|
|||||||
@ -11,3 +11,5 @@ export { ChooseEmailComp } from './src/main/ets/view/ChooseEmailComp'
|
|||||||
export { ChooseOfficePhoneComp } from './src/main/ets/view/ChooseOfficePhoneComp'
|
export { ChooseOfficePhoneComp } from './src/main/ets/view/ChooseOfficePhoneComp'
|
||||||
|
|
||||||
export { EditUserDataComp } from './src/main/ets/view/EditUserDataComp'
|
export { EditUserDataComp } from './src/main/ets/view/EditUserDataComp'
|
||||||
|
|
||||||
|
export { SpecialitySelectedSheet } from './src/main/ets/view/SpecialitySelectedSheet'
|
||||||
@ -1,12 +1,59 @@
|
|||||||
|
import { hdHttp, HdResponse, BasicConstant, ExpertData, authStore } from '@itcast/basic'
|
||||||
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
import promptAction from '@ohos.promptAction';
|
import promptAction from '@ohos.promptAction';
|
||||||
|
import HashMap from '@ohos.util.HashMap';
|
||||||
|
import { router } from '@kit.ArkUI';
|
||||||
|
|
||||||
|
interface callBackData {
|
||||||
|
code: number,
|
||||||
|
message:string,
|
||||||
|
msg:string,
|
||||||
|
data: string
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Component
|
@Component
|
||||||
export struct ChangePhoneComp {
|
export struct ChangePhoneComp {
|
||||||
@State phoneNumber: string = ''
|
@State phoneNumber: string = ''
|
||||||
@State smsCode: string = ''
|
@State smsCode: string = ''
|
||||||
@State countdown: number = 0
|
@State countdown: number = 0
|
||||||
|
|
||||||
|
uploadChangePhoneAction(){
|
||||||
|
const hashMap: HashMap<string, string> = new HashMap();
|
||||||
|
hashMap.set('newMobile',this.phoneNumber)
|
||||||
|
hashMap.set('oldMobile',authStore.getUser().photo)
|
||||||
|
hashMap.set('sms',this.smsCode)
|
||||||
|
hdHttp.httpReq<string>(BasicConstant.urlmyLan+'updateMobile',hashMap).then(async (res: HdResponse<string>) => {
|
||||||
|
let json:callBackData = JSON.parse(res+'') as callBackData;
|
||||||
|
console.log('更新手机号数据:',json);
|
||||||
|
if (json.code == 200) {
|
||||||
|
promptAction.showToast({message:'修改成功'});
|
||||||
|
router.back();
|
||||||
|
} else {
|
||||||
|
promptAction.showToast({message:json.message});
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`Response login succeeded: ${err}`);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadSmsAction(){
|
||||||
|
const hashMap: HashMap<string, string> = new HashMap();
|
||||||
|
hashMap.set('type','6');
|
||||||
|
hashMap.set('mobile',this.phoneNumber)
|
||||||
|
hdHttp.httpReq<string>(BasicConstant.urlmyLan+'smsSend',hashMap).then(async (res: HdResponse<string>) => {
|
||||||
|
let json:callBackData = JSON.parse(res+'') as callBackData;
|
||||||
|
console.log('获取验证码数据:',json);
|
||||||
|
if (json.code == 200) {
|
||||||
|
promptAction.showToast({message:'发送成功'});
|
||||||
|
this.startCountdown();
|
||||||
|
} else {
|
||||||
|
promptAction.showToast({message:json.message});
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`Response login succeeded: ${err}`);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 验证码倒计时
|
// 验证码倒计时
|
||||||
private startCountdown() {
|
private startCountdown() {
|
||||||
this.countdown = 60
|
this.countdown = 60
|
||||||
@ -54,6 +101,9 @@ export struct ChangePhoneComp {
|
|||||||
TextInput({ placeholder: '请输入验证码' })
|
TextInput({ placeholder: '请输入验证码' })
|
||||||
.fontSize(16)
|
.fontSize(16)
|
||||||
.backgroundColor(Color.White)
|
.backgroundColor(Color.White)
|
||||||
|
.onChange((value: string) => {
|
||||||
|
this.smsCode = value
|
||||||
|
})
|
||||||
}
|
}
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.width('60%')
|
.width('60%')
|
||||||
@ -76,11 +126,15 @@ export struct ChangePhoneComp {
|
|||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.enabled(this.countdown === 0)
|
.enabled(this.countdown === 0)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
if (this.phoneNumber.length >= 11) {
|
if (this.phoneNumber.length < 11 || !this.phoneNumber) {
|
||||||
this.startCountdown()
|
|
||||||
} else {
|
|
||||||
promptAction.showToast({message:'请输入手机号'})
|
promptAction.showToast({message:'请输入手机号'})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
if (!EMAIL_REGEX.test(this.phoneNumber)) {
|
||||||
|
promptAction.showToast({message:'请输入正确的手机号'})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.uploadSmsAction()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.width('95%')
|
.width('95%')
|
||||||
@ -100,18 +154,19 @@ export struct ChangePhoneComp {
|
|||||||
.fontSize(18)
|
.fontSize(18)
|
||||||
.position({x:'5%',y:'80%'})
|
.position({x:'5%',y:'80%'})
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
// 处理登录逻辑
|
if (this.phoneNumber.length < 11 || !this.phoneNumber) {
|
||||||
if (!/^1[3-9]\d{9}$/.test(this.phoneNumber)) {
|
promptAction.showToast({message:'请输入手机号'})
|
||||||
promptAction.showToast({message:'请输入有效手机号'})
|
return
|
||||||
|
}
|
||||||
|
if (!EMAIL_REGEX.test(this.phoneNumber)) {
|
||||||
|
promptAction.showToast({message:'请输入正确的手机号'})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.smsCode) {
|
if (!this.smsCode) {
|
||||||
promptAction.showToast({message:'请输入验证码'})
|
promptAction.showToast({message:'验证码不能为空'})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.uploadChangePhoneAction();
|
||||||
// 执行登录操作...
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
@ -119,3 +174,6 @@ export struct ChangePhoneComp {
|
|||||||
.backgroundColor('#FFFFFF')
|
.backgroundColor('#FFFFFF')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 手机正则表达式
|
||||||
|
const EMAIL_REGEX = /^1[3-9][0-9]{9}$/
|
||||||
|
|||||||
@ -1,10 +1,34 @@
|
|||||||
|
import { hdHttp, HdResponse, BasicConstant, ExpertData, authStore } from '@itcast/basic'
|
||||||
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
import promptAction from '@ohos.promptAction';
|
import promptAction from '@ohos.promptAction';
|
||||||
import { authStore } from '@itcast/basic';
|
import { router } from '@kit.ArkUI';
|
||||||
|
|
||||||
|
interface updateExtraData {
|
||||||
|
uuid: string,
|
||||||
|
userName: string,
|
||||||
|
birthDate: string,
|
||||||
|
type: string,
|
||||||
|
photo: string,
|
||||||
|
email: string,
|
||||||
|
certificateImg: string,
|
||||||
|
positionUuid: string,
|
||||||
|
officeUuid: string,
|
||||||
|
officeName: string,
|
||||||
|
diseaseUuids: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface callBackData {
|
||||||
|
expert:ExpertData,
|
||||||
|
code:number,
|
||||||
|
message:string,
|
||||||
|
specialy:[],
|
||||||
|
data:ExpertData,
|
||||||
|
special:[]
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Component
|
@Component
|
||||||
export struct ChooseEmailComp {
|
export struct ChooseEmailComp {
|
||||||
@State phoneNumber: string = ''
|
@State emailString: string = ''
|
||||||
@State countdown: number = 0
|
@State countdown: number = 0
|
||||||
|
|
||||||
// 验证码倒计时
|
// 验证码倒计时
|
||||||
@ -19,15 +43,43 @@ export struct ChooseEmailComp {
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commitEmailData(editEmail:string){
|
||||||
|
const updateDataUrl:string = BasicConstant.urlExpert + 'modify';
|
||||||
|
hdHttp.post<string>(updateDataUrl, {
|
||||||
|
uuid: authStore.getUser().uuid,
|
||||||
|
userName: authStore.getUser().userName,
|
||||||
|
email: editEmail,
|
||||||
|
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})
|
||||||
|
router.back();
|
||||||
|
} else {
|
||||||
|
console.error('更新用户邮箱失败:'+json.message)
|
||||||
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`更新用户邮箱请求失败: ${err}`);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private validateEmailFormat(email: string): boolean {
|
||||||
|
return EMAIL_REGEX.test(email.trim())
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column() {
|
||||||
// 手机号输入框
|
// 手机号输入框
|
||||||
Row() {
|
Row() {
|
||||||
TextInput({ placeholder: authStore.getUser().email.length>0?authStore.getUser().email:'请输入您的邮箱' })
|
TextInput({ placeholder: authStore.getUser().email.length>0?authStore.getUser().email:'请输入您的邮箱' })
|
||||||
.fontSize(16)
|
.fontSize(16)
|
||||||
|
.contentType(ContentType.EMAIL_ADDRESS)
|
||||||
.backgroundColor(Color.White)
|
.backgroundColor(Color.White)
|
||||||
.onChange((value: string) => {
|
.onChange((value: string) => {
|
||||||
this.phoneNumber = value
|
this.emailString = value
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
@ -62,13 +114,11 @@ export struct ChooseEmailComp {
|
|||||||
.fontSize(18)
|
.fontSize(18)
|
||||||
.position({x:'5%',y:'80%'})
|
.position({x:'5%',y:'80%'})
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
// 处理登录逻辑
|
// if (this.validateEmailFormat(this.emailString)) {
|
||||||
if (!/^1[3-9]\d{9}$/.test(this.phoneNumber)) {
|
// promptAction.showToast({message:'请输入正确的邮箱格式'})
|
||||||
promptAction.showToast({message:'请输入有效手机号'})
|
// return
|
||||||
return
|
// }
|
||||||
}
|
this.commitEmailData(this.emailString);
|
||||||
|
|
||||||
// 执行登录操作...
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
@ -76,3 +126,6 @@ export struct ChooseEmailComp {
|
|||||||
.backgroundColor('#FFFFFF')
|
.backgroundColor('#FFFFFF')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 邮箱正则表达式
|
||||||
|
const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
||||||
|
|||||||
@ -1,23 +1,58 @@
|
|||||||
|
import { hdHttp, HdResponse, BasicConstant, ExpertData, authStore } from '@itcast/basic'
|
||||||
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
import promptAction from '@ohos.promptAction';
|
import promptAction from '@ohos.promptAction';
|
||||||
import { authStore } from '@itcast/basic';
|
import { router } from '@kit.ArkUI';
|
||||||
|
|
||||||
|
interface updateExtraData {
|
||||||
|
uuid: string,
|
||||||
|
userName: string,
|
||||||
|
birthDate: string,
|
||||||
|
type: string,
|
||||||
|
photo: string,
|
||||||
|
email: string,
|
||||||
|
certificateImg: string,
|
||||||
|
positionUuid: string,
|
||||||
|
officeUuid: string,
|
||||||
|
officeName: string,
|
||||||
|
diseaseUuids: string,
|
||||||
|
officePhone: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface callBackData {
|
||||||
|
expert:ExpertData,
|
||||||
|
code:number,
|
||||||
|
message:string,
|
||||||
|
specialy:[],
|
||||||
|
data:ExpertData,
|
||||||
|
special:[]
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Component
|
@Component
|
||||||
export struct ChooseOfficePhoneComp {
|
export struct ChooseOfficePhoneComp {
|
||||||
@State phoneNumber: string = ''
|
@State officePhoneStr: string = ''
|
||||||
@State smsCode: string = ''
|
|
||||||
@State countdown: number = 0
|
@State countdown: number = 0
|
||||||
|
|
||||||
// 验证码倒计时
|
commitOfficePhoneData(officePhoneStr:string){
|
||||||
private startCountdown() {
|
const updateDataUrl:string = BasicConstant.urlExpert + 'modify';
|
||||||
this.countdown = 60
|
hdHttp.post<string>(updateDataUrl, {
|
||||||
const timer = setInterval(() => {
|
uuid: authStore.getUser().uuid,
|
||||||
if (this.countdown > 0) {
|
userName: authStore.getUser().userName,
|
||||||
this.countdown--
|
officePhone: this.officePhoneStr,
|
||||||
|
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})
|
||||||
|
router.back();
|
||||||
} else {
|
} else {
|
||||||
clearInterval(timer)
|
console.error('更新用户办公室电话失败:'+json.message)
|
||||||
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
}
|
}
|
||||||
}, 1000)
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`更新用户办公室电话请求失败: ${err}`);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
@ -28,7 +63,7 @@ export struct ChooseOfficePhoneComp {
|
|||||||
.fontSize(16)
|
.fontSize(16)
|
||||||
.backgroundColor(Color.White)
|
.backgroundColor(Color.White)
|
||||||
.onChange((value: string) => {
|
.onChange((value: string) => {
|
||||||
this.phoneNumber = value
|
this.officePhoneStr = value
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
@ -64,15 +99,11 @@ export struct ChooseOfficePhoneComp {
|
|||||||
.position({x:'5%',y:'80%'})
|
.position({x:'5%',y:'80%'})
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
// 处理登录逻辑
|
// 处理登录逻辑
|
||||||
if (!/^1[3-9]\d{9}$/.test(this.phoneNumber)) {
|
if (!/^1[3-9]\d{9}$/.test(this.officePhoneStr)) {
|
||||||
promptAction.showToast({message:'请输入有效手机号'})
|
promptAction.showToast({message:'请输入有效手机号'})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.commitOfficePhoneData(this.officePhoneStr);
|
||||||
if (!this.smsCode) {
|
|
||||||
promptAction.showToast({message:'请输入验证码'})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行登录操作...
|
// 执行登录操作...
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { formatDate } from '../util/DateUtils'
|
import { formatDate } from '../util/DateUtils'
|
||||||
|
import { authStore } from '@itcast/basic'
|
||||||
|
|
||||||
@CustomDialog
|
@CustomDialog
|
||||||
export struct DatePickerDialog {
|
export struct DatePickerDialog {
|
||||||
@ -18,7 +19,8 @@ export struct DatePickerDialog {
|
|||||||
// 初始化日期范围(示例为1930-至今)
|
// 初始化日期范围(示例为1930-至今)
|
||||||
private dateOptions: DatePickerOptions = {
|
private dateOptions: DatePickerOptions = {
|
||||||
start: new Date('1930-01-01'),
|
start: new Date('1930-01-01'),
|
||||||
end: new Date(this.selectedDateString)
|
end: new Date(this.selectedDateString),
|
||||||
|
selected: new Date(authStore.getUser().birthDate?authStore.getUser().birthDate:'1930-01-01'),
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
|
|||||||
@ -7,17 +7,38 @@ import { PhotoActionSheet } from './PhotoActionSheet'
|
|||||||
import { DatePickerDialog } from './DatePickerDialog'
|
import { DatePickerDialog } from './DatePickerDialog'
|
||||||
import { OfficeSelectedSheet } from './OfficeSelectedSheet'
|
import { OfficeSelectedSheet } from './OfficeSelectedSheet'
|
||||||
import { PositionSelectedSheet } from './PositionSelectedSheet'
|
import { PositionSelectedSheet } from './PositionSelectedSheet'
|
||||||
|
import { SpecialitySelectedSheet } from './SpecialitySelectedSheet'
|
||||||
import { http } from '@kit.NetworkKit';
|
import { http } from '@kit.NetworkKit';
|
||||||
|
|
||||||
interface extraData {
|
interface extraData {
|
||||||
uuid: string
|
uuid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface updateExtraData {
|
||||||
|
uuid: string,
|
||||||
|
userName: string,
|
||||||
|
birthDate: string,
|
||||||
|
type: string,
|
||||||
|
photo: string,
|
||||||
|
certificateImg: string,
|
||||||
|
positionUuid: string,
|
||||||
|
officeUuid: string,
|
||||||
|
officeName: string,
|
||||||
|
diseaseUuids: string
|
||||||
|
}
|
||||||
|
|
||||||
interface callBackData {
|
interface callBackData {
|
||||||
expert:ExpertData,
|
expert:ExpertData,
|
||||||
code:number,
|
code:number,
|
||||||
message:string,
|
message:string,
|
||||||
specialy:[]
|
specialy:[],
|
||||||
|
data:ExpertData,
|
||||||
|
special:[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UploadAvatarResponse {
|
||||||
|
url:string;
|
||||||
|
uploadAvatarUrl:string,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ -38,11 +59,14 @@ export struct EditUserDataComp {
|
|||||||
@State diseaseName:string = '';
|
@State diseaseName:string = '';
|
||||||
@State intro:string = authStore.getUser().intro;
|
@State intro:string = authStore.getUser().intro;
|
||||||
|
|
||||||
|
@State updateDataUrl:string = BasicConstant.urlExpert + 'modify';
|
||||||
|
|
||||||
private photoSheetDialog!: CustomDialogController;
|
private photoSheetDialog!: CustomDialogController;
|
||||||
private datePickerDialog!: CustomDialogController;
|
private datePickerDialog!: CustomDialogController;
|
||||||
private officePickerDialog!: CustomDialogController;
|
private officePickerDialog!: CustomDialogController;
|
||||||
private positionPickerDialog!: CustomDialogController;
|
private positionPickerDialog!: CustomDialogController;
|
||||||
private certificatePhotoSheetDialog!: CustomDialogController;
|
private certificatePhotoSheetDialog!: CustomDialogController;
|
||||||
|
private diseaseSheetDialog!:CustomDialogController;
|
||||||
|
|
||||||
aboutToAppear() {
|
aboutToAppear() {
|
||||||
this.initPhotoDialog();
|
this.initPhotoDialog();
|
||||||
@ -50,15 +74,18 @@ export struct EditUserDataComp {
|
|||||||
this.initOfficePickerDialog();
|
this.initOfficePickerDialog();
|
||||||
this.initPositionPickerDialog();
|
this.initPositionPickerDialog();
|
||||||
this.initCerficatePhotoDialog();
|
this.initCerficatePhotoDialog();
|
||||||
|
this.initDiseaseSheetDIalog();
|
||||||
this.uploadUserDataAction();
|
this.uploadUserDataAction();
|
||||||
console.log('用户资料:'+authStore.getUser().specialy);
|
console.log('用户资料:'+authStore.getUser().specialy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加public修饰符暴露方法
|
||||||
|
public refreshData() {
|
||||||
|
this.uploadUserDataAction();
|
||||||
|
}
|
||||||
|
|
||||||
uploadUserDataAction() {
|
uploadUserDataAction() {
|
||||||
const hashMap: HashMap<string, string> = new HashMap();
|
|
||||||
const userDataUrl:string = BasicConstant.urlExpert+'getExpertByUuid';
|
const userDataUrl:string = BasicConstant.urlExpert+'getExpertByUuid';
|
||||||
hashMap.set('uuid',authStore.getUser().uuid)
|
|
||||||
hdHttp.post<string>(userDataUrl, {
|
hdHttp.post<string>(userDataUrl, {
|
||||||
uuid: authStore.getUser().uuid,
|
uuid: authStore.getUser().uuid,
|
||||||
} as extraData).then(async (res: HdResponse<string>) => {
|
} as extraData).then(async (res: HdResponse<string>) => {
|
||||||
@ -96,9 +123,28 @@ export struct EditUserDataComp {
|
|||||||
this.photoSheetDialog = new CustomDialogController({
|
this.photoSheetDialog = new CustomDialogController({
|
||||||
builder: PhotoActionSheet({
|
builder: PhotoActionSheet({
|
||||||
controller: this.photoSheetDialog,
|
controller: this.photoSheetDialog,
|
||||||
onPhotoSelected: (uri: string) => {
|
onPhotoSelected: async (url: string) => {
|
||||||
this.photoPath = uri;
|
this.photoPath = url;
|
||||||
console.log('Selected image URI:', uri);
|
console.log('Selected image URI:', url);
|
||||||
|
try {
|
||||||
|
promptAction.showToast({ message: '正在上传图片...', duration: 2000 });
|
||||||
|
// 调用上传方法,使用明确的返回类型
|
||||||
|
const response = await hdHttp.uploadImage<UploadAvatarResponse>(
|
||||||
|
this.updateDataUrl,
|
||||||
|
url
|
||||||
|
);
|
||||||
|
if (response.code === 1) {
|
||||||
|
promptAction.showToast({ message: '图片上传成功' });
|
||||||
|
console.log('上传成功,返回数据:', response.data);
|
||||||
|
// 处理上传成功后的逻辑
|
||||||
|
// this.currentUser.avatar = response.data.avatarUrl;
|
||||||
|
} else {
|
||||||
|
promptAction.showToast({ message: response.message || '图片上传失败' });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('图片上传出错:', error);
|
||||||
|
promptAction.showToast({ message: '图片上传出错,请重试' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
alignment: DialogAlignment.Bottom,
|
alignment: DialogAlignment.Bottom,
|
||||||
@ -115,7 +161,26 @@ export struct EditUserDataComp {
|
|||||||
controller:this.officePickerDialog,
|
controller:this.officePickerDialog,
|
||||||
officeSelected: (name:string , uuid:string) => {
|
officeSelected: (name:string , uuid:string) => {
|
||||||
this.officeName = name;
|
this.officeName = name;
|
||||||
}
|
hdHttp.post<string>(this.updateDataUrl, {
|
||||||
|
uuid: authStore.getUser().uuid,
|
||||||
|
userName: authStore.getUser().userName,
|
||||||
|
officeName: name,
|
||||||
|
officeUuid:uuid,
|
||||||
|
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)
|
||||||
|
this.arrToStringSpecialy(json.special);
|
||||||
|
console.log('更新用户信息科室成功:', authStore.getUser().intro);
|
||||||
|
} else {
|
||||||
|
console.error('更新用户信息科室失败:'+json.message)
|
||||||
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`更新用户信息职称科室失败: ${err}`);
|
||||||
|
})
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
alignment: DialogAlignment.Bottom,
|
alignment: DialogAlignment.Bottom,
|
||||||
customStyle: true,
|
customStyle: true,
|
||||||
@ -131,6 +196,24 @@ export struct EditUserDataComp {
|
|||||||
controller:this.officePickerDialog,
|
controller:this.officePickerDialog,
|
||||||
officeSelected: (name:string , uuid:string) => {
|
officeSelected: (name:string , uuid:string) => {
|
||||||
this.positionName = name;
|
this.positionName = name;
|
||||||
|
hdHttp.post<string>(this.updateDataUrl, {
|
||||||
|
uuid: authStore.getUser().uuid,
|
||||||
|
userName: authStore.getUser().userName,
|
||||||
|
positionUuid: uuid,
|
||||||
|
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)
|
||||||
|
this.arrToStringSpecialy(json.special);
|
||||||
|
console.log('更新用户信息职称成功:', authStore.getUser().intro);
|
||||||
|
} else {
|
||||||
|
console.error('更新用户信息职称失败:'+json.message)
|
||||||
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`更新用户信息职称请求失败: ${err}`);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
alignment: DialogAlignment.Bottom,
|
alignment: DialogAlignment.Bottom,
|
||||||
@ -147,6 +230,24 @@ export struct EditUserDataComp {
|
|||||||
controller:this.datePickerDialog,
|
controller:this.datePickerDialog,
|
||||||
dateSelected:(date:string) => {
|
dateSelected:(date:string) => {
|
||||||
this.birthday = date;
|
this.birthday = date;
|
||||||
|
hdHttp.post<string>(this.updateDataUrl, {
|
||||||
|
uuid: authStore.getUser().uuid,
|
||||||
|
userName: authStore.getUser().userName,
|
||||||
|
birthDate: date,
|
||||||
|
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)
|
||||||
|
this.arrToStringSpecialy(json.special);
|
||||||
|
console.log('更新用户信息生日成功:', authStore.getUser().intro);
|
||||||
|
} else {
|
||||||
|
console.error('更新用户信息生日失败:'+json.message)
|
||||||
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`更新用户信息生日请求失败: ${err}`);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
alignment: DialogAlignment.Bottom,
|
alignment: DialogAlignment.Bottom,
|
||||||
@ -161,9 +262,9 @@ export struct EditUserDataComp {
|
|||||||
this.certificatePhotoSheetDialog = new CustomDialogController({
|
this.certificatePhotoSheetDialog = new CustomDialogController({
|
||||||
builder: PhotoActionSheet({
|
builder: PhotoActionSheet({
|
||||||
controller: this.certificatePhotoSheetDialog,
|
controller: this.certificatePhotoSheetDialog,
|
||||||
onPhotoSelected: (uri: string) => {
|
onPhotoSelected: (url: string) => {
|
||||||
this.certificatePhoto = uri;
|
this.certificatePhoto = url;
|
||||||
console.log('Selected image URI:', uri);
|
console.log('Selected image URI:', url);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
alignment: DialogAlignment.Bottom,
|
alignment: DialogAlignment.Bottom,
|
||||||
@ -174,6 +275,39 @@ export struct EditUserDataComp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initDiseaseSheetDIalog() {
|
||||||
|
this.diseaseSheetDialog = new CustomDialogController({
|
||||||
|
builder: SpecialitySelectedSheet({
|
||||||
|
controller:this.diseaseSheetDialog,
|
||||||
|
specialitySelected: (diseaseUuids:string)=>{
|
||||||
|
hdHttp.post<string>(this.updateDataUrl, {
|
||||||
|
uuid: authStore.getUser().uuid,
|
||||||
|
userName: authStore.getUser().userName,
|
||||||
|
diseaseUuids: diseaseUuids,
|
||||||
|
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)
|
||||||
|
this.arrToStringSpecialy(json.special);
|
||||||
|
console.log('更新用户信息专长成功:', authStore.getUser().intro);
|
||||||
|
} else {
|
||||||
|
console.error('更新用户信息专长失败:'+json.message)
|
||||||
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`更新用户信息专长请求失败: ${err}`);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
alignment: DialogAlignment.Bottom,
|
||||||
|
customStyle: true,
|
||||||
|
autoCancel: false,
|
||||||
|
backgroundColor: ('rgba(0,0,0,0.5)'),
|
||||||
|
height: '100%'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
Scroll() {
|
||||||
Column() {
|
Column() {
|
||||||
@ -199,7 +333,12 @@ export struct EditUserDataComp {
|
|||||||
EditUserDataItem({ label: '手机号码', required: true, content: this.phone , hasArrow: true})
|
EditUserDataItem({ label: '手机号码', required: true, content: this.phone , hasArrow: true})
|
||||||
.onClick(()=>{
|
.onClick(()=>{
|
||||||
router.pushUrl({
|
router.pushUrl({
|
||||||
url:'pages/MinePage/ChangePhonePage'
|
url:'pages/MinePage/ChangePhonePage',
|
||||||
|
params:{
|
||||||
|
onBack:()=>{
|
||||||
|
this.uploadUserDataAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
EditUserDataItem({ label: '邮箱', content: this.email , hasArrow: true})
|
EditUserDataItem({ label: '邮箱', content: this.email , hasArrow: true})
|
||||||
@ -239,6 +378,7 @@ export struct EditUserDataComp {
|
|||||||
EditUserDataItem({ label: '执业医师证图片或胸牌', required: true, content: this.certificatePhoto })
|
EditUserDataItem({ label: '执业医师证图片或胸牌', required: true, content: this.certificatePhoto })
|
||||||
.onClick(()=>this.certificatePhotoSheetDialog.open())
|
.onClick(()=>this.certificatePhotoSheetDialog.open())
|
||||||
EditUserDataItem({ label: '专长', required: true, content: this.diseaseName , hasArrow: true})
|
EditUserDataItem({ label: '专长', required: true, content: this.diseaseName , hasArrow: true})
|
||||||
|
.onClick(()=>this.diseaseSheetDialog.open())
|
||||||
EditUserDataItem({ label: '个人简介', content: this.intro, hasArrow: true })
|
EditUserDataItem({ label: '个人简介', content: this.intro, hasArrow: true })
|
||||||
.onClick(()=>{
|
.onClick(()=>{
|
||||||
router.pushUrl({
|
router.pushUrl({
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { hdHttp, HdResponse,BasicConstant, logger,RequestDefaultModel, Data } f
|
|||||||
import { promptAction } from '@kit.ArkUI'
|
import { promptAction } from '@kit.ArkUI'
|
||||||
import HashMap from '@ohos.util.HashMap';
|
import HashMap from '@ohos.util.HashMap';
|
||||||
import { BusinessError } from '@kit.BasicServicesKit';
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
|
import { authStore } from '@itcast/basic'
|
||||||
|
|
||||||
interface DefaultData {
|
interface DefaultData {
|
||||||
'officeName':string;
|
'officeName':string;
|
||||||
@ -16,6 +17,8 @@ export struct OfficeSelectedSheet {
|
|||||||
@Prop selectedOffice:object = new Object;
|
@Prop selectedOffice:object = new Object;
|
||||||
@State selectedModel:DefaultData = { officeName: '', officeUuid: '' };
|
@State selectedModel:DefaultData = { officeName: '', officeUuid: '' };
|
||||||
|
|
||||||
|
@State selectedIndex:number = 0;
|
||||||
|
|
||||||
// 添加回调函数属性
|
// 添加回调函数属性
|
||||||
private officeSelected: (name:string , uuid:string) => void = () => {};
|
private officeSelected: (name:string , uuid:string) => void = () => {};
|
||||||
|
|
||||||
@ -35,19 +38,23 @@ export struct OfficeSelectedSheet {
|
|||||||
|
|
||||||
uploadOffice() {
|
uploadOffice() {
|
||||||
hdHttp.httpReq<string>(this.officeRequestUrl,this.hashMap).then(async (res: HdResponse<string>) => {
|
hdHttp.httpReq<string>(this.officeRequestUrl,this.hashMap).then(async (res: HdResponse<string>) => {
|
||||||
logger.info('Response officelist success'+res);
|
|
||||||
console.info(`Response officelist succeeded: ${res}`);
|
|
||||||
let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel;
|
let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel;
|
||||||
if(json.code=='1') {
|
if(json.code=='1') {
|
||||||
this.officeArr = json.data as DefaultData[];
|
this.officeArr = json.data as DefaultData[];
|
||||||
this.officeNameArr = json.data.map(item => item.officeName);
|
this.officeNameArr = json.data.map(item => item.officeName);
|
||||||
console.log('科室名称数组:', this.officeNameArr);
|
console.log('科室名称数组:', this.officeNameArr);
|
||||||
|
for (let index = 0; index < this.officeNameArr.length; index++) {
|
||||||
|
const element = this.officeNameArr[index];
|
||||||
|
if (element == authStore.getUser().officeName) {
|
||||||
|
this.selectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error('科室数据失败:'+json.message)
|
console.error('科室数据失败:'+json.message)
|
||||||
promptAction.showToast({ message: json.message, duration: 1000 })
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
}
|
}
|
||||||
}).catch((err: BusinessError) => {
|
}).catch((err: BusinessError) => {
|
||||||
console.info(`Response login fail: ${err}`);
|
console.info(`Response fail: ${err}`);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +90,8 @@ export struct OfficeSelectedSheet {
|
|||||||
.height(40)
|
.height(40)
|
||||||
|
|
||||||
TextPicker({
|
TextPicker({
|
||||||
range:this.officeNameArr
|
range:this.officeNameArr,
|
||||||
|
selected:this.selectedIndex
|
||||||
})
|
})
|
||||||
.selectedTextStyle({
|
.selectedTextStyle({
|
||||||
color: '#007AFF',
|
color: '#007AFF',
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { hdHttp, HdResponse,BasicConstant, logger,RequestDefaultModel, Data } from '@itcast/basic'
|
import { hdHttp, HdResponse,BasicConstant,RequestDefaultModel } from '@itcast/basic'
|
||||||
import { promptAction } from '@kit.ArkUI'
|
import { promptAction } from '@kit.ArkUI'
|
||||||
import HashMap from '@ohos.util.HashMap';
|
import HashMap from '@ohos.util.HashMap';
|
||||||
import { BusinessError } from '@kit.BasicServicesKit';
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
|
import { authStore } from '@itcast/basic'
|
||||||
|
|
||||||
interface DefaultData {
|
interface DefaultData {
|
||||||
'name':string;
|
'name':string;
|
||||||
@ -16,6 +17,8 @@ export struct PositionSelectedSheet {
|
|||||||
@Prop selectedOffice:object = new Object;
|
@Prop selectedOffice:object = new Object;
|
||||||
@State selectedModel:DefaultData = { name: '', uuid: '' };
|
@State selectedModel:DefaultData = { name: '', uuid: '' };
|
||||||
|
|
||||||
|
@State selectedIndex:number = 0;
|
||||||
|
|
||||||
// 添加回调函数属性
|
// 添加回调函数属性
|
||||||
private officeSelected: (name:string , uuid:string) => void = () => {};
|
private officeSelected: (name:string , uuid:string) => void = () => {};
|
||||||
|
|
||||||
@ -35,19 +38,23 @@ export struct PositionSelectedSheet {
|
|||||||
|
|
||||||
uploadOffice() {
|
uploadOffice() {
|
||||||
hdHttp.httpReq<string>(this.officeRequestUrl,this.hashMap).then(async (res: HdResponse<string>) => {
|
hdHttp.httpReq<string>(this.officeRequestUrl,this.hashMap).then(async (res: HdResponse<string>) => {
|
||||||
logger.info('Response officelist success'+res);
|
|
||||||
console.info(`Response officelist succeeded: ${res}`);
|
|
||||||
let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel;
|
let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel;
|
||||||
if(json.code=='1') {
|
if(json.code=='1') {
|
||||||
this.officeArr = json.data as DefaultData[];
|
this.officeArr = json.data as DefaultData[];
|
||||||
this.officeNameArr = json.data.map(item => item.name);
|
this.officeNameArr = json.data.map(item => item.name);
|
||||||
|
for (let index = 0; index < this.officeNameArr.length; index++) {
|
||||||
|
const element = this.officeNameArr[index];
|
||||||
|
if (element == authStore.getUser().positionName) {
|
||||||
|
this.selectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
console.log('职称名称数组:', this.officeNameArr);
|
console.log('职称名称数组:', this.officeNameArr);
|
||||||
} else {
|
} else {
|
||||||
console.error('职称数据失败:'+json.message)
|
console.error('职称数据失败:'+json.message)
|
||||||
promptAction.showToast({ message: json.message, duration: 1000 })
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
}
|
}
|
||||||
}).catch((err: BusinessError) => {
|
}).catch((err: BusinessError) => {
|
||||||
console.info(`Response login fail: ${err}`);
|
console.info(`Response fail: ${err}`);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +90,8 @@ export struct PositionSelectedSheet {
|
|||||||
.height(40)
|
.height(40)
|
||||||
|
|
||||||
TextPicker({
|
TextPicker({
|
||||||
range:this.officeNameArr
|
range:this.officeNameArr,
|
||||||
|
selected:this.selectedIndex
|
||||||
})
|
})
|
||||||
.selectedTextStyle({
|
.selectedTextStyle({
|
||||||
color: '#007AFF',
|
color: '#007AFF',
|
||||||
|
|||||||
132
features/mypage/src/main/ets/view/SpecialitySelectedSheet.ets
Normal file
132
features/mypage/src/main/ets/view/SpecialitySelectedSheet.ets
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
import { hdHttp, HdResponse,BasicConstant,RequestDefaultModel } from '@itcast/basic'
|
||||||
|
import HashMap from '@ohos.util.HashMap';
|
||||||
|
import { promptAction } from '@kit.ArkUI'
|
||||||
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
|
|
||||||
|
interface DefaultData {
|
||||||
|
'name':string;
|
||||||
|
'uuid':string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CustomDialog
|
||||||
|
export struct SpecialitySelectedSheet {
|
||||||
|
controller: CustomDialogController;
|
||||||
|
|
||||||
|
@State specialityArr:Array<DefaultData> = [];
|
||||||
|
@State specialityNameArr:Array<string> = [];
|
||||||
|
@State selectedTags: Array<string> = [];
|
||||||
|
|
||||||
|
// 添加回调函数属性
|
||||||
|
private specialitySelected: (seletedTags:string) => void = () => {};
|
||||||
|
// 修改构造函数
|
||||||
|
constructor(controller: CustomDialogController, specialitySelected: (seletedTags:string) => void) {
|
||||||
|
super();
|
||||||
|
this.controller = controller;
|
||||||
|
this.specialitySelected = specialitySelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
aboutToAppear(): void {
|
||||||
|
this.uploadSpeciality();
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadSpeciality() {
|
||||||
|
const officeRequestUrl:string = BasicConstant.urlExpert+'disease'
|
||||||
|
const hashMap: HashMap<string, string> = new HashMap();
|
||||||
|
hdHttp.httpReq<string>(officeRequestUrl,hashMap).then(async (res: HdResponse<string>) => {
|
||||||
|
let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel;
|
||||||
|
if(json.code=='1') {
|
||||||
|
this.specialityArr = json.data as DefaultData[];
|
||||||
|
this.specialityNameArr = json.data.map(item => item.name);
|
||||||
|
console.log('请求专长接口成功,信息:', this.specialityArr);
|
||||||
|
} else {
|
||||||
|
console.error('请求专长接口失败:'+json.message)
|
||||||
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
||||||
|
}
|
||||||
|
}).catch((err: BusinessError) => {
|
||||||
|
console.info(`Response fail: ${err}`);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
// 操作按钮区域
|
||||||
|
Row({space:70}) {
|
||||||
|
Button('取消')
|
||||||
|
.layoutWeight(1)
|
||||||
|
.backgroundColor(Color.Transparent)
|
||||||
|
.fontColor($r('app.color.main_color'))
|
||||||
|
.backgroundColor(Color.White)
|
||||||
|
.width(80)
|
||||||
|
.onClick(() => {
|
||||||
|
this.controller.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
Text('请选择专长')
|
||||||
|
.fontSize(15)
|
||||||
|
.fontColor('#666666')
|
||||||
|
|
||||||
|
Button('确定')
|
||||||
|
.layoutWeight(1)
|
||||||
|
.backgroundColor(Color.Transparent)
|
||||||
|
.fontColor($r('app.color.main_color'))
|
||||||
|
.backgroundColor(Color.White)
|
||||||
|
.width(80)
|
||||||
|
.onClick(() => {
|
||||||
|
this.controller.close()
|
||||||
|
// 拼接为逗号分隔字符串
|
||||||
|
const diseaseName = this.selectedTags.join(',');
|
||||||
|
console.log('当前选中标签的uuid字符串:', diseaseName);
|
||||||
|
this.specialitySelected(diseaseName);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.height(40)
|
||||||
|
|
||||||
|
Grid() {
|
||||||
|
ForEach(this.specialityArr, (data: DefaultData) => {
|
||||||
|
GridItem() {
|
||||||
|
// 单个标签组件
|
||||||
|
Text(data.name)
|
||||||
|
.fontSize(12)
|
||||||
|
.width('100%')
|
||||||
|
.height(30)
|
||||||
|
.textAlign(TextAlign.Center)
|
||||||
|
.backgroundColor(this.isSelected(data.uuid) ? '#b58078' : '#FFFFFF')
|
||||||
|
.onClick(() => {
|
||||||
|
this.handleTagClick(data.uuid)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.height(30)
|
||||||
|
.width('25%') // 四等分宽度
|
||||||
|
.borderWidth(1)
|
||||||
|
.borderColor(Color.Gray)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
.height(240)
|
||||||
|
.backgroundColor(Color.White)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否选中
|
||||||
|
private isSelected(uuid: string): boolean {
|
||||||
|
return this.selectedTags.includes(uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleTagClick(uuid: string) {
|
||||||
|
const index = this.selectedTags.indexOf(uuid);
|
||||||
|
if (index === -1) {
|
||||||
|
// 添加选中(限制最多10个)
|
||||||
|
if (this.selectedTags.length >= 10) {
|
||||||
|
promptAction.showToast({ message: '最多可选择十项!', duration: 1000 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.selectedTags = [...this.selectedTags, uuid];
|
||||||
|
} else {
|
||||||
|
// 取消选中
|
||||||
|
const newSelected = [...this.selectedTags];
|
||||||
|
newSelected.splice(index, 1);
|
||||||
|
this.selectedTags = newSelected;
|
||||||
|
}
|
||||||
|
console.log('当前选中标签:', this.selectedTags)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,10 +4,17 @@ import { EditUserDataComp } from 'mypage'
|
|||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct EditUserDataPage {
|
struct EditUserDataPage {
|
||||||
|
// 使用$符号引用子组件
|
||||||
|
@State editUserDataCompRef: EditUserDataComp | null = null;
|
||||||
|
|
||||||
|
onPageShow(): void {
|
||||||
|
this.editUserDataCompRef?.refreshData();
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column(){
|
Column(){
|
||||||
HdNav({ title: '个人资料', showRightIcon: false, hasBorder: true });
|
HdNav({ title: '个人资料', showRightIcon: false, hasBorder: true });
|
||||||
EditUserDataComp();
|
EditUserDataComp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user