main.js
4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* eslint-disable node/prefer-global/process */
import { BrowserTracing } from "@sentry/tracing";
// 接入sentry
import * as Sentry from "@sentry/vue";
import { Request } from "glsk-toolkit";
// Vue
import Vue from "vue";
// import { GLCombiForm } from "glsx-components" // 权限按钮 (根据权限动态创建)
import VueLazyload from "vue-lazyload";
import { config } from "@/common/baseConfig";
import { installVueMapApi } from "@/common/installVueMapApi";
import notice from "@/common/notice";
import util from "@/libs/util.js";
// 针对template模板中使用可选链操作符
import chaining from "@/plugin/chaining";
// 核心插件
import d2Admin from "@/plugin/d2admin";
// store
import store from "@/store/index";
// import axios from 'axios'
// import i18n from './i18n'
import App from "./App";
// import D2Crud from '@d2-projects/d2-crud'
// 菜单和路由设置
import router from "./router";
import "default-passive-events";
import "element-ui/lib/theme-chalk/index.css";
installVueMapApi(Vue);
Vue.use(VueLazyload, {
// 懒加载默认加载图片
loading:
"https://img02.glsx.com.cn/weapp/resource/saas/dj/images/img_loading.png",
attempt: 3, // 尝试加载次数
});
// 实例化
process.env.NODE_ENV === "production"
&& process.env.VUE_APP_SIMPLE_SENTRY === "true"
&& Sentry.init({
Vue,
dsn: "https://39bc80d3bb0a419a8d7d9bf5a39678e3@sentry.glsx.com.cn/24",
// 与 vue.config 中 SentryWebpackPlugin.release 一致,sourcemap 才能正确解析栈
release: process.env.VUE_APP_VERSION,
// 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,
);
},
});
const baseConfig = config;
window.$gscApi = new Request({
...baseConfig.gsc,
session: {
requiresSession: true,
sessionId: _ => util.cookies.get("token"),
},
events: {
error: (error) => {
Vue.prototype.$message.error(error.msg);
},
logout: () => {
store.dispatch("d2admin/user/clear");
util.cookies.remove("token");
router.replace("/login");
Vue.prototype.$message.error("登录超时,请重新登录");
},
},
});
init();
function init() {
new Vue({
router,
store,
// i18n,
render: (h) => {
// baseConfig.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 };