修改上传图片安全验证问题
This commit is contained in:
@@ -51,7 +51,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '获取互关列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取互关列表失败:', error);
|
||||
console.warn('获取互关列表失败:', error);
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '获取粉丝列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取粉丝列表失败:', error);
|
||||
console.warn('获取粉丝列表失败:', error);
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '获取新增粉丝列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取新增粉丝列表失败:', error);
|
||||
console.warn('获取新增粉丝列表失败:', error);
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '获取关注列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取关注列表失败:', error);
|
||||
console.warn('获取关注列表失败:', error);
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
}
|
||||
@@ -178,7 +178,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '关注失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('关注失败:', error);
|
||||
console.warn('关注失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '取消关注失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('取消关注失败:', error);
|
||||
console.warn('取消关注失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -231,7 +231,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '获取推荐用户失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取推荐用户失败:', error);
|
||||
console.warn('获取推荐用户失败:', error);
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,7 @@ export class FollowService {
|
||||
return 'none';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查关注状态失败:', error);
|
||||
console.warn('检查关注状态失败:', error);
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ export class FollowService {
|
||||
throw new Error(response.message || '屏蔽推荐用户失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('屏蔽推荐用户失败:', error);
|
||||
console.warn('屏蔽推荐用户失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export const getGamesList = async (params?: Record<string, any>) => {
|
||||
// const fetchApi = isIntegrate ? '/games/integrate_list' : '/games/list'
|
||||
return httpService.post('/games/list', params, { showLoading: false })
|
||||
} catch (error) {
|
||||
console.error("列表数据获取失败:", error);
|
||||
console.warn("列表数据获取失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -41,7 +41,7 @@ export const getGamesIntegrateList = async (params?: Record<string, any>) => {
|
||||
try {
|
||||
return httpService.post('/games/integrate_list', params, { showLoading: false })
|
||||
} catch (error) {
|
||||
console.error("列表数据获取失败:", error);
|
||||
console.warn("列表数据获取失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -55,7 +55,7 @@ export const getGamesCount = async (params?: Record<string, any>) => {
|
||||
try {
|
||||
return httpService.post('/games/count', params, { showLoading: false })
|
||||
} catch (error) {
|
||||
console.error("列表数量获取失败:", error);
|
||||
console.warn("列表数量获取失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -71,7 +71,7 @@ export const getSearchHistory = async (params) => {
|
||||
return httpService.post('/games/search_history', params, { showLoading: false })
|
||||
} catch (error) {
|
||||
// 捕获并打印错误信息
|
||||
console.error("历史记录获取失败:", error);
|
||||
console.warn("历史记录获取失败:", error);
|
||||
// 抛出错误以便上层处理
|
||||
throw error;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ export const clearHistory = async (params) => {
|
||||
return httpService.post('/games/search_history/delete_all', params, { showLoading: false })
|
||||
} catch (error) {
|
||||
// 捕获并打印错误信息
|
||||
console.error("清除历史记录失败:", error);
|
||||
console.warn("清除历史记录失败:", error);
|
||||
// 抛出错误以便上层处理
|
||||
throw error;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ export const searchSuggestion = async (params) => {
|
||||
return httpService.post('/games/search_recommendations', params)
|
||||
} catch (error) {
|
||||
// 捕获并打印错误信息
|
||||
console.error("搜索建议获取失败:", error);
|
||||
console.warn("搜索建议获取失败:", error);
|
||||
// 抛出错误以便上层处理
|
||||
throw error;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ export const getCities = async () => {
|
||||
return httpService.post('/cities/tree', {})
|
||||
} catch (error) {
|
||||
// 捕获并打印错误信息
|
||||
console.error("城市列表获取失败:", error);
|
||||
console.warn("城市列表获取失败:", error);
|
||||
// 抛出错误以便上层处理
|
||||
throw error;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ export const getCityQrCode = async () => {
|
||||
return httpService.post('/hot_city_qr/list', {})
|
||||
} catch (error) {
|
||||
// 捕获并打印错误信息
|
||||
console.error("城市二维码获取失败:", error);
|
||||
console.warn("城市二维码获取失败:", error);
|
||||
// 抛出错误以便上层处理
|
||||
throw error;
|
||||
}
|
||||
@@ -140,7 +140,7 @@ export const getDistricts = async (params: { province: string; city: string }) =
|
||||
return httpService.post('/cities/cities', params)
|
||||
} catch (error) {
|
||||
// 捕获并打印错误信息
|
||||
console.error("行政区列表获取失败:", error);
|
||||
console.warn("行政区列表获取失败:", error);
|
||||
// 抛出错误以便上层处理
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ export const wechat_auth_login = async (
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("微信授权登录失败:", error);
|
||||
console.warn("微信授权登录失败:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "微信授权失败,请重试",
|
||||
@@ -160,7 +160,7 @@ export const phone_auth_login = async (
|
||||
await useUser.getState().fetchUserInfo();
|
||||
await useUser.getState().checkNicknameChangeStatus();
|
||||
} catch (error) {
|
||||
console.error("更新用户信息到 store 失败:", error);
|
||||
console.warn("更新用户信息到 store 失败:", error);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -178,7 +178,7 @@ export const phone_auth_login = async (
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("手机号登录失败:", error);
|
||||
console.warn("手机号登录失败:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message,
|
||||
@@ -206,7 +206,7 @@ export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("发送短信失败:", error);
|
||||
console.warn("发送短信失败:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message,
|
||||
@@ -232,7 +232,7 @@ export const verify_sms_code = async (
|
||||
user_info: response.data?.userInfo,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("验证验证码失败:", error);
|
||||
console.warn("验证验证码失败:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message,
|
||||
@@ -255,7 +255,7 @@ export const save_login_state = (token: string, user_info: WechatUserInfo) => {
|
||||
Taro.setStorageSync("is_logged_in", true);
|
||||
Taro.setStorageSync("login_time", Date.now());
|
||||
} catch (error) {
|
||||
console.error("保存登录状态失败:", error);
|
||||
console.warn("保存登录状态失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -270,7 +270,7 @@ export const clear_login_state = () => {
|
||||
Taro.removeStorageSync("is_logged_in");
|
||||
Taro.removeStorageSync("login_time");
|
||||
} catch (error) {
|
||||
console.error("清除登录状态失败:", error);
|
||||
console.warn("清除登录状态失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -374,7 +374,7 @@ export const refresh_login_status = async (): Promise<boolean> => {
|
||||
// 检查本地存储的登录状态
|
||||
return check_login_status();
|
||||
} catch (error) {
|
||||
console.error("刷新登录状态失败:", error);
|
||||
console.warn("刷新登录状态失败:", error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -385,7 +385,7 @@ export const updateUserPhone = async (payload: ChangePhoneParams) => {
|
||||
const response = await httpService.post("/user/update_phone", payload);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("更新用户手机号失败:", error);
|
||||
console.warn("更新用户手机号失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -402,7 +402,7 @@ export const getUserInfoById = async (id) => {
|
||||
);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("获取用户信息失败:", error);
|
||||
console.warn("获取用户信息失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -415,7 +415,7 @@ export const followUser = async (following_id) => {
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("关注失败:", error);
|
||||
console.warn("关注失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -428,7 +428,7 @@ export const unFollowUser = async (following_id) => {
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("取消关注失败:", error);
|
||||
console.warn("取消关注失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -464,7 +464,7 @@ export const silentLogin = async (): Promise<LoginResponse> => {
|
||||
console.log("微信登录结果:", login_result);
|
||||
|
||||
if (!login_result.code) {
|
||||
console.error("微信登录失败:未获取到code");
|
||||
console.warn("微信登录失败:未获取到code");
|
||||
return {
|
||||
success: false,
|
||||
message: "微信登录失败",
|
||||
@@ -506,14 +506,14 @@ export const silentLogin = async (): Promise<LoginResponse> => {
|
||||
user_info,
|
||||
};
|
||||
} else {
|
||||
console.error("静默登录失败:", auth_response.message);
|
||||
console.warn("静默登录失败:", auth_response.message);
|
||||
return {
|
||||
success: false,
|
||||
message: auth_response.message || "静默登录失败",
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("静默登录异常:", error);
|
||||
console.warn("静默登录异常:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "静默登录失败,请重试",
|
||||
|
||||
@@ -39,19 +39,28 @@ export interface uploadFileResponseData {
|
||||
updated_at: string,
|
||||
}
|
||||
|
||||
// 从上传错误中取出可展示的文案
|
||||
function get_upload_error_msg(error: any): string {
|
||||
if (!error) return "上传失败";
|
||||
const msg =
|
||||
error?.message ||
|
||||
(typeof error?.error === "string" ? error.error : error?.error?.message) ||
|
||||
(error?.data?.message ?? error?.data?.msg) ||
|
||||
"";
|
||||
return (msg && String(msg).trim()) || "上传失败";
|
||||
}
|
||||
|
||||
// 发布球局类
|
||||
class UploadApi {
|
||||
async upload(req: UploadFilesData): Promise<{ id: string, data: uploadFileResponseData }> {
|
||||
|
||||
let fullUrl = `${envConfig.apiBaseURL}/api/gallery/upload`
|
||||
|
||||
const authHeader = tokenManager.getAuthHeader()
|
||||
const { id, ...rest } = req
|
||||
const fullUrl = `${envConfig.apiBaseURL}/api/gallery/upload`;
|
||||
const authHeader = tokenManager.getAuthHeader();
|
||||
const { id, ...rest } = req;
|
||||
try {
|
||||
const res = await Taro.uploadFile({
|
||||
url: fullUrl,
|
||||
filePath: rest.filePath,
|
||||
name: 'file',
|
||||
name: "file",
|
||||
formData: {
|
||||
description: rest.description,
|
||||
tags: rest.tags,
|
||||
@@ -59,12 +68,17 @@ class UploadApi {
|
||||
},
|
||||
header: authHeader,
|
||||
});
|
||||
return {
|
||||
id,
|
||||
data: JSON.parse(res.data).data,
|
||||
const parsed = JSON.parse(res.data);
|
||||
if (parsed.code !== 0) {
|
||||
const msg = get_upload_error_msg(parsed);
|
||||
Taro.showToast({ title: msg, icon: "none" });
|
||||
throw new Error(msg);
|
||||
}
|
||||
return { id, data: parsed.data };
|
||||
} catch (error) {
|
||||
throw { id, error }
|
||||
const msg = get_upload_error_msg(error);
|
||||
Taro.showToast({ title: msg, icon: "none" });
|
||||
throw { id, error };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +117,7 @@ class UploadApi {
|
||||
throw new Error(result.message || '上传失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('上传图片失败:', error);
|
||||
console.warn('上传图片失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ export class UserService {
|
||||
throw new Error(response.message || "获取用户信息失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取用户信息失败:", error);
|
||||
console.warn("获取用户信息失败:", error);
|
||||
// 返回默认用户信息
|
||||
return {} as UserInfo;
|
||||
}
|
||||
@@ -392,7 +392,7 @@ export class UserService {
|
||||
throw new Error(response.message || "更新用户信息失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("更新用户信息失败:", error);
|
||||
console.warn("更新用户信息失败:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -417,7 +417,7 @@ export class UserService {
|
||||
throw new Error(response.message || "获取主办球局失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取主办球局失败:", error);
|
||||
console.warn("获取主办球局失败:", error);
|
||||
// 返回符合ListContainer data格式的模拟数据
|
||||
return [];
|
||||
}
|
||||
@@ -443,7 +443,7 @@ export class UserService {
|
||||
throw new Error(response.message || "获取参与球局失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取参与球局失败:", error);
|
||||
console.warn("获取参与球局失败:", error);
|
||||
// 返回符合ListContainer data格式的模拟数据
|
||||
return [];
|
||||
}
|
||||
@@ -485,7 +485,7 @@ export class UserService {
|
||||
throw new Error(response.message || "操作失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("关注操作失败:", error);
|
||||
console.warn("关注操作失败:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -543,7 +543,7 @@ export class UserService {
|
||||
throw new Error(response.message || "更新用户信息失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("保存用户信息失败:", error);
|
||||
console.warn("保存用户信息失败:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -573,26 +573,16 @@ export class UserService {
|
||||
throw new Error(response.message || "获取用户动态失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取用户动态失败:", error);
|
||||
console.warn("获取用户动态失败:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 上传头像
|
||||
// 上传头像:仅在上传成功且 save 成功时返回 ossPath;失败则抛出,由调用方处理,避免误调 user/update
|
||||
static async upload_avatar(file_path: string): Promise<string> {
|
||||
try {
|
||||
// 先上传文件到服务器
|
||||
const result = await uploadFiles.upload_oss_img(file_path);
|
||||
|
||||
await this.save_user_info({ avatar: result.ossPath });
|
||||
|
||||
// 使用新的响应格式中的file_url字段
|
||||
return result.ossPath;
|
||||
} catch (error) {
|
||||
console.error("头像上传失败:", error);
|
||||
// 如果上传失败,返回默认头像
|
||||
return require("../static/userInfo/default_avatar.svg");
|
||||
}
|
||||
const result = await uploadFiles.upload_oss_img(file_path);
|
||||
await this.save_user_info({ avatar: result.ossPath });
|
||||
return result.ossPath;
|
||||
}
|
||||
|
||||
// 解析用户手机号
|
||||
@@ -612,7 +602,7 @@ export class UserService {
|
||||
throw new Error(response.message || "获取手机号失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取手机号失败:", error);
|
||||
console.warn("获取手机号失败:", error);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -628,7 +618,7 @@ export class UserService {
|
||||
throw new Error(message || "获取职业树失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取职业树失败:", error);
|
||||
console.warn("获取职业树失败:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -644,7 +634,7 @@ export class UserService {
|
||||
throw new Error(message || "获取城市树失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取职业树失败:", error);
|
||||
console.warn("获取职业树失败:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -665,7 +655,7 @@ export class UserService {
|
||||
throw new Error(message || "注销账户失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("注销账户失败:", error);
|
||||
console.warn("注销账户失败:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -680,7 +670,7 @@ export const fetchUserProfile = async (): Promise<
|
||||
const response = await httpService.post("user/detail");
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("获取用户信息失败:", error);
|
||||
console.warn("获取用户信息失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -695,7 +685,7 @@ export const checkNicknameChangeStatus = async (): Promise<
|
||||
);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("获取昵称修改状态失败:", error);
|
||||
console.warn("获取昵称修改状态失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -707,7 +697,7 @@ export const updateNickname = async (nickname: string) => {
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("昵称修改失败:", error);
|
||||
console.warn("昵称修改失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -718,7 +708,7 @@ export const updateUserProfile = async (payload: Partial<UserInfoType>) => {
|
||||
const response = await httpService.post("/user/update", payload);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("更新用户信息失败:", error);
|
||||
console.warn("更新用户信息失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -737,7 +727,7 @@ export const updateUserLocation = async (
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("更新用户坐标位置失败:", error);
|
||||
console.warn("更新用户坐标位置失败:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -774,13 +764,13 @@ export const handleCustomerService = async (): Promise<void> => {
|
||||
console.log("打开客服成功:", res);
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error("打开客服失败:", error);
|
||||
console.warn("打开客服失败:", error);
|
||||
// 如果官方客服不可用,显示备用联系方式
|
||||
showCustomerServiceFallback(customerService);
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("客服功能异常:", error);
|
||||
console.warn("客服功能异常:", error);
|
||||
// 备用方案:显示联系信息
|
||||
showCustomerServiceFallback();
|
||||
}
|
||||
@@ -810,7 +800,7 @@ const showCustomerServiceFallback = (customerInfo?: any) => {
|
||||
phoneNumber: customerInfo.phoneNumber,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("拨打电话失败:", error);
|
||||
console.warn("拨打电话失败:", error);
|
||||
Taro.showToast({
|
||||
title: "拨打电话失败",
|
||||
icon: "none",
|
||||
@@ -827,7 +817,7 @@ const showCustomerServiceFallback = (customerInfo?: any) => {
|
||||
icon: "success",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("复制邮箱失败:", error);
|
||||
console.warn("复制邮箱失败:", error);
|
||||
Taro.showToast({
|
||||
title: "复制失败",
|
||||
icon: "none",
|
||||
|
||||
@@ -39,7 +39,7 @@ export class WalletService {
|
||||
throw new Error(response.message || "获取钱包信息失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取钱包信息失败:", error);
|
||||
console.warn("获取钱包信息失败:", error);
|
||||
// 返回模拟数据
|
||||
return {
|
||||
balance: 1588.80,
|
||||
@@ -62,7 +62,7 @@ export class WalletService {
|
||||
throw new Error(response.message || "获取交易记录失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取交易记录失败:", error);
|
||||
console.warn("获取交易记录失败:", error);
|
||||
// 返回模拟数据
|
||||
return [
|
||||
{
|
||||
@@ -107,7 +107,7 @@ export class WalletService {
|
||||
throw new Error(response.message || "提现申请提交失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("提现申请提交失败:", error);
|
||||
console.warn("提现申请提交失败:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user