From 5fa80e7c0064c5d30f8e7d793cde24e5086b48f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=B9=E6=9E=9C=E7=94=B5=E8=84=91?= Date: Wed, 23 Jul 2025 19:49:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B9=E6=9E=9C=E7=9A=84=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +- src/api/login.js | 142 ++++++++++---- src/pages/me/index.vue | 19 +- src/pages/setting/index.vue | 4 +- src/pages/test/index - 副本.vue | 183 +++++++++++++++--- src/pages/test/index.vue | 325 ++++++++++++++++---------------- 6 files changed, 431 insertions(+), 246 deletions(-) diff --git a/.env.development b/.env.development index 0f91d31d..a4dcf52c 100644 --- a/.env.development +++ b/.env.development @@ -9,7 +9,7 @@ ENV = 'development' # VITE_APP_BASE_API_Url = 'http://25.18.122.78:9786' # DEV -VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001' +VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002' # app入口 #VITE_APP_BASE_API_Url = 'http://25.16.122.65:7001' @@ -17,4 +17,4 @@ VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001' #VITE_APP_BASE_API_Url = 'http://25.18.122.66:9786' # h5专用地址 -VITE_APP_BASE_H5_API_Url = 'http://aitstest.jlbank.com.cn:7001' \ No newline at end of file +VITE_APP_BASE_H5_API_Url = 'http://aitstest.jlbank.com.cn:7002' \ No newline at end of file diff --git a/src/api/login.js b/src/api/login.js index fa52f126..020ae326 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -119,51 +119,111 @@ export const queryCurrentUser = (data) => request({ const base_url = get_base_url() // 预加载头像 // #ifdef APP-PLUS + // 更新用户信息中的头像路径 const updateUserAvatar = (imagePath) => { - const userInfo = getUserInfo() - setUserInfo({ - ...userInfo, - 'imagePath': imagePath - }) + const userInfo = getUserInfo() + setUserInfo({ + ...userInfo, + 'imagePath': imagePath + }) } - - try { - const pathName = res.body.imageAddr - const url = base_url + pathName - // 生成唯一文件名,避免冲突 - const filename = pathName.split('/').pop() - const localFilePath = '_downloads/' + filename - console.log('localFilePath', localFilePath, url); - // 先检查是否存在 - uni.getFileInfo({ - filePath: localFilePath, - success: () => { - console.log('头像已存在,无需下载'); - updateUserAvatar(localFilePath) - }, - fail: () => { - console.log('开始下载头像:', url); - const dtask = plus.downloader.createDownload( - url, { - method: 'GET', - filename: '_downloads/' + filename - }, - (download, status) => { - if (status === 200) { - console.log('头像下载成功:', download.filename); - updateUserAvatar(download.filename) - } - } - ) - dtask.start(); - } - }) - - - } catch (error) { - console.error('头像预加载过程发生错误:', error); + + // 确保目录存在 + const ensureDirectoryExists = (dirPath) => { + return new Promise((resolve) => { + plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => { + fs.root.getDirectory(dirPath, { create: true }, resolve, resolve) + }) + }) } + + // 生成唯一文件名 + const generateUniqueFilename = (pathName) => { + if (!pathName || typeof pathName !== 'string') { + throw new Error('无效的头像路径'); + } + + // 直接使用原始文件名(带扩展名) + const filename = pathName.split('/').pop(); + + if (!filename) { + throw new Error('无法从路径中提取文件名'); + } + + // 确保文件扩展名为.png (可选,根据实际需求) + const ext = filename.split('.').pop().toLowerCase(); + if (ext === 'png' || ext === 'jpg' || ext === 'jpeg' || ext === 'webp') { + return filename; + } + + // 如果没有有效扩展名,添加.png + return `${filename}.png`; + }; + + // 下载并保存头像 + const downloadAndSaveAvatar = async (fileUrl, localFilePath) => { + try { + await ensureDirectoryExists('avatar') + + return new Promise((resolve, reject) => { + console.log('开始下载头像:', fileUrl) + const dtask = plus.downloader.createDownload(fileUrl, { + filename: localFilePath + }, (d, status) => { + if (status === 200) { + console.log("保存路径:", d.filename) + resolve(d.filename) + } else { + console.error("文件下载失败:", status) + reject(new Error(`下载失败,状态码: ${status}`)) + } + }) + + dtask.start() + }) + } catch (error) { + console.error('创建目录失败:', error) + throw error + } + } + + // 检查文件是否存在 + const checkFileExists = (filePath) => { + return new Promise((resolve) => { + uni.getFileInfo({ + filePath, + success: () => resolve(true), + fail: () => resolve(false) + }) + }) + } + + // 主逻辑 + (async () => { + try { + const pathName = res.body.imageAddr + const fileUrl = base_url + pathName + + // 生成保存路径 + const filename = generateUniqueFilename(pathName) + const localFilePath = '_doc/avatar/' + filename + + // 检查文件是否存在 + const exists = await checkFileExists(localFilePath) + + if (exists) { + console.log('头像已存在,无需下载') + updateUserAvatar(localFilePath) + } else { + const savedPath = await downloadAndSaveAvatar(fileUrl, localFilePath) + updateUserAvatar(savedPath) + } + } catch (error) { + console.error('头像预加载过程发生错误:', error) + } + })() // #endif + return res.body }) diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index ca39711f..6fec5c48 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -8,9 +8,9 @@ - - + + + @@ -192,7 +192,6 @@ } } }); - const user_info = reactive({ userName: '', userId: '', @@ -220,10 +219,7 @@ }; onShow(() => { setMascot() - - const user_info_cache = getUserInfo(); - Object.assign(user_info, user_info_cache); - console.log('user_info', user_info); + Object.assign(user_info, getUserInfo()); statistics_data['get_statistics_data'](); // 获取统计数据 }); onPullDownRefresh(() => { @@ -266,11 +262,10 @@ await updateDfSysUserExtandInfoImageAddr({imageAddr : res.thumbFileId}) // 更新个人信息 const userData = await queryCurrentUser() - console.log('userData', ); + console.log('userData', userData); common.msg('修改成功') - - user_info.imageAddr = getUserInfo('imageAddr') - user_info.imagePath = getUserInfo('imagePath') + user_info.imageAddr = userData.imageAddr + user_info.imagePath = '' } catch { common.msg('修改失败') } diff --git a/src/pages/setting/index.vue b/src/pages/setting/index.vue index 0417c374..f6794230 100644 --- a/src/pages/setting/index.vue +++ b/src/pages/setting/index.vue @@ -151,8 +151,8 @@ // 更新个人信息 const userData = await queryCurrentUser() common.msg('修改成功') - userInfo.value.imageAddr = getUserInfo('imageAddr') - userInfo.value.imagePath = getUserInfo('imagePath') + userInfo.value.imageAddr = userData.imageAddr + userInfo.value.imagePath = '' } catch { common.msg('修改失败') } diff --git a/src/pages/test/index - 副本.vue b/src/pages/test/index - 副本.vue index df2af06d..b5f2b3b1 100644 --- a/src/pages/test/index - 副本.vue +++ b/src/pages/test/index - 副本.vue @@ -1,46 +1,169 @@ + + .title { + color: #000000; + font-size: 34rpx; + height: 34rpx; + font-weight: 600; + // margin-bottom: 30rpx; + line-height: 34rpx; + } + + .fixed_search_div { + padding: calc(10rpx + var(--status-bar-height)) 15rpx 24rpx 30rpx; + display: flex; + align-items: center; + background-color: #f6f7f8; + + .back_div { + margin-right: 10rpx; + + .back-icon { + position: relative; + width: 40rpx; + height: 40rpx; + cursor: pointer; + display: flex; + align-items: center; + } + + .back-icon::before, + .back-icon::after { + content: ''; + position: absolute; + transition: all 0.3s ease; + } + + .back-icon::after { + top: 25%; + left: 25%; + width: 40%; + height: 40%; + border-top: 4rpx solid #2b2c2e; + border-left: 4rpx solid #2b2c2e; + transform: rotate(-45deg); + } + } + } + \ No newline at end of file diff --git a/src/pages/test/index.vue b/src/pages/test/index.vue index b5f2b3b1..59472610 100644 --- a/src/pages/test/index.vue +++ b/src/pages/test/index.vue @@ -1,169 +1,176 @@ - - \ No newline at end of file + + \ No newline at end of file