From adc88bd9e76644badbbe006913addfa7cbe5d89c Mon Sep 17 00:00:00 2001
From: shixian.shi <shixian.shi@alibaba-inc.com>
Date: 星期四, 23 十一月 2023 20:40:15 +0800
Subject: [PATCH] Merge remote-tracking branch 'refs/remotes/origin/main' update contextual forward
---
web-pages/src/main.js | 142 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 142 insertions(+), 0 deletions(-)
diff --git a/web-pages/src/main.js b/web-pages/src/main.js
new file mode 100644
index 0000000..9f215bf
--- /dev/null
+++ b/web-pages/src/main.js
@@ -0,0 +1,142 @@
+import Vue from 'vue'
+// import queryString from 'query-string'
+import app from '@/views/app/index.vue'
+import { router } from '@/router/index.js'
+import store from '@/store/index.js'
+// 璇锋眰瀵硅薄
+import Axios from 'axios'
+// 椤圭洰鏈湴缁勪欢鍏ㄥ眬娉ㄥ唽
+import globalComponents from './globalComponents'
+// 椤圭洰鏈湴鍏ㄥ眬鏂规硶
+import globalFunctions from './globalFunctions'
+
+// 绗笁鏂圭粍浠�
+// ant-design-vue 缁勪欢 鎸夐渶鍔犺浇
+import { ConfigProvider, Input } from 'ant-design-vue'
+
+Vue.use(globalComponents)
+Vue.use(globalFunctions)
+
+Vue.use(ConfigProvider)
+Vue.use(Input)
+
+const axiosInstance = Axios.create({
+ timeout: 60000
+})
+
+// 鍔犺浇椤圭洰鍩虹鏍峰紡鏂囦欢
+require('@/assets/css/normalize.css')
+// 鍔犺浇椤圭洰缁勪欢瑕嗙洊鏍峰紡锛屽叏灞�妯″潡鏍峰紡
+require('@/assets/css/index.scss')
+// 杞挱鎻掍欢swiper鏍峰紡
+require('swiper/css/swiper.min.css')
+
+// 璁剧疆涓� false 浠ラ樆姝� vue 鍦ㄥ惎鍔ㄦ椂鐢熸垚鐢熶骇鎻愮ず
+Vue.config.productionTip = false
+process.env.VUE_APP_env === 'devmock' && require('../mock')
+
+Vue.prototype.$axios = axiosInstance
+
+// axios 閰嶇疆 璇锋眰鍜屽搷搴旀嫤鎴�
+axiosInstance.interceptors.request.use(
+ (config) => {
+ // 绂佺敤浠ょ墝
+ if (
+ typeof config.headers.disabletoken !== 'undefined' &&
+ config.headers.disabletoken === true
+ ) {
+ delete config.headers.disabletoken
+ return config
+ }
+
+ if (
+ typeof config.headers.token === 'undefined' &&
+ localStorage.getItem('token') !== null
+ ) {
+ config.headers.token = localStorage.getItem('token')
+ }
+ return config
+ },
+ (error) => {
+ return Promise.reject(error)
+ }
+)
+// 寮傚父澶勭悊
+axiosInstance.interceptors.response.use(
+ (config) => {
+ if (typeof config.headers.token !== 'undefined') {
+ localStorage.setItem('token', config.headers.token)
+ }
+ if (
+ config.data &&
+ config.data.statusCode &&
+ config.data.statusCode !== '00'
+ ) {
+ // 涓氬姟寮傚父澶勭悊
+ let msg = 'biz error, statusCode: ' + config.data.statusCode
+ if (config.data.statusMsg) {
+ msg = msg + ', statusMsg: ' + config.data.statusMsg
+ }
+
+ // 鎵撳嵃寮傚父淇℃伅
+ console.log(msg)
+ }
+ return config
+ },
+ (error) => {
+ // 鎵撳嵃寮傚父淇℃伅
+ console.log(error)
+
+ if (
+ typeof error.response !== 'undefined' &&
+ error.response.status === 401
+ ) {
+ console.log(error)
+ }
+
+ return Promise.reject(error)
+ }
+)
+
+// 鑾峰彇蹇呰鐨勬暟鎹�
+const checkNecessaryData = (callbackFun) => {
+ const promiseList = []
+ if (promiseList.length > 0) {
+ Promise.all(promiseList)
+ .then((res) => {
+ localStorage.removeItem('getInitDataErrorCount')
+ callbackFun && callbackFun()
+ })
+ .catch((res) => {
+ const errorCount = localStorage.getItem(
+ 'getInitDataErrorCount'
+ )
+ if (errorCount) {
+ let count = Number.parseInt(errorCount)
+ if (count <= 3) {
+ localStorage.setItem('getInitDataErrorCount', ++count)
+ // 鑿滃崟鎴栬�呯敤鎴疯鑹插垪琛ㄦ暟鎹姹傚け璐ワ紝灏卞埛鏂伴〉闈�
+ window.location.reload(window.location.href)
+ }
+ } else {
+ localStorage.setItem('getInitDataErrorCount', 1)
+ // 鑿滃崟鎴栬�呯敤鎴疯鑹插垪琛ㄦ暟鎹姹傚け璐ワ紝灏卞埛鏂伴〉闈�
+ window.location.reload(window.location.href)
+ }
+ })
+ } else {
+ callbackFun && callbackFun()
+ }
+}
+
+router.beforeEach((to, from, next) => {
+ checkNecessaryData(() => {
+ next()
+ })
+})
+
+new Vue({
+ render: (h) => h(app),
+ router: router,
+ store: store
+}).$mount('#app')
--
Gitblit v1.9.1