Commit f0faeae7 by 张立顺

Merge branch 'SAAS+V5.3.0-1117' of 192.168.3.233:saas_plus/sales-assistant into SAAS+V5.3.0-1117

2 parents 0c732a7f 84123d5d
// app.js // app.js
// 初始化sentry
import sentryInit from '~/utils/sentryConfig/sentryInit'
sentryInit()
import util from './utils/util' import util from './utils/util'
import wxApi from './utils/utils_wx' import wxApi from './utils/utils_wx'
import '~/router/routerBefore' import '~/router/routerBefore'
import router from './router/index' import router from './router/index'
import sentry from './utils/sentry'
// 有问题 前后顺序不能随意调整 // 有问题 前后顺序不能随意调整
...@@ -54,6 +51,7 @@ App({ ...@@ -54,6 +51,7 @@ App({
wx.$storage = $Storage /** 挂载全局缓存方法 */ wx.$storage = $Storage /** 挂载全局缓存方法 */
wx.$eventbus = eventbus wx.$eventbus = eventbus
wx.$track = $Track wx.$track = $Track
wx.$sentry = sentry
wx.$areaList = areaList wx.$areaList = areaList
wx.$versionConfig = new Version({ wx.$versionConfig = new Version({
request: { request: {
......
...@@ -14,4 +14,4 @@ export const appId = 'wx2c28337db96364d2' ...@@ -14,4 +14,4 @@ export const appId = 'wx2c28337db96364d2'
// 开发指定的小程序 // 开发指定的小程序
// sentry Dsn 地址 // sentry Dsn 地址
export const dsnUrl = 'https://59c3cfc3ffb84ed68fc0dda26fb09e12@sentry.glsx.com.cn/30' export const dsnUrl = 'https://b121b1af6f72463da9e6a2e3f502bad8@sentry.glsx.com.cn/47'
...@@ -159,6 +159,12 @@ Component({ ...@@ -159,6 +159,12 @@ Component({
businessType: businessTypeObj[current] businessType: businessTypeObj[current]
} }
wx.$api.showLoading() wx.$api.showLoading()
if (!params.merchantId) {
wx.$sentry.reportParamError(
'KPI进度参数异常: merchantId',
params
)
}
CustomerApi.getKPIData(params).then(res => { CustomerApi.getKPIData(params).then(res => {
wx.$api.hideLoading() wx.$api.hideLoading()
res?.forEach(val => { res?.forEach(val => {
......
...@@ -64,6 +64,12 @@ Component({ ...@@ -64,6 +64,12 @@ Component({
getDetailData() { getDetailData() {
let { merchantId } = this.data let { merchantId } = this.data
wx.$api.showLoading() wx.$api.showLoading()
if (!merchantId) {
wx.$sentry.reportParamError(
'门店信息参数异常: merchantId',
merchantId
)
}
CustomerApi.getStoreOverviewData({id: merchantId}).then(res => { CustomerApi.getStoreOverviewData({id: merchantId}).then(res => {
wx.$api.hideLoading() wx.$api.hideLoading()
res?.safetyIndexWarningList?.forEach(val => { res?.safetyIndexWarningList?.forEach(val => {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
.store-message { .store-message {
background: #FFFFFF; background: #FFFFFF;
overflow: hidden; overflow: hidden;
margin-bottom: 200rpx;
.cell-title { .cell-title {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
......
...@@ -97,6 +97,12 @@ Page({ ...@@ -97,6 +97,12 @@ Page({
}, },
getDetail(par) { getDetail(par) {
if (!par.id) {
wx.$sentry.reportParamError(
'潜客详情参数异常: id',
par
)
}
CustomerApi.getCustomerData({id: par.id}).then(res => { CustomerApi.getCustomerData({id: par.id}).then(res => {
// 处理数据 // 处理数据
this.progressData(res) this.progressData(res)
......
...@@ -226,6 +226,12 @@ Page({ ...@@ -226,6 +226,12 @@ Page({
if (this.data.confirmFlag) return if (this.data.confirmFlag) return
this.setData({confirmFlag: true}) this.setData({confirmFlag: true})
wx.$api.showLoading() wx.$api.showLoading()
if (!params.potentialCustomerId) {
wx.$sentry.reportParamError(
'新增拜访参数异常: potentialCustomerId',
params
)
}
CustomerApi.addVisit(params).then(res => { CustomerApi.addVisit(params).then(res => {
this.setData({confirmFlag: false}) this.setData({confirmFlag: false})
wx.$api.hideLoading() wx.$api.hideLoading()
......
...@@ -90,6 +90,12 @@ Page({ ...@@ -90,6 +90,12 @@ Page({
getMerchantDetail(pageQuery) { getMerchantDetail(pageQuery) {
wx.$api.showLoading() wx.$api.showLoading()
if (!pageQuery.merchantId) {
wx.$sentry.reportParamError(
'门店详情参数异常: merchantId',
pageQuery
)
}
CustomerApi.getMaterialData({id: pageQuery.merchantId}).then(res => { CustomerApi.getMaterialData({id: pageQuery.merchantId}).then(res => {
wx.$api.hideLoading() wx.$api.hideLoading()
this.setData({showPage: true}) this.setData({showPage: true})
...@@ -99,35 +105,129 @@ Page({ ...@@ -99,35 +105,129 @@ Page({
}, },
progressData(data) { progressData(data) {
if (!data || typeof data !== 'object') {
wx.$sentry.reportError(
'门店详情数据异常: data',
data
)
this.setData({
infoDetail: {}
})
return
}
try {
const businessSceneNames = {0: '轻改', 1: '权益', 2: '延保'} const businessSceneNames = {0: '轻改', 1: '权益', 2: '延保'}
// 主营品牌 // 主营品牌
data.mainCategory = data.mainBrand data.mainCategory = data.mainBrand || ''
// 合作模式 // 合作模式
data.coopMode = data?.cooperationModeList?.map(val => { data.coopMode = ''
if (Array.isArray(data?.cooperationModeList)) {
data.coopMode = data.cooperationModeList.map(val => {
try {
if (!val || typeof val !== 'object') return ''
const sceneName = businessSceneNames[val.businessSceneType] || '' const sceneName = businessSceneNames[val.businessSceneType] || ''
const cooperationItem = COOPERATIONMODELIST.find(v => const cooperationItem = COOPERATIONMODELIST?.find(v =>
val.directSalesFlag && v.value == val.directSalesFlag val.directSalesFlag && v?.value == val.directSalesFlag
) )
const cooperationName = cooperationItem?.name || '' const cooperationName = cooperationItem?.name || ''
return `${sceneName}:${cooperationName}` return sceneName && cooperationName ? `${sceneName}:${cooperationName}` : ''
}).filter(item => item) // 过滤空字符串 } catch (error) {
.join('/') wx.$sentry.reportError(
'合作模式数据异常: data.cooperationModeList',
data.cooperationModeList
)
return ''
}
}).filter(item => item && item !== ':') // 过滤空项和只有冒号的项
.join('/') || ''
}
// 流量情况 // 流量情况
data.flowScale = data.flowSituation ? TRSFFICSTATUSLIST?.find(val => val.value == data.flowSituation)?.name : '' data.flowScale = ''
// 业务类型 if (data.flowSituation) {
data.bizType = data?.businessTypeList?.map(val => { return `${SCENELIST?.find(v => v.value == val).name}` })?.join('/') try {
data.flowScale = TRSFFICSTATUSLIST?.find(val => val?.value == data.flowSituation)?.name || ''
} catch (error) {
wx.$sentry.reportError(
'流量情况数据异常: data.flowSituation',
data.flowSituation
)
}
}
// 业务类型 - 添加保护
data.bizType = ''
if (Array.isArray(data?.businessTypeList)) {
data.bizType = data.businessTypeList.map(val => {
try {
return SCENELIST?.find(v => v?.value == val)?.name || ''
} catch (error) {
wx.$sentry.reportError(
'业务类型数据异常: data.businessTypeList',
data.businessTypeList
)
return ''
}
}).filter(item => item) // 过滤空字符串
.join('/') || ''
}
// 人员类型 // 人员类型
data.salePotentialCustomerPersonnelInfoDTOList?.forEach(val => { if (Array.isArray(data?.salePotentialCustomerPersonnelInfoDTOList)) {
val.roleName = ROLELIST?.find(v => v.value == val.personnelType)?.label data.salePotentialCustomerPersonnelInfoDTOList.forEach(val => {
try {
if (val && typeof val === 'object') {
val.roleName = ROLELIST?.find(v => v?.value == val.personnelType)?.label || ''
}
} catch (error) {
wx.$sentry.reportError(
'人员信息数据异常: data.salePotentialCustomerPersonnelInfoDTOList',
data.salePotentialCustomerPersonnelInfoDTOList
)
val.roleName = ''
}
}) })
}
// 店面门头照片 // 店面门头照片
data.storePhotoList = data.storePhoto?.split(',') data.storePhotoList = []
if (typeof data.storePhoto === 'string') {
try {
data.storePhotoList = data.storePhoto.split(',')
} catch (error) {
wx.$sentry.reportError(
'店面照片数据异常: data.storePhoto',
data.storePhoto
)
}
}
// 设置数据
this.setData({ this.setData({
infoDetail: data infoDetail: data
}, () => { }, () => {
this.buildInfoBoard() try {
this.recordTabTop() this.buildInfoBoard && this.buildInfoBoard()
this.recordTabTop && this.recordTabTop()
} catch (error) {
console.error('执行回调函数时出错:', error)
}
})
} catch (error) {
wx.$sentry.reportParamError(
'门店详情数据异常: data',
data
)
// 确保即使出错也有基本的数据结构
this.setData({
infoDetail: {
...data,
mainCategory: '',
coopMode: '',
flowScale: '',
bizType: '',
salePotentialCustomerPersonnelInfoDTOList: [],
storePhotoList: []
}
}) })
}
}, },
tabClick(e) { tabClick(e) {
......
...@@ -71,8 +71,15 @@ Page({ ...@@ -71,8 +71,15 @@ Page({
getPotentialDetail() { getPotentialDetail() {
let { pageQuery } = this.data let { pageQuery } = this.data
wx.$api.showLoading() wx.$api.showLoading()
if (!pageQuery.id) {
wx.$sentry.reportParamError(
'潜客详情参数异常: id',
pageQuery
)
}
CustomerApi.getCustomerData({id: pageQuery.id}).then(res => { CustomerApi.getCustomerData({id: pageQuery.id}).then(res => {
wx.$api.hideLoading() wx.$api.hideLoading()
this.setData({showPage: true})
// 处理数据回显 // 处理数据回显
this.progressData(res) this.progressData(res)
}) })
...@@ -87,27 +94,138 @@ Page({ ...@@ -87,27 +94,138 @@ Page({
}, },
progressData(data) { progressData(data) {
// 添加基础数据校验
if (!data || typeof data !== 'object') {
wx.$sentry.reportError(
'潜客详情数据异常: data',
data
)
this.setData({
infoDetail: {}
})
return
}
try {
// 主营品牌 // 主营品牌
data.mainCategory = data?.salePotentialCustomerBrandDTOList?.map(val => {return `${val.mainBrandName}${val.subBrandName}`})?.join('/') data.mainCategory = ''
if (Array.isArray(data?.salePotentialCustomerBrandDTOList)) {
data.mainCategory = data.salePotentialCustomerBrandDTOList.map(val => {
try {
if (!val || typeof val !== 'object') return ''
const mainBrand = val.mainBrandName || ''
const subBrand = val.subBrandName || ''
return mainBrand || subBrand ? `${mainBrand}${subBrand}` : ''
} catch (error) {
wx.$sentry.reportError(
'主营品牌数据异常: data.salePotentialCustomerBrandDTOList',
data.salePotentialCustomerBrandDTOList
)
return ''
}
}).filter(item => item) // 过滤空字符串
.join('/') || ''
}
// 合作模式 // 合作模式
data.coopMode = COOPERATIONMODELIST.find(v => v.value == data.cooperationMode)?.name data.coopMode = ''
if (data.cooperationMode !== undefined && data.cooperationMode !== null) {
try {
data.coopMode = COOPERATIONMODELIST?.find(v => v?.value == data.cooperationMode)?.name || ''
} catch (error) {
wx.$sentry.reportError(
'合作模式数据异常: data.cooperationMode',
data.cooperationMode
)
}
}
// 流量情况 // 流量情况
data.flowScale = data.flowSituation ? TRSFFICSTATUSLIST?.find(val => val.value == data.flowSituation)?.name : '' data.flowScale = ''
if (data.flowSituation !== undefined && data.flowSituation !== null) {
try {
data.flowScale = TRSFFICSTATUSLIST?.find(val => val?.value == data.flowSituation)?.name || ''
} catch (error) {
wx.$sentry.reportError(
'流量情况数据异常: data.flowSituation',
data.flowSituation
)
}
}
// 业务类型 // 业务类型
data.bizType = data?.businessTypeList?.map(val => { return `${SCENELIST?.find(v => v.value == val).name}` })?.join('/') data.bizType = ''
if (Array.isArray(data?.businessTypeList)) {
data.bizType = data.businessTypeList.map(val => {
try {
const sceneItem = SCENELIST?.find(v => v?.value == val)
return sceneItem?.name || ''
} catch (error) {
wx.$sentry.reportError(
'业务类型数据异常: data.businessTypeList',
data.businessTypeList
)
return ''
}
}).filter(item => item) // 过滤空字符串
.join('/') || ''
}
// 人员类型 // 人员类型
data.salePotentialCustomerPersonnelInfoDTOList?.forEach(val => { if (Array.isArray(data?.salePotentialCustomerPersonnelInfoDTOList)) {
val.roleName = ROLELIST?.find(v => v.value == val.personnelType)?.label data.salePotentialCustomerPersonnelInfoDTOList.forEach(val => {
try {
if (val && typeof val === 'object') {
val.roleName = ROLELIST?.find(v => v?.value == val.personnelType)?.label || ''
}
} catch (error) {
wx.$sentry.reportError(
'人员信息数据异常: data.salePotentialCustomerPersonnelInfoDTOList',
data.salePotentialCustomerPersonnelInfoDTOList
)
val.roleName = ''
}
}) })
}
// 店面门头照片 // 店面门头照片
data.storePhotoList = data.storePhoto?.split(',') data.storePhotoList = []
if (typeof data.storePhoto === 'string') {
try {
data.storePhotoList = data.storePhoto.split(',')
} catch (error) {
wx.$sentry.reportError(
'店面照片数据异常: data.storePhoto',
data.storePhoto
)
}
}
// 设置数据,添加错误处理
this.setData({ this.setData({
infoDetail: data, infoDetail: data
showPage: true
}, () => { }, () => {
this.buildInfoBoard() try {
this.recordTabTop() this.buildInfoBoard && this.buildInfoBoard()
this.recordTabTop && this.recordTabTop()
} catch (error) {
console.error('执行回调函数时出错:', error)
}
}) })
} catch (error) {
wx.$sentry.reportParamError(
'潜客详情数据异常: data',
data
)
// 确保即使出错也有基本的数据结构
this.setData({
infoDetail: {
...data,
mainCategory: '',
coopMode: '',
flowScale: '',
bizType: '',
salePotentialCustomerPersonnelInfoDTOList: [],
storePhotoList: []
}
})
}
}, },
recordTabTop() { recordTabTop() {
...@@ -141,6 +259,12 @@ Page({ ...@@ -141,6 +259,12 @@ Page({
// 加载逻辑 // 加载逻辑
resetAndLoad() { resetAndLoad() {
let { pageQuery } = this.data let { pageQuery } = this.data
if (!pageQuery.id) {
wx.$sentry.reportParamError(
'拜访记录参数异常: id',
pageQuery
)
}
CustomerApi.getVisitList({id: pageQuery.id}).then(res => { CustomerApi.getVisitList({id: pageQuery.id}).then(res => {
this.setData({ this.setData({
visitRecords: res || [] visitRecords: res || []
......
...@@ -180,6 +180,12 @@ Page({ ...@@ -180,6 +180,12 @@ Page({
if (this.data.confirmFlag) return if (this.data.confirmFlag) return
this.setData({confirmFlag: true}) this.setData({confirmFlag: true})
wx.$api.showLoading() wx.$api.showLoading()
if (!pageQuery.id) {
wx.$sentry.reportParamError(
'结果反馈参数异常: id',
params
)
}
CustomerApi.reslutFeedbackApi(params).then(res => { CustomerApi.reslutFeedbackApi(params).then(res => {
wx.$api.hideLoading() wx.$api.hideLoading()
this.setData({confirmFlag: false}) this.setData({confirmFlag: false})
......
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;
console.log(sentryInit())
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,13 @@ import { dsnUrl } from '~/config' ...@@ -2,12 +2,13 @@ import { dsnUrl } from '~/config'
import * as Sentry from '~/utils/lib/sentry-miniapp' import * as Sentry from '~/utils/lib/sentry-miniapp'
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: '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!