Browse Source

feat: 绑定上级

xiansin 2 years ago
parent
commit
19af7e1ec1
2 changed files with 16 additions and 15 deletions
  1. 2 11
      mini/App.vue
  2. 14 4
      mini/pages/index/index.vue

+ 2 - 11
mini/App.vue

xqd
@@ -14,21 +14,12 @@ export default {
       Cache.set('parent_id', query.user_id)
     }
     // 微信小程序 对应的二维码是 scene_code
-    if (typeof query.scene_code !== 'undefined' && query.scene_code) {
-      Cache.set('parent_id', query.scene_code)
+    if (typeof query.scene !== 'undefined' && query.scene) {
+      Cache.set('parent_id', query.scene)
     }
     if (this.$api.user.isLogin()) {
       await this.$api.user.info().then(res => {
         this.$store.dispatch('user/info', res.data)
-        // 绑定上级
-        const parentId = Cache.get('parent_id')
-        if (parentId && !res.data.info.parent_id) {
-          this.$api.user.bind(parentId).then(res => {
-            console.log('-->bind parent success')
-            this.$store.dispatch('user/info', res.data)
-            Cache.remove('parent_id')
-          })
-        }
       })
     } else {
       uni.reLaunch({

+ 14 - 4
mini/pages/index/index.vue

xqd xqd xqd
@@ -53,6 +53,7 @@ import NavBar from '../../components/NavBar/index'
 import Recent from './components/Recent'
 import CheckLogin from '../../components/CheckLogin/index'
 import { mapState } from 'vuex'
+import Cache from '../../utils/cache'
 export default {
   components: { CheckLogin, Recent, NavBar, TabBar, EpisodeBox, SwiperBox },
   data() {
@@ -78,8 +79,13 @@ export default {
     })
   },
   onLoad(options) {
+    // 微信小程序 对应的二维码是 scene_code
+    if (typeof options.scene !== 'undefined' && options.scene) {
+      Cache.set('parent_id', options.scene)
+    }
     console.log('-->index data', options)
     this.isLogin && this.getHomeColumn()
+    this.isLogin && this.bindParent()
   },
   methods: {
     handleSearch() {
@@ -103,10 +109,14 @@ export default {
       })
     },
     bindParent() {
-      this.$api.user.bind(this.parent_id ? this.parent_id : this.scene_code).then(res => {
-        console.log('-->bind success')
-        this.$store.dispatch('user/info', res.data)
-      })
+      const parentId = Cache.get('parent_id')
+      if (parentId && !this.userInfo.parent_id) {
+        this.$api.user.bind(parentId).then(res => {
+          console.log('-->bind success')
+          this.$store.dispatch('user/info', res.data)
+          Cache.remove('parent_id')
+        })
+      }
     }
   },
   onShareAppMessage() {