main.js 4.35 KB
/* eslint-disable eqeqeq */
/*
 * @Descripttion:
 * @version:
 * @Author: limin
 * @Date: 2021-06-07 14:12:32
 * @LastEditors: limin
 * @LastEditTime: 2021-06-29 15:35:47
 */
// 兼容 IE
// https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#babelpolyfill
// import 'core-js/stable'
// import 'regenerator-runtime/runtime'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import api from './api'
// import { fetchConfig, cfg } from '@/config'
import '@/assets/css/index.scss'
import { bus, tools, store as local, util } from './utils'
import './utils/util'
import 'components'
import { components } from '@/plugins/vant'
components.forEach(component => {
  // console.log(component)
  Vue.use(component)
})
Vue.prototype.api = api
Vue.prototype.bus = bus
Vue.prototype.tools = tools
Vue.prototype.local = local
Vue.prototype.to = function (name, params) {
  if (name === -1) {
    router.go(-1)
    return
  }
  router.push({ name, params })
}
// 移动端适配 rem
// import 'lib-flexible/flexible.js'

import VConsole from 'vconsole'
var baseConfig = {
  axios: {
    appkey: 'd7ffc3346fc9a45bccaaa35300d59022',
    secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353'
  }
}
import * as Sentry from '@sentry/vue'
import { BrowserTracing } from '@sentry/tracing'

// 实例化
process.env.NODE_ENV === 'production' &&
  Sentry.init({
    Vue,
    dsn: 'https://f0db411905b541eebe6d591707f561a4@sentry.glsx.com.cn/26',
    integrations: [
      new BrowserTracing({
        routingInstrumentation: Sentry.vueRouterInstrumentation(router),
        tracingOrigins: ['localhost', 'my-site-url.com', /^\//]
      })
    ],
    // Set tracesSampleRate to 1.0 to capture 100%
    // of transactions for performance monitoring.
    // We recommend adjusting this value in production
    tracesSampleRate: 1.0
  })

// const isMock = ['prod', 'production'].includes(process.env.NODE_ENV)
// 使用fetch 解决axios提前实例化导致sign里面的secret不能通过配置中心动态获取
fetch('https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=dj-car-life-alipay-config')
  .then(
    response => {
      // 处理http响应
      return response.json()
    },
    error => {
      // 处理错误
      console.log(error)
    }
  )
  .then(response => {
    console.log(response)

    const { code, data } = response
    code == '200' && ((baseConfig = data), (window.$fetchConfig = data))
  })
  .catch(el => {
    // console.log(el)
    baseConfig = {
      sysName: '嘀加支付宝h5系统',
      hasReg: false,
      hasAuth: false,
      vconsole: true,
      env: 'develop',
      axios: {
        baseURL: 'http://192.168.3.226:9711',
        appkey: '48e5e13229b82c1b4e6e8c96151f0637',
        secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b',
        timeout: 50000,
        result: {
          data_key: 'data',
          message_key: 'message',
          code_key: 'code',
          code_success_value: 0,
          code_message_map: {}
        }
      }
    }
  })
  .finally(() => {
    init()
  })
function init() {
  baseConfig.vconsole && new VConsole()
  new Vue({
    router,
    store,
    // i18n,
    render: h => {
      // data.axios.baseURL =
      //   'http://dj.test.glsx.com.cn/rop-dj-smartcarlife/router'
      // Vue.prototype.baseConfig = data
      return h(App)
    }
    // created () {
    // 处理路由 得到每一级的路由设置
    // this.$store.commit('d2admin/page/init', frameInRoutes)
    // 设置顶栏菜单 (暂时不需要)
    // this.$store.commit('d2admin/menu/headerSet', menuHeader)
    // 设置侧边栏菜单 (TODO 进行过滤)
    // this.$store.commit('d2admin/menu/asideSet', menuAside)
    // 初始化菜单搜索功能
    // this.$store.commit('d2admin/search/init', menuHeader)
    // },
    // created() {
    //   // 系统配置
    //   Vue.config.devtools = true
    //   // 展示系统信息
    //   this.$store.commit('d2admin/releases/versionShow')
    //   // 用户登录后从数据库加载一系列的设置
    //   this.$store.dispatch('d2admin/account/load')
    //   // 获取并记录用户 UA
    //   this.$store.commit('d2admin/ua/get')
    //   // 初始化全屏监听
    //   this.$store.dispatch('d2admin/fullscreen/listen')
    // },
    // mounted() {}
  }).$mount('#app')
}
export { baseConfig }