import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 引入lib-flexible
import 'lib-flexible'
import './assets/fonts/iconfont.css';
Vue.config.productionTip = false
import VConsole from 'vconsole'
// new VConsole()

// 开发环境引入 vConsole调试工具
if (process.env.NODE_ENV === 'production' && process.env.VUE_APP_RealEnv !== 'production') {
    // TODO: vConsole
    // new VConsole()
}

// url传参(在工程信息化 商管APP中 才能调用到的方法),存放store
window.__keyCallback = function (data) {
    if(data.text){
        store.commit('SETURL', data.text)
    }else{
        store.commit('SETURL', null)
    }
}

const ua = navigator.userAgent
let flag = false
// 打包后,使用cordova插件,需要监听deviceready事件
if (process.env.NODE_ENV === 'production' && ua.match(/(iPhone | Android)/)) {
    window.addEventListener('deviceready', function() {
        flag = true
        new Vue({
            router,
            store,
            render: (h) => h(App),
        }).$mount('#app')
    })
} else {
    flag = true
    new Vue({
        router,
        store,
        render: (h) => h(App),
    }).$mount('#app')        
}
// 如果直接在电脑上预览,2s后,dispatch deviceready
setTimeout(() => {
    if (flag) {
        return
    }
    const myEvent = new CustomEvent('deviceready', {
        detail: {
            title: 'This is deviceready!',
        },
    })
    window.addEventListener('deviceready', function(event) {
        // console.log('deviceready success')
    })
    // 随后在对应的元素上触发该事件
    if (window.dispatchEvent) {
        window.dispatchEvent(myEvent)
    } else {
        window.fireEvent(myEvent)
    }
}, 2000)

// new Vue({
//     router,
//     store,
//     render: (h) => h(App),
// }).$mount('#app')
