|
|
@@ -5,9 +5,16 @@
|
|
|
<view class="nav-back" @click="goBack">
|
|
|
<text class="nav-back-icon">←</text>
|
|
|
</view>
|
|
|
-<view class="nav-right" @click="showMemberPicker = true">
|
|
|
- <text class="nav-current-member">{{ currentMemberName }}</text>
|
|
|
- <text class="nav-arrow">▼</text>
|
|
|
+ <!-- 我的 / 全家 切换 Tab -->
|
|
|
+ <view class="nav-tabs">
|
|
|
+ <view class="nav-tab" :class="{ active: currentView !== 'family' }" @click="switchView('self')">
|
|
|
+ <text class="nav-tab-icon">{{ currentMemberIcon }}</text>
|
|
|
+ <text class="nav-tab-label">{{ currentTabLabel }}</text>
|
|
|
+ </view>
|
|
|
+ <view class="nav-tab" :class="{ active: currentView === 'family' }" @click="switchView('family')">
|
|
|
+ <text class="nav-tab-icon">🏠</text>
|
|
|
+ <text class="nav-tab-label">全家</text>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -27,7 +34,7 @@
|
|
|
</template>
|
|
|
|
|
|
<!-- 已登录 -->
|
|
|
- <template v-else-if="!loading && sandboxData">
|
|
|
+ <template v-else-if="!loading && (familySandboxData || sandboxData)">
|
|
|
<!-- ===== 能量总览卡 ===== -->
|
|
|
<view class="overview-card">
|
|
|
<view class="overview-header">
|
|
|
@@ -132,33 +139,6 @@
|
|
|
<!-- 底部占位 -->
|
|
|
<view class="bottom-spacer"></view>
|
|
|
</template>
|
|
|
-
|
|
|
- <!-- 成员选择弹窗 -->
|
|
|
- <view class="modal-mask" v-if="showMemberPicker" @click="showMemberPicker = false">
|
|
|
- <view class="member-picker" @click.stop>
|
|
|
- <view class="picker-header">
|
|
|
- <text class="picker-title">选择查看对象</text>
|
|
|
- <text class="picker-close" @click="showMemberPicker = false">×</text>
|
|
|
- </view>
|
|
|
- <view class="picker-item" :class="{ active: currentView === 'family' }" @click="switchView('family')">
|
|
|
- <text class="picker-icon">🏠</text>
|
|
|
- <text class="picker-label">全家总览</text>
|
|
|
- <text class="picker-desc">家庭整体能量状态</text>
|
|
|
- </view>
|
|
|
- <view
|
|
|
- class="picker-item"
|
|
|
- v-for="m in familyMembers"
|
|
|
- :key="m.memberId"
|
|
|
- :class="{ active: selectedMemberId === m.memberId }"
|
|
|
- @click="selectMember(m); showMemberPicker = false">
|
|
|
- <view class="picker-avatar" :style="{ background: memberColor(m) }">
|
|
|
- <text class="picker-avatar-text">{{ m.name ? m.name.charAt(0) : '?' }}</text>
|
|
|
- </view>
|
|
|
- <text class="picker-label">{{ m.name || '成员' }}</text>
|
|
|
- <text class="picker-desc">{{ m.familyRole || m.memberType || '' }}</text>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
@@ -181,6 +161,7 @@ export default {
|
|
|
loading: true,
|
|
|
isLoggedIn: false,
|
|
|
sandboxData: null,
|
|
|
+ familySandboxData: null,
|
|
|
familyMembers: [],
|
|
|
selectedMemberId: null,
|
|
|
currentView: 'self', // self | family
|
|
|
@@ -191,7 +172,10 @@ export default {
|
|
|
dimList() { return DIM_CONFIG },
|
|
|
currentMember() {
|
|
|
if (this.currentView === 'family') return null
|
|
|
- return this.familyMembers.find(m => m.memberId === this.selectedMemberId) || null
|
|
|
+ if (this.familySandboxData && this.familySandboxData.members) {
|
|
|
+ return this.familySandboxData.members.find(function(m) { return m.memberId === this.selectedMemberId }.bind(this)) || null
|
|
|
+ }
|
|
|
+ return this.familyMembers.find(function(m) { return m.memberId === this.selectedMemberId }) || null
|
|
|
},
|
|
|
currentMemberName() {
|
|
|
if (this.currentView === 'family') return '全家'
|
|
|
@@ -205,11 +189,14 @@ export default {
|
|
|
},
|
|
|
overallScore() {
|
|
|
if (this.currentView === 'family') {
|
|
|
- return this.sandboxData && this.sandboxData.overallScore
|
|
|
+ return this.familySandboxData && this.familySandboxData.overallScore
|
|
|
}
|
|
|
if (this.currentMember) {
|
|
|
return this.currentMember.overallScore
|
|
|
}
|
|
|
+ if (this.sandboxData) {
|
|
|
+ return this.sandboxData.overallScore
|
|
|
+ }
|
|
|
return null
|
|
|
},
|
|
|
avatarChar() {
|
|
|
@@ -223,6 +210,16 @@ export default {
|
|
|
return 'linear-gradient(135deg,#8B5CF6,#A78BFA)'
|
|
|
},
|
|
|
navTitle() { return this.currentMemberName + ' · 五维能量' },
|
|
|
+ currentMemberIcon() {
|
|
|
+ if (this.currentView === 'family') return '🏠'
|
|
|
+ if (this.currentMember) return (this.currentMember.name || '?').charAt(0)
|
|
|
+ return '👤'
|
|
|
+ },
|
|
|
+ currentTabLabel() {
|
|
|
+ if (this.currentView === 'family') return '全家'
|
|
|
+ if (!this.currentMember) return '我的'
|
|
|
+ return this.currentMember.name || '我的'
|
|
|
+ },
|
|
|
navGradient() {
|
|
|
if (this.currentView === 'family') return 'linear-gradient(135deg,#667eea,#764ba2)'
|
|
|
if (this.currentMember) {
|
|
|
@@ -237,11 +234,14 @@ export default {
|
|
|
},
|
|
|
radarScores() {
|
|
|
if (this.currentView === 'family') {
|
|
|
- var d = this.sandboxData
|
|
|
- return DIM_CONFIG.map(dim => d ? (d[dim.code + 'Score'] || 0) : 0)
|
|
|
+ var d = this.familySandboxData
|
|
|
+ return DIM_CONFIG.map(function(dim) { return d ? (d[dim.code + 'Score'] || 0) : 0 })
|
|
|
}
|
|
|
if (this.currentMember) {
|
|
|
- return DIM_CONFIG.map(dim => this.currentMember[dim.code + 'Score'] || 0)
|
|
|
+ return DIM_CONFIG.map(function(dim) { return this.currentMember[dim.code + 'Score'] || 0 }.bind(this))
|
|
|
+ }
|
|
|
+ if (this.sandboxData) {
|
|
|
+ return DIM_CONFIG.map(function(dim) { return this.sandboxData[dim.code + 'Score'] || 0 }.bind(this))
|
|
|
}
|
|
|
return [0, 0, 0, 0, 0]
|
|
|
}
|
|
|
@@ -276,7 +276,7 @@ export default {
|
|
|
},
|
|
|
getDimScore(code) {
|
|
|
if (this.currentView === 'family') {
|
|
|
- return this.sandboxData ? (this.sandboxData[code + 'Score'] || 0) : 0
|
|
|
+ return this.familySandboxData ? (this.familySandboxData[code + 'Score'] || 0) : 0
|
|
|
}
|
|
|
if (this.currentMember) {
|
|
|
return this.currentMember[code + 'Score'] || 0
|
|
|
@@ -286,22 +286,39 @@ export default {
|
|
|
async loadData() {
|
|
|
this.loading = true
|
|
|
try {
|
|
|
+ // 个人沙盘(当前登录用户五维)
|
|
|
var res = await getFamilyEnergySandbox()
|
|
|
if (res && res.code === 200 && res.data) {
|
|
|
this.sandboxData = res.data
|
|
|
- // 如果是新格式,提取 familyData
|
|
|
- if (res.data.familyData) {
|
|
|
+ // 兼容新格式:解包 personalData
|
|
|
+ if (res.data.personalData) {
|
|
|
+ this.sandboxData = res.data.personalData
|
|
|
+ } else if (res.data.familyData) {
|
|
|
this.sandboxData = res.data.familyData
|
|
|
}
|
|
|
}
|
|
|
- // 加载家庭成员
|
|
|
+ // 家庭沙盘(全家聚合 + 各成员个人数据,作为成员分数来源)
|
|
|
+ var famRes = await getEnergySandbox('family')
|
|
|
+ if (famRes && famRes.code === 200 && famRes.data && famRes.data.familyData) {
|
|
|
+ this.familySandboxData = famRes.data.familyData
|
|
|
+ }
|
|
|
+ // 加载家庭成员(visibleOnly 列表,用于 isSelf/name 等展示属性)
|
|
|
var memRes = await getFamilyMemberList({ visibleOnly: true })
|
|
|
if (memRes && memRes.code === 200 && memRes.data) {
|
|
|
this.familyMembers = memRes.data
|
|
|
- // 默认选中第一个非自己(如果有)
|
|
|
- if (this.familyMembers.length > 0 && !this.selectedMemberId) {
|
|
|
- this.selectedMemberId = this.familyMembers[0].memberId
|
|
|
+ }
|
|
|
+ // 确定默认选中成员:优先全局切换的成员
|
|
|
+ var switchedId = uni.getStorageSync('currentMemberId') || uni.getStorageSync('currentChildId')
|
|
|
+ var pool = (this.familySandboxData && this.familySandboxData.members) || this.familyMembers
|
|
|
+ if (switchedId && pool.length > 0) {
|
|
|
+ var matched = pool.find(function(m) { return m.memberId === switchedId })
|
|
|
+ if (matched) {
|
|
|
+ this.selectedMemberId = switchedId
|
|
|
+ } else if (pool.length > 0) {
|
|
|
+ this.selectedMemberId = pool[0].memberId
|
|
|
}
|
|
|
+ } else if (pool.length > 0 && !this.selectedMemberId) {
|
|
|
+ this.selectedMemberId = pool[0].memberId
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.error('加载能量数据失败', e)
|
|
|
@@ -313,6 +330,18 @@ export default {
|
|
|
this.currentView = view
|
|
|
if (view === 'family') {
|
|
|
this.selectedMemberId = null
|
|
|
+ } else if (!this.selectedMemberId) {
|
|
|
+ // 「我的」Tab:若尚未选中成员,绑定全局切换成员或第一个
|
|
|
+ var switchedId = uni.getStorageSync('currentMemberId') || uni.getStorageSync('currentChildId')
|
|
|
+ if (switchedId && this.familyMembers.length > 0) {
|
|
|
+ var matched = this.familyMembers.find(function(m) { return m.memberId === switchedId })
|
|
|
+ if (matched) {
|
|
|
+ this.selectedMemberId = switchedId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!this.selectedMemberId && this.familyMembers.length > 0) {
|
|
|
+ this.selectedMemberId = this.familyMembers[0].memberId
|
|
|
+ }
|
|
|
}
|
|
|
this.showMemberPicker = false
|
|
|
},
|