Browse Source

座位预定-接口请求在微信内请求头携带wechatToken参数

panyong 3 years ago
parent
commit
b1f93350de

+ 1 - 1
htmldev/dashboard/public/index.html

@@ -18,7 +18,7 @@
     Please enable it to continue.</strong>
 </noscript>
 <div id="app"></div>
-<div id="af-qrcode"></div>
+<div id="af-qrcode" style="display: none;"></div>
 <!-- built files will be auto injected -->
 </body>
 <script>

+ 6 - 1
htmldev/dashboard/src/api/request.js

@@ -1,3 +1,4 @@
+import Vue from 'vue'
 import axios from 'axios'
 import router from '../router'
 import { getCookieValue } from '../utils'
@@ -17,11 +18,14 @@ if (platform.isAlipay) {
 } else if (platform.isWeixin) {
   tingbangSource = 'wechat'
 }
-// todo wechatToken
+
 // Add a request interceptor
 request.interceptors.request.use(request => {
   request.headers.token = getCookieValue('afhousetoken')
   request.headers.tingbangSource = tingbangSource
+  if (platform.isWeixin) {
+    request.headers.wechatToken = getCookieValue('afhousewechatToken')
+  }
   return request
 }, error => {
   // Do something with request error
@@ -33,6 +37,7 @@ request.interceptors.response.use(response => {
   // Do something with response data
   const { code, authorizeUrl } = response.data
   if (code === 301 && authorizeUrl) {
+    Vue.cookie.delete('afhousewechatToken')
     location.replace(authorizeUrl)
   } else if (code === 403) {
     router.push('/login')

+ 6 - 0
htmldev/dashboard/src/router/index.js

@@ -1,5 +1,6 @@
 import Vue from 'vue'
 import VueRouter from 'vue-router'
+import { updateWechatToken } from '../utils'
 
 Vue.use(VueRouter)
 
@@ -91,4 +92,9 @@ const router = new VueRouter({
   }
 })
 
+router.beforeEach((to, from, next) => {
+  updateWechatToken()
+  next()
+})
+
 export default router

+ 12 - 0
htmldev/dashboard/src/utils/index.js

@@ -1,5 +1,7 @@
 import Vue from 'vue'
 import store from '../store'
+import { getQueryString } from '@/utils/getQueryString'
+import { platform } from '@/utils/platform'
 
 /**
  * 清除登录信息
@@ -43,3 +45,13 @@ export function yuan2Fen (num) {
 export function getCookieValue (name) {
   return Object.prototype.toString.call(Vue.cookie.get(name)) === '[object Null]' ? '' : Vue.cookie.get(name)
 }
+
+/**
+ * 获取wechatToken,只有在微信内才有这个参数
+ */
+export function updateWechatToken () {
+  const wechatToken = getQueryString('wechatToken') || ''
+  if (wechatToken && platform.isWeixin) {
+    Vue.cookie.set('afhousewechatToken', wechatToken)
+  }
+}

+ 1 - 1
htmldev/dashboard/src/views/place/reserve/index.vue

@@ -146,7 +146,7 @@ export default {
           Toast('退款成功')
           this.reserveList.splice(idx, 1, {
             ...item,
-            order_status: 2 // TODO 手工改
+            order_status: 2 // 这里没有调用接口,手动修改订单状态
           })
         } else {
           Toast(msg)