feat(miniapp): final 3 pages migrated to TypeScript (matchmaker/messages/mine)
D1 debt cleared: all 11 miniapp core pages now TS-only. tsc --noEmit -> 0 errors. JS sources deleted.
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* 我的页 U30-U33
|
||||
*
|
||||
* 不变量(AGENTS.md):
|
||||
* - 第 8 条:敏感数据默认拒绝——Profile 不展示身份证号/手机号/完整生日
|
||||
* - 第 2 条:Required 不可自动放宽
|
||||
* - 第 9 条:PostgreSQL 是 Source of Truth
|
||||
*/
|
||||
import { userStore, authStore, matchStore, appStore } from '../../stores';
|
||||
import { ROUTE, DANGER_ACTION, RELATIONSHIP_STATUS, PROFILE_REVIEW } from '../../constants';
|
||||
|
||||
const RELATIONSHIP_TEXT: Record<string, string> = {
|
||||
[RELATIONSHIP_STATUS.SEARCHING]: '正在寻找',
|
||||
[RELATIONSHIP_STATUS.GETTING_TO_KNOW]: '正在了解',
|
||||
[RELATIONSHIP_STATUS.PAUSED]: '已暂停寻找',
|
||||
[RELATIONSHIP_STATUS.MATCHED_SUCCESSFULLY]: '已成功牵手',
|
||||
[RELATIONSHIP_STATUS.SERVICE_EXITED]: '已退出服务',
|
||||
};
|
||||
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
profile: null as any,
|
||||
userState: null as any,
|
||||
verificationStatus: 'not_submitted',
|
||||
loadStatus: 'idle',
|
||||
isRealNameVerified: false,
|
||||
isProfileApproved: false,
|
||||
reviewStatusText: '',
|
||||
relationshipText: '',
|
||||
canPause: false,
|
||||
canResume: false,
|
||||
likersCount: 0,
|
||||
matchCount: 0,
|
||||
showLogoutDialog: false,
|
||||
logoutAction: DANGER_ACTION.LOGOUT,
|
||||
loginActions: [{ text: '微信登录', event: 'login', variant: 'primary' }],
|
||||
hasOperatorToken: false,
|
||||
profileCompleteness: 0,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
(this as any)._unsubUser = userStore.subscribe((state: any) => this._syncFromUserStore(state));
|
||||
this._syncFromUserStore(userStore.state);
|
||||
(this as any)._unsubMatch = matchStore.subscribe((state: any) => {
|
||||
this.setData({
|
||||
likersCount: state.likersCount || 0,
|
||||
matchCount: Array.isArray(state.mutualList) ? state.mutualList.length : 0,
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (authStore.state.isLoggedIn) {
|
||||
userStore.fetchStatus().catch((err: any) => appStore.toastError(err));
|
||||
userStore.fetchProfile().catch(() => {});
|
||||
userStore.fetchVerificationStatus().catch(() => {});
|
||||
matchStore.fetchLikersCount().catch(() => {});
|
||||
matchStore.fetchMutualList().catch(() => {});
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if ((this as any)._unsubUser) (this as any)._unsubUser();
|
||||
if ((this as any)._unsubMatch) (this as any)._unsubMatch();
|
||||
},
|
||||
|
||||
_syncFromUserStore(state: any) {
|
||||
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;
|
||||
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,
|
||||
profileCompleteness: state.profile?.profileCompletion || 0,
|
||||
});
|
||||
},
|
||||
|
||||
// ============ 登录 ============
|
||||
|
||||
onLoginAction(e: any) {
|
||||
if ((e.detail || {}).event === 'login') wx.navigateTo({ url: ROUTE.AUTH.LOGIN });
|
||||
},
|
||||
|
||||
// ============ 资料编辑 ============
|
||||
|
||||
onEditProfile() { wx.navigateTo({ url: ROUTE.ONBOARDING.PROFILE_INTRO }); },
|
||||
onEditPreference() { wx.navigateTo({ url: ROUTE.ONBOARDING.PROFILE_PREFERENCE }); },
|
||||
onEditPhotos() { wx.navigateTo({ url: ROUTE.ONBOARDING.PROFILE_PHOTOS }); },
|
||||
|
||||
// ============ 匹配 ============
|
||||
|
||||
onGoMessages() { wx.switchTab({ url: ROUTE.TAB.MESSAGES }); },
|
||||
onGoLikers() { wx.navigateTo({ url: ROUTE.DETAIL.LIKERS }); },
|
||||
|
||||
// ============ 账户与安全 ============
|
||||
|
||||
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 }); },
|
||||
|
||||
// ============ 关系状态切换 ============
|
||||
|
||||
async onPause() {
|
||||
try {
|
||||
appStore.showLoading('处理中…');
|
||||
await userStore.pauseSearching();
|
||||
appStore.hideLoading();
|
||||
appStore.toastSuccess('已暂停寻找');
|
||||
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
|
||||
},
|
||||
|
||||
async onResume() {
|
||||
try {
|
||||
appStore.showLoading('处理中…');
|
||||
await userStore.resumeSearching();
|
||||
appStore.hideLoading();
|
||||
appStore.toastSuccess('已恢复寻找');
|
||||
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
|
||||
},
|
||||
|
||||
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 }); },
|
||||
|
||||
// ============ 其他 ============
|
||||
|
||||
onGoSettings() { wx.navigateTo({ url: ROUTE.SETTINGS.SETTINGS }); },
|
||||
onGoHelp() { wx.navigateTo({ url: ROUTE.SETTINGS.HELP_CENTER }); },
|
||||
onGoAbout() { wx.navigateTo({ url: ROUTE.SETTINGS.ABOUT }); },
|
||||
|
||||
// ============ 身份切换 ============
|
||||
|
||||
onSwitchRole() {
|
||||
const token = wx.getStorageSync('operatorToken');
|
||||
if (token) wx.navigateTo({ url: ROUTE.OPERATOR.WORKBENCH });
|
||||
else wx.navigateTo({ url: ROUTE.OPERATOR.LOGIN });
|
||||
},
|
||||
|
||||
onLogout() { this.setData({ showLogoutDialog: true }); },
|
||||
|
||||
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); }
|
||||
},
|
||||
|
||||
onCancelLogout() { this.setData({ showLogoutDialog: false }); },
|
||||
});
|
||||
Reference in New Issue
Block a user