Files
danyang-match/miniapp/pages/mine/mine.ts
T

193 lines
7.3 KiB
TypeScript
Raw Normal View History

2026-09-09 22:05:00 +08:00
/**
* 我的页 U30-U33
2026-09-09 22:05:00 +08:00
*
* 不变量(AGENTS.md):
* - 第 8 条:敏感数据默认拒绝——Profile 不展示身份证号/手机号/完整生日
* - 第 2 条:Required 不可自动放宽
* - 第 9 条:PostgreSQL 是 Source of Truth
2026-09-09 22:05:00 +08:00
*/
import { userStore, authStore, matchStore, appStore } from '../../stores';
import { ROUTE, DANGER_ACTION, RELATIONSHIP_STATUS, PROFILE_REVIEW } from '../../constants';
// 顶部安全区:实测右上角胶囊按钮矩形,避免「编辑资料」与设置入口被胶囊压住(见 utils/nav-metrics.js)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { navSafeData } = require('../../utils/nav-metrics');
2026-09-09 22:05:00 +08:00
const RELATIONSHIP_TEXT: Record<string, string> = {
2026-09-09 22:05:00 +08:00
[RELATIONSHIP_STATUS.SEARCHING]: '正在寻找',
[RELATIONSHIP_STATUS.GETTING_TO_KNOW]: '正在了解',
[RELATIONSHIP_STATUS.PAUSED]: '已暂停寻找',
[RELATIONSHIP_STATUS.MATCHED_SUCCESSFULLY]: '已成功牵手',
[RELATIONSHIP_STATUS.SERVICE_EXITED]: '已退出服务',
};
Page({
data: {
navVars: '',
2026-09-09 22:05:00 +08:00
isLoggedIn: false,
profile: null as any,
userState: null as any,
2026-09-09 22:05:00 +08:00
verificationStatus: 'not_submitted',
loadStatus: 'idle',
isRealNameVerified: false,
isProfileApproved: false,
reviewStatusText: '',
relationshipText: '',
canPause: false,
canResume: false,
likersCount: 0,
2026-09-14 07:05:20 +08:00
matchCount: 0,
2026-09-09 22:05:00 +08:00
showLogoutDialog: false,
logoutAction: DANGER_ACTION.LOGOUT,
loginActions: [{ text: '微信登录', event: 'login', variant: 'primary' }],
hasOperatorToken: false,
2026-09-14 07:05:20 +08:00
profileCompleteness: 0,
2026-09-09 22:05:00 +08:00
},
onLoad() {
// 顶部安全区先算:onLoad 早于首次渲染,避免出现「先压住胶囊再跳开」的闪动
this.setData(navSafeData());
(this as any)._unsubUser = userStore.subscribe((state: any) => this._syncFromUserStore(state));
2026-09-09 22:05:00 +08:00
this._syncFromUserStore(userStore.state);
(this as any)._unsubMatch = matchStore.subscribe((state: any) => {
2026-09-14 07:05:20 +08:00
this.setData({
likersCount: state.likersCount || 0,
matchCount: Array.isArray(state.mutualList) ? state.mutualList.length : 0,
});
});
2026-09-09 22:05:00 +08:00
},
onShow() {
if (authStore.state.isLoggedIn) {
userStore.fetchStatus().catch((err: any) => appStore.toastError(err));
2026-09-09 22:05:00 +08:00
userStore.fetchProfile().catch(() => {});
userStore.fetchVerificationStatus().catch(() => {});
matchStore.fetchLikersCount().catch(() => {});
2026-09-14 07:05:20 +08:00
matchStore.fetchMutualList().catch(() => {});
2026-09-09 22:05:00 +08:00
}
},
onUnload() {
if ((this as any)._unsubUser) (this as any)._unsubUser();
if ((this as any)._unsubMatch) (this as any)._unsubMatch();
2026-09-09 22:05:00 +08:00
},
_syncFromUserStore(state: any) {
2026-09-09 22:05:00 +08:00
const us = state.userState;
const isLoggedIn = !!us || authStore.state.isLoggedIn;
const isRealNameVerified = !!us && !!us.isRealNameVerified;
const reviewStatus = us ? us.profileReviewStatus : null;
const isProfileApproved = reviewStatus === PROFILE_REVIEW.APPROVED;
let reviewStatusText = '未提交';
if (reviewStatus === PROFILE_REVIEW.PENDING) reviewStatusText = '审核中';
else if (reviewStatus === PROFILE_REVIEW.APPROVED) reviewStatusText = '已审核';
else if (reviewStatus === PROFILE_REVIEW.NEED_EDIT) reviewStatusText = '需修改';
else if (reviewStatus === PROFILE_REVIEW.REJECTED) reviewStatusText = '未通过';
const rel = us ? us.relationshipStatus : null;
const relationshipText = rel ? RELATIONSHIP_TEXT[rel] || '' : '';
const canPause = rel === RELATIONSHIP_STATUS.SEARCHING || rel === RELATIONSHIP_STATUS.GETTING_TO_KNOW;
2026-09-09 22:05:00 +08:00
const canResume = rel === RELATIONSHIP_STATUS.PAUSED;
this.setData({
isLoggedIn,
profile: state.profile,
userState: us,
verificationStatus: state.verificationStatus,
loadStatus: state.loadStatus,
isRealNameVerified,
isProfileApproved,
reviewStatusText,
relationshipText,
canPause,
canResume,
2026-09-14 07:05:20 +08:00
profileCompleteness: state.profile?.profileCompletion || 0,
2026-09-09 22:05:00 +08:00
});
},
// ============ 登录 ============
onLoginAction(e: any) {
if ((e.detail || {}).event === 'login') wx.navigateTo({ url: ROUTE.AUTH.LOGIN });
2026-09-09 22:05:00 +08:00
},
// ============ 资料编辑 ============
onEditProfile() { wx.navigateTo({ url: ROUTE.ONBOARDING.PROFILE_INTRO }); },
onEditPreference() { wx.navigateTo({ url: ROUTE.ONBOARDING.PROFILE_PREFERENCE }); },
onEditPhotos() { wx.navigateTo({ url: ROUTE.ONBOARDING.PROFILE_PHOTOS }); },
2026-09-09 22:05:00 +08:00
// ============ 匹配 ============
onGoMessages() { wx.switchTab({ url: ROUTE.TAB.MESSAGES }); },
onGoLikers() { wx.navigateTo({ url: ROUTE.DETAIL.LIKERS }); },
2026-09-09 22:05:00 +08:00
// ============ 账户与安全 ============
onGoVerification() { wx.navigateTo({ url: ROUTE.AUTH.VERIFICATION }); },
onGoPrivacy() { wx.navigateTo({ url: ROUTE.SETTINGS.PRIVACY }); },
onGoBlacklist() { wx.navigateTo({ url: ROUTE.SETTINGS.BLACKLIST }); },
onGoAccountStatus() { wx.navigateTo({ url: ROUTE.SETTINGS.ACCOUNT_STATUS_PAGE }); },
2026-09-09 22:05:00 +08:00
// ============ 关系状态切换 ============
async onPause() {
try {
appStore.showLoading('处理中…');
await userStore.pauseSearching();
appStore.hideLoading();
appStore.toastSuccess('已暂停寻找');
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
2026-09-09 22:05:00 +08:00
},
async onResume() {
try {
appStore.showLoading('处理中…');
await userStore.resumeSearching();
appStore.hideLoading();
appStore.toastSuccess('已恢复寻找');
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
2026-09-09 22:05:00 +08:00
},
onGoFate() { wx.navigateTo({ url: ROUTE.MAIN.FATE_CENTER }); },
onGoMatchmaker() { wx.navigateTo({ url: ROUTE.MAIN.MATCHMAKER }); },
onGoCounseling() { wx.navigateTo({ url: ROUTE.SERVICE.COUNSELING }); },
onGoActivities() { wx.navigateTo({ url: ROUTE.DETAIL.MY_ACTIVITIES }); },
onGoAppointments() { wx.navigateTo({ url: ROUTE.SERVICE.MY_APPOINTMENTS }); },
onGoServiceHistory() { wx.navigateTo({ url: ROUTE.SERVICE.HISTORY }); },
onGoSafety() { wx.navigateTo({ url: ROUTE.SETTINGS.MY_REPORTS }); },
onGoClassroom() { wx.navigateTo({ url: ROUTE.SERVICE.CLASSROOM }); },
onGoAntiFraud() { wx.navigateTo({ url: ROUTE.SERVICE.ANTI_FRAUD }); },
onGoStation() { wx.navigateTo({ url: ROUTE.SERVICE.STATION }); },
// Phase 19:U49 公益服务中心此前只有 app.json 注册、全仓无任何入口(用户不可达)。
onGoServiceCenter() { wx.navigateTo({ url: ROUTE.SERVICE.CENTER }); },
2026-09-09 22:05:00 +08:00
// ============ 其他 ============
onGoSettings() { wx.navigateTo({ url: ROUTE.SETTINGS.SETTINGS }); },
onGoHelp() { wx.navigateTo({ url: ROUTE.SETTINGS.HELP_CENTER }); },
onGoAbout() { wx.navigateTo({ url: ROUTE.SETTINGS.ABOUT }); },
2026-09-09 22:05:00 +08:00
// ============ 身份切换 ============
onSwitchRole() {
const token = wx.getStorageSync('operatorToken');
if (token) wx.navigateTo({ url: ROUTE.OPERATOR.WORKBENCH });
else wx.navigateTo({ url: ROUTE.OPERATOR.LOGIN });
2026-09-09 22:05:00 +08:00
},
onLogout() { this.setData({ showLogoutDialog: true }); },
2026-09-09 22:05:00 +08:00
async onConfirmLogout() {
this.setData({ showLogoutDialog: false });
try {
appStore.showLoading('退出中…');
await authStore.logout();
appStore.hideLoading();
wx.reLaunch({ url: ROUTE.AUTH.LOGIN });
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
2026-09-09 22:05:00 +08:00
},
onCancelLogout() { this.setData({ showLogoutDialog: false }); },
2026-09-09 22:05:00 +08:00
});