Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

libai / Static

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Static
  • js
  • webAppComm.js
Find file
BlameHistoryPermalink
  • agan's avatar
    xg · fab73eb9
    agan committed a year ago
    fab73eb9
webAppComm.js 17.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
// 2:跳转到WebViewFragment
// 3:分享
// 4:客服
// 5:跳轉到外部瀏覽器
// 6:打开兑换宝石页面
// 7:绑定手机
// 8:跳转微信绑定页面
// 9:是否分享或帮助
// 10:判断某个app是否存在
// 11:网页标题 (棄用)
// 13:半屏网页声音开启关闭:
// 12:跳转逻辑
// 13:关闭声音
// 14:关闭网页
// 15:通用viepager標題
// 16:成功转让黄金萤火虫
// 17:关闭半屏网页,打开自己的礼物面板
// 18: 打開購買VIP
// 19:打開購買守護彈窗
// 20:播放座驾预览
// 23:自動添加直播間聊天消息
// 24:获取网页图片下标
// 25:点击web
// 26:是否显示客服入口
// 27:直接唤起 苹果支付 和 google支付:(萤火虫6000版本新增)
// 28:判断是否在外部可以关闭webview
// 29:webview上面的图标 (旧)
// 30:注销账号后退出
// 31:弹出WEB弹窗
// 32:webview上面的图标 (新)
// 33:打开更多功能面板
// 34:修改标题
// 35:打开游戏
// 36:播放動畫

// 37: web页面加载完毕时通知客户端
// 38: 打开签到提醒
// 39: 告知客户端渠道信息
// 40: 跳转任务界面

// 41: 修改webview底色
// 42: 振动

function webAppComm() {
    this.data = null;
    this.langList = [
        {
            'lang1': 'Events Rule',
            'lang2': 'Refresh',
            'lang3': 'Customer Service',
            'lang4': 'Compartir',
            'lang5': 'Event Zone',
            'lang6': 'Close Page',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //1英文
        {
            'lang1': 'Events Rule',
            'lang2': 'Refresh',
            'lang3': 'Customer Service',
            'lang4': 'Compartir',
            'lang5': 'Event Zone',
            'lang6': 'Close Page',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //2繁体
        {
            'lang1': '活動規則',
            'lang2': '刷新',
            'lang3': '客服咨詢',
            'lang4': '推薦朋友',
            'lang5': '活動專區',
            'lang6': '關閉頁面',
            'lang7': '露水',
            'lang8': '寶石'
        },
        //3泰语
        {
            'lang1': 'กฎกติกากิจกรรม',
            'lang2': 'รีเฟรช',
            'lang3': 'บริการลูกค้า',
            'lang4': 'แชร์',
            'lang5': 'โซนกิจกรรม',
            'lang6': 'ปิดหน้านี้',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //4日语
        {
            'lang1': 'イベントルール',
            'lang2': '更新する',
            'lang3': 'カスタマーサービス',
            'lang4': '共有',
            'lang5': 'イベントゾーン',
            'lang6': 'ページを閉じる',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //5印尼
        {
            'lang1': 'Aturan acara',
            'lang2': 'Segarkan',
            'lang3': 'Layanan Pelanggan',
            'lang4': 'Bagikan',
            'lang5': 'Zona Acara',
            'lang6': 'Tutup halaman',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //6
        {
            'lang1': 'Events Rule',
            'lang2': 'Refresh',
            'lang3': 'Customer Service',
            'lang4': 'Compartir',
            'lang5': 'Event Zone',
            'lang6': 'Close Page',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //7阿拉伯
        {
            'lang1': 'قواعد الحدث',
            'lang2': 'تحديث',
            'lang3': 'خدمة العملاء',
            'lang4': 'مشاركة',
            'lang5': 'منطقة الفعاليات',
            'lang6': 'إغلاق الصفحة',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //8越南
        {
            'lang1': 'Quy tắc sự kiện',
            'lang2': 'Làm mới',
            'lang3': 'Dịch vụ khách hàng',
            'lang4': 'Chia sẻ',
            'lang5': 'Khu vực sự kiện',
            'lang6': 'Đóng trang',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //9韩文
        {
            'lang1': 'Events Rule',
            'lang2': 'Refresh',
            'lang3': 'Customer Service',
            'lang4': 'Compartir',
            'lang5': 'Event Zone',
            'lang6': 'Close Page',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        },
        //10西班牙
        {
            'lang1': 'Reglas del evento',
            'lang2': 'Actualizar',
            'lang3': 'Servicio al Cliente',
            'lang4': 'Share',
            'lang5': 'Zona de Eventos',
            'lang6': 'Cerrar página',
            'lang7': 'DEWs',
            'lang8': 'GEMs'
        }
    ];
    this.urlData = this.url_get_params(location.href);
    this.langType = this.urlData.lang;
    this.needRefresh = false;
}

//分享
webAppComm.prototype.goShare = function (shareContent, shareType) {
    let mShare = shareType || { //1图片  2文字  3网页
        "wechat": 3,
        "wechat_moment": 3,
        "facebook": 3,
        "line": 3,
        "link": 3,
        "whatsApp": 3,
        "twitter": 3
    }
    let obj = {
        "cid": 3,
        "reqCode": new Date().getTime(),
        "data": {
            "shareContent": shareContent,
            "shareType": mShare
        }

    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2)
}

//客服
webAppComm.prototype.goCustomerService = function () {
    let obj = {
        "cid": 4,
        "reqCode": new Date().getTime(),
        "data": {
            "msg": "Hi,請問有什麼可以幫到您?",
            "customerLayer": 1,
            "uid": 1000,
            "face": 'https://app.ixiulive.com/static/images/yhx.png',
            "nickname": "客服",
            "title": "客服",
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2)
}

//跳转外部浏览器
webAppComm.prototype.goExternalWeb = function (h5Url) {
    let obj = {
        "cid": 5,
        "reqCode": new Date().getTime(),
        "data": {
            "url": h5Url,
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//打开兑换宝石页面
webAppComm.prototype.goExchangeGem = function () {
    let obj = {
        "cid": 6,
        "reqCode": new Date().getTime(),
        "data": {
            "msg": '打开兑换寶石'
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//绑定手机
webAppComm.prototype.goBindPhone = function () {
    let obj2 = {
        "cid": 7,
        "reqCode": new Date().getTime(),
        "data": {
            msg: '点击跳转绑定手机页面',
        }
    }
    let obj = JSON.stringify(obj2);
    webAppCollaboration(obj);
}

//绑定微信
webAppComm.prototype.goBindWechat = function () {
    let obj2 = {
        "cid": 8,
        "reqCode": new Date().getTime(),
        "data": {
            msg: '跳转微信绑定页面'
        }
    }
    let obj = JSON.stringify(obj2);
    webAppCollaboration(obj)
}

//弹出帮助
webAppComm.prototype.needHelp = function () {
    let obj = {
        "cid": 9,
        "reqCode": new Date().getTime(),
        "data": {
            msg: '是否分享或帮助',
            shareType: 1,
            helpType: 0,
        }
    }
    let obj2 = JSON.stringify(obj)
    webAppCollaboration(obj2)
}

//确认是否有该APP
webAppComm.prototype.ifHasApp = function (type) { //1微信 2line 3facebook 4Twitter 5WhatsApp 6微博 7QQ
    let obj2 = {
        "cid": 10,
        "reqCode": new Date().getTime(),
        "data": {
            msg: '點擊確認有沒有這個APP',
            type: type
        }
    }
    let obj = JSON.stringify(obj2);
    webAppCollaboration(obj)
}

//跳转
webAppComm.prototype.goOthers = function (jumptype, url, isHide) {
    let arr = { 16: '去儲值', 18: '跳轉到座駕', 3: '跳轉集合功能', 13: 'VIP中心', 26: '设置' };
    let obj = {
        "cid": 12,
        "reqCode": new Date().getTime(),
        "data": {
            "msg": arr[jumptype],
            "jumptype": jumptype,  //16: 去储值  18: 跳转到座驾  3:跳转集合功能   28:跳转直播间  29:空间  26:设置  40:半屏宝石储值  41:礼物列表  42:背包列表
            "url": url, //41 42时传入礼物id。
            "hideTitle": isHide // 1隐藏头部,0 不隐藏, 默认为0
        }
    }

    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//关闭网页
webAppComm.prototype.closeWebView = function (callback) {
    callback && callback();
    let obj = {
        "cid": 14,
        "reqCode": new Date().getTime(),
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//打开多网页面板
webAppComm.prototype.openRecords = function (urls, type) {
    let obj = {
        "cid": 15,
        "reqCode": new Date().getTime(),
        "data": {
            "urls": [
                {
                    "url": $url + '/Nesting/recording/gem.html' + window.location.search,
                    "title": langList[langType].dew18,
                    "rightBtnImageURL": '',
                    "rightBtnClickURL": ''
                },
                {
                    "url": $url + '/Nesting/recording/dew.html' + window.location.search,
                    "title": langList[langType].dewExchangeTitle3,
                    "rightBtnImageURL": '',
                    "rightBtnClickURL": ''
                }
            ],
            "select": type,
            "titleColor": "",
            "titleSelectedColor": "",
            "titleBackground": '',

        }
    }
    let obj2 = JSON.stringify(obj);
    appCollaboration(obj2);
}

// 31: 打开半屏网页
webAppComm.prototype.openHalfWeb = function (param) {
    let obj = {
        "cid": 31,
        "data": {
            popupType: param.type,   //popupType   1全屏2半屏3浮动屏(默认居中)
            heightR: param.height,  //heightR  弹窗高度 单位vw;
            widthR: param.width,   //widthR 弹窗宽度vw
            clickBlank: param.clickBlank,  //clickBlank  点击区域外是否关闭 0不关闭  1关闭
            url: param.url,  //url   需要打开的url (默认拼接uid token roomid等参数)
            top: param.top || 0,   //top 距离顶部位置 单位vw
            left: param.left || 0,  //left 距离左边位置
            bottom: param.bottom || 0,  //bottom 距离底部位置
            right: param.right || 0,  //right 距离右边位置
            isThrough: param.isThrough,   //isThrough  是否可穿透 0不可穿透 1可穿透   默认为0 
            afterReady: param.afterReady, // afterReady 是否加载完成后再显示。   0否  1是。  默认为0,
            needMounted: param.needMounted,  //ios专用 0不独立 1独立。  默认是0.
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}



//webview右上角的icon
webAppComm.prototype.showIcons = function (infos) {
    let obj = {
        "cid": 32,  //新的右上角展示
        "data": {
            "msg": "h5网页右上角显示图标",
            "info": infos,
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//打开更多功能面板
webAppComm.prototype.openExtra = function (infos) {
    let obj = {
        "cid": 33,  //打开额外功能面板
        "data": {
            "msg": '打开额外功能面板',
            "info": infos
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

webAppComm.prototype.changeTitle = function (param) {
    let obj = {
        "cid": 34,  //修改网页title  居中显示。
        "data": {
            "type": param.type,  //1 图片  2文本。 
            "imgTxt": param.text,
            "imgUrl": param.url, //1
            "style": {
                //图片
                "width": param.w, //1
                "height": param.h, //1
            }
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//修改网页标题
webAppComm.prototype.changeTitle1 = function () {
    let obj = {
        "cid": 34,  //修改网页title  居中显示。
        "data": {
            "type": 1,  //1 图片  2文本。 
            "imgUrl": 'https://app.ixiulive.com/static/app/img/title.png?v=20230425', //1
            "style": {
                //图片
                "width": '161', //1
                "height": '70', //1
            }
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//修改网页标题
webAppComm.prototype.changeTitle2 = function () {
    let obj = {
        "cid": 34,  //修改网页title  居中显示。
        "data": {
            "type": 2,  //1 图片  2文本。 
            "imgTxt": $("title").text(),//2
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//修改网页标题
webAppComm.prototype.changeTitle3 = function (imgUrl, param) {
    let obj = {
        "cid": 34,  //修改网页title  居中显示。
        "data": {
            "type": 1,  //1 图片  2文本。 
            "imgUrl": imgUrl,
            "style": {
                //图片
                "width": param.width, //1
                "height": param.height, //1
            }
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//刷新网页
webAppComm.prototype.refreshWeb = function (callback) {
    callback && callback();
    if (this.needRefresh) {
        location.reload();
    }
}

// 35:打开游戏
webAppComm.prototype.goGame = function (mData) {
    let obj = {
        "cid": 35,
        "data": mData
    }

    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

// 36:播放動畫
webAppComm.prototype.playAnimate = function (mData) {
    let obj = {
        "cid": 36,
        "data": mData
    }

    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

// 37:web加载完毕
webAppComm.prototype.domReady = function (mData) {
    let obj = {
        "cid": 37,
        "data": mData
    }

    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

// 38:web打开/关闭签到提醒
webAppComm.prototype.openSignRemind = function () {
    let obj = {
        "cid": 38,
        "data": {
            "msg": '打开签到提醒'
        }
    }

    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}
// 39: 告知客户端渠道信息和uid
webAppComm.prototype.sendBindInfos = function (cid, uid, lang, type) {
    let obj = {
        "cid": 39,
        "data": {
            "channelId": cid,
            "agentUid": uid,
            "lang": lang,
            "bindType": type
        }
    }

    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

// 40: 跳转任务界面
webAppComm.prototype.jumpToTask = function (type) {
    let obj = {
        "cid": 40,
        "data": {
            "taskType": type   // 1:新手任务 2:每日任务 3:主播任务 4:奖励领取 
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//41: 修改webview的背景底色
webAppComm.prototype.setBackground = function (color) {
    let obj = {
        "cid": 41,
        "data": {
            "background": color   // # color值为HEX色值 例:#FFFFFF, 若为透明则是transparent
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//42: 手机振动
webAppComm.prototype.toVibrate = function (duration) {
    let obj = {
        "cid": 42,
        "data": {
            "duration": duration   // # duration为振动的秒数
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}

//43: 修改webview宽高
webAppComm.prototype.setRatio = function (type, wr, hr, position, unit) {
    let obj = {
        "cid": 43,
        "data": {
            "type": type,     //1活动框架   2游戏框架。
            "width": wr,   // #单位为vw  默认值为-1   未传或传-1时,则不修改宽度
            "height": hr,    //单位为vw   默认值为-1   未传或传-1时,则不修改高度
            "position": position, // 1右贴边 2左贴边   默认右贴边。
            "unit": unit,   //单位  默认1 vw    2 pt
        }
    }
    let obj2 = JSON.stringify(obj);
    webAppCollaboration(obj2);
}



//接收客戶端的消息
webAppComm.prototype.reMsgFromApp = function (callback) {
    callback && callback();
}

webAppComm.prototype.url_get_params = function (url_path) {
    let url = url_path;
    let theRequest = new Object();
    if (url.indexOf("?") != -1) {
        let str = url.substr(url.indexOf("?") + 1);
        strs = str.split("&");
        for (let i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}


function webAppCollaboration(msg) {
    let sUserAgent = navigator.userAgent.toLowerCase();
    let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    let bIsMidp = sUserAgent.match(/midp/i) == "midp";
    let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    let bIsAndroid = sUserAgent.match(/android/i) == "android";
    let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
    }
    else if (bIsAndroid) {
        window.yazhai.appCollaboration(msg);
    } else if (bIsIphoneOs || bIsIpad) {
        window.webkit.messageHandlers.appCollaboration.postMessage(msg);
    }
}



window.$firefly = new webAppComm();