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 @@ - + {{ feed.nickname ? feed.nickname[0] : '酒' }} @@ -67,7 +67,7 @@ diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index bbad5d6..1dc2c4e 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -4,9 +4,9 @@ "requires": true, "packages": { "node_modules/HaveADrink": { - "version": "1.0.15", - "resolved": "https://npm.wash-painting.cn/HaveADrink/-/HaveADrink-1.0.15.tgz", - "integrity": "sha512-ZKgrIKuwXXuKRY2D34FRNUwlr1Y4bAUtXwrjpoHwLPa30KNGVvuXhfYvxAWf5cDvTJw3b/lm8JSSYwCqcIZ3Bw==", + "version": "1.0.16", + "resolved": "https://npm.wash-painting.cn/HaveADrink/-/HaveADrink-1.0.16.tgz", + "integrity": "sha512-NKaV3AZHHVYT23Eo4WGTzZ7H+FVfQoHa8EE3k5SnHCi9yxGAxnExBqRYde5AEFI1pJNe7OzqzbxAykxN757LXQ==", "license": "ISC" } } diff --git a/node_modules/HaveADrink/README.md b/node_modules/HaveADrink/README.md index c378baf..d994092 100644 --- a/node_modules/HaveADrink/README.md +++ b/node_modules/HaveADrink/README.md @@ -14,7 +14,7 @@ * 6. 社交模块 - 朋友圈动态、点赞 -**版本:** v1.0.15 +**版本:** v1.0.16 ## 安装 @@ -355,6 +355,7 @@ client.GetFeed(req).then(...).catch(...) ### 上传照片 +**已废弃:** 请使用 upload.api 上传照片 POST `/api/have_a_drink/v1/photo/upload/photo` @@ -382,6 +383,7 @@ client.UploadPhoto(req).then(...).catch(...) ### 批量上传照片 +**已废弃:** 请使用 upload.api 批量上传照片 POST `/api/have_a_drink/v1/photo/upload/photos` @@ -1144,6 +1146,33 @@ const req = new GetUserBasicInfoReq() client.GetUserBasicInfo(req).then(...).catch(...) ``` +### 更新用户头像 + + + +PUT `/api/have_a_drink/v1/user/user/avatar` + +#### 请求参数 +|名称|类型|校验规则|说明| +|:-|:-|:-|:-| +|avatar|`string`|| 头像URL| + + + + +#### 返回值 +|名称|类型|说明| +|:-|:-:|:-| +|ok|`boolean`| 是否成功
| + + + + +```javascript +const req = new UpdateUserAvatarReq() +client.UpdateUserAvatar(req).then(...).catch(...) +``` + ### 上传文件 diff --git a/node_modules/HaveADrink/index.d.ts b/node_modules/HaveADrink/index.d.ts index 16596ec..5f36209 100644 --- a/node_modules/HaveADrink/index.d.ts +++ b/node_modules/HaveADrink/index.d.ts @@ -2573,6 +2573,52 @@ export declare class GetUserBasicInfoResp { static fromObject(o: Object): GetUserBasicInfoResp; } +/** + * + */ +export declare class UpdateUserAvatarReq { + [key: string]: any; + /** + * 头像URL + */ + avatar: string; + + /** + * @param avatar string 头像URL + */ + constructor(avatar: string,); + /** + * 从对象创建 UpdateUserAvatarReq + * + * @param o Object + * - avatar: string, // 头像URL + */ + static fromObject(o: Object): UpdateUserAvatarReq; +} + +/** + * + */ +export declare class UpdateUserAvatarResp { + [key: string]: any; + /** + * 是否成功 + */ + ok: boolean; + + /** + * @param ok boolean 是否成功 + */ + constructor(ok: boolean,); + /** + * 从对象创建 UpdateUserAvatarResp + * + * @param o Object + * - ok: boolean, // 是否成功 + */ + static fromObject(o: Object): UpdateUserAvatarResp; +} + /** * 上传图片参数 */ @@ -5118,6 +5164,7 @@ export default class HaveADrink { /** * 上传照片 * + * @deprecated 请使用 upload.api 上传照片 * @param req UploadPhotoReq 上传照片请求 * @return UploadPhotoResp 上传照片响应 */ @@ -5126,6 +5173,7 @@ export default class HaveADrink { /** * 批量上传照片 * + * @deprecated 请使用 upload.api 批量上传照片 * @param req UploadPhotosReq 批量上传照片请求 * @return UploadPhotosResp 批量上传照片响应 */ @@ -5219,6 +5267,14 @@ export default class HaveADrink { */ public GetUserBasicInfo(req: GetUserBasicInfoReq) : Promise; + /** + * 更新用户头像 + * + * @param req UpdateUserAvatarReq + * @return UpdateUserAvatarResp + */ + public UpdateUserAvatar(req: UpdateUserAvatarReq) : Promise; + /** * 上传文件 * diff --git a/node_modules/HaveADrink/index.js b/node_modules/HaveADrink/index.js index 3c7fd32..b2076ce 100644 --- a/node_modules/HaveADrink/index.js +++ b/node_modules/HaveADrink/index.js @@ -1864,6 +1864,38 @@ export class GetUserBasicInfoResp { } } +/** + * + */ +export class UpdateUserAvatarReq { + /** + * @param avatar: string 头像URL + */ + constructor(avatar,) { + this.avatar = avatar; + + } + static fromObject(o) { + return new UpdateUserAvatarReq(o.avatar,); + } +} + +/** + * + */ +export class UpdateUserAvatarResp { + /** + * @param ok: boolean 是否成功 + */ + constructor(ok,) { + this.ok = ok; + + } + static fromObject(o) { + return new UpdateUserAvatarResp(o.ok,); + } +} + /** * 上传图片参数 */ @@ -4152,6 +4184,38 @@ export default class HaveADrink { }); } + /** + * 更新用户头像 + */ + UpdateUserAvatar(req) { + return new Promise((reslove, reject)=>{ + let data = req; + let url = `${this.host}/api/have_a_drink/v1/user/user/avatar`; + + + this.http_request(url, { + uri: '/api/have_a_drink/v1/user/user/avatar', + method: 'PUT', + data: data, + responseType: 'json', + headers: { + 'Content-Type': 'application/json', + }, + }).then((data)=>{ + if (data.hasOwnProperty("fail")) { + if (data.fail) { + reject(data.msg); + } else { + reslove(data.data); + } + } else { + reslove(data); + } + }).catch((err)=>reject(err)); + + }); + } + /** * 上传文件 */ diff --git a/node_modules/HaveADrink/package.json b/node_modules/HaveADrink/package.json index e29c760..22c3adb 100644 --- a/node_modules/HaveADrink/package.json +++ b/node_modules/HaveADrink/package.json @@ -1,7 +1,7 @@ { "name": "HaveADrink", "type": "module", - "version": "v1.0.15", + "version": "v1.0.16", "description": "喝酒了么 API 服务", "main": "index.js", "scripts": { diff --git a/package-lock.json b/package-lock.json index 00a1629..7be49c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,13 +5,13 @@ "packages": { "": { "dependencies": { - "HaveADrink": "^1.0.15" + "HaveADrink": "^1.0.16" } }, "node_modules/HaveADrink": { - "version": "1.0.15", - "resolved": "https://npm.wash-painting.cn/HaveADrink/-/HaveADrink-1.0.15.tgz", - "integrity": "sha512-ZKgrIKuwXXuKRY2D34FRNUwlr1Y4bAUtXwrjpoHwLPa30KNGVvuXhfYvxAWf5cDvTJw3b/lm8JSSYwCqcIZ3Bw==", + "version": "1.0.16", + "resolved": "https://npm.wash-painting.cn/HaveADrink/-/HaveADrink-1.0.16.tgz", + "integrity": "sha512-NKaV3AZHHVYT23Eo4WGTzZ7H+FVfQoHa8EE3k5SnHCi9yxGAxnExBqRYde5AEFI1pJNe7OzqzbxAykxN757LXQ==", "license": "ISC" } } diff --git a/package.json b/package.json index 0467c76..54007a2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "HaveADrink": "^1.0.15" + "HaveADrink": "^1.0.16" } } diff --git a/pages/chat-list/chat-list.vue b/pages/chat-list/chat-list.vue index b977aa4..a6f5a64 100644 --- a/pages/chat-list/chat-list.vue +++ b/pages/chat-list/chat-list.vue @@ -28,7 +28,7 @@ > - + {{ conv.nickname ? conv.nickname[0] : '酒' }} @@ -69,6 +69,7 @@ import EmptyState from '../../components/EmptyState.vue' import { GetConversations } from '../../common/api' import wsManager from '../../common/websocket' import themeMixin from '../../common/theme-mixin' +import { isValidAvatar } from '../../common/utils' export default { mixins: [themeMixin], @@ -93,6 +94,7 @@ export default { this.unbindWsEvents() }, methods: { + isValidAvatar, async loadConversations() { this.loading = true try { diff --git a/pages/login/login.vue b/pages/login/login.vue index ee74d88..6448037 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -90,7 +90,7 @@