ArvinQi 6 anni fa
parent
commit
3811fcc912
5 ha cambiato i file con 31 aggiunte e 28 eliminazioni
  1. 4 18
      components/type/vip/mobile.vue
  2. 15 0
      mixins/getDeviceType.js
  3. 1 1
      nuxt.config.js
  4. 6 3
      pages/type/vip.vue
  5. 5 6
      plugins/nuxtAxios.js

+ 4 - 18
components/type/vip/mobile.vue

@@ -128,9 +128,7 @@ export default {
       // 当前是企业页
       currentCom: false,
       // 会员详情
-      vipDetail: null,
-      // 设备类型
-      deviceType: 'pc'
+      vipDetail: null
     }
   },
   mixins: [getDeviceType],
@@ -156,22 +154,10 @@ export default {
     },
   },
   mounted() {
-    this.getDeviceType();
     this.getVipDetail();
   },
   methods: {
     /**
-     * 设备判断
-     */
-    getDeviceType() {
-      if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS
-        this.deviceType = 'ios';
-      } else if (/(Android)/i.test(navigator.userAgent)) { //判断Android
-        this.deviceType = 'android';
-      } else { //pc
-      };
-    },
-    /**
      * 点击开通
      */
     async clickPay(item) {
@@ -180,15 +166,15 @@ export default {
         number: 3,
         product_id: item.id
       }
-      console.log(this.deviceType)
       if (this.deviceType === 'ios') {
+        let cookie = this.getCookie();
         let res = await this.$axios.$post('/api/vip/pay', {
           product_type: 11,
           number: 3,
           product_id: item.id,
-          channel: 'apple'
+          channel: 'apple',
+          ...cookie
         });
-        console.log(res)
         if (res && res.data) {
           query = Object.assign({}, query, res.data);
         }

+ 15 - 0
mixins/getDeviceType.js

@@ -19,6 +19,21 @@ export default {
         this.deviceType = 'android';
       } else { //pc
       };
+    },
+    /**
+     * get cookie
+     */
+    getCookie() {
+      const cookie = {};
+      if (document && document.cookie) {
+        document.cookie.split(/; ?/).forEach(item => {
+          if (item) {
+            const it = item.split('=');
+            cookie[it[0]] = it[1];
+          }
+        });
+      }
+      return cookie;
     }
   }
 }

+ 1 - 1
nuxt.config.js

@@ -75,7 +75,7 @@ module.exports = {
     timeout: 15000,
     credentials: true,
     proxyHeaders: true,
-    // debug: true
+    debug: true
   },
   /**
    * Proxy

+ 6 - 3
pages/type/vip.vue

@@ -9,6 +9,7 @@ import { mapState } from 'vuex'
 import pc from '@/components/type/vip/pc'
 import mobile from '@/components/type/vip/mobile'
 import getDeviceType from '@/mixins/getDeviceType'
+import qs from 'qs';
 
 export default {
   // async asyncData({ $axios, params }) {
@@ -42,9 +43,11 @@ export default {
   },
   methods: {
     async getList() {
-      const deviceSign = this.deviceType ? 'ios 7.0.0' : 'android 9.0.0';
-      const extraHeaders = this.deviceType === 'ios' ? { x_app: 'ios 4.6.0', x_nonce_str: '1558105441627', x_signature: 'h5' } : {};
-      let res = await this.$axios.$get(`/api/vip/getList`, { headers: { ...extraHeaders } })
+      let extraHeaders = {};
+      if (this.deviceType === 'ios') {
+        extraHeaders = this.getCookie();
+      }
+      let res = await this.$axios.$post(`/api/vip/getList`, extraHeaders)
       if (res) {
         this.vipList = res.data
       }

+ 5 - 6
plugins/nuxtAxios.js

@@ -17,18 +17,17 @@ export default function ({ $axios, redirect, req, ...args }) {
         }
         // stringify post data
         if (config.method === 'post') {
-            console.log(config, req&& req);
             // config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
             const data = config.data;
-            const cookie = config.headers.cookie || config.headers.common.cookie || '';
-            let formData = ''
+            // const cookie = config.headers.cookie || config.headers.common.cookie || '';
+            let formData = '';
             for(const key in data) {
                 if(data.hasOwnProperty(key)) {
-                    const element = data[key]
-                    formData += `${key}=${element}&`
+                    const element = data[key];
+                    formData += `${key}=${element}&`;
                 }
             }
-            formData += cookie.split(';').join('&');
+            // formData += cookie.split(';').join('&');
             config.data = formData;
             // config.data = qs.stringify(config.data);
         }