Showing
2 changed files
with
23 additions
and
11 deletions
| ... | @@ -2,13 +2,14 @@ | ... | @@ -2,13 +2,14 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-28 10:17:40 | 3 | * @Date: 2022-05-28 10:17:40 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2022-06-30 00:10:50 | 5 | + * @LastEditTime: 2022-06-30 01:16:40 |
| 6 | * @FilePath: /tswj/src/utils/axios.js | 6 | * @FilePath: /tswj/src/utils/axios.js |
| 7 | * @Description: | 7 | * @Description: |
| 8 | */ | 8 | */ |
| 9 | import axios from 'axios'; | 9 | import axios from 'axios'; |
| 10 | import router from '@/router'; | 10 | import router from '@/router'; |
| 11 | import qs from 'Qs' | 11 | import qs from 'Qs' |
| 12 | +import { strExist } from '@/utils/tools' | ||
| 12 | // import { parseQueryString } from '@/utils/tools' | 13 | // import { parseQueryString } from '@/utils/tools' |
| 13 | 14 | ||
| 14 | axios.defaults.params = { | 15 | axios.defaults.params = { |
| ... | @@ -23,14 +24,12 @@ axios.interceptors.request.use( | ... | @@ -23,14 +24,12 @@ axios.interceptors.request.use( |
| 23 | // const url_params = parseQueryString(location.href); | 24 | // const url_params = parseQueryString(location.href); |
| 24 | // GET请求默认打上时间戳,避免从缓存中拿数据。 | 25 | // GET请求默认打上时间戳,避免从缓存中拿数据。 |
| 25 | const timestamp = config.method === 'get' ? (new Date()).valueOf() : ''; | 26 | const timestamp = config.method === 'get' ? (new Date()).valueOf() : ''; |
| 26 | - // 上传相关接口需要屏蔽掉封装, 不能序列化数据会报错。 | 27 | + if (config.method === 'post') { |
| 27 | - if ( | 28 | + // 上传相关接口需要屏蔽掉封装, 不能序列化,数据会报错。 |
| 28 | - config.method === 'post' && | 29 | + if (!strExist(['a=upload', 'upload.qiniup.com'], config.url)) { |
| 29 | - (config.url.indexOf('a=upload') === -1 && config.url.indexOf('upload.qiniup.com') === -1) | 30 | + // POST PHP需要修改数据格式 |
| 30 | - ) | 31 | + config.data = qs.stringify(config.data) |
| 31 | - { | 32 | + } |
| 32 | - // POST PHP需要修改数据格式 | ||
| 33 | - config.data = qs.stringify(config.data) | ||
| 34 | } | 33 | } |
| 35 | // 绑定默认请求头 | 34 | // 绑定默认请求头 |
| 36 | config.params = { ...config.params, timestamp } | 35 | config.params = { ...config.params, timestamp } | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2022-04-18 15:59:42 | 2 | * @Date: 2022-04-18 15:59:42 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-06-29 22:35:51 | 4 | + * @LastEditTime: 2022-06-30 01:15:33 |
| 5 | * @FilePath: /tswj/src/utils/tools.js | 5 | * @FilePath: /tswj/src/utils/tools.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -58,4 +58,17 @@ const parseQueryString = url => { | ... | @@ -58,4 +58,17 @@ const parseQueryString = url => { |
| 58 | return json; | 58 | return json; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | -export { formatDate, wxInfo, hasEllipsis, parseQueryString }; | 61 | +/** |
| 62 | + * 字符串包含字符数组中字符的状态 | ||
| 63 | + * @param {*} array 字符数组 | ||
| 64 | + * @param {*} str 字符串 | ||
| 65 | + * @returns 包含状态 | ||
| 66 | + */ | ||
| 67 | +const strExist = (array, str) => { | ||
| 68 | + const exist = array.filter(arr => { | ||
| 69 | + if (str.indexOf(arr) >= 0) return str; | ||
| 70 | + }) | ||
| 71 | + return exist.length > 0 | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +export { formatDate, wxInfo, hasEllipsis, parseQueryString, strExist }; | ... | ... |
-
Please register or login to post a comment