125 lines
3.5 KiB
JavaScript
125 lines
3.5 KiB
JavaScript
/**
|
||||
|
|
* 个人介绍页 U11(Phase 04 P04-T26)
|
|||
|
|
*
|
|||
|
|
* 重构要点(遵循 AGENTS.md 不变量):
|
|||
|
|
* - 数据:profileService.getProfile + userStore.updateProfile(第 9 条)
|
|||
|
|
* - 字数限制:BUSINESS_LIMITS.MIN_INTRO_LENGTH / MAX_INTRO_LENGTH(第 12 条,不硬编码)
|
|||
|
|
* - 审核规则提示:禁止手机号/微信号/二维码/广告等(功能清单 §4.6)
|
|||
|
|
* - 草稿恢复:onLoad 读 ONBOARDING_DRAFT.intro,保存前写回
|
|||
|
|
* - 下一步:跳 profile-preference
|
|||
|
|
*/
|
|||
|
|
const { userStore, appStore } = require('../../stores');
|
|||
|
|
const { profileService } = require('../../services');
|
|||
|
|
const { ROUTE, STORAGE_KEYS, BUSINESS_LIMITS } = require('../../constants');
|
|||
|
|
|
|||
|
|
Page({
|
|||
|
|
data: {
|
|||
|
|
statusBarHeight: 20,
|
|||
|
|
navBarHeight: 44,
|
|||
|
|
loading: false,
|
|||
|
|
saving: false,
|
|||
|
|
selfIntro: '',
|
|||
|
|
minLen: BUSINESS_LIMITS.MIN_INTRO_LENGTH,
|
|||
|
|
maxLen: BUSINESS_LIMITS.MAX_INTRO_LENGTH,
|
|||
|
|
currentLen: 0,
|
|||
|
|
guidelines: [
|
|||
|
|
'可以介绍工作、性格、兴趣、生活状态',
|
|||
|
|
'以及你期待怎样的感情',
|
|||
|
|
'禁止填写手机号、微信号、二维码',
|
|||
|
|
'禁止广告、色情低俗、投资引流内容',
|
|||
|
|
],
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
onLoad() {
|
|||
|
|
this._initSystemInfo();
|
|||
|
|
this._applyDraft();
|
|||
|
|
this.loadProfile();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
_initSystemInfo() {
|
|||
|
|
try {
|
|||
|
|
const sysInfo = wx.getSystemInfoSync();
|
|||
|
|
this.setData({
|
|||
|
|
statusBarHeight: sysInfo.statusBarHeight || 20,
|
|||
|
|
navBarHeight: 44,
|
|||
|
|
});
|
|||
|
|
} catch (e) { /* 使用默认值 */ }
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
async loadProfile() {
|
|||
|
|
this.setData({ loading: true });
|
|||
|
|
try {
|
|||
|
|
const profile = await profileService.getProfile();
|
|||
|
|
const d = this._readDraft();
|
|||
|
|
const selfIntro = d.selfIntro || (profile && profile.selfIntro) || '';
|
|||
|
|
this.setData({
|
|||
|
|
selfIntro,
|
|||
|
|
currentLen: selfIntro.length,
|
|||
|
|
loading: false,
|
|||
|
|
});
|
|||
|
|
} catch (err) {
|
|||
|
|
this.setData({ loading: false });
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// ============ 草稿 ============
|
|||
|
|
_readDraft() {
|
|||
|
|
try {
|
|||
|
|
const draft = wx.getStorageSync(STORAGE_KEYS.ONBOARDING_DRAFT) || {};
|
|||
|
|
return draft.intro || {};
|
|||
|
|
} catch (e) {
|
|||
|
|
return {};
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
_applyDraft() {
|
|||
|
|
const d = this._readDraft();
|
|||
|
|
if (!d || Object.keys(d).length === 0) return;
|
|||
|
|
const selfIntro = d.selfIntro || '';
|
|||
|
|
this.setData({ selfIntro, currentLen: selfIntro.length });
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
_writeDraft() {
|
|||
|
|
try {
|
|||
|
|
const draft = wx.getStorageSync(STORAGE_KEYS.ONBOARDING_DRAFT) || {};
|
|||
|
|
draft.intro = { selfIntro: this.data.selfIntro };
|
|||
|
|
draft.currentStep = 'intro';
|
|||
|
|
wx.setStorageSync(STORAGE_KEYS.ONBOARDING_DRAFT, draft);
|
|||
|
|
} catch (e) { /* ignore */ }
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// ============ 交互 ============
|
|||
|
|
onIntroInput(e) {
|
|||
|
|
const value = e.detail.value || '';
|
|||
|
|
this.setData({ selfIntro: value, currentLen: value.length });
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// ============ 导航 ============
|
|||
|
|
onBack() {
|
|||
|
|
this._writeDraft();
|
|||
|
|
wx.navigateBack();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
async onNext() {
|
|||
|
|
if (this.data.saving) return;
|
|||
|
|
const { selfIntro, minLen, maxLen } = this.data;
|
|||
|
|
if (selfIntro.length < minLen) {
|
|||
|
|
return appStore.toast(`至少填写 ${minLen} 字`);
|
|||
|
|
}
|
|||
|
|
if (selfIntro.length > maxLen) {
|
|||
|
|
return appStore.toast(`最多填写 ${maxLen} 字`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.setData({ saving: true });
|
|||
|
|
this._writeDraft();
|
|||
|
|
try {
|
|||
|
|
await userStore.updateProfile({ selfIntro });
|
|||
|
|
this.setData({ saving: false });
|
|||
|
|
wx.navigateTo({ url: ROUTE.ONBOARDING.PROFILE_PREFERENCE });
|
|||
|
|
} catch (err) {
|
|||
|
|
this.setData({ saving: false });
|
|||
|
|
appStore.toastError(err, '保存失败');
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
});
|