第一次提交:微信小程序前端最新完整代码

This commit is contained in:
XingQue
2026-06-12 21:55:06 +08:00
commit 84be8489b4
330 changed files with 74263 additions and 0 deletions

38
utils/avatar.js Normal file
View File

@@ -0,0 +1,38 @@
/** 统一头像 URL无有效头像时始终返回 ossImageUrl + morentouxiang */
function isBlankPath(p) {
if (p == null) return true;
if (typeof p !== 'string') return true;
const s = p.trim();
return !s || s === 'null' || s === 'undefined' || s === 'none';
}
export function getDefaultAvatarUrl(app) {
return resolveAvatarUrl('', app);
}
export function resolveAvatarUrl(rawPath, app) {
app = app || getApp();
const oss = app.globalData.ossImageUrl || '';
const def = app.globalData.morentouxiang || 'avatar/default.jpg';
if (!isBlankPath(rawPath)) {
if (rawPath.startsWith('http://') || rawPath.startsWith('https://')) {
return rawPath;
}
const path = rawPath.startsWith('/') ? rawPath : '/' + rawPath;
return oss + path;
}
if (def.startsWith('http://') || def.startsWith('https://')) {
return def;
}
const defPath = def.startsWith('/') ? def : '/' + def;
return oss + defPath;
}
export function resolveAvatarFromStorage(app) {
app = app || getApp();
const tx = wx.getStorageSync('touxiang') || '';
return resolveAvatarUrl(tx, app);
}