From 4e7dd994b4818ebc0760b2762c02cd0c28bb5d1e Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Fri, 6 Jun 2025 21:59:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(index.vue):=20=E4=BF=AE=E6=94=B9toast?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=96=B9=E6=B3=95=EF=BC=8C=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=BD=BF=E7=94=A8toast.show?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/mine/index.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/mine/index.vue b/src/pages/mine/index.vue index c22773c..714fcff 100644 --- a/src/pages/mine/index.vue +++ b/src/pages/mine/index.vue @@ -162,7 +162,7 @@ const handlePassword = () => { // 消息通知 const handleInform = () => { // uni.navigateTo({ url: `/pages/mine/inform/index` }) - toast.success('功能开发中') + toast.show('功能开发中') } // 应用更新 const handleAppUpdate = () => { @@ -173,9 +173,9 @@ const handleAppUpdate = () => { // 请求完新版本信息的回调 // console.log(res.hasUpdate) if (res.hasUpdate) { - toast.success('检测到新版本,正在下载中...') + toast.show('检测到新版本,正在下载中...') } else { - toast.success('已是最新版本') + toast.show('已是最新版本') } }) updateManager.onUpdateReady(function (res) { @@ -198,7 +198,7 @@ const handleAppUpdate = () => { // #endif // #ifndef MP - toast.success('功能开发中') + toast.show('功能开发中') // #endif } // 关于我们 @@ -217,7 +217,7 @@ const handleClearCache = () => { uni.clearStorageSync() // 清除用户信息并跳转到登录页 useUserStore().logout() - toast.success('清除缓存成功') + toast.show('清除缓存成功') } catch (err) { console.error('清除缓存失败:', err) toast.error('清除缓存失败') @@ -237,7 +237,7 @@ const handleLogout = () => { useUserStore().logout() hasLogin.value = false // 执行退出登录逻辑 - toast.success('退出登录成功') + toast.show('退出登录成功') // #ifdef MP-WEIXIN // 微信小程序,去首页 // uni.reLaunch({ url: '/pages/index/index' }) From b5a71b7788be7c8928d865e4c8d0699d4eacbdcb Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Fri, 6 Jun 2025 22:31:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(useUpload):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81H5=E5=92=8C=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useUpload.ts | 43 +++++++++++++++++++++++++--------------- src/pages/mine/index.vue | 7 +++++-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/hooks/useUpload.ts b/src/hooks/useUpload.ts index 8a94ecd..7a45163 100644 --- a/src/hooks/useUpload.ts +++ b/src/hooks/useUpload.ts @@ -36,7 +36,21 @@ export default function useUpload(options: TOptions = {} const chooseFileOptions = { count: 1, success: (res: any) => { - handleFileChoose({ tempFilePath: res.tempFilePaths[0], tempFiles: res.tempFiles[0] }) + console.log('File selected successfully:', res) + // h5中res:{errMsg: "chooseImage:ok", tempFilePaths: "blob:http://localhost:9000/f74ab6b8-a14d-4cb6-a10d-fcf4511a0de5", tempFiles: [File]} + // h5的File有一下字段:{name: "girl.jpeg", size: 48976, type: "image/jpeg"} + // 小程序中res:{errMsg: "chooseImage:ok", tempFiles: [{fileType: "image", size: 48976, tempFilePath: "http://tmp/5iG1WpIxTaJf3ece38692a337dc06df7eb69ecb49c6b.jpeg"}]} + let tempFilePath = '' + let size = 0 + // #ifdef H5 + tempFilePath = res.tempFilePaths[0] + size = res.tempFiles[0].size + // #endif + // #ifdef MP-WEIXIN + tempFilePath = res.tempFiles[0].tempFilePath + size = res.tempFiles[0].size + // #endif + handleFileChoose({ tempFilePath, size }) }, fail: (err: any) => { console.error('File selection failed:', err) @@ -64,11 +78,8 @@ export default function useUpload(options: TOptions = {} } } - const handleFileChoose = (file: { - tempFilePath: string - tempFiles?: { size?: number; name?: string } - }) => { - if (file?.tempFiles?.size && file.tempFiles.size > maxSize) { + const handleFileChoose = ({ tempFilePath, size }: { tempFilePath: string; size: number }) => { + if (size > maxSize) { uni.showToast({ title: `文件大小不能超过 ${maxSize / 1024 / 1024}MB`, icon: 'none', @@ -76,20 +87,20 @@ export default function useUpload(options: TOptions = {} return } - const fileExtension = file?.tempFiles?.name?.split('.').pop()?.toLowerCase() - const isTypeValid = accept.some((type) => type === '*' || type.toLowerCase() === fileExtension) + // const fileExtension = file?.tempFiles?.name?.split('.').pop()?.toLowerCase() + // const isTypeValid = accept.some((type) => type === '*' || type.toLowerCase() === fileExtension) - if (!isTypeValid) { - uni.showToast({ - title: `仅支持 ${accept.join(', ')} 格式的文件`, - icon: 'none', - }) - return - } + // if (!isTypeValid) { + // uni.showToast({ + // title: `仅支持 ${accept.join(', ')} 格式的文件`, + // icon: 'none', + // }) + // return + // } loading.value = true uploadFile({ - tempFilePath: file.tempFilePath, + tempFilePath: tempFilePath, formData, onSuccess: (res) => { data.value = res diff --git a/src/pages/mine/index.vue b/src/pages/mine/index.vue index 714fcff..b9d9e69 100644 --- a/src/pages/mine/index.vue +++ b/src/pages/mine/index.vue @@ -134,10 +134,13 @@ const onChooseAvatar = (e: any) => { console.log('选择头像', e.detail) const { avatarUrl } = e.detail const { run } = useUpload( - uploadFileUrl.USER_AVATAR, + import.meta.env.VITE_UPLOAD_BASEURL, {}, { - onSuccess: (res) => useUserStore().getUserInfo(), + onSuccess: (res) => { + console.log('头像上传成功', res) + // 更新用户信息 + }, }, avatarUrl, ) From 008a1cc58a26a9c3da8213d94af5d9c0e0c4678b Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Fri, 6 Jun 2025 22:38:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix(upload):=20=E6=9B=B4=E6=96=B0=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E4=B8=8A=E4=BC=A0=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9C=B0=E5=9D=80=EF=BC=8C=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=9B=9E=E8=B0=83=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/mine/index.vue | 9 ++++++--- src/store/user.ts | 4 ++++ src/utils/uploadFile.ts | 20 +++++++------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/pages/mine/index.vue b/src/pages/mine/index.vue index b9d9e69..9bcd6b8 100644 --- a/src/pages/mine/index.vue +++ b/src/pages/mine/index.vue @@ -88,7 +88,7 @@