main.js 5.94 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"
import { config } from "@/common/baseConfig"
import GLMapSdk from "@/common/glsk-mapapi-sdk"
// import { GLCombiForm } from "glsx-components" // 权限按钮 (根据权限动态创建)
import VueLazyload from "vue-lazyload"
Vue.prototype.$mapapi = new GLMapSdk()
Vue.use(VueLazyload, {
  // 懒加载默认加载图片
  loading:
    "https://img02.glsx.com.cn/weapp/resource/saas/dj/images/img_loading.png",
  attempt: 3 // 尝试加载次数
})
// 实例化
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,
    // 解决火狐浏览器 无法捕获错误的问题
    beforeSend(event, hint) {
      const isNonErrorException =
        event.exception.values[0].value.startsWith(
          "Non-Error exception captured"
        ) ||
        hint.originalException.message.startsWith(
          "Non-Error exception captured"
        )
      if (isNonErrorException) {
        // We want to ignore those kind of errors
        return null
      }
      return event
    }
    // "send-default-pii": true
  })

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

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

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

Vue.prototype.$EventBus = new Vue()

Vue.directive("preventReClick", {
  bind: (el, binding) => {
    let time = binding.value // 防抖时间
    if (!time) {
      // 用户若不设置防抖时间,则默认1s
      time = 1000
    }
    let fun
    el.addEventListener(
      "click",
      (event) => {
        if (!fun) {
          // 第一次执行
          fun = setTimeout(() => {
            fun = null
          }, time)
        } else {
          // 直接取消当前事件
          event && event.stopImmediatePropagation()
        }
      },
      true
    )
  }
})
let baseConfig = config
// 使用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
    // console.log("response", response)

    // response.axios.baseURL  = 'https://dj.test.glsx.com.cn/rop-dj-smartcarlife/router'
    // response.axios.baseURL  = 'http://192.168.1.104:8392/rop-dj-smartcarlife/router'
    if (code == "200") {
      console.log(data)

      baseConfig = data
      // console.log("baseConfig", baseConfig)
      // window.$fetchConfig = data
    } else {
      // response = {
      //   // 系统名字
      //   sysName: "嘀加智享车生活",
      //   // 系统说明
      //   subName: "让你的生意慧简单",
      //   // 是否需要注册-true;false
      //   hasReg: false,
      //   // 是否需要配置账号权限;true-有权限,从后台获取权限信息;false-无需权限
      //   hasAuth: true,
      //   env: "backendSingle",
      //   css_url:
      //     "https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config/index.css",
      //   axios: {
      //     // "baseURL":  "http://192.168.1.129:8392/rop-dj-smartcarlife/router", //周杭
      //     // "baseURL":  "http://192.168.1.204:8392/rop-dj-smartcarlife/router",//陈希
      //     baseURL: "http://192.168.1.169:8392/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: {}
      //     }
      //   }
      // }
      baseConfig = response
      window.$fetchConfig = response
    }
  })
  .finally(() => {
    init()
  })
function init() {
  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 = baseConfig
      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 }