浏览代码

解决ios页面无法请求问题

huangxiaojing 4 年之前
父节点
当前提交
8039bd9df8
共有 1 个文件被更改,包括 74 次插入44 次删除
  1. 74 44
      microserviceUserH5/vcloud/invite.html

+ 74 - 44
microserviceUserH5/vcloud/invite.html

@@ -3,7 +3,7 @@
 
 <head>
     <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
     <title>邀请有礼</title>
     <link rel="icon" href="../static/img/favicon2.ico" type="img/x-ico">
     <link rel="stylesheet" href="../static/js/vender/toastr/toastr.min.css">
@@ -95,54 +95,84 @@
             btnMsg = '复制邀请链接'
         }
         $('#recv_btn').append(btnMsg)
+        if (isiOS) {
+            $.ajax({
+                url: baseUrl + '/api/user/v3/invitation/client/getInvitationInfo',
+                type: 'get',
+                headers: {
+                    'Authorization': id  //id
+                },
+                contentType: "application/json",
+                dataType: 'json',
+                cache: false,
+                success: function (res) {
+                    var jsonStr = JSON.stringify(res.data)
+                    var jsonObj = JSON.parse(jsonStr)
+                    // WKWebView使用
+                    // 使用下方方法,会报错,为使界面执行逻辑通畅,因此使用try-catch
+                    try {
+                        getMessage(jsonObj);
+                    } catch (error) {
+                        console.log(error)
+                    }
+                    try {
+                        window.webkit.messageHandlers.getMessage.postMessage(jsonObj)
+                    } catch (error) {
+                        console.log(error)
+                    }
+                }
+            })
+        } else if (isAndroid) {
+            window.native.onClikWebView()
+        } else {
+            $.ajax({
+                url: baseUrl + '/api/user/v3/invitation/client/getInvitationInfo',
+                type: 'get',
+                headers: {
+                    'Authorization': id  //id
+                },
+                contentType: "application/json",
+                dataType: 'json',
+                cache: false,
+                success: function (res) {
+                    $('#invitationCode').text(res.data.invitationCode)
+                    //加载数据
+                    $('#passwordCopy').val($('#invitationCode').text());
 
-        $.ajax({
-            url: baseUrl + '/api/user/v3/invitation/client/getInvitationInfo',
-            type: 'get',
-            headers: {
-                'Authorization': id  //id
-            },
-            contentType: "application/json",
-            dataType: 'json',
-            cache: false,
-            success: function (res) {
-                $('#invitationCode').text(res.data.invitationCode)
-                //加载数据
-                $('#passwordCopy').val($('#invitationCode').text());
-
-                //复制按钮
-                $('.btn-code-copy').on('click', function () {
-                    var input = document.getElementById("passwordCopy");
-                    // 选中文本
-                    input.select();
-                    // 执行浏览器复制命令
-                    document.execCommand("copy");
-                    toastr.error('复制成功', 0)
-                });
+                    //复制按钮
+                    $('.btn-code-copy').on('click', function () {
+                        var input = document.getElementById("passwordCopy");
+                        // 选中文本
+                        input.select();
+                        // 执行浏览器复制命令
+                        document.execCommand("copy");
+                        toastr.error('复制成功', 0)
+                    });
 
-                if (res.data.friendList.length > 0) {
-                    var str = '<ul class="goodFriend-title-list"><li class="tal">被邀请好友帐号</li><li class="tac">获时长数(小时)</li><li class="tar">邀请时间</li></ul>'
-                    for (var i = 0; i < res.data.friendList.length; i++) {
-                        var phone = res.data.friendList[i].newPhone
-                        var inviteMsg = res.data.friendList[i].duration
-                        var registerTime = res.data.friendList[i].createTime
-                        var nPhone = phone.substr(0, 3) + '****' + phone.substring(7, 11)
-                        str += '<div class="goodFriend-item">'
-                        str += '<span class="tal">' + nPhone + '</span>'
-                        str += Number(inviteMsg) && inviteMsg > 0 ? '<span class="tac cF04646">' + inviteMsg + '</span>' : '<span class="tac">' + inviteMsg + '</span>'
-                        str += '<span class="tar">' + registerTime + '</span>'
-                        str += '</div>';
+                    if (res.data.friendList.length > 0) {
+                        var str = '<ul class="goodFriend-title-list"><li class="tal">被邀请好友帐号</li><li class="tac">获时长数(小时)</li><li class="tar">邀请时间</li></ul>'
+                        for (var i = 0; i < res.data.friendList.length; i++) {
+                            var phone = res.data.friendList[i].newPhone
+                            var inviteMsg = res.data.friendList[i].duration
+                            var registerTime = res.data.friendList[i].createTime
+                            var nPhone = phone.substr(0, 3) + '****' + phone.substring(7, 11)
+                            str += '<div class="goodFriend-item">'
+                            str += '<span class="tal">' + nPhone + '</span>'
+                            str += Number(inviteMsg) && inviteMsg > 0 ? '<span class="tac cF04646">' + inviteMsg + '</span>' : '<span class="tac">' + inviteMsg + '</span>'
+                            str += '<span class="tar">' + registerTime + '</span>'
+                            str += '</div>';
+                        }
+                    } else if (res.data.friendList.length === 0) {
+                        str = '<div class="no-data">还没有邀请到好友哦~</div>'
                     }
-                } else if (res.data.friendList.length === 0) {
+                    $('#goode').append(str);
+                }, 
+                error: function () {
                     str = '<div class="no-data">还没有邀请到好友哦~</div>'
+                    $('#goode').append(str)
                 }
-                $('#goode').append(str);
-            }, 
-            error: function () {
-                str = '<div class="no-data">还没有邀请到好友哦~</div>'
-                $('#goode').append(str)
-            }
-        })
+            })
+        }
 
         $("#recv_ipt").bind('input propertychange', function (e) {
             var ipt_phones = $('#recv_ipt').val();