feat(api): 升级 HaveADrink 依赖并实现用户头像上传功能

- 将 HaveADrink 依赖从 1.0.15 升级至 1.0.16 版本
- 新增 UpdateUserAvatar API 接口用于更新用户头像
- 添加 isValidAvatar 工具函数验证头像 URL 有效性
- 在登录流程中集成头像上传逻辑,支持微信头像选择
- 更新多个组件中的头像显示逻辑,过滤无效头像地址
- 优化 tabBar 主题应用逻辑,修复异步错误处理问题
- 修复微信新规范下头像选择的临时路径处理机制
This commit is contained in:
cg
2026-08-16 22:19:10 +08:00
parent 81e7a3afa5
commit 019262289c
15 changed files with 269 additions and 39 deletions
+32 -2
View File
@@ -15,6 +15,15 @@ export function isIconPath(val) {
return typeof val === 'string' && val.charAt(0) === '/'
}
/**
* 判断头像地址是否可用
* wxfile://tmp_ 等本地临时路径仅本机当次有效,不能用于展示他人头像,
* 展示层对此类地址应回退为占位头像
*/
export function isValidAvatar(url) {
return typeof url === 'string' && /^https?:\/\//.test(url)
}
/**
* 标准杯换算引擎
* 核心公式: 标准杯 = (饮用量ml × 酒精度数% × 0.8) / 10
@@ -303,7 +312,25 @@ export function applyNavBarTheme(theme) {
export function applyTabBarTheme(theme) {
// 仅在 tabBar 页面上调用 setTabBarStyle,避免报错
const tabBarPages = ['pages/index/index', 'pages/profile/profile']
// 页面清单直接从 pages.json 读取,新增 tab 页无需改这里
let tabBarPages = []
try {
// #ifdef MP-WEIXIN
tabBarPages = (typeof __wxConfig !== 'undefined' && __wxConfig.tabBar && __wxConfig.tabBar.list)
? __wxConfig.tabBar.list.map(t => t.pagePath)
: []
// #endif
if (!tabBarPages.length && typeof require === 'function') {
const cfg = require('../pages.json')
tabBarPages = (cfg.tabBar && cfg.tabBar.list) ? cfg.tabBar.list.map(t => t.pagePath) : []
}
} catch (e) {
tabBarPages = []
}
// 两种方式都取不到清单时兜底,保证主题正常应用
if (!tabBarPages.length) {
tabBarPages = ['pages/index/index', 'pages/circle/circle', 'pages/profile/profile']
}
const pages = getCurrentPages()
if (!pages.length) return
const currentPath = pages[pages.length - 1].route
@@ -329,7 +356,10 @@ export function applyTabBarTheme(theme) {
color: s.color,
selectedColor: s.selectedColor,
backgroundColor: s.backgroundColor,
borderStyle: s.borderStyle
borderStyle: s.borderStyle,
// 必须传 fail 回调吞错:不传时 uni API 返回 Promise,
// 异步 reject 无法被 try/catch 捕获,会产生 UnhandledPromiseRejection
fail: () => {}
})
} catch (e) {}
}