hookehuyr

refactor(request): 移除未使用的qs和工具函数并简化认证跳转逻辑

清理不再使用的qs库导入和strExist工具函数
移除未使用的isPlainObject工具函数
简化POST请求的URL编码处理逻辑
注释掉认证失败时的页面跳转代码
1 /* 1 /*
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2026-01-06 21:41:47 4 + * @LastEditTime: 2026-01-07 21:44:54
5 - * @FilePath: /itomix/git/xyxBooking-weapp/src/utils/request.js 5 + * @FilePath: /xyxBooking-weapp/src/utils/request.js
6 * @Description: 简单axios封装,后续按实际处理 6 * @Description: 简单axios封装,后续按实际处理
7 */ 7 */
8 // import axios from 'axios' 8 // import axios from 'axios'
9 import axios from 'axios-miniprogram'; 9 import axios from 'axios-miniprogram';
10 import Taro from '@tarojs/taro' 10 import Taro from '@tarojs/taro'
11 -import qs from 'qs' 11 +// import qs from 'qs'
12 -import { strExist } from './tools' 12 +// import { strExist } from './tools'
13 import { routerStore } from '@/stores/router' 13 import { routerStore } from '@/stores/router'
14 14
15 // import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress'; 15 // import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress';
...@@ -49,10 +49,10 @@ const getCurrentPageFullPath = () => { ...@@ -49,10 +49,10 @@ const getCurrentPageFullPath = () => {
49 } 49 }
50 } 50 }
51 51
52 -const isPlainObject = (value) => { 52 +// const isPlainObject = (value) => {
53 - if (value === null || typeof value !== 'object') return false 53 +// if (value === null || typeof value !== 'object') return false
54 - return Object.prototype.toString.call(value) === '[object Object]' 54 +// return Object.prototype.toString.call(value) === '[object Object]'
55 -} 55 +// }
56 56
57 // create an axios instance 57 // create an axios instance
58 const service = axios.create({ 58 const service = axios.create({
...@@ -86,21 +86,21 @@ service.interceptors.request.use( ...@@ -86,21 +86,21 @@ service.interceptors.request.use(
86 config.params = { ...config.params, timestamp: (new Date()).valueOf() } 86 config.params = { ...config.params, timestamp: (new Date()).valueOf() }
87 } 87 }
88 88
89 - if ((config.method || '').toLowerCase() === 'post') { 89 + // if ((config.method || '').toLowerCase() === 'post') {
90 - const url = config.url || '' 90 + // const url = config.url || ''
91 - const headers = config.headers || {} 91 + // const headers = config.headers || {}
92 - const contentType = headers['content-type'] || headers['Content-Type'] 92 + // const contentType = headers['content-type'] || headers['Content-Type']
93 - const shouldUrlEncode = 93 + // const shouldUrlEncode =
94 - !contentType || String(contentType).includes('application/x-www-form-urlencoded') 94 + // !contentType || String(contentType).includes('application/x-www-form-urlencoded')
95 - 95 +
96 - if (shouldUrlEncode && !strExist(['upload.qiniup.com'], url) && isPlainObject(config.data)) { 96 + // if (shouldUrlEncode && !strExist(['upload.qiniup.com'], url) && isPlainObject(config.data)) {
97 - config.headers = { 97 + // config.headers = {
98 - ...headers, 98 + // ...headers,
99 - 'content-type': 'application/x-www-form-urlencoded' 99 + // 'content-type': 'application/x-www-form-urlencoded'
100 - } 100 + // }
101 - config.data = qs.stringify(config.data) 101 + // config.data = qs.stringify(config.data)
102 - } 102 + // }
103 - } 103 + // }
104 104
105 return config 105 return config
106 }, 106 },
...@@ -138,9 +138,7 @@ service.interceptors.response.use( ...@@ -138,9 +138,7 @@ service.interceptors.response.use(
138 if (currentPath) { 138 if (currentPath) {
139 router.add(currentPath) 139 router.add(currentPath)
140 } 140 }
141 - Taro.navigateTo({ 141 + // Taro.navigateTo({ url: '/pages/auth/index' });
142 - url: '/pages/auth/index'
143 - });
144 } 142 }
145 return response; // 返回 response 以便业务代码处理(或者这里 reject) 143 return response; // 返回 response 以便业务代码处理(或者这里 reject)
146 } 144 }
......