From 071af024826bf35d73a1a7d612be58a6a1c20b45 Mon Sep 17 00:00:00 2001 From: Peanut Date: Wed, 24 Jun 2026 21:40:34 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=BC=96=E8=BE=91=E8=B5=84?= =?UTF-8?q?=E6=96=99=E9=A1=B5=20form=20=E5=A2=9E=E5=8A=A0=E5=BA=93?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=B9=B6=E5=AF=B9=E8=80=81=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - form reactive 新增 personalityTagLibrary 和 hobbyLibrary 字段 - syncFromStore 增加库字段加载逻辑,后端有则用后端数据 - 老用户(后端无库字段)使用预设 + 已选合并去重初始化 - 新增 buildInitialLibrary 辅助函数处理数组合并去重 --- mini-program/src/pages/onboarding/index.vue | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mini-program/src/pages/onboarding/index.vue b/mini-program/src/pages/onboarding/index.vue index 7bcee2a..857c6e2 100644 --- a/mini-program/src/pages/onboarding/index.vue +++ b/mini-program/src/pages/onboarding/index.vue @@ -225,6 +225,8 @@ const form = reactive({ company: '', personalityTags: [], hobbies: [], + personalityTagLibrary: [], // 新增 + hobbyLibrary: [], // 新增 childhood: { date: '', text: '' }, joy: { date: '', text: '' }, low: { date: '', text: '' }, @@ -243,8 +245,32 @@ const birthdayDisplay = computed(() => { return `${year}年${month}月${day}日` }) +/** + * 合并预设数组与已选数组,去重返回完整库 + */ +const buildInitialLibrary = (preset, selected) => { + const library = [...preset] + if (Array.isArray(selected)) { + selected.forEach((tag) => { + if (!library.includes(tag)) library.push(tag) + }) + } + return library +} + const syncFromStore = () => { const source = store.userProfile || store.registrationData || {} + + // 性格标签库:后端有则用后端,否则用预设 + 已选合并(老用户兼容) + const personalityTagLibrary = Array.isArray(source.personalityTagLibrary) && source.personalityTagLibrary.length > 0 + ? [...source.personalityTagLibrary] + : buildInitialLibrary(personalityTags, source.personalityTags) + + // 兴趣爱好库:后端有则用后端,否则用预设 + 已选合并(老用户兼容) + const hobbyLibrary = Array.isArray(source.hobbyLibrary) && source.hobbyLibrary.length > 0 + ? [...source.hobbyLibrary] + : buildInitialLibrary(hobbyOptions, source.hobbies) + Object.assign(form, { nickname: source.nickname || '', gender: source.gender || '', @@ -256,6 +282,8 @@ const syncFromStore = () => { company: source.company || '', personalityTags: Array.isArray(source.personalityTags) ? [...source.personalityTags] : [], hobbies: Array.isArray(source.hobbies) ? [...source.hobbies] : [], + personalityTagLibrary, + hobbyLibrary, childhood: { date: source.childhood?.date || '', text: source.childhood?.text || '' }, joy: { date: source.joy?.date || '', text: source.joy?.text || '' }, low: { date: source.low?.date || '', text: source.low?.text || '' },