main.js 5.22 KB
// Vue
import Vue from "vue"
// import axios from 'axios'
// import i18n from './i18n'
import App from "./App"
// 核心插件
import d2Admin from "@/plugin/d2admin"
// store
import store from "@/store/index"
// 针对template模板中使用可选链操作符
import chaining from "@/plugin/chaining"

// 接入sentry
import * as Sentry from "@sentry/vue"
import { BrowserTracing } from "@sentry/tracing"
// import D2Crud from '@d2-projects/d2-crud'
// 菜单和路由设置
import router from "./router"
import "default-passive-events"
import notice from "@/common/notice"
import "element-ui/lib/theme-chalk/index.css"
// 实例化
process.env.NODE_ENV === "production" &&
  Sentry.init({
    Vue,
    dsn: "https://39bc80d3bb0a419a8d7d9bf5a39678e3@sentry.glsx.com.cn/24",
    // dsn: 'http://6225fb8e73fb453a8455a9371f3517da@192.168.3.115:9000/4',
    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,
    logErrors: true
    // "send-default-pii": true
  })

// d2Admin 已导入
// import ElementUI from 'element-ui'
// Vue.use(ElementUI)

// 核心插件
Vue.use(d2Admin)
Vue.use(chaining)
Vue.prototype.notice = notice

const isProd = process.env.NODE_ENV === "production"
// console.log(isProd)
if (!isProd) {
  Vue.config.devtools = true
}

// console.log(test)
// Vue.use(D2Crud)
// 动态导入vuex 模块
// Vue.use(function () {
//   Vue.mixin({
//     beforeCreate: function () {
//       // $options是组件选项,包含组件.vue文件的 `export default` 的属性
//       // 为了拿到在组件定义的是否按需加载的属性值 `isNeedVuex`
//       // console.log(this.$options.isNeedVuex)
//       if (this.$options.isNeedVuex) {
//         // 需要设置.vue文件的name属性,跟单文件组件名字命名一样
//         const name = this.$options.name
//         // console.log(name)
//         import(`./store/modules/${name}/index`).then((res) => {
//           // console.log("res", res)
//           // res.default就是代表我们在store/modules文件夹下对应文件的export default对象
//           // registerModule是vuex自带的方法,请自行搜索
//           // 第一个参数是动态注入的模块名,第二个参数是模块导出对象
//           this.$store.registerModule(name, res.default)
//         })
//       }
//     }
//   })
// })

var baseConfig = {
  axios: {
    appkey: "d7ffc3346fc9a45bccaaa35300d59022",
    secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353"
  }
}
// 使用fetch 解决axios提前实例化导致sign里面的secret不能通过配置中心动态获取
fetch(
  "https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=dj-car-life-system-config"
)
  .then(
    (response) => {
      // 处理http响应
      return response.json()
    },
    (error) => {
      // 处理错误
      console.log(error)
    }
  )
  .then((response) => {
    const { code, data } = response
    // const code = "200"
    // // console.log(response)
    // const data = {
    //   // 系统名字
    //   sysName: "嘀加智享车生活",
    //   // 系统说明
    //   subName: "让你的生意慧简单",
    //   // 是否需要注册-true;false
    //   hasReg: false,
    //   // 是否需要配置账号权限;true-有权限,从后台获取权限信息;false-无需权限
    //   hasAuth: true,
    //   env: "develop",
    //   alipayPath: "https://zlsdev.glsx.com.cn/#/alipay",
    //   css_url:
    //     "https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config/index.css",
    //   axios: {
    //     baseURL: "http://192.168.3.226:9203/rop-dj-smartcarlife/router",
    //     appkey: "48e5e13229b82c1b4e6e8c96151f0637",
    //     secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
    //     timeout: 50000,
    //     result: {
    //       data_key: "data",
    //       message_key: "message",
    //       code_key: "code",
    //       code_success_value: 0,
    //       code_message_map: {}
    //     }
    //   }
    // }
    code == "200" && (baseConfig = data)
    new Vue({
      router,
      store,
      // i18n,
      render: (h) => {
        // data.axios.baseURL =
        //   'http://dj.test.glsx.com.cn/rop-dj-smartcarlife/router'
        // data
        console.log(data)
        Vue.prototype.baseConfig = data
        return h(App)
      },
      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 }