Commit 2a7ec92f by 李伟康

```

feat(storeSignboard): 更新策略中心门店看板数据获取逻辑

- 在员工概览组件中添加bizs参数以优化策略员工汇总数据获取
- 修复时间范围类型值获取逻辑,确保周期类型默认值为2
- 调整门店看板主组件中的时间范围参数处理,增加时间范围类型的映射转换
```
1 parent 1d822e8e
...@@ -441,6 +441,7 @@ export default { ...@@ -441,6 +441,7 @@ export default {
this.staffInfoLoading = true this.staffInfoLoading = true
let data = await getStrategyStaffSummaryDuration({ let data = await getStrategyStaffSummaryDuration({
// ...params, // ...params,
bizs:1,
staffUuids: [item.staffId], staffUuids: [item.staffId],
staffPhone: item.staffPhone staffPhone: item.staffPhone
}) })
......
...@@ -149,11 +149,11 @@ export default { ...@@ -149,11 +149,11 @@ export default {
// 处理日期范围变化 // 处理日期范围变化
handleDateRangeChange (dateRange) { handleDateRangeChange (dateRange) {
this.$nextTick(() => { this.$nextTick(() => {
let { value } = this.$refs.calendarCustom.value let { value } = this.timeRangeType
this.$emit('dateChange', { this.$emit('dateChange', {
startTime: dateRange.startDate, startTime: dateRange.startDate,
endTime: dateRange.endDate, endTime: dateRange.endDate,
cycleType: value cycleType: value || 2
}) })
}) })
}, },
......
...@@ -124,13 +124,19 @@ export default { ...@@ -124,13 +124,19 @@ export default {
this.paramsInfo.merchantIds = [merchantNo || ''] this.paramsInfo.merchantIds = [merchantNo || '']
this.merchantName = storeName || '' this.merchantName = storeName || ''
let { timeRangeType, startDate, endDate } = this.$route.query; let { timeRangeType, startDate, endDate } = this.$route.query;
if (timeRangeType) this.paramsInfo.cycleType = timeRangeType if (timeRangeType || startDate || endDate) {
if (timeRangeType) this.paramsInfo.cycleType = {
1: 2,
2: 3,
4: 4
}[timeRangeType] || 2
if (startDate) this.paramsInfo.startTime = startDate if (startDate) this.paramsInfo.startTime = startDate
if (endDate) this.paramsInfo.endTime = endDate if (endDate) this.paramsInfo.endTime = endDate
this.storeSignboardInfoRef.setDate(timeRangeType, { this.storeSignboardInfoRef.setDate(this.paramsInfo.cycleType, {
startDate, startDate,
endDate endDate
}) })
}
this.$nextTick(() => this.init()) this.$nextTick(() => this.init())
} }
......
  • @limin
    commented
    Owner

    你好,我是负责此次代码审查的工程师。你提交的代码主要涉及策略中心门店看板的参数透传逻辑优化及 API 调用调整。

    整体来看,本次提交修复了时间周期的逻辑问题,但引入了潜在的类型解构错误以及较多的魔术数字(Magic Numbers),这会降低代码的健壮性和可维护性。

    以下是本次审查的核心问题与优化建议:

    一、关键问题与优化建议(Top 3)

    1. StoreSignboardInfo 组件中存在潜在的解构赋值错误(高风险)

    • 问题描述:在 src/.../StoreSignboardInfo/index.vue 中,代码使用了 let { value } = this.timeRangeType。
    • 影响分析:根据上下文(特别是 index.vue 中的路由参数处理),timeRangeType 很可能是一个基本数据类型(如 Number 或 String),而不是一个包含 value 属性的对象。
      • 如果 this.timeRangeType 是数字 1,解构 { value } 后的 value 为 undefined。
      • 这会导致 cycleType 永远取默认值 2,从而使上游传入的配置失效,引发业务逻辑 Bug。
    • 优化建议:确认 timeRangeType 的数据结构。如果是基本类型,请直接使用;如果是对象,请确保非空校验。 ```javascript // 修改前 let { value } = this.timeRangeType // ... cycleType: value || 2

    // 建议修改(假设 timeRangeType 是基本类型值) const cycleType = this.timeRangeType || 2; this.$emit('dateChange', { // ... cycleType })

    
    **2. 严重依赖“魔术数字”且缺乏语义化常量(中风险)**
    - **问题描述**:代码中多次出现不明含义的数字。
        - `src/.../StaffOverview/index.vue`: `bizs: 1`
        - `src/.../storeSignboard/index.vue`: 映射逻辑 `{ 1: 2, 2: 3, 4: 4 }` 以及默认值 `2`。
    - **影响分析**:
        - **可读性差**:其他开发者无法理解 `bizs: 1` 或 `cycleType: 2` 代表什么(是“日”、“周”还是“月”?)。
        - **维护困难**:如果后端修改了枚举定义,前端需要全局搜索替换这些分散的数字,极易遗漏。
    - **优化建议**:建立常量映射或枚举文件。
    ```javascript
    // 建议定义常量 (e.g., in constants.js)
    const CYCLE_TYPE_MAP = {
      DAILY: 1,
      WEEKLY: 2,
      MONTHLY: 3
    };
    
    // 在业务代码中使用
    // bizs: BUSINESS_TYPE.STRATEGY
    // cycleType: CYCLE_TYPE_MAP[timeRangeType] || CYCLE_TYPE_MAP.WEEKLY
    

    3. 路由参数类型转换逻辑脆弱(低风险)

    • 问题描述:在 src/.../storeSignboard/index.vue 中,直接使用 this.$route.query.timeRangeType 作为对象的 Key 进行查找。
    • 影响分析:$route.query 获取的参数通常是字符串(String),而映射对象的 Key 如果是数字字面量,虽然 JS 对象会自动转换 Key,但这种隐式转换在 TypeScript 迁移或严格模式下可能报错。此外,直接在组件内写 paramsInfo.cycleType = { ... }[val] 的内联逻辑难以复用和测试。
    • 优化建议:显式转换类型,并将转换逻辑提取为方法。 javascript // 建议修改 const queryType = Number(timeRangeType); // 显式转换为数字 const TYPE_MAPPING = { 1: 2, 2: 3, 4: 4 }; if (queryType) { this.paramsInfo.cycleType = TYPE_MAPPING[queryType] || 2; }

    二、评分明细

    1. 功能实现的正确性与健壮性(25/40分)
      • 扣分项:StoreSignboardInfo 中的解构赋值极大概率是 Bug,会导致参数传递失效。路由参数未做显式类型转换,存在隐患。
    2. 安全性与潜在风险(30/30分)
      • 无明显 XSS、SQL 注入或敏感信息泄露风险。
    3. 最佳实践与可维护性(12/20分)
      • 扣分项:大量使用魔术数字(Magic Numbers),代码意图不明确。bizs: 1 硬编码在 API 调用中降低了组件复用性。
    4. 性能与资源利用(5/5分)
      • 逻辑简单,无性能瓶颈。
    5. 提交信息质量(5/5分)
      • Commit Message 格式规范(type(scope): subject),描述清晰,符合变更内容。

    三、总分

    总分:77分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!