main.js 5.66 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 { GLCombiForm } from "glsx-components" // 权限按钮 (根据权限动态创建)

// 实例化
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.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
    )
  }
})

var baseConfig = {
  // 系统名字
  sysName: "嘀加智享车生活",
  // 系统说明
  subName: "让你的生意慧简单",
  // 是否需要注册-true;false
  hasReg: false,
  // 是否需要配置账号权限;true-有权限,从后台获取权限信息;false-无需权限
  hasAuth: true,
  subShopMerchantName: true, // 是否显示财务列表二级流量方
  env: "production",
  alipayPath: "https://dj.glsx.com.cn/dj-carlife-web-alipay/#/alipay",
  css_url:
    "https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config/index.css",
  axios: {
    baseURL: "https://dj.glsx.com.cn/rop-dj-smartcarlife/router",
    appkey: "d7ffc3346fc9a45bccaaa35300d59022",
    secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
    timeout: 50000,
    result: {
      data_key: "data",
      message_key: "message",
      code_key: "code",
      code_success_value: 0,
      code_message_map: {}
    }
  }
}
// 使用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)
    // const code = "200"
    // 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 }