Browse Source

环境配置;globalApi莫名其妙地拿不到了;网络请求拦截器逻辑优化

任一存 2 years ago
parent
commit
cb42cb8b17

+ 1 - 1
.env.dev

@@ -1,4 +1,4 @@
 CLI_MODE=dev
 NODE_ENV=development
 PUBLIC_PATH=/
-VUE_APP_API_PREFIX=http://192.168.20.55:8043
+VUE_APP_API_PREFIX=https://wlgbwg.4dage.com

+ 4 - 0
.env.prod

@@ -0,0 +1,4 @@
+CLI_MODE=prod
+NODE_ENV=production
+PUBLIC_PATH=/display/
+VUE_APP_API_PREFIX=

+ 1 - 1
.env.test

@@ -1,4 +1,4 @@
 CLI_MODE=test
 NODE_ENV=production
 PUBLIC_PATH=/wenlange/display/
-VUE_APP_API_PREFIX=http://192.168.20.55:8043
+VUE_APP_API_PREFIX=https://wlgbwg.4dage.com

+ 1 - 0
package.json

@@ -5,6 +5,7 @@
   "scripts": {
     "serve": "vue-cli-service serve --mode dev",
     "build-test": "vue-cli-service build --mode test",
+    "build-prod": "vue-cli-service build --mode prod",
     "build": "vue-cli-service build",
     "lint": "vue-cli-service lint"
   },

+ 2 - 1
public/static/js/Hot.js

@@ -38,7 +38,8 @@ window.initHot = function (model) {
     var querySectionInLink = link.split('?')[1]
     var langParam = "en" == manage.number("lang") ? "&lang=" + manage.number("lang") : ""
     // return `http://192.168.20.16:8084/#/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
-    return `/wenlange/hotspot/index.html#/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
+    // return `/wenlange/hotspot/index.html#/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
+    return `/hotspot/index.html#/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
   }
   var removeSrcPostMark = function (url) {//去除texture.load时自动加上的'?'
     var index = url.indexOf('?')

+ 1 - 0
src/App.vue

@@ -24,6 +24,7 @@
 <script>
 import '@/assets/style/reset.less'
 import { mapMutations } from 'vuex'
+import globalApi from "@/api"
 
 export default {
   mounted() {

+ 7 - 3
src/api.js

@@ -2,18 +2,22 @@ import axios from "axios"
 import { encodeStr } from "@/utils/pass.js"
 import { Base64 } from "js-base64"
 import store from "@/store/index.js"
+import router from "@/router"
 
 axios.interceptors.response.use(function (response) {
   // 2xx 范围内的状态码都会触发该函数。
-  // 对响应数据做点什么
   if (response.data.code === 5001 || response === 5002) {
     store.commit('logoutCallback')
+    router.push({ name: 'Login' })
+    return Promise.reject('登录态过期')
   }
   return response
 }, function (error) {
   // 超出 2xx 范围的状态码都会触发该函数。
-  // 对响应错误做点什么
   console.log(error)
+  store.commit('logoutCallback')
+  router.push({ name: 'Login' })
+  return Promise.reject('登录态过期')
 })
 
 async function fetchBadgeAndVisitData() {
@@ -86,7 +90,7 @@ export default {
           token: lastToken,
         }
       })
-      if (res.data.code === 0 && res.data.data) {
+      if (res?.data?.code === 0 && res?.data?.data) {
         store.commit('setLoginStatus', true)
         store.commit('setToken', lastToken)
         store.commit('setUserInfo', JSON.parse(lastUserInfoStr))

+ 2 - 0
src/views/gui/Login.vue

@@ -67,6 +67,8 @@
 </template>
 
 <script>
+import globalApi from "@/api"
+
 export default {
   data() {
     return {

+ 1 - 0
src/views/gui/QuestionPositionTip.vue

@@ -66,6 +66,7 @@
 
 <script>
 import quizData, { badgeTypeCode2txt } from "@/quizData.js"
+import globalApi from "@/api"
 
 export default {
   data() {

+ 2 - 0
src/views/gui/RuleDesc.vue

@@ -83,6 +83,8 @@
 </template>
 
 <script>
+import globalApi from "@/api"
+
 export default {
   data() {
     return {

+ 2 - 0
src/views/gui/RuleDescMobile.vue

@@ -76,6 +76,8 @@
 </template>
 
 <script>
+import globalApi from "@/api"
+
 export default {
   data() {
     return {

+ 1 - 2
src/views/gui/Share.vue

@@ -114,6 +114,7 @@
 <script>
 import html2canvas from "html2canvas"
 import QRCode from 'qrcode'
+import globalApi from "@/api"
 
 export default {
   data() {
@@ -160,8 +161,6 @@ export default {
       this.answerNumber = res.length
     })
     this.$nextTick(() => {
-      var canvas = document.getElementById('qrcode-canvas')
-
       QRCode.toDataURL(`${location.origin}${process.env.BASE_URL || '/'}index.html#/?m=768`).then((url) => {
         this.qrcodeDataUrl = url
       })

+ 2 - 0
src/views/gui/SignUp.vue

@@ -90,6 +90,8 @@
 </template>
 
 <script>
+import globalApi from "@/api"
+
 export default {
   data() {
     return {

+ 2 - 0
src/views/gui/UserInfo.vue

@@ -151,6 +151,8 @@
 </template>
 
 <script>
+import globalApi from "@/api"
+
 export default {
   data() {
     return {

+ 2 - 0
src/views/gui/UserInfoMobile.vue

@@ -135,6 +135,8 @@
 </template>
 
 <script>
+import globalApi from "@/api"
+
 export default {
   data() {
     return {