Forráskód Böngészése

feature:增加授权页的返回按钮监听

zeng.chen 19 órája
szülő
commit
f03b4387c8
1 módosított fájl, 35 hozzáadás és 1 törlés
  1. 35 1
      src/pages/ximalaya/index.vue

+ 35 - 1
src/pages/ximalaya/index.vue

@@ -11,15 +11,49 @@ export default {
   data() {
     return {
       type: 'spinner-cycle',
-      title: '加载中...'
+      title: '加载中...',
+      isSuccess: false,
     }
   },
+    mounted() {
+    window.addEventListener('popstate', this.handleBack);
+  },
+  beforeDestroy() {
+    window.removeEventListener('popstate', this.handleBack);
+  },
+     handleBack() {
+ 
+    const name = 'authXmlyWeb'
+      const code = this.isSuccess ? "1" : "0"
+      const postMessage = `?name=${name}&code=${code}`
+    if (window.wx && window.wx.miniProgram) {
+      uni.showToast({
+        title: "微信小程序环境2",
+        icon: 'none',
+        duration: 2000
+      });
+      window.wx.miniProgram.postMessage(postMessage);
+    } else if (window.webChannel) {
+      uni.showToast({
+        title: "app环境2",
+        icon: 'none',
+        duration: 2000
+      });
+      webChannel.postMessage(postMessage)
+    } else {
+      uni.showToast({
+        title: "其他环境2",
+        icon: 'none',
+        duration: 2000
+      });}
+    },
   onLoad(e) {
     const deviceid = window.location.hash.split('=')[1]
     getCallBack({ ...e, deviceid: deviceid }).then(res => {
       if (res.code === 0) {
         this.type = 'checkbox-filled'
         this.title = '授权成功!'
+        this.isSuccess = true
       } else {
         this.type = 'clear'
         this.title = '授权失败!'