import Vue from 'vue'
import App from './App.vue'
import '@/assets/iconfont/iconfont.css'
// element引入
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// sdk引入
import sdk from '@ct/iframe-connect-sdk'
import router from './router'
import store from './store'

import { pxToRemMixin } from './pxToRem.js'

Vue.mixin(pxToRemMixin)
Vue.config.productionTip = false
// 挂载请求sdk
const { iframeSDK, requestSDK, postMsgUtil } = sdk
Vue.prototype.$iframeSDK = iframeSDK
Vue.prototype.$requestSDK = requestSDK
Vue.prototype.$postMsgUtil = postMsgUtil

Vue.use(Element, { size: 'small' })
Vue.prototype.isCross = true

localStorage.setItem('isCross', true)
postMsgUtil.listen('checkCrossResult', function ({ data }) {
  Vue.prototype.isCross = data !== 200
  localStorage.setItem('isCross', data !== 200)
})

const setRootFontSize = (direction = 'v') => {
  const htmlElement = document.documentElement
  const baseHeight = direction === 'v' ? 1080 : 1920
  const referenceHeight = 1032
  htmlElement.style.fontSize = direction === 'v' ? `calc((100vh / ${baseHeight}) * 100 * (${baseHeight} / ${referenceHeight}))` : `calc((100vw / ${baseHeight}) * 100)`
}
setRootFontSize('v')
new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount('#app')
