Просмотр исходного кода

feat(store): 切换孩子前检查家庭成员中是否有child角色

新增switchToChildWithCheck/switchToMemberWithCheck actions,无孩子时弹提示不切换

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Sisyphus 3 месяцев назад
Родитель
Сommit
6809ca9d83
1 измененных файлов с 27 добавлено и 0 удалено
  1. 27 0
      cfc-frontend/store/index.js

+ 27 - 0
cfc-frontend/store/index.js

@@ -164,6 +164,33 @@ const store = new Vuex.Store({
     },
     updateChildren({ commit }, children) {
       commit('setChildren', children)
+    },
+    // 切换孩子前检查家庭中是否有孩子成员
+    switchToChildWithCheck({ commit }, { childId, members }) {
+      var hasChildren = members && members.some(function(m) {
+        return m.effectiveRole === 'child'
+      })
+      if (!hasChildren) {
+        uni.showToast({ title: '家庭中暂无孩子', icon: 'none' })
+        return false
+      }
+      commit('switchToChild', childId)
+      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
+        }
+      }
+      commit('switchToMember', payload)
+      return true
     }
   }
 ,