chore:修改了会员中心页面弹出【网络异常,请稍后重试】,无法获取推荐码。
This commit is contained in:
@@ -173,8 +173,19 @@ export default {
|
||||
|
||||
_sendRequestNow(params) {
|
||||
|
||||
var method = params.data != undefined ? 'POST' : 'GET',
|
||||
url = (Config.baseUrl + params.url).replace(/(?<!:)\/+/g, '/'),
|
||||
// ✅ 关键修复 1:支持调用方指定 params.method(GET/POST/PUT/DELETE);
|
||||
// 没指定时按老规则:有 data → POST,没 data → GET
|
||||
var method;
|
||||
if (params.method && typeof params.method === 'string') {
|
||||
method = String(params.method).toUpperCase();
|
||||
if (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].indexOf(method) === -1) {
|
||||
method = 'GET';
|
||||
}
|
||||
} else {
|
||||
method = params.data != undefined ? 'POST' : 'GET';
|
||||
}
|
||||
|
||||
var url = (Config.baseUrl + params.url).replace(/(?<!:)\/+/g, '/'),
|
||||
data = {
|
||||
app_type: appType,
|
||||
app_type_name: appTypeName
|
||||
@@ -194,9 +205,22 @@ export default {
|
||||
|
||||
if (params.data != undefined) Object.assign(data, params.data);
|
||||
|
||||
const header = params.header || {
|
||||
'content-type': 'application/x-www-form-urlencoded;application/json'
|
||||
};
|
||||
// ✅ 关键修复 2:Content-Type 合法值,两个 MIME 类型不要乱拼接
|
||||
// 规则:
|
||||
// - 调用方 params.header 里指定了 content-type → 优先用调用方的(保持原有 override 能力)
|
||||
// - GET/HEAD/DELETE:application/x-www-form-urlencoded(URL query 编码)
|
||||
// - POST/PUT/PATCH Object data:application/json(uni.request 会自动 JSON.stringify)
|
||||
// - 如果调用方传 FormData / ArrayBuffer 等二进制:不设 Content-Type,让 uni 自动处理
|
||||
var autoHeader = {};
|
||||
if (method === 'GET' || method === 'HEAD' || method === 'DELETE') {
|
||||
autoHeader['content-type'] = 'application/x-www-form-urlencoded';
|
||||
} else {
|
||||
// POST/PUT/PATCH:默认用 application/json,后端能直接 json_decode(file_get_contents('php://input'))
|
||||
autoHeader['content-type'] = 'application/json';
|
||||
}
|
||||
// 调用方 params.header 合并(调用方指定的覆盖自动设置的)
|
||||
const header = Object.assign({}, autoHeader, (params.header && typeof params.header === 'object') ? params.header : {});
|
||||
|
||||
const dataType = params.dataType || 'json';
|
||||
const responseType = params.responseType || 'text';
|
||||
|
||||
@@ -227,8 +251,9 @@ export default {
|
||||
uni.request({
|
||||
url: Config.baseUrl + '/api/upload/headimgBase64',
|
||||
method: 'POST',
|
||||
// ✅ 修复:application/json,后端能直接 json_decode
|
||||
header: {
|
||||
'content-type': 'application/x-www-form-urlencoded;application/json'
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
data: {
|
||||
app_type: appType,
|
||||
@@ -241,7 +266,7 @@ export default {
|
||||
console.log('[HTTP][RESPONSE] uploadBase64', 'statusCode=', res.statusCode, JSON.stringify(res.data));
|
||||
typeof params.success == 'function' && params.success(res.data);
|
||||
},
|
||||
fail: () => {
|
||||
fail: (res) => {
|
||||
console.error('[HTTP][FAIL] uploadBase64', JSON.stringify(res));
|
||||
typeof params.fail == 'function' && params.fail(res);
|
||||
}
|
||||
@@ -252,8 +277,9 @@ export default {
|
||||
uni.request({
|
||||
url: Config.baseUrl + '/api/upload/headimgPull',
|
||||
method: 'POST',
|
||||
// ✅ 修复:application/json
|
||||
header: {
|
||||
'content-type': 'application/x-www-form-urlencoded;application/json'
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
data: {
|
||||
app_type: appType,
|
||||
@@ -266,7 +292,7 @@ export default {
|
||||
console.log('[HTTP][RESPONSE] pullImage', 'statusCode=', res.statusCode, JSON.stringify(res.data));
|
||||
typeof params.success == 'function' && params.success(res.data);
|
||||
},
|
||||
fail: () => {
|
||||
fail: (res) => {
|
||||
console.error('[HTTP][FAIL] pullImage', JSON.stringify(res));
|
||||
typeof params.fail == 'function' && params.fail(res);
|
||||
}
|
||||
@@ -274,6 +300,17 @@ export default {
|
||||
},
|
||||
upload(params) {
|
||||
console.log('[HTTP][REQUEST] upload', Config.baseUrl + params.url, 'name=', params.name || 'file');
|
||||
// ✅ 关键修复:uni.uploadFile **绝对不能手动设置 Content-Type**!
|
||||
// 因为 uni.uploadFile 会自动设置成 multipart/form-data; boundary=----xxxxxx
|
||||
// 手动设置会覆盖掉 boundary,后端无法解析分段上传,导致文件/表单字段解析为空
|
||||
var uploadHeader = {};
|
||||
// 只合并调用方传的自定义 header,不默认加 content-type
|
||||
if (params.header && typeof params.header === 'object') {
|
||||
Object.assign(uploadHeader, params.header);
|
||||
// 兜底:如果调用方误传了 content-type,就删掉,让 uni 自动设置 multipart/form-data
|
||||
delete uploadHeader['content-type'];
|
||||
delete uploadHeader['Content-Type'];
|
||||
}
|
||||
uni.uploadFile({
|
||||
url: Config.baseUrl + params.url,
|
||||
filePath: params.filePath,
|
||||
@@ -282,10 +319,10 @@ export default {
|
||||
formData: {
|
||||
app_type: appType,
|
||||
app_type_name: appTypeName,
|
||||
token: store.state.token || '',
|
||||
uniacid: uni.getStorageSync('uniacid') || Config.uniacid
|
||||
},
|
||||
header: {
|
||||
'content-type': 'application/x-www-form-urlencoded;application/json'
|
||||
},
|
||||
header: uploadHeader,
|
||||
success: (res) => {
|
||||
console.log('[HTTP][RESPONSE] upload', Config.baseUrl + params.url, 'statusCode=', res.statusCode, res.data);
|
||||
typeof params.success == 'function' && params.success(JSON.parse(res.data));
|
||||
|
||||
@@ -1481,7 +1481,7 @@ export default {
|
||||
// title/enable_set_title/page_params 仍需透传到目标 URL,page_params 放最后
|
||||
|
||||
// ✅ 内部页:把推荐码写进 page_params(最终会被拼成 URL query,diy-form onLoad options 能收到)
|
||||
// 仅在当前登录已拿到推荐码时追加,不覆盖上游已有值;双写 recommend_code(老师标准)+ invite(历史兼容)
|
||||
// 仅在当前登录已拿到推荐码时追加,不覆盖上游已有值;双写 recommend_code+ invite(历史兼容)
|
||||
var _curRecommendCode = _getCurrentRecommendCode();
|
||||
if (_curRecommendCode) {
|
||||
if (!link.page_params || typeof link.page_params !== 'object') link.page_params = {};
|
||||
|
||||
1179
components-diy/components-recommend-diy.vue
Normal file
1179
components-diy/components-recommend-diy.vue
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user