main.js 11.3 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,
      //   subShopMerchantName: true, // 是否显示财务列表二级流量方
      //   env: "backendSingle",
      //   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",
      //     baseURL: "http://dj.dev.glsx.com.cn/rop-dj-smartcarlife/router",
      //     // "baseURL":  "http://192.168.1.88:8392/rop-dj-smartcarlife/router", //周杭
      //     // baseURL: "http://192.168.1.227:8392/rop-dj-smartcarlife/router", //陈希
      //     // baseURL: "http://192.168.1.169:8392/rop-dj-smartcarlife/router", // 蔡远明
      //     // "baseURL": "http://192.168.1.105:8392/rop-dj-smartcarlife/router", //王润泽
      //     // "baseURL": "http://192.168.1.104: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: {}
      //     }
      //   },
      //   axios2: {
      //     baseURL: "https://scrm.dev.glsx.com.cn/rop-scrm-shopmall/router",
      //     appkey: "48e5e13229b82c1b4e6e8c96151f0637",
      //     secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
      //     timeout: 50000,
      //     result: {
      //       data_key: "data",
      //       message_key: "message",
      //       code_key: "code",
      //       code_success_value: 0,
      //       code_message_map: {}
      //     }
      //   },
      //   common: {
      //     baseURL:
      //       "http://didicb.glsx.com.cn?method=glsx.accounts.biz.common.pictureUpload",
      //     appkey: "48e5e13229b82c1b4e6e8c96151f0637",
      //     secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
      //     timeout: 50000,
      //     result: {
      //       data_key: "data",
      //       message_key: "message",
      //       code_key: "code",
      //       code_success_value: 0,
      //       code_message_map: {}
      //     }
      //   },
      //   errCode: {
      //     1: "系统开小差了,错误码1",
      //     2: "开发者权限不足",
      //     3: "用户权限不足",
      //     4: "图片上传失败,错误码4",
      //     5: "系统开小差了,错误码5",
      //     6: "编码错误",
      //     7: "请求被禁止",
      //     8: "系统开小差了,错误码8",
      //     9: "业务逻辑出错",
      //     20: "系统开小差了,错误码20",
      //     21: "系统开小差了,错误码21",
      //     22: "系统开小差了,错误码22",
      //     23: "系统开小差了,错误码23",
      //     24: "系统开小差了,错误码24",
      //     25: "系统开小差了,错误码25",
      //     26: "系统开小差了,错误码26",
      //     27: "系统开小差了,错误码27",
      //     28: "系统开小差了,错误码28",
      //     29: "系统开小差了,错误码29",
      //     30: "系统开小差了,错误码30",
      //     31: "系统开小差了,错误码31",
      //     32: "系统开小差了,错误码32",
      //     33: "非法的参数",
      //     34: "用户调用服务的次数超限",
      //     35: "会话调用服务的次数超限",
      //     36: "应用调用服务的次数超限",
      //     37: "应用调用服务的频率超限",
      //     "-4000": "系统开小差了,错误码-4000",
      //     "-1": "系统开小差了,错误码-1",
      //     "-2": "系统开小差了,错误码-2",
      //     "-3": "系统开小差了,错误码-3",
      //     "-4": "系统开小差了,错误码-4",
      //     "-5": "系统开小差了,错误码-5",
      //     "-6": "系统开小差了,错误码-6",
      //     "-5001": "请校验并输入必填选项,错误码-5001",
      //     "-5002": "系统开小差了,错误码-5002",
      //     "-5003": "请校验并输入必填选项,错误码-5003",
      //     "-5004": "必填项格式有误,请正确填写,错误码-5004",
      //     "-5005": "请校验并输入必填选项,错误码-5005",
      //     "-9000": "流量限制",
      //     30210101: "该手机号已存在"
      //   },
      //   equitySceneType: [73, 102, 146, 158], // 开发环境 2.0场景 会员权益升级 类目
      //   solarFilmArr: [1, 111, 112], // 太阳膜类 1太阳膜 111太阳膜(众筹)售后众筹场景 112太阳膜(众筹)
      //   selfBuildGoodsType: "109,115,116,117,118", // 开发环境 自建商品类目值
      //   supplierCode: ["19"],
      //   extendedPosiType: [114, 120], // 延保类 类目值
      //   membraneTypeList: [1, 4, 6, 12, 14, 115, 116, 117], // 所有膜类类目值
      //   shelfManageDivisionConfig: [1, 2], // 嘀加上架分账类目 流量费,服务商分润
      //   shelfManageFinanceConfig: [706, 808, 809, 901, 807], // 嘀加上架对账类目 管理层市场费1,管理层市场费2,一线阳光激励费,一线阳光2激励费,人力成本
      //   brandId: 2978,
      //   childrenBrandId: 3454, // 问界二级品牌Id
      //   roleName: "服务商老板", // 账户中心创建在广联数科下的员工(角色类型=服务商老板,督导)
      //   yqMerchantObj: {
      //     hzgl: {
      //       yqMerchantId: "44217689",
      //       yqMerchantName: "惠州广联数科科技有限公司",
      //       yqMerchantIdName: "惠州广联数科科技有限公司44217689"
      //     },
      //     glsk: {
      //       yqMerchantId: "44209813",
      //       yqMerchantName: "广联数科(内部使用)",
      //       yqMerchantIdName: "广联数科(内部使用)44209813"
      //     }
      //   },
      //   alyOss: {
      //     accessKeyId: "LTAI5tRXYZswFNkkGAF2fk4e",
      //     accessKeySecret: "iYJdlgs6khO53YqoQYDOtHXCk83d5C",
      //     bucket: "jinrong-huidan-test",
      //     endpoint: "https://oss-cn-shenzhen.aliyuncs.com"
      //   }
      // }
      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 }