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 || '' },