Commit 68d14ce8 by Lin

feat: 配置列表不可以有初始值、结束值为空的行

1 parent 80bf3b01
......@@ -90,6 +90,25 @@ export default {
handleAppendTableRow() {
const templateType = this.curParamsConfig.templateType;
// 检查现有数据,确保没有初始值或结束值为空的行
const existingRows = this.curParamsConfig[templateType] || [];
for (let i = 0; i < existingRows.length; i++) {
const row = existingRows[i];
const priceRange = row?.priceRange || [];
const startValue = priceRange[0];
const endValue = priceRange[1];
// 检查初始值或结束值是否为空(undefined、null、空字符串)
if (startValue === undefined || startValue === null || startValue === "") {
this.$message.warning("存在初始值为空的行,请先完善数据后再新增");
return;
}
if (endValue === undefined || endValue === null || endValue === "") {
this.$message.warning("存在结束值为空的行,请先完善数据后再新增");
return;
}
}
const lastPriceRange = last(this.curParamsConfig[templateType])?.priceRange || [0, 0];
const nPriceRange = [undefined, undefined];
if (lastPriceRange && lastPriceRange[1]) {
......
<template>
<template>
<div class="params-config-table">
<el-table border
class="params-config-table"
......@@ -15,7 +15,8 @@
:controls="false"
:disabled="$index === 0"
type="number"
v-bind="curParamsConfig.priceRangeProps">
v-bind="curParamsConfig.priceRangeProps"
@change="handlePriceRangeChange($index, 0)">
</EditableText>
<div class="tag">
-
......@@ -23,7 +24,8 @@
<EditableText v-model="curParamsConfig.ParamsType1[$index].priceRange[1]"
:controls="false"
type="number"
v-bind="curParamsConfig.priceRangeProps">
v-bind="curParamsConfig.priceRangeProps"
@change="handlePriceRangeChange($index, 1)">
</EditableText>
</div>
</template>
......@@ -134,6 +136,8 @@ export default {
data() {
return {
commissionTypeEnum,
// 记录已提示过的行索引,确保每行只提示一次
validatedRows: new Set(),
};
},
computed: {
......@@ -197,6 +201,31 @@ export default {
},
methods: {
// 验证价格范围:结束值必须大于起始值
handlePriceRangeChange(rowIndex, rangeIndex) {
console.log("asda");
const priceRange = this.curParamsConfig.ParamsType1[rowIndex].priceRange;
const startValue = Number(priceRange[0]);
const endValue = Number(priceRange[1]);
// 检查值是否有效
if (isNaN(startValue) || isNaN(endValue) || startValue === null || endValue === null || startValue === undefined || endValue === undefined) {
return;
}
// 验证结束值必须大于起始值
if (endValue <= startValue) {
// 确保每行只提示一次
if (!this.validatedRows.has(rowIndex)) {
this.validatedRows.add(rowIndex);
this.$message.warning("结束值必须大于起始值,且不可等于起始值");
}
} else {
// 如果验证通过,从 Set 中移除该行索引,允许下次再次提示
this.validatedRows.delete(rowIndex);
}
},
handleProductChange(value) {
console.log("product change", value);
},
......
  • @limin
    commented
    Owner

    你好,我是负责本次代码审查的工程师。你提交的代码主要涉及参数配置列表的校验逻辑增强。

    以下是针对本次提交(src/views/residentManage/... 等文件)的审查意见:

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

    1. 校验逻辑不严谨,无法阻止非法数据入库(功能正确性)

    • 问题描述:在 type1.vue 的 handlePriceRangeChange 方法中,当检测到 endValue <= startValue 时,代码仅弹出了 $message.warning 提示,但并没有重置或清除 v-model 绑定的非法值。
    • 影响分析:用户收到警告后若忽略该提示直接提交表单,非法的价格区间(如 [100, 50])将被写入数据模型并发送给后端,导致业务逻辑错误或脏数据。
    • 优化建议:

      1. 校验失败时,应将当前输入框的值重置为空或回退到修改前的值。
      2. 或者,引入表单校验状态(Validate State),在最终提交时再次校验整个列表。 代码示例: ```javascript // src/views/residentManage/salaryPerformance/performanceScheme/components/paramConfigList/type1.vue

      handlePriceRangeChange(rowIndex, rangeIndex) { // ... 获取数值逻辑 ...

      // 验证结束值必须大于起始值
      if (endValue <= startValue) {
          this.$message.warning("结束值必须大于起始值,且不可等于起始值");
      
          // 【建议】重置当前非法的输入值,强制用户重新输入
          // 注意:需确保 Vue 能检测到数组变更,使用 $set 或直接赋值
          this.curParamsConfig.ParamsType1[rowIndex].priceRange[rangeIndex] = undefined; 
      
          // 如果需要更友好的体验,可以使用 nextTick 聚焦回该输入框
      } 
      // ...
      

      }

    2. 包含无关的大量格式化变更,污染提交历史(最佳实践)

    • 问题描述:提交信息为“配置列表不可以有初始值...”,但 src/.../storeSelect/index.vue 文件中包含了大量仅涉及空格、换行和缩进的格式化修改(Prettier/ESLint 自动修复痕迹),且该文件逻辑似乎未发生实质性变更。
    • 影响分析:
      1. Code Review 困难:审查者难以在数百行格式变更中找到真正的逻辑修改。
      2. 破坏原子性:功能开发与代码格式化应分开提交。
      3. Git Blame 干扰:未来的维护者查看该文件历史时,会发现大量代码行被此次无关的提交“归属”,影响问题追溯。
    • 优化建议:请回滚 storeSelect/index.vue 的格式化修改,或将其单独拆分为一个 style: format code in storeSelect 的 Commit。本次提交应只包含逻辑变更。

    3. 生产环境残留调试代码(代码质量)

    • 问题描述:在 type1.vue 第 205 行保留了 console.log("asda");。
    • 影响分析:这类无意义的日志会污染浏览器控制台,显得代码不专业,且可能泄露开发时的调试意图。
    • 优化建议:请删除该行代码。建议在提交前使用 ESLint 规则(如 no-console)或 Git Hook 进行自动检查。

    二、评分明细

    1. 功能实现的正确性与健壮性(25/40分)
      • 扣分点:type1.vue 中的校验逻辑仅停留在 UI 提示层面,未对数据模型进行实质性拦截(Top 1 问题),这是严重的功能缺陷。index.vue 中的判空逻辑基本正确。
    2. 安全性与潜在风险(28/30分)
      • 理由:无明显的 XSS/SQL 注入风险。但前端校验失效可能导致后端接收到脏数据,依赖后端进行二次校验(假设后端有校验)。
    3. 最佳实践与可维护性(10/20分)
      • 扣分点:提交中混合了大量无关的格式化代码(Top 2 问题),严重影响 Review 效率;保留了无意义的 console.log(Top 3 问题)。命名规范尚可。
    4. 性能与资源利用(5/5分)
      • 理由:逻辑简单,无明显性能瓶颈。
    5. 提交信息质量(3/5分)
      • 理由:Commit Message 描述了主要功能点,但未提及 storeSelect 文件的变更(虽然是不应该提交的变更)。

    三、总分

    总分:71分

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