import Vue from 'vue'
import App from './QywxApp.vue'
// import App from './App.vue'
import axios from 'axios'
import router from './router/index'
import store from './store/index'
// 1. 引入配置FastClick的js文件
import './plugins/fastClick'

// 2. 引入全局样式
import './style/commen.less'

// Vue.prototype.$http = axios

// const needForwardRefresh = [
//     'home',
//     'searchCase',
//     'searchCaseResult',
//     'searchCaseDetails',
//
//     'SearchDishonesty',
//     'SearchDishonestyResult',
//     'SearchDishonestyDetails',
//
//     'searchFinancing',
//     'searchFinancingDetails',
//
//     'SearchPublicSentiment',
//     'SearchPublicSentimentResult',
//     'SearchPublicSentimentDetails',
//
//     'SearchRelationship',
//     'SearchRelationshipResult',
// ];

// router.beforeEach((to, from, next) => {
//     console.log(111,to.name)
//     if (needForwardRefresh.indexOf(to.name) >= 0) {
//         const toDepth = to.path.split('/').length;
//         const fromDepth = from.path.split('/').length;
//         console.log(222,toDepth,fromDepth)
//         if (toDepth < fromDepth) {
//             to.meta.keepAlive = true;
//             from.meta.keepAlive = false;
//
//             console.log(111,to,from)
//         }
//
//     }
//     next()
// })


import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(Element)

// 3. 引入全局UI组件库
import './plugins/vant'

// 4. 引入rem
// import './config/rem'

// 5. 引入全局过滤器
import './config/filters'

// 6. 配置二维码插件
import VueQriously from "vue-qriously/dist/vue-qriously";
import {Divider} from "vant"
import { getQiWeiConfig } from "@/service/api/home.js";
import { rejects } from 'assert'
import { urlLink } from "@/config/config";
Vue.use(Divider)
Vue.use(VueQriously)
if(!sessionStorage.getItem('url')){
    sessionStorage.setItem("url", window.location.href);
}
async function initWxWork(){
    console.log(sessionStorage.getItem('url'),999999);
    let sessionUrl = sessionStorage.getItem('url') || '';
    let orgId= '';
    if(sessionUrl.includes('orgId')){
        orgId = sessionUrl.split('#')[0].split('=')[1];
        const qyUrl = window.location.href.split('#')[0];
        const res = await getQiWeiConfig({
            orgId,
            qyUrl:encodeURIComponent(qyUrl)
        });
        console.log(res,'res',);
        localStorage.setItem('appId',res?.data?.appId);
        localStorage.setItem('agentId',res?.data?.agentId);
        localStorage.setItem('orgId',orgId);
        if(res.code == '00000000'){
            if(!window.wx){
                console.log('企业微信SDK未正确引入')
                return;
            }
            return new Promise(resolve=>{
                wx.config({
                    beta:true, // 必须，否则调用Api无效
                    debug:false,
                    appId:res?.data?.appId, // 企业id
                    // agentid:'1000052', // 应用id
                    timestamp:res?.data?.timestamp, // 时间戳
                    nonceStr:res?.data?.nonceStr, //随机字符串
                    signature:res?.data?.signature, // 签名
                    jsApiList:['getLocation','openLocation','chooseImage'] // 所有需要调用的API
                })
        
                wx.ready(()=>{
                    console.log('企业微信注册成功')
                    resolve(wx);
                })
        
                wx.error((res)=>{
                    console.log('企业微信注册失败',res)
                })
            })
    
        }
    }
}
initWxWork().then(()=>{
    new Vue({
        router,
        store,
        render: h => h(App)
    }).$mount('#app')
})
