浏览代码

Merge branch 'develop/3.3.0' into test

* develop/3.3.0:
  feature:增加授权页的返回按钮监听
  feature:增加弹框提示
zeng.chen 16 小时之前
父节点
当前提交
5cd3b50255
共有 1 个文件被更改,包括 52 次插入3 次删除
  1. 52 3
      src/pages/ximalaya/index.vue

+ 52 - 3
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 = '授权失败!'
@@ -29,10 +63,25 @@ export default {
       const code = res.code === 0 ? "1" : "0"
       const postMessage = `?name=${name}&code=${code}`
     if (window.wx && window.wx.miniProgram) {
-      window.wx && window.wx.miniProgram.postMessage(postMessage);
+      uni.showToast({
+        title: "微信小程序环境",
+        icon: 'none',
+        duration: 2000
+      });
+      window.wx.miniProgram.postMessage(postMessage);
     } else if (window.webChannel) {
+      uni.showToast({
+        title: "app环境",
+        icon: 'none',
+        duration: 2000
+      });
       webChannel.postMessage(postMessage)
-    }
+    } else {
+      uni.showToast({
+        title: "其他环境",
+        icon: 'none',
+        duration: 2000
+      });}
     })
   },  getEnvType() {
     if (window.wx && window.wx.miniProgram) {