From 019262289c7bb7c685e536987420a8a6728f6fcd Mon Sep 17 00:00:00 2001
From: cheng <545895878@qq.com>
Date: Sun, 16 Aug 2026 22:19:10 +0800
Subject: [PATCH] =?UTF-8?q?feat(api):=20=E5=8D=87=E7=BA=A7=20HaveADrink=20?=
=?UTF-8?q?=E4=BE=9D=E8=B5=96=E5=B9=B6=E5=AE=9E=E7=8E=B0=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 将 HaveADrink 依赖从 1.0.15 升级至 1.0.16 版本
- 新增 UpdateUserAvatar API 接口用于更新用户头像
- 添加 isValidAvatar 工具函数验证头像 URL 有效性
- 在登录流程中集成头像上传逻辑,支持微信头像选择
- 更新多个组件中的头像显示逻辑,过滤无效头像地址
- 优化 tabBar 主题应用逻辑,修复异步错误处理问题
- 修复微信新规范下头像选择的临时路径处理机制
---
common/api.js | 6 +++
common/utils.js | 34 +++++++++++++-
components/CommentItem.vue | 7 ++-
components/FeedCard.vue | 5 ++-
components/FriendItem.vue | 9 +++-
node_modules/.package-lock.json | 6 +--
node_modules/HaveADrink/README.md | 31 ++++++++++++-
node_modules/HaveADrink/index.d.ts | 56 +++++++++++++++++++++++
node_modules/HaveADrink/index.js | 64 ++++++++++++++++++++++++++
node_modules/HaveADrink/package.json | 2 +-
package-lock.json | 8 ++--
package.json | 2 +-
pages/chat-list/chat-list.vue | 4 +-
pages/login/login.vue | 67 ++++++++++++++++++++--------
pages/profile/profile.vue | 7 +--
15 files changed, 269 insertions(+), 39 deletions(-)
diff --git a/common/api.js b/common/api.js
index 66f8a8f..01fdcd5 100644
--- a/common/api.js
+++ b/common/api.js
@@ -336,3 +336,9 @@ export async function UploadImage({ filePath }) {
const res = await client.UploadImage({ image: filePath })
return { data: res }
}
+
+/** 更新当前用户头像(avatar 必须是上传后的 http(s) 远程地址,需 token) */
+export async function UpdateUserAvatar({ avatar }) {
+ const res = await client.UpdateUserAvatar({ avatar })
+ return { data: res }
+}
diff --git a/common/utils.js b/common/utils.js
index b83735e..6c67fc6 100644
--- a/common/utils.js
+++ b/common/utils.js
@@ -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) {}
}
diff --git a/components/CommentItem.vue b/components/CommentItem.vue
index 0524f32..9e4e9a0 100644
--- a/components/CommentItem.vue
+++ b/components/CommentItem.vue
@@ -1,7 +1,7 @@
diff --git a/components/FeedCard.vue b/components/FeedCard.vue
index be9cc92..4794f6c 100644
--- a/components/FeedCard.vue
+++ b/components/FeedCard.vue
@@ -3,7 +3,7 @@