CI/CD Pipeline / Test Shell Guard (Phase 23 Gate) (push) Canceled after 0s
CI/CD Pipeline / Backend Build & Test (push) Canceled after 0s
CI/CD Pipeline / Admin Web Build (push) Canceled after 0s
CI/CD Pipeline / Mini Program Compile Check (push) Canceled after 0s
CI/CD Pipeline / Migration Validation (push) Canceled after 0s
CI/CD Pipeline / UI Contracts (source-structure gates) (push) Canceled after 0s
CI/CD Pipeline / E2E (live stack) (push) Canceled after 0s
193 lines
7.3 KiB
TypeScript
193 lines
7.3 KiB
TypeScript
/**
|
||
* 我的页 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';
|
||
// 顶部安全区:实测右上角胶囊按钮矩形,避免「编辑资料」与设置入口被胶囊压住(见 utils/nav-metrics.js)
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||
const { navSafeData } = require('../../utils/nav-metrics');
|
||
|
||
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: {
|
||
navVars: '',
|
||
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() {
|
||
// 顶部安全区先算:onLoad 早于首次渲染,避免出现「先压住胶囊再跳开」的闪动
|
||
this.setData(navSafeData());
|
||
(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.navigateTo({ url: ROUTE.SETTINGS.NOTIFICATIONS }); },
|
||
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 }); },
|
||
// Phase 19:U49 公益服务中心此前只有 app.json 注册、全仓无任何入口(用户不可达)。
|
||
onGoServiceCenter() { wx.navigateTo({ url: ROUTE.SERVICE.CENTER }); },
|
||
|
||
// ============ 其他 ============
|
||
|
||
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 }); },
|
||
});
|