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:
@@ -1,16 +1,15 @@
|
||||
/**
|
||||
* 我的页 U30-U33(重构:用 userStore 派生状态 + ui-section-header)
|
||||
* 我的页 U30-U33
|
||||
*
|
||||
* 不变量(AGENTS.md):
|
||||
* - 第 8 条:敏感数据默认拒绝——Profile 中不展示身份证号/手机号/完整生日,
|
||||
* 仅展示前台脱敏字段(昵称/年龄/地区/职业大类)。
|
||||
* - 第 2 条:Required 不可自动放宽——择偶条件入口仅跳转编辑页,不在本页软化。
|
||||
* - 第 9 条:PostgreSQL 是 Source of Truth——本页状态全部来自 userStore 拉取的 /me/status。
|
||||
* - 第 8 条:敏感数据默认拒绝——Profile 不展示身份证号/手机号/完整生日
|
||||
* - 第 2 条:Required 不可自动放宽
|
||||
* - 第 9 条:PostgreSQL 是 Source of Truth
|
||||
*/
|
||||
const { userStore, authStore, matchStore, appStore } = require('../../stores');
|
||||
const { ROUTE, OPERATOR, DANGER_ACTION, RELATIONSHIP_STATUS, PROFILE_REVIEW } = require('../../constants');
|
||||
import { userStore, authStore, matchStore, appStore } from '../../stores';
|
||||
import { ROUTE, DANGER_ACTION, RELATIONSHIP_STATUS, PROFILE_REVIEW } from '../../constants';
|
||||
|
||||
const RELATIONSHIP_TEXT = {
|
||||
const RELATIONSHIP_TEXT: Record<string, string> = {
|
||||
[RELATIONSHIP_STATUS.SEARCHING]: '正在寻找',
|
||||
[RELATIONSHIP_STATUS.GETTING_TO_KNOW]: '正在了解',
|
||||
[RELATIONSHIP_STATUS.PAUSED]: '已暂停寻找',
|
||||
@@ -21,8 +20,8 @@ const RELATIONSHIP_TEXT = {
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
profile: null,
|
||||
userState: null,
|
||||
profile: null as any,
|
||||
userState: null as any,
|
||||
verificationStatus: 'not_submitted',
|
||||
loadStatus: 'idle',
|
||||
isRealNameVerified: false,
|
||||
@@ -41,11 +40,9 @@ Page({
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 订阅 userStore,派生展示状态
|
||||
this._unsubUser = userStore.subscribe((state) => this._syncFromUserStore(state));
|
||||
(this as any)._unsubUser = userStore.subscribe((state: any) => this._syncFromUserStore(state));
|
||||
this._syncFromUserStore(userStore.state);
|
||||
// 绑定 matchStore.likersCount(驱动"喜欢我"徽标)
|
||||
this._unsubMatch = matchStore.subscribe((state) => {
|
||||
(this as any)._unsubMatch = matchStore.subscribe((state: any) => {
|
||||
this.setData({
|
||||
likersCount: state.likersCount || 0,
|
||||
matchCount: Array.isArray(state.mutualList) ? state.mutualList.length : 0,
|
||||
@@ -54,9 +51,8 @@ Page({
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// 检测红娘工作台登录状态
|
||||
if (authStore.state.isLoggedIn) {
|
||||
userStore.fetchStatus().catch((err) => appStore.toastError(err));
|
||||
userStore.fetchStatus().catch((err: any) => appStore.toastError(err));
|
||||
userStore.fetchProfile().catch(() => {});
|
||||
userStore.fetchVerificationStatus().catch(() => {});
|
||||
matchStore.fetchLikersCount().catch(() => {});
|
||||
@@ -65,12 +61,11 @@ Page({
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this._unsubUser && this._unsubUser();
|
||||
this._unsubMatch && this._unsubMatch();
|
||||
if ((this as any)._unsubUser) (this as any)._unsubUser();
|
||||
if ((this as any)._unsubMatch) (this as any)._unsubMatch();
|
||||
},
|
||||
|
||||
/** 把 userStore 状态派生为页面展示字段 */
|
||||
_syncFromUserStore(state) {
|
||||
_syncFromUserStore(state: any) {
|
||||
const us = state.userState;
|
||||
const isLoggedIn = !!us || authStore.state.isLoggedIn;
|
||||
const isRealNameVerified = !!us && !!us.isRealNameVerified;
|
||||
@@ -85,8 +80,7 @@ Page({
|
||||
|
||||
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 canPause = rel === RELATIONSHIP_STATUS.SEARCHING || rel === RELATIONSHIP_STATUS.GETTING_TO_KNOW;
|
||||
const canResume = rel === RELATIONSHIP_STATUS.PAUSED;
|
||||
|
||||
this.setData({
|
||||
@@ -107,53 +101,27 @@ Page({
|
||||
|
||||
// ============ 登录 ============
|
||||
|
||||
onLoginAction(e) {
|
||||
if ((e.detail || {}).event === 'login') {
|
||||
wx.navigateTo({ url: ROUTE.AUTH.LOGIN });
|
||||
}
|
||||
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 });
|
||||
},
|
||||
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 });
|
||||
},
|
||||
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 });
|
||||
},
|
||||
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 }); },
|
||||
|
||||
// ============ 关系状态切换 ============
|
||||
|
||||
@@ -163,10 +131,7 @@ Page({
|
||||
await userStore.pauseSearching();
|
||||
appStore.hideLoading();
|
||||
appStore.toastSuccess('已暂停寻找');
|
||||
} catch (err) {
|
||||
appStore.hideLoading();
|
||||
appStore.toastError(err);
|
||||
}
|
||||
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
|
||||
},
|
||||
|
||||
async onResume() {
|
||||
@@ -175,10 +140,7 @@ Page({
|
||||
await userStore.resumeSearching();
|
||||
appStore.hideLoading();
|
||||
appStore.toastSuccess('已恢复寻找');
|
||||
} catch (err) {
|
||||
appStore.hideLoading();
|
||||
appStore.toastError(err);
|
||||
}
|
||||
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
|
||||
},
|
||||
|
||||
onGoFate() { wx.navigateTo({ url: ROUTE.MAIN.FATE_CENTER }); },
|
||||
@@ -191,34 +153,22 @@ Page({
|
||||
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 });
|
||||
},
|
||||
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 });
|
||||
}
|
||||
if (token) wx.navigateTo({ url: ROUTE.OPERATOR.WORKBENCH });
|
||||
else wx.navigateTo({ url: ROUTE.OPERATOR.LOGIN });
|
||||
},
|
||||
|
||||
onLogout() {
|
||||
this.setData({ showLogoutDialog: true });
|
||||
},
|
||||
onLogout() { this.setData({ showLogoutDialog: true }); },
|
||||
|
||||
async onConfirmLogout() {
|
||||
this.setData({ showLogoutDialog: false });
|
||||
@@ -227,13 +177,8 @@ Page({
|
||||
await authStore.logout();
|
||||
appStore.hideLoading();
|
||||
wx.reLaunch({ url: ROUTE.AUTH.LOGIN });
|
||||
} catch (err) {
|
||||
appStore.hideLoading();
|
||||
appStore.toastError(err);
|
||||
}
|
||||
} catch (err: any) { appStore.hideLoading(); appStore.toastError(err); }
|
||||
},
|
||||
|
||||
onCancelLogout() {
|
||||
this.setData({ showLogoutDialog: false });
|
||||
},
|
||||
onCancelLogout() { this.setData({ showLogoutDialog: false }); },
|
||||
});
|
||||
Reference in New Issue
Block a user