优化了样式,抽象出了 WXSS/JS 库

This commit is contained in:
2026-06-13 18:19:46 +08:00
parent 6fbae9b32c
commit 3dc03f6fe5
51 changed files with 7154 additions and 9035 deletions

View File

@@ -1,26 +1,15 @@
// pages/dashouzhongxin/dashouzhongxin.js
import request from '../../utils/request.js'
import popupService from '../../services/popupService.js'
import {
isRoleStatusActive,
isCenterPageActive,
syncRoleStatuses,
syncProfileFields,
syncGroupFields,
ensureRoleOnCenterPage,
clearCacheAndEnterNormal,
} from '../../utils/role-tab-bar.js'
import { lockPrimaryRole, migrateLegacyCenterRole, enterLockedRole } from '../../utils/primary-role.js'
import { resolveAvatarUrl, resolveAvatarFromStorage } from '../../utils/avatar.js'
import { createPage, request, isRoleStatusActive, isCenterPageActive, syncRoleStatuses, syncProfileFields, syncGroupFields, ensureRoleOnCenterPage, clearCacheAndEnterNormal, lockPrimaryRole, migrateLegacyCenterRole, enterLockedRole, parseSceneOptions } from '../../utils/base-page.js'
import { resolveAvatarUrl } from '../../utils/avatar.js'
import { openPrivateChat, buildInviterPeerId } from '../../utils/im-user.js'
const PLATFORM_INVITE_CODE = '0000008RffVgKHMj7kQC'
Page({
Page(createPage({
data: {
// 图片路径对象
imgUrls: {},
isDashou: false,
isGuanshi: false,
isZuzhang: false,
@@ -31,7 +20,6 @@ Page({
assetBreakdown: [],
pendingAuthList: [],
showAuthSection: false,
isLoading: false,
inviteCode: '',
guanshiInviteCode: '',
zuzhangInviteCode: '',
@@ -48,8 +36,6 @@ Page({
clumber: [],
chengjiaoliang: '',
zaixianZhuangtai: 0,
lastRefreshTime: 0,
canRefresh: true,
isAutoRegistering: false,
inviterCache: null,
zuzhangInviterCache: null,
@@ -165,17 +151,10 @@ Page({
});
this.checkRoleStatuses();
const registerType = options.registerType || 'dashou';
if (options.scene) {
try {
const scene = decodeURIComponent(options.scene);
options.inviteCode = scene;
} catch (e) {
console.error('scene解码失败', e);
}
}
const parsed = parseSceneOptions(options);
const registerType = parsed.registerType || 'dashou';
const { inviteCode } = parsed;
this.checkDashouStatus();
const { inviteCode } = options || {};
if (inviteCode) {
if (registerType === 'guanshi') {
this.setData({ guanshiInviteCode: inviteCode });
@@ -189,26 +168,7 @@ Page({
}, 500);
}
}
// 注意:不再重复声明 app
if (!app.globalData.hasShownPopupOnColdStart) {
app.globalData.hasShownPopupOnColdStart = true;
setTimeout(() => {
popupService.checkAndShow(this, 'dashouduan');
}, 300);
}
},
onReady() {
if (isCenterPageActive(this, 'isDashou', 'dashoustatus')) {
ensureRoleOnCenterPage(this, 'dashou');
}
},
onHide() {
const popupComp = this.selectComponent('#popupNotice');
if (popupComp && popupComp.cleanup) {
popupComp.cleanup();
}
this.checkColdStartPopup('dashouduan');
},
onShow() {
@@ -324,60 +284,36 @@ Page({
});
},
_isApiSuccess(body) {
if (!body) return false;
const code = Number(body.code);
return code === 200 || code === 0;
},
_getApiMsg(body) {
if (!body) return '';
return body.msg || body.message || '';
},
_extractUserData(body) {
if (!body) return {};
if (body.data && typeof body.data === 'object' && !Array.isArray(body.data)) {
return body.data;
}
const userData = { ...body };
delete userData.code;
delete userData.msg;
delete userData.message;
return userData;
},
async refreshAllInfo(showToast = true) {
const now = Date.now();
if (!this.data.canRefresh || (now - this.data.lastRefreshTime < 3000)) return;
this.setData({ lastRefreshTime: now, canRefresh: false, isLoading: true });
try {
this.checkRoleStatuses();
const results = await Promise.allSettled([
this._fetchDashouInfoSilent(),
this.fetchChenghaoList(),
this._fetchGuanshiInfoSilent(),
this.fetchGuanshiChenghaoList(),
this._fetchZuzhangInfoSilent(),
this._fetchKaoheguanInfoSilent(),
]);
this.checkRoleStatuses();
const dashouOk = results[0].status === 'fulfilled';
if (showToast) {
wx.showToast({
title: dashouOk ? '刷新成功' : '刷新失败',
icon: dashouOk ? 'success' : 'none',
duration: 1500,
});
this.throttledRefresh(async () => {
this.setData({ isLoading: true });
try {
this.checkRoleStatuses();
const results = await Promise.allSettled([
this._fetchDashouInfoSilent(),
this.fetchChenghaoList(),
this._fetchGuanshiInfoSilent(),
this.fetchGuanshiChenghaoList(),
this._fetchZuzhangInfoSilent(),
this._fetchKaoheguanInfoSilent(),
]);
this.checkRoleStatuses();
const dashouOk = results[0].status === 'fulfilled';
if (showToast) {
wx.showToast({
title: dashouOk ? '刷新成功' : '刷新失败',
icon: dashouOk ? 'success' : 'none',
duration: 1500,
});
}
} catch (e) {
if (showToast) {
wx.showToast({ title: '刷新失败', icon: 'none' });
}
} finally {
this.setData({ isLoading: false });
}
} catch (e) {
if (showToast) {
wx.showToast({ title: '刷新失败', icon: 'none' });
}
} finally {
this.setData({ isLoading: false });
setTimeout(() => this.setData({ canRefresh: true }), 3000);
}
}, 3000);
},
refreshDashouInfo() {
@@ -875,17 +811,6 @@ Page({
});
},
registerNotificationComponent() {
const app = getApp();
const notificationComp = this.selectComponent('#global-notification');
if (notificationComp && notificationComp.showNotification) {
app.globalData.globalNotification = {
show: (data) => notificationComp.showNotification(data),
hide: () => notificationComp.hideNotification()
};
}
},
checkDashouStatus() {
try {
const dashoustatus = wx.getStorageSync('dashoustatus');
@@ -905,11 +830,6 @@ Page({
}
},
loadAvatar() {
const avatarUrl = resolveAvatarFromStorage(getApp());
this.setData({ avatarUrl });
},
checkGlobalData() {
const app = getApp();
const globalData = app.globalData || {};
@@ -1058,19 +978,6 @@ Page({
ensureRoleOnCenterPage(this, 'dashou');
},
copyUid() {
const { uid } = this.data;
if (!uid) {
wx.showToast({ title: 'UID不存在', icon: 'none', duration: 1500 });
return;
}
wx.setClipboardData({
data: uid,
success: () => wx.showToast({ title: '已复制UID', icon: 'success', duration: 1500 }),
fail: () => wx.showToast({ title: '复制失败', icon: 'error', duration: 1500 })
});
},
previewAvatar() {
const { avatarUrl } = this.data;
if (avatarUrl) wx.previewImage({ urls: [avatarUrl] });
@@ -1079,19 +986,6 @@ Page({
goToWithdraw() { wx.navigateTo({ url: '/pages/withdraw/withdraw' }) },
goToTotalWithdraw() { this.goToWithdraw(); },
goToKefu() {
const app = getApp();
const { link, enterpriseId } = app.globalData.kefuConfig || {};
if (!link || !enterpriseId) {
wx.showToast({ title: '客服配置未加载', icon: 'none' });
return;
}
wx.openCustomerServiceChat({
extInfo: { url: link },
corpId: enterpriseId,
});
},
goToAuth(e) {
const type = e.currentTarget.dataset.type;
if (!type || !['dashou', 'shangjia', 'guanshi', 'zuzhang'].includes(type)) return;
@@ -1171,20 +1065,4 @@ Page({
});
},
clearCache() {
wx.showModal({
title: '清除缓存',
content: '将清除所有登录与身份数据,并回到点单端,确定继续?',
confirmText: '确定',
cancelText: '取消',
success: (r) => {
if (r.confirm) clearCacheAndEnterNormal(this);
},
});
},
switchToNormal() {
lockPrimaryRole('normal');
wx.reLaunch({ url: '/pages/mine/mine' });
},
})
}, { roleConfig: { role: 'dashou', statusKey: 'dashoustatus', dataFlag: 'isDashou', pageId: 'dashouduan', apiUrl: '/yonghu/dashouxinxi' } }))