From e70d240522af1aae7eea3b6441596cc0ae61a157 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Wed, 30 Dec 2020 17:17:18 +0800 Subject: [PATCH] 修复微信pc端请求没有带cookie的问题 --- bases/Fetcher.js | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/bases/Fetcher.js b/bases/Fetcher.js index f80ee41..689321c 100644 --- a/bases/Fetcher.js +++ b/bases/Fetcher.js @@ -4,6 +4,7 @@ */ import Taro from '@tarojs/taro'; +import Qs from 'qs'; import {Tools} from '@components/common/Tools'; export class Fetcher { @@ -29,8 +30,9 @@ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Ax-Rq-Type': 'separation', }, + credentials: 'same-origin', dataType: 'json', - timeout: 10000, + timeout: 30 * 1000, }; /** @@ -80,6 +82,12 @@ * @return {Promise<any>} */ get(url, data, remap = [], options = null) { + const params = Qs.stringify(data); + if (url.indexOf('?') >= 0) { + url += '&' + params; + } else { + url += '?' + params; + } return this.query('get', url, null, remap, options); } @@ -92,7 +100,15 @@ * @return {Promise<any>} */ post(url, data, remap = [], options = null) { - return this.query('post', url, data, remap, options); + const params = Qs.stringify(data); + const data2 = {}; + params.split('&').forEach(param => { + if (param) { + const item = param.split('='); + data2[decodeURIComponent(item[0])] = decodeURIComponent(item[1]); + } + }); + return this.query('post', url, data2, remap, options); } /** @@ -104,7 +120,7 @@ * @param {object} [options] * @return {Promise<any>|} */ - query(type, url, data = null, remap, options) { + query(type, url, data = null, remap, options = {}) { return new Promise((resolve, reject) => { Taro.request({ ...this._defaultConfig, @@ -426,7 +442,7 @@ } else { // 修复补齐 if (type === 'fix') { - if (!path || /^\/(upload|static)/.test(path)) { + if (!path || /^(http|\/upload|\/static)/.test(path)) { return path; } else { return '/upload/' + path; -- Gitblit v1.9.1