Browse Source

feat(frontend): 切换入口确认提示 + 退出切换统一密码校验

iwt 2 weeks ago
parent
commit
bc60698908

+ 11 - 17
cfc-frontend/components/ProfileHeader.vue

@@ -112,27 +112,21 @@ export default {
         }
       })
     },
-    onExitSwitch() {
+    async onExitSwitch() {
       if (!this.isSwitchedChild) return
+      var self = this
       uni.showModal({
         title: '退出切换',
-        content: '请输入家长密码以确认退出',
+        content: '请输入原用户密码以确认退出',
         editable: true,
-        success: (res) => {
-          if (res.confirm && res.content) {
-            verifyPassword(res.content).then((result) => {
-              if (result.code === 200) {
-                this.$store.commit('switchBackToParent')
-                this.isSwitchedChild = false
-                this.role = 'parent'
-                uni.showToast({ title: '已退出切换', icon: 'success' })
-                uni.reLaunch({ url: '/pages/index-home/index' })
-              } else {
-                uni.showToast({ title: '密码错误', icon: 'none' })
-              }
-            }).catch(() => {
-              uni.showToast({ title: '验证失败', icon: 'none' })
-            })
+        success: async function(res) {
+          if (!res.confirm || !res.content) return
+          var ok = await self.$store.dispatch('switchBackWithPassword', res.content)
+          if (ok) {
+            self.isSwitchedChild = false
+            self.role = 'parent'
+            uni.showToast({ title: '已退出切换', icon: 'success' })
+            uni.reLaunch({ url: '/pages/index-home/index' })
           }
         }
       })

+ 24 - 16
cfc-frontend/pages/home-pages/parent-index.vue

@@ -1032,23 +1032,31 @@ export default {
     },
     async onFamilyMemberSwitch(member) {
       if (!member || !member.id) return
-      try {
-        var res = await switchToFamilyMember(member.id, member.source || 'family_member')
-        if (res.code === 200 && res.data) {
-          store.commit('switchToMember', {
-            memberId: res.data.memberId,
-            effectiveRole: res.data.effectiveRole
-          })
-          uni.showToast({ title: '已切换到' + (member.nickname || '该成员'), icon: 'success' })
-          setTimeout(function() {
-            uni.reLaunch({ url: '/pages/index-home/index' })
-          }, 1000)
-        } else {
-          uni.showToast({ title: res.message || '切换失败', icon: 'none' })
+      var self = this
+      uni.showModal({
+        title: '切换确认',
+        content: '切换到"' + (member.nickname || '该成员') + '"后,退出时需要输入您的密码。是否继续?',
+        success: async function(res) {
+          if (!res.confirm) return
+          try {
+            var result = await switchToFamilyMember(member.id, member.source || 'family_member')
+            if (result.code === 200 && result.data) {
+              store.commit('switchToMember', {
+                memberId: result.data.memberId,
+                effectiveRole: result.data.effectiveRole
+              })
+              uni.showToast({ title: '已切换到' + (member.nickname || '该成员'), icon: 'success' })
+              setTimeout(function() {
+                uni.reLaunch({ url: '/pages/index-home/index' })
+              }, 1000)
+            } else {
+              uni.showToast({ title: result.message || '切换失败', icon: 'none' })
+            }
+          } catch (e) {
+            uni.showToast({ title: '切换失败', icon: 'none' })
+          }
         }
-      } catch (e) {
-        uni.showToast({ title: '切换失败', icon: 'none' })
-      }
+      })
     },
     onMicroActionCompleted() {
       this.loadData()