|
|
@@ -5,6 +5,7 @@ import tianpan from './modules/tianpan'
|
|
|
import feedback from './feedback'
|
|
|
import healthAlert from './health-alert'
|
|
|
import healthScore from './health-score'
|
|
|
+import { switchBackVerify } from '../utils/api.js'
|
|
|
|
|
|
Vue.use(Vuex)
|
|
|
|
|
|
@@ -80,7 +81,8 @@ const store = new Vuex.Store({
|
|
|
uni.setStorageSync('isSwitchedChild', false)
|
|
|
uni.setStorageSync('currentView', 'self')
|
|
|
},
|
|
|
- // 通过family_members切换到某个成员
|
|
|
+ // 通过family_members切换到某个成员(member 语义统一入口)
|
|
|
+ // 注:effectiveRole 为 'child' 时同步设置 currentChildId/isSwitchedChild 兼容旧页面
|
|
|
switchToMember(state, payload) {
|
|
|
state.currentRole = payload.effectiveRole
|
|
|
state.currentMemberId = payload.memberId
|
|
|
@@ -193,20 +195,34 @@ const store = new Vuex.Store({
|
|
|
commit('switchToChild', memberId)
|
|
|
return true
|
|
|
},
|
|
|
- // 切换到家庭成员前检查(仅 child 角色需要前置检查)
|
|
|
+ // 切换到家庭成员前检查(仅不可登录成员可切换)
|
|
|
switchToMemberWithCheck({ commit }, payload) {
|
|
|
- if (payload.effectiveRole === 'child') {
|
|
|
- var members = payload.members || []
|
|
|
- var hasChildren = members.some(function(m) {
|
|
|
- return m.effectiveRole === 'child'
|
|
|
- })
|
|
|
- if (!hasChildren) {
|
|
|
- uni.showToast({ title: '家庭中暂无孩子', icon: 'none' })
|
|
|
- return false
|
|
|
- }
|
|
|
+ var member = payload.member || {}
|
|
|
+ if (member.isSwitchable === false) {
|
|
|
+ uni.showToast({ title: '该成员可通过微信登录,不能切换为TA的身份', icon: 'none' })
|
|
|
+ return false
|
|
|
}
|
|
|
commit('switchToMember', payload)
|
|
|
return true
|
|
|
+ },
|
|
|
+ // 带密码校验退出成员切换(返回原用户身份)
|
|
|
+ async switchBackWithPassword({ commit }, password) {
|
|
|
+ if (!password) {
|
|
|
+ uni.showToast({ title: '请输入原用户密码', icon: 'none' })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const res = await switchBackVerify(password)
|
|
|
+ if (res.code === 200) {
|
|
|
+ commit('switchBackFromMember')
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ uni.showToast({ title: res.message || '密码错误', icon: 'none' })
|
|
|
+ return false
|
|
|
+ } catch (e) {
|
|
|
+ uni.showToast({ title: '校验失败', icon: 'none' })
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
,
|