Commit edbefe64 by wangzhihui

Merge branch 'SAAS+V4.56.0-0908' of http://192.168.3.233:8090/saas/mini-program/…

…points-mall into SAAS+V4.56.0-0908
2 parents d2786fd1 ccb86990
// app.js // app.js
// 初始化sentry
import sentryInit from "~/utils/sentryConfig/sentryInit";
sentryInit();
import api from "./api/index"; import api from "./api/index";
import { router, routerBefore } from "./router/index"; import { router, routerBefore } from "./router/index";
// 判断小程序是否需要更新 // 判断小程序是否需要更新
......
...@@ -13,11 +13,11 @@ export const OrderStatusEnum = { ...@@ -13,11 +13,11 @@ export const OrderStatusEnum = {
WAIT_RECEIVE: "10002", //待收货 WAIT_RECEIVE: "10002", //待收货
COMPLETED: "10003", //已完成 COMPLETED: "10003", //已完成
AFTER_SALE: "10004", //售后 (没有这个状态 显示用) AFTER_SALE: "10004", //售后 (没有这个状态 显示用)
AFTER_SALE_PENDING_REVIEW: "10005", //售后中 -待审核 AFTER_SALE_PENDING_REVIEW: "1000401", //售后中 -待审核
AFTER_SALE_WAIT_RECEIVE: "10006", //售后中 -待收货(审核通过) AFTER_SALE_WAIT_RECEIVE: "1000402", //售后中 -待收货(审核通过)
AFTER_SALE_REJECTED: "10007", //售后审核不通过 AFTER_SALE_REJECTED: "1000403", //售后审核不通过
AFTER_SALE_REFUNDED: "10008", //已退款 AFTER_SALE_REFUNDED: "1000404", //已退款
AFTER_SALE_REFUNDED_FAILED: "10009", //退款失败 AFTER_SALE_REFUNDED_FAILED: "1000405", //退款失败
AFTER_SALE_REVEAL: "10010", //所有其他状态 AFTER_SALE_REVEAL: "10010", //所有其他状态
}; };
// export const AfterSaleStatusEnum = { // export const AfterSaleStatusEnum = {
......
...@@ -198,7 +198,9 @@ Page({ ...@@ -198,7 +198,9 @@ Page({
contactPhone: val.receiveMobile, contactPhone: val.receiveMobile,
contactAddress: `${val.provinceName}${val.cityName}${val.countyName}${val.address}` contactAddress: `${val.provinceName}${val.cityName}${val.countyName}${val.address}`
} }
} else { }
})
if (!Object.keys(obj)?.length) {
let data = res[0] let data = res[0]
obj = { obj = {
...data, ...data,
...@@ -207,7 +209,6 @@ Page({ ...@@ -207,7 +209,6 @@ Page({
contactAddress: `${data.provinceName}${data.cityName}${data.countyName}${data.address}` contactAddress: `${data.provinceName}${data.cityName}${data.countyName}${data.address}`
} }
} }
})
this.setData({ this.setData({
contactInfo: obj, contactInfo: obj,
isDefault: obj?.isDefault == 1, isDefault: obj?.isDefault == 1,
......
...@@ -42,7 +42,8 @@ Page({ ...@@ -42,7 +42,8 @@ Page({
subOrderCode, subOrderCode,
tparReturnOrderCode, tparReturnOrderCode,
goodsSkuCode, goodsSkuCode,
}).then((res) => { })
.then((res) => {
// let status = 0 // let status = 0
// if (res.returnOrderStatus == 1000 || res.returnOrderStatus == 1002 || res.returnOrderStatus == 1001 || res.returnOrderStatus == 1004 || (res.returnOrderStatus == 1003 && res.outRefundType == 2)) { // if (res.returnOrderStatus == 1000 || res.returnOrderStatus == 1002 || res.returnOrderStatus == 1001 || res.returnOrderStatus == 1004 || (res.returnOrderStatus == 1003 && res.outRefundType == 2)) {
// status = 0 // status = 0
...@@ -53,7 +54,7 @@ Page({ ...@@ -53,7 +54,7 @@ Page({
// } // }
// const { returnOrderStatus } = res; // const { returnOrderStatus } = res;
const status = getOrder(res); //getAfterSaleDetail({ returnOrderStatus }); const status = getOrder(res); //getAfterSaleDetail({ returnOrderStatus });
const button = status.detail.buttons?.[goodsSource][0]||{}; //status.buttons?.[goodsSource][0]; const button = status.detail.buttons?.[goodsSource][0] || {}; //status.buttons?.[goodsSource][0];
// button.action = this[button.handler] // button.action = this[button.handler]
let str = ""; let str = "";
if (res.sendbackAddressModel) { if (res.sendbackAddressModel) {
...@@ -61,14 +62,17 @@ Page({ ...@@ -61,14 +62,17 @@ Page({
str = `${sendbackAddressModel.provinceName}${sendbackAddressModel.cityName}${sendbackAddressModel.countyName}${sendbackAddressModel.address}`; str = `${sendbackAddressModel.provinceName}${sendbackAddressModel.cityName}${sendbackAddressModel.countyName}${sendbackAddressModel.address}`;
} }
res.addressInfo = str; res.addressInfo = str;
const { ___qty, ___price, ___totalPrice } = calcOrderProp(res.orderGoods); const { ___qty, ___price, ___totalPrice } = calcOrderProp(
res.orderGoods
);
Object.assign(res.orderGoods, { ___qty, ___price, ___totalPrice }); Object.assign(res.orderGoods, { ___qty, ___price, ___totalPrice });
this.setData({ this.setData({
orderInfo: res, orderInfo: res,
status, status,
button, button,
}); });
}).finally(() => { })
.finally(() => {
wx.hideLoading(); wx.hideLoading();
}); });
}, },
...@@ -124,7 +128,8 @@ Page({ ...@@ -124,7 +128,8 @@ Page({
}) })
.catch(() => { .catch(() => {
wx.p.wxApi.showToast("已取消"); wx.p.wxApi.showToast("已取消");
}).finally(() => { })
.finally(() => {
wx.hideLoading(); wx.hideLoading();
}); });
}, },
......
...@@ -138,10 +138,19 @@ Page({ ...@@ -138,10 +138,19 @@ Page({
keyword, keyword,
} = this.data; } = this.data;
const userInfo = wx.p.storage.get("userInfo") || {}; const userInfo = wx.p.storage.get("userInfo") || {};
let { merchantId, channelSource } = userInfo; let { merchantId, channelSource, phone } = userInfo;
//如果 merchantId, channelSource, phone 这三个参数有一个未获取到,给sentry上报异常,并且带上具体的值
if (!merchantId || !channelSource || !phone) {
// 设置自定义上下文信息
wx.p.sentry.reportParamError(
"订单列表异常:merchantId, channelSource, phone 参数异常",
userInfo
);
}
let obj = { let obj = {
requestType, requestType,
merchantId, merchantId,
phone,
pageSize: 99999, pageSize: 99999,
currentPage: pageNum, currentPage: pageNum,
scoreSource: channelSource, scoreSource: channelSource,
......
...@@ -10,4 +10,5 @@ import routerApi from './routerApi' ...@@ -10,4 +10,5 @@ import routerApi from './routerApi'
import WxValidate from './WxValidate' import WxValidate from './WxValidate'
import cache from './cache/index' import cache from './cache/index'
import GlMap from './mapapi/mapapi' import GlMap from './mapapi/mapapi'
module.exports ={util,wxApi,constants,draw,emoji,eventbus,format,network,routerApi,WxValidate,cache,GlMap}
\ No newline at end of file \ No newline at end of file
import sentry from './sentry'
module.exports ={util,wxApi,constants,draw,emoji,eventbus,format,network,routerApi,WxValidate,cache,GlMap,sentry}
import sentryInit from "~/utils/sentryConfig/sentryInit";
const sentry = sentryInit();
/**
* 通用 Sentry 错误上报方法
* 1. 遍历参数对象的每一项,分别作为自定义参数上报
* 2. 将整个对象 JSON.stringify 后作为特殊参数一起上报
* @param {string} errorMessage - 错误信息
* @param {Object} customParams - 自定义参数对象
* @param {Object} options - 可选配置
* @param {string} [options.errorType='general_error'] - 错误类型标签
* @param {string} [options.level='error'] - 错误级别 (error, warning, info, debug)
* @param {string} [options.fullObjectKey='full_params'] - 完整对象参数的键名
* @param {Object} [options.tags] - 额外的标签对象
* @param {Object} [options.contexts] - 额外的上下文对象
*/
function reportSentryError(errorMessage, customParams = {}, options = {}) {
const {
errorType = 'general_error',
level = 'error',
fullObjectKey = 'full_params',
tags = {},
contexts = {}
} = options;
try {
sentry.configureScope((scope) => {
// 第一步:遍历参数对象的每一项,分别作为自定义参数上报
Object.keys(customParams).forEach(key => {
const value = customParams[key];
// 如果值是对象,转换为 JSON 字符串
const processedValue = typeof value === 'object' && value !== null
? JSON.stringify(value)
: value;
// 设置为上下文信息(每个参数单独设置)
scope.setContext(key, {
value: processedValue,
originalType: typeof value,
timestamp: new Date().toISOString()
});
});
// 第二步:将整个对象 JSON.stringify 后作为特殊参数上报
const fullObjectString = JSON.stringify(customParams);
scope.setContext(fullObjectKey, {
data: fullObjectString,
type: 'full_object',
size: fullObjectString.length,
timestamp: new Date().toISOString()
});
// 如果完整对象字符串不太长,也设置为用户属性
if (fullObjectString.length <= 1000) {
scope.setUser({
...scope._user,
[fullObjectKey]: fullObjectString
});
}
// 设置错误类型标签
scope.setTag('error_type', errorType);
// 设置参数统计标签
scope.setTag('params_count', Object.keys(customParams).length);
scope.setTag('full_object_size', fullObjectString.length > 1000 ? 'large' : 'normal');
// 设置额外的标签
Object.keys(tags).forEach(tagKey => {
scope.setTag(tagKey, tags[tagKey]);
});
// 设置额外的上下文
Object.keys(contexts).forEach(contextKey => {
scope.setContext(contextKey, contexts[contextKey]);
});
// 设置错误级别
scope.setLevel(level);
});
// 上报错误
sentry.captureException(new Error(errorMessage));
} catch (error) {
console.error('Sentry 错误上报失败:', error);
}
}
/**
* 简化版本 - 只设置自定义参数和基本错误信息
* @param {string} errorMessage - 错误信息
* @param {Object} customParams - 自定义参数对象
* @param {string} [level='error'] - 错误级别
*/
function reportError(errorMessage, customParams = {}, level = 'error') {
return reportSentryError(errorMessage, customParams, { level });
}
/**
* 专门用于参数验证失败的错误上报
* @param {string} errorMessage - 错误信息
* @param {Object} params - 参数对象
*/
function reportParamError(errorMessage, params = {}) {
return reportSentryError(errorMessage, params, {
errorType: 'param_validation_error',
level: 'warning',
fullObjectKey: 'validation_full_params',
tags: {
category: 'validation'
}
});
}
/**
* 用于 API 错误上报的专用方法
* @param {string} errorMessage - 错误信息
* @param {Object} apiParams - API 相关参数
*/
function reportApiError(errorMessage, apiParams = {}) {
return reportSentryError(errorMessage, apiParams, {
errorType: 'api_error',
level: 'error',
fullObjectKey: 'api_full_params',
tags: {
category: 'api'
}
});
}
module.exports = {
reportSentryError,
reportError,
reportParamError,
reportApiError,
sentry
};
//## 使用示例:
// ### 1. 基本使用 - 传入任意参数对象
// const { reportSentryError } = require('../../utils/sentry');
// 用户信息相关错误
/* const userParams = {
merchantId: this.data.merchantId,
channelSource: this.data.channelSource,
phone: this.data.phone,
userId: this.data.userId,
userInfo: this.data.userInfo
};
reportSentryError('用户信息获取失败', userParams, {
errorType: 'user_info_error',
level: 'warning'
});
// API 请求相关错误
const apiParams = {
url: '/api/order/list',
method: 'POST',
requestData: { page: 1, size: 10 },
responseCode: 500,
responseMessage: 'Internal Server Error'
};
reportSentryError('API 请求失败', apiParams, {
errorType: 'api_error',
level: 'error',
tags: {
api_category: 'order',
http_status: '500'
}
}); */
// 简化使用
// 简单的错误上报
/*reportError('支付失败', {
orderId: '12345',
amount: 99.99,
paymentMethod: 'wechat'
}); */
// const { reportParamError } = require('../../utils/sentry');
// 参数验证错误专用
/*const missingParams = {
merchantId: this.data.merchantId,
channelSource: this.data.channelSource,
phone: this.data.phone,
userInfo: this.data.userInfo
};
reportParamError('订单列表异常:merchantId, channelSource, phone 这三个参数有一个未获取到', missingParams); */
//复杂场景使用
// 购物车操作错误
/*const cartParams = {
cartId: 'cart_123',
productId: 'prod_456',
quantity: 2,
operation: 'add_to_cart',
userAgent: wx.getSystemInfoSync(),
timestamp: Date.now()
};
reportSentryError('购物车操作失败', cartParams, {
errorType: 'cart_operation_error',
level: 'warning',
tags: {
operation_type: 'add_item',
user_type: 'premium'
},
contexts: {
device_info: wx.getSystemInfoSync(),
app_version: '1.2.3'
}
});*/
...@@ -2,12 +2,12 @@ import { dsnUrl } from "~/config"; ...@@ -2,12 +2,12 @@ import { dsnUrl } from "~/config";
import { Sentry } from "~/lib/index"; import { Sentry } from "~/lib/index";
export default function sentryInit() { export default function sentryInit() {
// accountInfo.miniProgram.envVersion == 'release' && // accountInfo.miniProgram.envVersion == 'release' &&
const accountInfo = wx.getAccountInfoSync(); // const accountInfo = wx.getAccountInfoSync();
//测试和生产才开发sentry //测试和生产才开发sentry
const env = ["trial", "release"]; // const env = ["trial", "release"];
env.includes(accountInfo.miniProgram.envVersion) && // env.includes(accountInfo.miniProgram.envVersion) &&
Sentry.init({ Sentry.init({
// dsn: 'http://ebcf31c417cc4ce185782f046e4a87a2@sentry.glsx.com.cn/5'
dsn: dsnUrl, dsn: dsnUrl,
}); });
return Sentry;
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!