chore: 抢单端UI回退前备份当前完整工作区

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-06-29 17:59:23 +08:00
parent 6e2f7bc39f
commit e8fb32c1fe
53 changed files with 3410 additions and 1065 deletions

View File

@@ -1,4 +1,4 @@
/** 统一头像 URL无有效头像时始终返回 ossImageUrl + morentouxiang */
/** 统一头像 URL无有效头像时始终返回 ossImageUrl + morentouxiang(后端配置) */
function isBlankPath(p) {
if (p == null) return true;
@@ -7,28 +7,71 @@ function isBlankPath(p) {
return !s || s === 'null' || s === 'undefined' || s === 'none';
}
function readConfigFallback(app) {
if (!app || typeof app.readConfigFromStorage !== 'function') return null;
try {
return app.readConfigFromStorage();
} catch (e) {
return null;
}
}
function getOssBase(app) {
let oss = app.globalData?.ossImageUrl || '';
if (!oss) {
const cfg = readConfigFallback(app);
oss = cfg?.cos?.ossImageUrl || '';
}
return oss;
}
function getDefaultRelative(app) {
let def = app.globalData?.morentouxiang || '';
if (!def) {
const cfg = readConfigFallback(app);
def = cfg?.otherConfig?.morentouxiang || '';
}
return def || 'avatar/default.jpg';
}
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';
const oss = getOssBase(app);
const def = getDefaultRelative(app);
if (!isBlankPath(rawPath)) {
if (rawPath.startsWith('http://') || rawPath.startsWith('https://')) {
return rawPath;
}
const path = rawPath.startsWith('/') ? rawPath : '/' + rawPath;
return oss + path;
const path = rawPath.startsWith('/') ? rawPath : `/${rawPath}`;
if (oss) return oss + path;
return path;
}
if (def.startsWith('http://') || def.startsWith('https://')) {
return def;
}
const defPath = def.startsWith('/') ? def : '/' + def;
return oss + defPath;
const defPath = def.startsWith('/') ? def : `/${def}`;
if (oss) return oss + defPath;
// 配置未就绪时仍返回相对路径,由 binderror 回退;有 oss 时必须拼完整 URL
return defPath;
}
/** 是否已是可加载的完整头像 URL */
export function isUsableAvatarUrl(url) {
return url && (url.startsWith('http://') || url.startsWith('https://'));
}
export function ensureAvatarUrl(rawPath, app) {
app = app || getApp();
const resolved = resolveAvatarUrl(rawPath, app);
if (isUsableAvatarUrl(resolved)) return resolved;
const def = getDefaultAvatarUrl(app);
return isUsableAvatarUrl(def) ? def : resolved;
}
export function resolveAvatarFromStorage(app) {
@@ -36,3 +79,19 @@ export function resolveAvatarFromStorage(app) {
const tx = wx.getStorageSync('touxiang') || '';
return resolveAvatarUrl(tx, app);
}
/** 配置加载后刷新页面头像(聊天页等订阅 configApplied */
export function subscribeConfigAvatarRefresh(page, refreshFn) {
const app = getApp();
if (!app || typeof refreshFn !== 'function') return null;
const handler = () => refreshFn();
if (app.on) app.on('configApplied', handler);
return () => { if (app.off) app.off('configApplied', handler); };
}
/** 消息列表/聊天页 image 加载失败时回退默认头像 */
export function onAvatarImageError(page, dataKey, app) {
if (!page || !dataKey) return;
const def = getDefaultAvatarUrl(app || getApp());
page.setData({ [dataKey]: def });
}