feat(api): 重构图片地址管理与上传机制

- 替换开发环境API基础URL为本地服务地址
- 实现签名URL本地缓存机制,解决微信按URL缓存图片导致重复下载问题
- 添加缓存清理功能,包括过期清理和按需删除特定缓存项
- 集成阿里云OSS上传功能,支持直传减少服务器带宽占用
- 优化头像地址处理逻辑,统一使用签名缓存避免地址频繁变化
- 移除过时的OSS上传示例文件oss-upload.js
- 更新课程页面实现跳转第三方小程序功能
- 调整打卡记录图片地址获取方式,统一使用新的签名缓存逻辑
- 优化图片上传流程,增加压缩处理和批量上传支持
- 完善认证模块中的缓存清理逻辑,切换账号时清除相关图片缓存
- 添加后端环境变量配置模板和代理文档说明
This commit is contained in:
王宏豪
2026-09-23 17:46:40 +08:00
parent ca21b1b9dc
commit ba2d9245ef
11 changed files with 448 additions and 290 deletions

View File

@@ -107,7 +107,10 @@ Page({
profile: res,
phoneError: '',
loadError: '',
avatarSrc: this.fullUrl(res.wechat_avatar),
// 必须走 api.avatarUrl(内部先查本地签名缓存),不能直接取 res.avatar_url:
// 后端每次请求都现签一个新 URL,直接用会让地址每次进页面都变,
// 而微信是按 URL 缓存图片的 —— 等于每次重新下载头像。
avatarSrc: this.fullUrl(res),
avatarFallback: this.firstChar(displayName),
roleLabel: this.roleLabel(res.role),
loginTypeLabel: this.loginTypeLabel(res.login_type),
@@ -131,9 +134,13 @@ Page({
return LOGIN_TYPE_LABELS[type] || type || '手机号';
},
fullUrl(rel) {
if (!rel) return '';
return /^https?:\/\//i.test(rel) ? rel : api.STATIC_BASE_URL + rel;
/**
* 头像转可显示地址。整个 payload 交给 api.avatarUrl,这样它既能查本地签名缓存,
* 也能在后端给了 avatar_url 时写回缓存 —— 与打卡附件走的是同一套逻辑。
* 兼容 avatars/{uid}/x 与 /clock/static/avatars/{uid}/x 两种历史格式。
*/
fullUrl(payload) {
return api.avatarUrl(payload);
},
firstChar(str) {
@@ -162,7 +169,11 @@ Page({
}
if (data.success && data.wechat_avatar) {
const newAvatar = data.wechat_avatar;
const newUrl = this.fullUrl(newAvatar);
// ⚠️ 换头像 = **key 没变、内容变了**。必须清掉缓存里的那一条,
// 否则下次进「我的」页会命中旧 URL —— 微信按 URL 缓存图片,用户会看到旧头像。
api.forgetSignedUrl(newAvatar);
// 本页立刻用后端刚签的地址显示(不走缓存),确保看到的就是新头像
const newUrl = data.avatar_url || this.fullUrl(data);
this.setData({
'profile.wechat_avatar': newAvatar,
avatarSrc: newUrl