From ab1f72ba6c60f7d13a6519167bbd91a6e2d025f9 Mon Sep 17 00:00:00 2001 From: xiaoxiao Date: Tue, 13 May 2025 17:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .hvigor/outputs/sync/fileCache.json | 2 +- commons/basic/src/main/ets/utils/request.ets | 138 +++++++++++++-- features/mypage/Index.ets | 4 +- .../src/main/ets/view/ChangePhoneComp.ets | 80 +++++++-- .../src/main/ets/view/ChooseEmailComp.ets | 75 ++++++-- .../main/ets/view/ChooseOfficePhoneComp.ets | 69 ++++++-- .../src/main/ets/view/DatePickerDialog.ets | 4 +- .../src/main/ets/view/EditUserDataComp.ets | 164 ++++++++++++++++-- .../src/main/ets/view/OfficeSelectedSheet.ets | 16 +- .../main/ets/view/PositionSelectedSheet.ets | 18 +- .../main/ets/view/SpecialitySelectedSheet.ets | 132 ++++++++++++++ .../ets/pages/MinePage/EditUserDataPage.ets | 9 +- 12 files changed, 627 insertions(+), 84 deletions(-) create mode 100644 features/mypage/src/main/ets/view/SpecialitySelectedSheet.ets diff --git a/.hvigor/outputs/sync/fileCache.json b/.hvigor/outputs/sync/fileCache.json index e0c202d..26b9a0e 100644 --- a/.hvigor/outputs/sync/fileCache.json +++ b/.hvigor/outputs/sync/fileCache.json @@ -1 +1 @@ -{"CACHE_SYNC_FILE_HASH":{"/Users/gandanxiangzhao/Downloads/Expert/harmony/hvigor/hvigor-config.json5":"20319a4ef107cc47d2bf9a1ac691d6c733fd711688e908e288fb7925f48930b1","/Users/gandanxiangzhao/Downloads/Expert/harmony/build-profile.json5":"4f159b63fd533768ffc0f154aab15dbece8a78dee82421b19c7ccc2259583fb3","/Users/gandanxiangzhao/Downloads/Expert/harmony/hvigorfile.ts":"4b8b0f7c80f5ab496f613571147388f5fa2db267caf23c0c395e235f684243da","/Users/gandanxiangzhao/Downloads/Expert/harmony/oh-package.json5":"068f92ff2d99e7ba31124a3f88c32815b3c0220d46317ef5e63d4e5507dec3c5","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/build-profile.json5":"b05f2e93717d5619d015242ddf5c0b16878efafb308ea35409fe4aaf5261fdb3","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/hvigorfile.ts":"4b8b0f7c80f5ab496f613571147388f5fa2db267caf23c0c395e235f684243da","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/oh-package.json5":"4a8598ab9bf6607c1ab389b74dd4753a36a31df93879c9ab6aed959cb36b9dce","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/build-profile.json5":"b703fbdf4e8f4a927137bccc699dfccc8e9a989c10f883710f4c5e9f7e58f84a","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/hvigorfile.ts":"e27f4d8160361104348dff98f8f86381a7444a112f8b6bdb1945fce3cab2dfb6","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/oh-package.json5":"d88b8312eae1ab7dc655d34e352876a1eb87ab0fe512aff1a04498acb1ab051d","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/build-profile.json5":"9ce5eceb1bc7d4b80401ecab45117eb2a82eb7231e27e60d1080d0bfe5755524","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/hvigorfile.ts":"8a05edf077b615a93dd193b8b219a9d81fd802c57234a16b8a2acd6b942a018e","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/oh-package.json5":"6b911a31909105546015d359633369267c125b97a5d0f3b0dc3bcab12a08c9e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/build-profile.json5":"9b89183c24483338b38d9b2fb345a66c75e97fbd32e2f9ee70f1f25edb3269c8","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/hvigorfile.ts":"999b9b9a715325665778aae13050f00201629564c8f760fe11116a4b678e02da","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/oh-package.json5":"b8057721cf5c5fe8da4dab5d2d5e06d33b00d067411be974917ac552d2c0589c","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/build-profile.json5":"7477805ff4b896e8475f6cfa1509715e6e8c7694fe643c0a1b76185626c5d2f8","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/hvigorfile.ts":"fd8160090e16e49c719256141a1407758987c28d92f10db27e1bf1d6f38f2d3a","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/oh-package.json5":"88f9db9e1bf86367a620c95d302ded2bedc172a78ba9ebea6b09353a8ccde631","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/build-profile.json5":"abf2da0306988ce6712bae36a070c0a13f764d5936124218c21e368db81052f7","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/hvigorfile.ts":"c91ffa76d2a6eb8d2f7f83a6ce26354851f3bafb02bbf4de8706741b3378e443","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/oh-package.json5":"bc1845dce5016980622f462664e167e3789359f8bafff276e6c3297fb23723e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/build-profile.json5":"a82329b08da958ff28f376e8c7b454aa462ad933c3554ce1598cf67dfc1d71dd","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/hvigorfile.ts":"c8227f76f37b0315187105ccc7f5e8ece7fb3163b39202df7c9614310d99c0e0","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/oh-package.json5":"4673942b26a12891f0adc0c1d565477298a3989a4cc0a43ff6cbaa2950d453f2","/Users/gandanxiangzhao/Downloads/Expert/harmony/.hvigor/outputs/sync/output.json":"ffba716d0052856c42c134faa6b84ca96fc59f0e1a4d3274bf5e33b303311874","SDK_LOCATION":"/Applications/DevEco-Studio.app/Contents/sdk"},"OHPM_INSTALL_FILE_HASH":{"/Users/gandanxiangzhao/Downloads/Expert/harmony/oh-package.json5":"068f92ff2d99e7ba31124a3f88c32815b3c0220d46317ef5e63d4e5507dec3c5","/Users/gandanxiangzhao/Downloads/Expert/harmony/oh_modules/.ohpm/lock.json5":"c8209b1f96d8efbb5ab6929623cca6509939fa817b35c8dba960b93deb6b6b00","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/oh-package.json5":"4a8598ab9bf6607c1ab389b74dd4753a36a31df93879c9ab6aed959cb36b9dce","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/oh-package.json5":"d88b8312eae1ab7dc655d34e352876a1eb87ab0fe512aff1a04498acb1ab051d","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/oh-package.json5":"6b911a31909105546015d359633369267c125b97a5d0f3b0dc3bcab12a08c9e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/oh-package.json5":"b8057721cf5c5fe8da4dab5d2d5e06d33b00d067411be974917ac552d2c0589c","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/oh-package.json5":"88f9db9e1bf86367a620c95d302ded2bedc172a78ba9ebea6b09353a8ccde631","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/oh-package.json5":"bc1845dce5016980622f462664e167e3789359f8bafff276e6c3297fb23723e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/oh-package.json5":"4673942b26a12891f0adc0c1d565477298a3989a4cc0a43ff6cbaa2950d453f2","/Users/gandanxiangzhao/Downloads/Expert/harmony/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/oh_modules":false,"/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/oh_modules":false,"/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/oh_modules":true}} \ No newline at end of file +{"CACHE_SYNC_FILE_HASH":{"/Users/gandanxiangzhao/Downloads/Expert/harmony/hvigor/hvigor-config.json5":"20319a4ef107cc47d2bf9a1ac691d6c733fd711688e908e288fb7925f48930b1","/Users/gandanxiangzhao/Downloads/Expert/harmony/build-profile.json5":"4f159b63fd533768ffc0f154aab15dbece8a78dee82421b19c7ccc2259583fb3","/Users/gandanxiangzhao/Downloads/Expert/harmony/hvigorfile.ts":"4b8b0f7c80f5ab496f613571147388f5fa2db267caf23c0c395e235f684243da","/Users/gandanxiangzhao/Downloads/Expert/harmony/oh-package.json5":"068f92ff2d99e7ba31124a3f88c32815b3c0220d46317ef5e63d4e5507dec3c5","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/build-profile.json5":"b05f2e93717d5619d015242ddf5c0b16878efafb308ea35409fe4aaf5261fdb3","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/hvigorfile.ts":"4b8b0f7c80f5ab496f613571147388f5fa2db267caf23c0c395e235f684243da","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/oh-package.json5":"4a8598ab9bf6607c1ab389b74dd4753a36a31df93879c9ab6aed959cb36b9dce","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/build-profile.json5":"b703fbdf4e8f4a927137bccc699dfccc8e9a989c10f883710f4c5e9f7e58f84a","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/hvigorfile.ts":"e27f4d8160361104348dff98f8f86381a7444a112f8b6bdb1945fce3cab2dfb6","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/oh-package.json5":"d88b8312eae1ab7dc655d34e352876a1eb87ab0fe512aff1a04498acb1ab051d","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/build-profile.json5":"9ce5eceb1bc7d4b80401ecab45117eb2a82eb7231e27e60d1080d0bfe5755524","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/hvigorfile.ts":"8a05edf077b615a93dd193b8b219a9d81fd802c57234a16b8a2acd6b942a018e","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/oh-package.json5":"6b911a31909105546015d359633369267c125b97a5d0f3b0dc3bcab12a08c9e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/build-profile.json5":"9b89183c24483338b38d9b2fb345a66c75e97fbd32e2f9ee70f1f25edb3269c8","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/hvigorfile.ts":"999b9b9a715325665778aae13050f00201629564c8f760fe11116a4b678e02da","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/oh-package.json5":"b8057721cf5c5fe8da4dab5d2d5e06d33b00d067411be974917ac552d2c0589c","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/build-profile.json5":"7477805ff4b896e8475f6cfa1509715e6e8c7694fe643c0a1b76185626c5d2f8","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/hvigorfile.ts":"fd8160090e16e49c719256141a1407758987c28d92f10db27e1bf1d6f38f2d3a","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/oh-package.json5":"88f9db9e1bf86367a620c95d302ded2bedc172a78ba9ebea6b09353a8ccde631","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/build-profile.json5":"abf2da0306988ce6712bae36a070c0a13f764d5936124218c21e368db81052f7","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/hvigorfile.ts":"c91ffa76d2a6eb8d2f7f83a6ce26354851f3bafb02bbf4de8706741b3378e443","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/oh-package.json5":"bc1845dce5016980622f462664e167e3789359f8bafff276e6c3297fb23723e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/build-profile.json5":"a82329b08da958ff28f376e8c7b454aa462ad933c3554ce1598cf67dfc1d71dd","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/hvigorfile.ts":"c8227f76f37b0315187105ccc7f5e8ece7fb3163b39202df7c9614310d99c0e0","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/oh-package.json5":"4673942b26a12891f0adc0c1d565477298a3989a4cc0a43ff6cbaa2950d453f2","/Users/gandanxiangzhao/Downloads/Expert/harmony/.hvigor/outputs/sync/output.json":"a7a6013e1c5fcd6885efb02e35495b6984f98bad24043f71102759815240a02d","SDK_LOCATION":"/Applications/DevEco-Studio.app/Contents/sdk"},"OHPM_INSTALL_FILE_HASH":{"/Users/gandanxiangzhao/Downloads/Expert/harmony/oh-package.json5":"068f92ff2d99e7ba31124a3f88c32815b3c0220d46317ef5e63d4e5507dec3c5","/Users/gandanxiangzhao/Downloads/Expert/harmony/oh_modules/.ohpm/lock.json5":"fa6f6dd5c4997542ca57d1a66557e15390428df1da944736d61f8ab0d24de172","/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/oh-package.json5":"4a8598ab9bf6607c1ab389b74dd4753a36a31df93879c9ab6aed959cb36b9dce","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/oh-package.json5":"d88b8312eae1ab7dc655d34e352876a1eb87ab0fe512aff1a04498acb1ab051d","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/oh-package.json5":"6b911a31909105546015d359633369267c125b97a5d0f3b0dc3bcab12a08c9e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/oh-package.json5":"b8057721cf5c5fe8da4dab5d2d5e06d33b00d067411be974917ac552d2c0589c","/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/oh-package.json5":"88f9db9e1bf86367a620c95d302ded2bedc172a78ba9ebea6b09353a8ccde631","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/oh-package.json5":"bc1845dce5016980622f462664e167e3789359f8bafff276e6c3297fb23723e9","/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/oh-package.json5":"4673942b26a12891f0adc0c1d565477298a3989a4cc0a43ff6cbaa2950d453f2","/Users/gandanxiangzhao/Downloads/Expert/harmony/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/products/expert/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/uicomponents/oh_modules":false,"/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/utils/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/features/mypage/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/commons/basic/oh_modules":false,"/Users/gandanxiangzhao/Downloads/Expert/harmony/features/Home/oh_modules":true,"/Users/gandanxiangzhao/Downloads/Expert/harmony/features/register/oh_modules":true}} \ No newline at end of file diff --git a/commons/basic/src/main/ets/utils/request.ets b/commons/basic/src/main/ets/utils/request.ets index 453935f..b3abd2c 100644 --- a/commons/basic/src/main/ets/utils/request.ets +++ b/commons/basic/src/main/ets/utils/request.ets @@ -8,6 +8,7 @@ import { CryptoJS } from '@ohos/crypto-js' import { Base64Util } from './Base64Util'; import { ChangeUtil } from './ChangeUtil' import { BasicConstant } from '../constants/BasicConstant' +import image from '@ohos.multimedia.image'; interface HdRequestOptions { baseURL?: string @@ -175,7 +176,6 @@ class HdHttp { return this.request(url, http.RequestMethod.POST, data) } httpReq(url: string, datas: HashMap): Promise> { - // 创建httpRequest对象。 let httpRequest = http.createHttp(); let url1 = "https://dev-app.igandan.com/app/manager/getSystemTimeStamp"; @@ -204,29 +204,22 @@ class HdHttp { datas.set("client_type", 'A'); datas.set("version",'4.0.0' ); datas.set('timestamp',tp+''); - return this.posts(url, datas); - } - else - { + } else { return this.posts(url, datas); } } - ).catch((err:BusinessError) => { logger.info('Response httpReq error:' + JSON.stringify(err)); return Promise.reject(err); - }).finally(() => { httpRequest.destroy() }) - } - httpReqSimply(url: string) { + httpReqSimply(url: string) { // 创建httpRequest对象。 let httpRequest = http.createHttp(); - let promise = httpRequest.request( // 请求url地址 url, @@ -248,16 +241,14 @@ class HdHttp { const result = data.result as HdResponse return result } - ).catch((err:BusinessError) => { logger.info('Response httpReq error:' + JSON.stringify(err)); return Promise.reject(err); - }).finally(() => { httpRequest.destroy() }) - } + getSign(extraDatas1:HashMap): string { let secret= extraDatas1.get("timestamp") if(secret!=null) { @@ -275,14 +266,125 @@ class HdHttp { let Md5keyValueStr: string = CryptoJS.MD5(keyValueStr).toString(); let base64Str:string=Base64Util.encodeToStrSync(Md5keyValueStr); return base64Str; - } - else - { + } else { return ''; } - - } + + /** + * 上传图片方法 + * @param url 上传地址 + * @param imageUri 图片URI + * @param params 其他参数 + * @returns Promise> + */ + async uploadImage(url: string, imageUrl: string): Promise> { + 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(); + 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(url, hashMap); + } catch (error) { + logger.error('uploadImage error:' + JSON.stringify(error)); + promptAction.showToast({ message: '图片上传失败' }); + return Promise.reject(error); + } + } + + /** + * 将图片转换为base64字符串 + * @param imageUri 图片URI + * @returns Promise base64字符串 + */ + private async imageToBase64(imageUrl: string): Promise { + // 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: '' }) diff --git a/features/mypage/Index.ets b/features/mypage/Index.ets index c0b523b..851a54d 100644 --- a/features/mypage/Index.ets +++ b/features/mypage/Index.ets @@ -10,4 +10,6 @@ export { ChooseEmailComp } from './src/main/ets/view/ChooseEmailComp' export { ChooseOfficePhoneComp } from './src/main/ets/view/ChooseOfficePhoneComp' -export { EditUserDataComp } from './src/main/ets/view/EditUserDataComp' \ No newline at end of file +export { EditUserDataComp } from './src/main/ets/view/EditUserDataComp' + +export { SpecialitySelectedSheet } from './src/main/ets/view/SpecialitySelectedSheet' \ No newline at end of file diff --git a/features/mypage/src/main/ets/view/ChangePhoneComp.ets b/features/mypage/src/main/ets/view/ChangePhoneComp.ets index 1a96e93..fd69bb6 100644 --- a/features/mypage/src/main/ets/view/ChangePhoneComp.ets +++ b/features/mypage/src/main/ets/view/ChangePhoneComp.ets @@ -1,12 +1,59 @@ +import { hdHttp, HdResponse, BasicConstant, ExpertData, authStore } from '@itcast/basic' +import { BusinessError } from '@kit.BasicServicesKit'; 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 export struct ChangePhoneComp { @State phoneNumber: string = '' @State smsCode: string = '' @State countdown: number = 0 + uploadChangePhoneAction(){ + const hashMap: HashMap = new HashMap(); + hashMap.set('newMobile',this.phoneNumber) + hashMap.set('oldMobile',authStore.getUser().photo) + hashMap.set('sms',this.smsCode) + hdHttp.httpReq(BasicConstant.urlmyLan+'updateMobile',hashMap).then(async (res: HdResponse) => { + 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 = new HashMap(); + hashMap.set('type','6'); + hashMap.set('mobile',this.phoneNumber) + hdHttp.httpReq(BasicConstant.urlmyLan+'smsSend',hashMap).then(async (res: HdResponse) => { + 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() { this.countdown = 60 @@ -54,6 +101,9 @@ export struct ChangePhoneComp { TextInput({ placeholder: '请输入验证码' }) .fontSize(16) .backgroundColor(Color.White) + .onChange((value: string) => { + this.smsCode = value + }) } .margin({ top: 10 }) .width('60%') @@ -76,11 +126,15 @@ export struct ChangePhoneComp { .margin({ top: 10 }) .enabled(this.countdown === 0) .onClick(() => { - if (this.phoneNumber.length >= 11) { - this.startCountdown() - } else { + if (this.phoneNumber.length < 11 || !this.phoneNumber) { promptAction.showToast({message:'请输入手机号'}) + return } + if (!EMAIL_REGEX.test(this.phoneNumber)) { + promptAction.showToast({message:'请输入正确的手机号'}) + return + } + this.uploadSmsAction() }) } .width('95%') @@ -100,18 +154,19 @@ export struct ChangePhoneComp { .fontSize(18) .position({x:'5%',y:'80%'}) .onClick(() => { - // 处理登录逻辑 - if (!/^1[3-9]\d{9}$/.test(this.phoneNumber)) { - promptAction.showToast({message:'请输入有效手机号'}) + if (this.phoneNumber.length < 11 || !this.phoneNumber) { + promptAction.showToast({message:'请输入手机号'}) + return + } + if (!EMAIL_REGEX.test(this.phoneNumber)) { + promptAction.showToast({message:'请输入正确的手机号'}) return } - if (!this.smsCode) { - promptAction.showToast({message:'请输入验证码'}) + promptAction.showToast({message:'验证码不能为空'}) return } - - // 执行登录操作... + this.uploadChangePhoneAction(); }) } .width('100%') @@ -119,3 +174,6 @@ export struct ChangePhoneComp { .backgroundColor('#FFFFFF') } } + +// 手机正则表达式 +const EMAIL_REGEX = /^1[3-9][0-9]{9}$/ diff --git a/features/mypage/src/main/ets/view/ChooseEmailComp.ets b/features/mypage/src/main/ets/view/ChooseEmailComp.ets index e975252..130bbd8 100644 --- a/features/mypage/src/main/ets/view/ChooseEmailComp.ets +++ b/features/mypage/src/main/ets/view/ChooseEmailComp.ets @@ -1,10 +1,34 @@ +import { hdHttp, HdResponse, BasicConstant, ExpertData, authStore } from '@itcast/basic' +import { BusinessError } from '@kit.BasicServicesKit'; 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 export struct ChooseEmailComp { - @State phoneNumber: string = '' + @State emailString: string = '' @State countdown: number = 0 // 验证码倒计时 @@ -19,15 +43,43 @@ export struct ChooseEmailComp { }, 1000) } + commitEmailData(editEmail:string){ + const updateDataUrl:string = BasicConstant.urlExpert + 'modify'; + hdHttp.post(updateDataUrl, { + uuid: authStore.getUser().uuid, + userName: authStore.getUser().userName, + email: editEmail, + type:'2' + } as updateExtraData).then(async (res: HdResponse) => { + 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() { Column() { // 手机号输入框 Row() { TextInput({ placeholder: authStore.getUser().email.length>0?authStore.getUser().email:'请输入您的邮箱' }) .fontSize(16) + .contentType(ContentType.EMAIL_ADDRESS) .backgroundColor(Color.White) .onChange((value: string) => { - this.phoneNumber = value + this.emailString = value }) } .margin({ top: 10 }) @@ -62,13 +114,11 @@ export struct ChooseEmailComp { .fontSize(18) .position({x:'5%',y:'80%'}) .onClick(() => { - // 处理登录逻辑 - if (!/^1[3-9]\d{9}$/.test(this.phoneNumber)) { - promptAction.showToast({message:'请输入有效手机号'}) - return - } - - // 执行登录操作... + // if (this.validateEmailFormat(this.emailString)) { + // promptAction.showToast({message:'请输入正确的邮箱格式'}) + // return + // } + this.commitEmailData(this.emailString); }) } .width('100%') @@ -76,3 +126,6 @@ export struct ChooseEmailComp { .backgroundColor('#FFFFFF') } } + +// 邮箱正则表达式 +const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; diff --git a/features/mypage/src/main/ets/view/ChooseOfficePhoneComp.ets b/features/mypage/src/main/ets/view/ChooseOfficePhoneComp.ets index 9dc5291..e3e4fa4 100644 --- a/features/mypage/src/main/ets/view/ChooseOfficePhoneComp.ets +++ b/features/mypage/src/main/ets/view/ChooseOfficePhoneComp.ets @@ -1,23 +1,58 @@ +import { hdHttp, HdResponse, BasicConstant, ExpertData, authStore } from '@itcast/basic' +import { BusinessError } from '@kit.BasicServicesKit'; 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 export struct ChooseOfficePhoneComp { - @State phoneNumber: string = '' - @State smsCode: string = '' + @State officePhoneStr: string = '' @State countdown: number = 0 - // 验证码倒计时 - private startCountdown() { - this.countdown = 60 - const timer = setInterval(() => { - if (this.countdown > 0) { - this.countdown-- + commitOfficePhoneData(officePhoneStr:string){ + const updateDataUrl:string = BasicConstant.urlExpert + 'modify'; + hdHttp.post(updateDataUrl, { + uuid: authStore.getUser().uuid, + userName: authStore.getUser().userName, + officePhone: this.officePhoneStr, + type:'2' + } as updateExtraData).then(async (res: HdResponse) => { + 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 { - clearInterval(timer) + console.error('更新用户办公室电话失败:'+json.message) + promptAction.showToast({ message: json.message, duration: 1000 }) } - }, 1000) + }).catch((err: BusinessError) => { + console.info(`更新用户办公室电话请求失败: ${err}`); + }) } build() { @@ -28,7 +63,7 @@ export struct ChooseOfficePhoneComp { .fontSize(16) .backgroundColor(Color.White) .onChange((value: string) => { - this.phoneNumber = value + this.officePhoneStr = value }) } .margin({ top: 10 }) @@ -64,15 +99,11 @@ export struct ChooseOfficePhoneComp { .position({x:'5%',y:'80%'}) .onClick(() => { // 处理登录逻辑 - if (!/^1[3-9]\d{9}$/.test(this.phoneNumber)) { + if (!/^1[3-9]\d{9}$/.test(this.officePhoneStr)) { promptAction.showToast({message:'请输入有效手机号'}) return } - - if (!this.smsCode) { - promptAction.showToast({message:'请输入验证码'}) - return - } + this.commitOfficePhoneData(this.officePhoneStr); // 执行登录操作... }) diff --git a/features/mypage/src/main/ets/view/DatePickerDialog.ets b/features/mypage/src/main/ets/view/DatePickerDialog.ets index 39b2e7c..3ce28ff 100644 --- a/features/mypage/src/main/ets/view/DatePickerDialog.ets +++ b/features/mypage/src/main/ets/view/DatePickerDialog.ets @@ -1,4 +1,5 @@ import { formatDate } from '../util/DateUtils' +import { authStore } from '@itcast/basic' @CustomDialog export struct DatePickerDialog { @@ -18,7 +19,8 @@ export struct DatePickerDialog { // 初始化日期范围(示例为1930-至今) private dateOptions: DatePickerOptions = { 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() { diff --git a/features/mypage/src/main/ets/view/EditUserDataComp.ets b/features/mypage/src/main/ets/view/EditUserDataComp.ets index f1273e2..546a3b7 100644 --- a/features/mypage/src/main/ets/view/EditUserDataComp.ets +++ b/features/mypage/src/main/ets/view/EditUserDataComp.ets @@ -7,17 +7,38 @@ import { PhotoActionSheet } from './PhotoActionSheet' import { DatePickerDialog } from './DatePickerDialog' import { OfficeSelectedSheet } from './OfficeSelectedSheet' import { PositionSelectedSheet } from './PositionSelectedSheet' +import { SpecialitySelectedSheet } from './SpecialitySelectedSheet' import { http } from '@kit.NetworkKit'; interface extraData { 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 { expert:ExpertData, code:number, message:string, - specialy:[] + specialy:[], + data:ExpertData, + special:[] +} + +interface UploadAvatarResponse { + url:string; + uploadAvatarUrl:string, } @Component @@ -38,11 +59,14 @@ export struct EditUserDataComp { @State diseaseName:string = ''; @State intro:string = authStore.getUser().intro; + @State updateDataUrl:string = BasicConstant.urlExpert + 'modify'; + private photoSheetDialog!: CustomDialogController; private datePickerDialog!: CustomDialogController; private officePickerDialog!: CustomDialogController; private positionPickerDialog!: CustomDialogController; private certificatePhotoSheetDialog!: CustomDialogController; + private diseaseSheetDialog!:CustomDialogController; aboutToAppear() { this.initPhotoDialog(); @@ -50,15 +74,18 @@ export struct EditUserDataComp { this.initOfficePickerDialog(); this.initPositionPickerDialog(); this.initCerficatePhotoDialog(); - + this.initDiseaseSheetDIalog(); this.uploadUserDataAction(); console.log('用户资料:'+authStore.getUser().specialy); } + // 添加public修饰符暴露方法 + public refreshData() { + this.uploadUserDataAction(); + } + uploadUserDataAction() { - const hashMap: HashMap = new HashMap(); const userDataUrl:string = BasicConstant.urlExpert+'getExpertByUuid'; - hashMap.set('uuid',authStore.getUser().uuid) hdHttp.post(userDataUrl, { uuid: authStore.getUser().uuid, } as extraData).then(async (res: HdResponse) => { @@ -96,9 +123,28 @@ export struct EditUserDataComp { this.photoSheetDialog = new CustomDialogController({ builder: PhotoActionSheet({ controller: this.photoSheetDialog, - onPhotoSelected: (uri: string) => { - this.photoPath = uri; - console.log('Selected image URI:', uri); + onPhotoSelected: async (url: string) => { + this.photoPath = url; + console.log('Selected image URI:', url); + try { + promptAction.showToast({ message: '正在上传图片...', duration: 2000 }); + // 调用上传方法,使用明确的返回类型 + const response = await hdHttp.uploadImage( + 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, @@ -115,7 +161,26 @@ export struct EditUserDataComp { controller:this.officePickerDialog, officeSelected: (name:string , uuid:string) => { this.officeName = name; - } + hdHttp.post(this.updateDataUrl, { + uuid: authStore.getUser().uuid, + userName: authStore.getUser().userName, + officeName: name, + officeUuid:uuid, + type:'2' + } as updateExtraData).then(async (res: HdResponse) => { + 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, @@ -131,6 +196,24 @@ export struct EditUserDataComp { controller:this.officePickerDialog, officeSelected: (name:string , uuid:string) => { this.positionName = name; + hdHttp.post(this.updateDataUrl, { + uuid: authStore.getUser().uuid, + userName: authStore.getUser().userName, + positionUuid: uuid, + type:'2' + } as updateExtraData).then(async (res: HdResponse) => { + 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, @@ -147,6 +230,24 @@ export struct EditUserDataComp { controller:this.datePickerDialog, dateSelected:(date:string) => { this.birthday = date; + hdHttp.post(this.updateDataUrl, { + uuid: authStore.getUser().uuid, + userName: authStore.getUser().userName, + birthDate: date, + type:'2' + } as updateExtraData).then(async (res: HdResponse) => { + 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, @@ -161,9 +262,9 @@ export struct EditUserDataComp { this.certificatePhotoSheetDialog = new CustomDialogController({ builder: PhotoActionSheet({ controller: this.certificatePhotoSheetDialog, - onPhotoSelected: (uri: string) => { - this.certificatePhoto = uri; - console.log('Selected image URI:', uri); + onPhotoSelected: (url: string) => { + this.certificatePhoto = url; + console.log('Selected image URI:', url); } }), 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(this.updateDataUrl, { + uuid: authStore.getUser().uuid, + userName: authStore.getUser().userName, + diseaseUuids: diseaseUuids, + type:'2' + } as updateExtraData).then(async (res: HdResponse) => { + 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() { Scroll() { Column() { @@ -199,7 +333,12 @@ export struct EditUserDataComp { EditUserDataItem({ label: '手机号码', required: true, content: this.phone , hasArrow: true}) .onClick(()=>{ router.pushUrl({ - url:'pages/MinePage/ChangePhonePage' + url:'pages/MinePage/ChangePhonePage', + params:{ + onBack:()=>{ + this.uploadUserDataAction(); + } + } }) }) EditUserDataItem({ label: '邮箱', content: this.email , hasArrow: true}) @@ -239,6 +378,7 @@ export struct EditUserDataComp { EditUserDataItem({ label: '执业医师证图片或胸牌', required: true, content: this.certificatePhoto }) .onClick(()=>this.certificatePhotoSheetDialog.open()) EditUserDataItem({ label: '专长', required: true, content: this.diseaseName , hasArrow: true}) + .onClick(()=>this.diseaseSheetDialog.open()) EditUserDataItem({ label: '个人简介', content: this.intro, hasArrow: true }) .onClick(()=>{ router.pushUrl({ diff --git a/features/mypage/src/main/ets/view/OfficeSelectedSheet.ets b/features/mypage/src/main/ets/view/OfficeSelectedSheet.ets index 36651b8..2baba98 100644 --- a/features/mypage/src/main/ets/view/OfficeSelectedSheet.ets +++ b/features/mypage/src/main/ets/view/OfficeSelectedSheet.ets @@ -2,6 +2,7 @@ import { hdHttp, HdResponse,BasicConstant, logger,RequestDefaultModel, Data } f import { promptAction } from '@kit.ArkUI' import HashMap from '@ohos.util.HashMap'; import { BusinessError } from '@kit.BasicServicesKit'; +import { authStore } from '@itcast/basic' interface DefaultData { 'officeName':string; @@ -16,6 +17,8 @@ export struct OfficeSelectedSheet { @Prop selectedOffice:object = new Object; @State selectedModel:DefaultData = { officeName: '', officeUuid: '' }; + @State selectedIndex:number = 0; + // 添加回调函数属性 private officeSelected: (name:string , uuid:string) => void = () => {}; @@ -35,19 +38,23 @@ export struct OfficeSelectedSheet { uploadOffice() { hdHttp.httpReq(this.officeRequestUrl,this.hashMap).then(async (res: HdResponse) => { - logger.info('Response officelist success'+res); - console.info(`Response officelist succeeded: ${res}`); let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel; if(json.code=='1') { this.officeArr = json.data as DefaultData[]; this.officeNameArr = json.data.map(item => item.officeName); 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 { console.error('科室数据失败:'+json.message) promptAction.showToast({ message: json.message, duration: 1000 }) } }).catch((err: BusinessError) => { - console.info(`Response login fail: ${err}`); + console.info(`Response fail: ${err}`); }) } @@ -83,7 +90,8 @@ export struct OfficeSelectedSheet { .height(40) TextPicker({ - range:this.officeNameArr + range:this.officeNameArr, + selected:this.selectedIndex }) .selectedTextStyle({ color: '#007AFF', diff --git a/features/mypage/src/main/ets/view/PositionSelectedSheet.ets b/features/mypage/src/main/ets/view/PositionSelectedSheet.ets index e4f6ea3..29eb919 100644 --- a/features/mypage/src/main/ets/view/PositionSelectedSheet.ets +++ b/features/mypage/src/main/ets/view/PositionSelectedSheet.ets @@ -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 HashMap from '@ohos.util.HashMap'; import { BusinessError } from '@kit.BasicServicesKit'; +import { authStore } from '@itcast/basic' interface DefaultData { 'name':string; @@ -16,6 +17,8 @@ export struct PositionSelectedSheet { @Prop selectedOffice:object = new Object; @State selectedModel:DefaultData = { name: '', uuid: '' }; + @State selectedIndex:number = 0; + // 添加回调函数属性 private officeSelected: (name:string , uuid:string) => void = () => {}; @@ -35,19 +38,23 @@ export struct PositionSelectedSheet { uploadOffice() { hdHttp.httpReq(this.officeRequestUrl,this.hashMap).then(async (res: HdResponse) => { - logger.info('Response officelist success'+res); - console.info(`Response officelist succeeded: ${res}`); let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel; if(json.code=='1') { this.officeArr = json.data as DefaultData[]; 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); } else { console.error('职称数据失败:'+json.message) promptAction.showToast({ message: json.message, duration: 1000 }) } }).catch((err: BusinessError) => { - console.info(`Response login fail: ${err}`); + console.info(`Response fail: ${err}`); }) } @@ -83,7 +90,8 @@ export struct PositionSelectedSheet { .height(40) TextPicker({ - range:this.officeNameArr + range:this.officeNameArr, + selected:this.selectedIndex }) .selectedTextStyle({ color: '#007AFF', diff --git a/features/mypage/src/main/ets/view/SpecialitySelectedSheet.ets b/features/mypage/src/main/ets/view/SpecialitySelectedSheet.ets new file mode 100644 index 0000000..3d61835 --- /dev/null +++ b/features/mypage/src/main/ets/view/SpecialitySelectedSheet.ets @@ -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 = []; + @State specialityNameArr:Array = []; + @State selectedTags: Array = []; + + // 添加回调函数属性 + 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 = new HashMap(); + hdHttp.httpReq(officeRequestUrl,hashMap).then(async (res: HdResponse) => { + 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) + } +} diff --git a/products/expert/src/main/ets/pages/MinePage/EditUserDataPage.ets b/products/expert/src/main/ets/pages/MinePage/EditUserDataPage.ets index c2fd0e7..84e6e41 100644 --- a/products/expert/src/main/ets/pages/MinePage/EditUserDataPage.ets +++ b/products/expert/src/main/ets/pages/MinePage/EditUserDataPage.ets @@ -4,10 +4,17 @@ import { EditUserDataComp } from 'mypage' @Entry @Component struct EditUserDataPage { + // 使用$符号引用子组件 + @State editUserDataCompRef: EditUserDataComp | null = null; + + onPageShow(): void { + this.editUserDataCompRef?.refreshData(); + } + build() { Column(){ HdNav({ title: '个人资料', showRightIcon: false, hasBorder: true }); - EditUserDataComp(); + EditUserDataComp() } } } \ No newline at end of file