Commit 1ac60e7f by Jaxon

chore: 重构 main.js 文件,优化导入顺序和代码格式

- 调整模块导入顺序,将 Vue 核心依赖前置
- 统一代码缩进为 2 个空格并修复对象尾随逗号
- 更新配置中心请求的模块 URL 参数
- 保持所有功能逻辑不变,仅改进代码结构和可读性
1 parent 80bf3b01
Showing 1 changed file with 89 additions and 89 deletions
import { BrowserTracing } from "@sentry/tracing";
// 接入sentry
import * as Sentry from "@sentry/vue";
import { Request } from "glsk-toolkit";
// Vue // Vue
import Vue from "vue"; import Vue from "vue"
// import { GLCombiForm } from "glsx-components" // 权限按钮 (根据权限动态创建)
import VueLazyload from "vue-lazyload";
import { config } from "@/common/baseConfig";
import GLMapSdk from "@/common/glsk-mapapi-sdk";
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 axios from 'axios'
// import i18n from './i18n' // import i18n from './i18n'
import App from "./App"; 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 D2Crud from '@d2-projects/d2-crud'
// 菜单和路由设置 // 菜单和路由设置
import router from "./router"; import router from "./router"
import "default-passive-events"; import "default-passive-events"
import "element-ui/lib/theme-chalk/index.css"; 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"
import { Request } from "glsk-toolkit"
import util from "@/libs/util.js"
Vue.prototype.$mapapi = new GLMapSdk(); Vue.prototype.$mapapi = new GLMapSdk()
Vue.use(VueLazyload, { Vue.use(VueLazyload, {
// 懒加载默认加载图片 // 懒加载默认加载图片
loading: loading:
"https://img02.glsx.com.cn/weapp/resource/saas/dj/images/img_loading.png", "https://img02.glsx.com.cn/weapp/resource/saas/dj/images/img_loading.png",
attempt: 3, // 尝试加载次数 attempt: 3 // 尝试加载次数
}); })
// 实例化 // 实例化
process.env.NODE_ENV === "production" process.env.NODE_ENV === "production" &&
&& Sentry.init({ Sentry.init({
Vue, Vue,
dsn: "https://39bc80d3bb0a419a8d7d9bf5a39678e3@sentry.glsx.com.cn/24", dsn: "https://39bc80d3bb0a419a8d7d9bf5a39678e3@sentry.glsx.com.cn/24",
// dsn: 'http://6225fb8e73fb453a8455a9371f3517da@192.168.3.115:9000/4', // dsn: 'http://6225fb8e73fb453a8455a9371f3517da@192.168.3.115:9000/4',
integrations: [ integrations: [
new BrowserTracing({ new BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(router), routingInstrumentation: Sentry.vueRouterInstrumentation(router),
tracingOrigins: ["localhost", "my-site-url.com", /^\//], tracingOrigins: ["localhost", "my-site-url.com", /^\//]
}), })
], ],
// Set tracesSampleRate to 1.0 to capture 100% // Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring. // of transactions for performance monitoring.
...@@ -52,119 +52,119 @@ process.env.NODE_ENV === "production" ...@@ -52,119 +52,119 @@ process.env.NODE_ENV === "production"
logErrors: true, logErrors: true,
// 解决火狐浏览器 无法捕获错误的问题 // 解决火狐浏览器 无法捕获错误的问题
beforeSend(event, hint) { beforeSend(event, hint) {
const isNonErrorException const isNonErrorException =
= event.exception.values[0].value.startsWith( event.exception.values[0].value.startsWith(
"Non-Error exception captured", "Non-Error exception captured"
) ||
hint.originalException.message.startsWith(
"Non-Error exception captured"
) )
|| hint.originalException.message.startsWith(
"Non-Error exception captured",
);
if (isNonErrorException) { if (isNonErrorException) {
// We want to ignore those kind of errors // We want to ignore those kind of errors
return null; return null
}
return event
} }
return event;
},
// "send-default-pii": true // "send-default-pii": true
}); })
// d2Admin 已导入 // d2Admin 已导入
// import ElementUI from 'element-ui' // import ElementUI from 'element-ui'
// Vue.use(ElementUI) // Vue.use(ElementUI)
// 核心插件 // 核心插件
Vue.use(d2Admin); Vue.use(d2Admin)
Vue.use(chaining); Vue.use(chaining)
// Vue.use(GLCombiForm) // Vue.use(GLCombiForm)
Vue.prototype.notice = notice; Vue.prototype.notice = notice
const isProd = process.env.NODE_ENV === "production"; const isProd = process.env.NODE_ENV === "production"
// console.log(isProd) // console.log(isProd)
if (!isProd) { if (!isProd) {
Vue.config.devtools = true; Vue.config.devtools = true
} }
Vue.prototype.$EventBus = new Vue(); Vue.prototype.$EventBus = new Vue()
Vue.directive("preventReClick", { Vue.directive("preventReClick", {
bind: (el, binding) => { bind: (el, binding) => {
let time = binding.value; // 防抖时间 let time = binding.value // 防抖时间
if (!time) { if (!time) {
// 用户若不设置防抖时间,则默认1s // 用户若不设置防抖时间,则默认1s
time = 1000; time = 1000
} }
let fun; let fun
el.addEventListener( el.addEventListener(
"click", "click",
(event) => { (event) => {
if (!fun) { if (!fun) {
// 第一次执行 // 第一次执行
fun = setTimeout(() => { fun = setTimeout(() => {
fun = null; fun = null
}, time); }, time)
} else { } else {
// 直接取消当前事件 // 直接取消当前事件
event && event.stopImmediatePropagation(); event && event.stopImmediatePropagation()
} }
}, },
true, true
); )
}, }
}); })
let baseConfig = config; let baseConfig = config
// 使用fetch 解决axios提前实例化导致sign里面的secret不能通过配置中心动态获取 // 使用fetch 解决axios提前实例化导致sign里面的secret不能通过配置中心动态获取
fetch( fetch(
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=dj-car-life-system-config-sj", "https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=dj-car-life-system-config"
) )
.then( .then(
(response) => { (response) => {
// 处理http响应 // 处理http响应
return response.json(); return response.json()
}, },
(error) => { (error) => {
// 处理错误 // 处理错误
console.log(error); console.log(error)
}, }
) )
.then((response) => { .then((response) => {
const { code, data } = response; const { code, data } = response
console.log("response", code, response); console.log("response", code, response)
if (code == "200") { if (code == "200") {
console.log(data); console.log(data)
baseConfig = data; baseConfig = data
// console.log("baseConfig", baseConfig) // console.log("baseConfig", baseConfig)
// window.$fetchConfig = data // window.$fetchConfig = data
} else { } else {
baseConfig = response; baseConfig = response
window.$fetchConfig = response; window.$fetchConfig = response
console.log(response); console.log(response)
window.$gscApi = new Request({ window.$gscApi = new Request({
...response.gsc, ...response.gsc,
// baseURL:'http://192.168.3.145:9898/gsc-vcp-web-facade', // baseURL:'http://192.168.3.145:9898/gsc-vcp-web-facade',
// baseURL: 'http://gsc.test.glsx.com.cn/gsc-vcp-web-facade', // baseURL: 'http://gsc.test.glsx.com.cn/gsc-vcp-web-facade',
session: { session: {
requiresSession: true, requiresSession: true,
sessionId: _ => util.cookies.get("token"), sessionId: (_) => util.cookies.get("token")
}, },
events: { events: {
error: (error, config) => { error: (error, config) => {
Vue.prototype.$message.error(error.msg); Vue.prototype.$message.error(error.msg)
}, },
logout: (response, config) => { logout: (response, config) => {
store.dispatch("d2admin/user/clear"); store.dispatch("d2admin/user/clear")
util.cookies.remove("token"); util.cookies.remove("token")
router.replace("/login"); router.replace("/login")
Vue.prototype.$message.error("登录超时,请重新登录"); Vue.prototype.$message.error("登录超时,请重新登录")
}, }
}, }
}); })
console.log(window.$gscApi, "========"); console.log(window.$gscApi, "========")
} }
}) })
.finally(() => { .finally(() => {
init(); init()
}); })
function init() { function init() {
new Vue({ new Vue({
router, router,
...@@ -174,22 +174,22 @@ function init() { ...@@ -174,22 +174,22 @@ function init() {
// baseConfig.axios.baseURL = 'http://dj.test.glsx.com.cn/rop-dj-smartcarlife/router' // baseConfig.axios.baseURL = 'http://dj.test.glsx.com.cn/rop-dj-smartcarlife/router'
// data // data
// console.log(data) // console.log(data)
Vue.prototype.baseConfig = baseConfig; Vue.prototype.baseConfig = baseConfig
return h(App); return h(App)
}, },
created() { created() {
// 系统配置 // 系统配置
Vue.config.devtools = true; Vue.config.devtools = true
// 展示系统信息 // 展示系统信息
this.$store.commit("d2admin/releases/versionShow"); this.$store.commit("d2admin/releases/versionShow")
// 用户登录后从数据库加载一系列的设置 // 用户登录后从数据库加载一系列的设置
this.$store.dispatch("d2admin/account/load"); this.$store.dispatch("d2admin/account/load")
// 获取并记录用户 UA // 获取并记录用户 UA
this.$store.commit("d2admin/ua/get"); this.$store.commit("d2admin/ua/get")
// 初始化全屏监听 // 初始化全屏监听
this.$store.dispatch("d2admin/fullscreen/listen"); this.$store.dispatch("d2admin/fullscreen/listen")
}, },
mounted() {}, mounted() {}
}).$mount("#app"); }).$mount("#app")
} }
export { baseConfig }; export { baseConfig }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!