import request from '@/utils/request'
import store from '@/store'

const BASE_URL = store.getters.request_config_baseUrl;

// 获取设备档案列表
export function ApplicationCenterApi(data) {
    return request({
        url: BASE_URL + '/3rd/app/query',
        method: 'get',
        params: data
    })
}


export function opencommonDetail(url, url2, urldata) {
    if(url == 1 || url == 2 || url == 3){
        setupWebViewJavascriptBridge(function (bridge) {
            bridge.callHandler('Open', {'url': url}, function responseCallback(responseData) {
                console.log("JS received response:", responseData)
            })
        })
    }else{
        console.log(window.location.href = url2+'&isOpen='+urldata.isOpen+'&aId='+urldata.aId+'&cId='+urldata.cId)
        //判断url2中有没有aId cId
        if (url2.indexOf("aId") != -1 && url2.indexOf("cId") != -1) {
            window.location.href = url2
        } else {
            // window.location.href = url2+'?cId='+urldata.cId+'&aId='+urldata.aId+'&isOpen='+urldata.isOpen;
            window.location.href = url2+'&isOpen='+urldata.isOpen+'&aId='+urldata.aId+'&cId='+urldata.cId+'&gId='+urldata.gId;
        }
    }

    function setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) {
            return callback(WebViewJavascriptBridge);
        }
        if (window.WVJBCallbacks) {
            return window.WVJBCallbacks.push(callback);
        }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
        WVJBIframe.src = 'https://__bridge_loaded__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function () {
            document.documentElement.removeChild(WVJBIframe)
        }, 0)
    }
}