Commit 71cd2902 by wangzhihui

Merge branch 'SAAS+V5.6.1' of http://192.168.3.233:8090/saas_plus/dj-car-life-sy…

…stem into SAAS+V5.6.1
2 parents e358750b 3b2f8ee2
......@@ -67,7 +67,7 @@
</el-form-item>
<el-form-item label="适配业务:" prop="businessType">
<el-radio-group v-model="businessType">
<el-radio-group v-model="businessType" @change="handleBusinessTypeChange">
<el-radio :label="0">
轻改
</el-radio>
......@@ -148,6 +148,8 @@ export default {
// TODO: 强力设置表格内的所有goodType
}
// 只验证当前字段
this.validateCurrentField("goodsConfigTypes");
},
/**
......@@ -209,6 +211,8 @@ export default {
this.setCommissionTypes(newTypes);
this.$nextTick(() => {
this.isUpdating = false;
// 只验证当前字段
this.validateCurrentField("commissionBases");
});
},
......@@ -221,6 +225,8 @@ export default {
this.setCommissionBases(newBases);
this.$nextTick(() => {
this.isUpdating = false;
// 只验证当前字段
this.validateCurrentField("commissionTypes");
});
},
......@@ -228,6 +234,20 @@ export default {
// 根据 value 数组从 assessmentFactorOptions 中找出对应的完整项
const selectedItems = this.assessmentFactorOptions.filter(item => value.includes(item.value));
this.touchAssessment(selectedItems);
// 只验证当前字段
this.validateCurrentField("assessmentFactorValue");
},
handleBusinessTypeChange() {
// 只验证当前字段
this.validateCurrentField("businessType");
},
// 验证当前字段(只验证单个字段,不触发全表单验证)
validateCurrentField(prop) {
// 通过 $parent 访问父组件的表单引用
const form = this.$parent?.$refs?.form;
if (form && !this.$parent?.shouldValidateAll) {
form.validateField(prop, () => {});
}
},
},
};
......
......@@ -36,7 +36,8 @@
:picker-options="pickerOptions"
placeholder="请选择"
type="month"
value-format="yyyy-MM">
value-format="yyyy-MM"
@change="handleEffectiveMonthChange">
</el-date-picker>
</el-form-item>
<el-dialog v-if="dialog.storeApply.visible"
......@@ -165,6 +166,18 @@ export default {
this.setMerchantBrandRefList(deepClone(selectedMerchantList));
this.changeStoreApplyVisible();
},
handleEffectiveMonthChange() {
// 只验证当前字段
this.validateCurrentField("effectiveMonth");
},
// 验证当前字段(只验证单个字段,不触发全表单验证)
validateCurrentField(prop) {
// 通过 $parent 访问父组件的表单引用
const form = this.$parent?.$refs?.form;
if (form && !this.$parent?.shouldValidateAll) {
form.validateField(prop, () => {});
}
},
},
};
</script>
......
......@@ -108,17 +108,31 @@ function getPerformanceParamConfigConditions(paramsType2Item, paramsConfig) {
const conditionParamsData = paramsType2Item[`conditionType${paramsType2Item.condition}`];
console.log(paramsConfig.goodsCategory === 0
? buildGoodsTypePayload(goodsCategory, conditionParamsData.productValue, buildGoodsTypePayloadOptions)
: buildProductDefinePayload(productDefineList, conditionParamsData.productValue, buildProductDefinePayloadOptions));
// 如果 conditionParamsData 不存在,直接返回空的 conditionItem
if (!conditionParamsData) {
return conditionItem;
}
if (paramsType2Item.condition === 1) {
// 检查四个渗透率字段是否有值
const hasPermeabilityValue
= (conditionParamsData.permeabilityMax !== undefined && conditionParamsData.permeabilityMax !== null && conditionParamsData.permeabilityMax !== "")
|| (conditionParamsData.permeabilityMax1 !== undefined && conditionParamsData.permeabilityMax1 !== null && conditionParamsData.permeabilityMax1 !== "")
|| (conditionParamsData.permeabilityMin !== undefined && conditionParamsData.permeabilityMin !== null && conditionParamsData.permeabilityMin !== "")
|| (conditionParamsData.permeabilityMin1 !== undefined && conditionParamsData.permeabilityMin1 !== null && conditionParamsData.permeabilityMin1 !== "");
// 如果四个渗透率字段全部没有值,直接返回空的 conditionItem,不进行后续处理
if (!hasPermeabilityValue) {
return conditionItem;
}
extend.conditionStartValue = conditionParamsData.permeabilityMin;
extend.conditionEndValue = conditionParamsData.permeabilityMax;
extend = {
...extend,
...paramsConfig.goodsCategory === 0
? buildGoodsTypePayload(goodsCategory, conditionParamsData.productValue, buildGoodsTypePayloadOptions)
: buildProductDefinePayload(productDefineList, conditionParamsData.productValue, buildProductDefinePayloadOptions),
? buildGoodsTypePayload(goodsCategory, conditionParamsData.productValue || [], buildGoodsTypePayloadOptions)
: buildProductDefinePayload(productDefineList, conditionParamsData.productValue || [], buildProductDefinePayloadOptions),
};
conditionItem.push({
conditionType: paramsType2Item.condition,
......@@ -126,8 +140,8 @@ function getPerformanceParamConfigConditions(paramsType2Item, paramsConfig) {
conditionEndValue: conditionParamsData.permeabilityMax1,
conditionGoodsConfigType: paramsConfig.goodsCategory,
...paramsConfig.goodsCategory === 0
? buildGoodsTypePayload(goodsCategory, conditionParamsData.productValue1, buildGoodsTypePayloadOptions)
: buildProductDefinePayload(productDefineList, conditionParamsData.productValue1, buildProductDefinePayloadOptions),
? buildGoodsTypePayload(goodsCategory, conditionParamsData.productValue1 || [], buildGoodsTypePayloadOptions)
: buildProductDefinePayload(productDefineList, conditionParamsData.productValue1 || [], buildProductDefinePayloadOptions),
});
}
if (paramsType2Item.condition === 2) {
......@@ -141,8 +155,8 @@ function getPerformanceParamConfigConditions(paramsType2Item, paramsConfig) {
extend = {
...extend,
...paramsConfig.goodsCategory === 0
? buildGoodsTypePayload(goodsCategory, conditionParamsData.productValue, buildGoodsTypePayloadOptions)
: buildProductDefinePayload(productDefineList, conditionParamsData.productValue, buildProductDefinePayloadOptions),
? buildGoodsTypePayload(goodsCategory, conditionParamsData.productValue || [], buildGoodsTypePayloadOptions)
: buildProductDefinePayload(productDefineList, conditionParamsData.productValue || [], buildProductDefinePayloadOptions),
};
}
......@@ -159,6 +173,15 @@ function buildProductDefinePayload(tree, pathIds, options = {
name: "productDefineName",
type: "goodsConfigType",
}) {
// 如果 pathIds 不存在或不是数组,返回空对象
if (!pathIds || !Array.isArray(pathIds) || pathIds.length === 0) {
return {
[options.id]: null,
[options.name]: null,
[options.type]: null,
};
}
let currentLevel = tree;
let targetNode = null;
......@@ -186,7 +209,11 @@ function buildGoodsTypePayload(tree, pathIds, options = {
}) {
const result = {};
let currentLevel = tree;
// 如果 pathIds 不存在或不是数组,返回空对象
if (!pathIds || !Array.isArray(pathIds) || pathIds.length === 0) {
return result;
}
pathIds.forEach((id, index) => {
let node = {};
......@@ -208,8 +235,6 @@ function buildGoodsTypePayload(tree, pathIds, options = {
result[options.level3Id] = node.categoryType;
result[options.level3Name] = node.categoryName;
}
currentLevel = node.children || [];
});
return result;
......
<template>
<d2-container v-loading="$store.state.d2admin.loading.value" class="performance-scheme-wrapper">
<el-form class="form-performance-name"
<el-form ref="form"
class="form-performance-name"
label-width="170px"
:model="formData"
:rules="rules">
:rules="rules"
:validate-on-rule-change="false">
<div class="warp-box">
<div class="title space-b">
......@@ -22,12 +24,13 @@
</div>
</div>
<div class="warp-content">
<el-form-item label="当前方案名称:" prop="name">
<el-form-item label="当前方案名称:" prop="schemeName">
<el-input v-model="schemeName"
clearable
maxlength="20"
placeholder="请输入当前方案名称"
style="width:290px" />
style="width:290px"
@blur="handleFieldBlur('schemeName')" />
</el-form-item>
<ParamConfigList v-for="(parameter, index) in formData.paramConfigList"
......@@ -76,7 +79,7 @@
<script>
import { groupBy } from "lodash-es";
import { mapGetters, mapMutations, mapState } from "vuex";
import { mapMutations, mapState } from "vuex";
import { getAllCategory } from "@/api/product.js";
import { getPerformanceConfigDetailAPI, getTargetProductConfigListAPI, postSalaryPerformanceScheme } from "@/api/resident";
import DetailDialog from "../../components/approvalView";
......@@ -87,6 +90,7 @@ import StoreApply from "../components/storeApply/index.vue";
import { bindFormFields } from "../store/helper.js";
import { convertBackendToData } from "../utils/convertBackendToData.js";
import { convertDataToBackend } from "../utils/index.js";
import { getFormRules, validateParamConfigList } from "../utils/rules.js";
// 提成方案配置
export default {
......@@ -110,12 +114,30 @@ export default {
id: 0,
rules: {},
detailVisible: false,
shouldValidateAll: false, // 是否应该验证所有字段
};
},
computed: {
...mapState("PerformanceFormStore", ["formData", "merchantBrandRefList"]),
schemeName: bindFormFields("schemeName"),
},
watch: {
formData: {
handler() {
// 当formData变化时,更新rules
this.rules = getFormRules(this.formData, this.merchantBrandRefList);
},
deep: true,
immediate: true,
},
merchantBrandRefList: {
handler() {
// 当门店列表变化时,更新rules
this.rules = getFormRules(this.formData, this.merchantBrandRefList);
},
deep: true,
},
},
async mounted() {
await this.initLoad();
if (this.$route?.query?.id) {
......@@ -148,8 +170,41 @@ export default {
this.handleCancelSubmit();
}
},
// 处理单个字段失焦事件,只验证当前字段
handleFieldBlur(prop) {
if (!this.shouldValidateAll && this.$refs.form) {
this.$refs.form.validateField(prop, () => {});
}
},
// 提交保存
async handleSubmitSave(isConfirm = false) {
console.log("handleSubmitSave", this.formData);
// 设置需要验证所有字段
this.shouldValidateAll = true;
// 表单校验
try {
await this.$refs.form.validate();
} catch (error) {
this.$message.warning("请完善表单信息");
this.shouldValidateAll = false;
return;
}
this.shouldValidateAll = false;
// 校验门店列表
if (!this.merchantBrandRefList || this.merchantBrandRefList.length === 0) {
this.$message.warning("请至少选择一个门店");
return;
}
// 校验参数配置列表
const paramConfigError = validateParamConfigList(this.formData);
if (paramConfigError) {
this.$message.warning(paramConfigError);
return;
}
console.log(this.formData, "this.formData");
const params = convertDataToBackend({
...this.formData,
merchantBrandRefList: this.merchantBrandRefList,
......@@ -160,7 +215,7 @@ export default {
params.schemeType = this.formData.schemeType;
}
}
let res = await postSalaryPerformanceScheme(params);
const res = await postSalaryPerformanceScheme(params);
this.id = res;
console.log(res, "res");
if (res && isConfirm) {
......
<template>
<d2-container v-loading="$store.state.d2admin.loading.value"
class="performance-scheme-wrapper">
<el-form class="form-performance-name"
<el-form ref="form"
class="form-performance-name"
label-width="170px"
:model="formData"
:rules="rules">
:rules="rules"
:validate-on-rule-change="false">
<div class="warp-box">
<div class="title space-b">
<div class="title-wrap">
......@@ -36,12 +38,13 @@
</div>
</div>
<div class="warp-content">
<el-form-item label="当前方案名称:" prop="name">
<el-form-item label="当前方案名称:" prop="schemeName">
<el-input v-model="schemeName"
clearable
maxlength="20"
placeholder="请输入当前方案名称"
style="width: 290px" />
style="width: 290px"
@blur="handleFieldBlur('schemeName')" />
</el-form-item>
<ParamConfigList v-for="(parameter, index) in formData.paramConfigList"
......@@ -64,7 +67,8 @@
:picker-options="pickerOptions"
placeholder="请选择"
type="month"
value-format="yyyy-MM">
value-format="yyyy-MM"
@blur="handleFieldBlur('effectiveMonth')">
</el-date-picker>
</el-form-item>
</div>
......@@ -95,11 +99,10 @@
<script>
import { groupBy } from "lodash-es";
import { mapGetters, mapMutations, mapState } from "vuex";
import { mapMutations, mapState } from "vuex";
import { getAllCategory } from "@/api/product.js";
import {
getConfigMerchantDetail,
getPerformanceConfigDetailAPI,
getTargetProductConfigListAPI,
postBrandMerchant,
postSalaryPerformanceScheme,
......@@ -112,6 +115,7 @@ import { assessmentFactorOptions } from "../components/performanceRuleSelection/
import { bindFormFields } from "../store/helper.js";
import { convertBackendToData } from "../utils/convertBackendToData.js";
import { convertDataToBackend } from "../utils/index.js";
import { getFormRules, validateParamConfigList } from "../utils/rules.js";
// 门店提成方案
export default {
......@@ -129,6 +133,7 @@ export default {
rules: {},
detailVisible: false,
detailVisibleId: undefined,
shouldValidateAll: false, // 是否应该验证所有字段
pickerOptions: {
disabledDate(time) {
......@@ -161,6 +166,23 @@ export default {
},
},
},
watch: {
formData: {
handler() {
// 当formData变化时,更新rules
this.rules = getFormRules(this.formData, this.merchantBrandRefList);
},
deep: true,
immediate: true,
},
merchantBrandRefList: {
handler() {
// 当门店列表变化时,更新rules
this.rules = getFormRules(this.formData, this.merchantBrandRefList);
},
deep: true,
},
},
async mounted() {
console.log("this.$route.query", this.$route.query);
if (this.$route.query?.id) {
......@@ -205,9 +227,36 @@ export default {
this.handleCancelSubmit();
}
},
async handleSubmitCheck(isConfirm = false) {
// 处理单个字段失焦事件,只验证当前字段
handleFieldBlur(prop) {
if (!this.shouldValidateAll && this.$refs.form) {
this.$refs.form.validateField(prop, () => {});
}
},
// 提交审核
async handleSubmitCheck() {
// 表单校验
this.shouldValidateAll = true;
try {
await this.$refs.form.validate();
} catch (error) {
this.$message.warning("请完善表单信息");
this.shouldValidateAll = false;
return;
}
this.shouldValidateAll = false;
// 校验参数配置列表
const paramConfigError = validateParamConfigList(this.formData);
if (paramConfigError) {
this.$message.warning(paramConfigError);
return;
}
const params = convertDataToBackend({
...this.formData,
// 门店提成方案不需要门店列表,传空数组
merchantBrandRefList: [],
});
if (this.formData.id) {
params.id = this.formData.id;
......@@ -216,17 +265,10 @@ export default {
params.schemeType = this.formData.schemeType;
}
params.merchantBrandRefList = this.merchantBrandRefList;
this.detailVisibleId = await postSalaryPerformanceScheme(params);
if (this.detailVisibleId && isConfirm) {
this.$message.success("保存成功 ");
if (this.detailVisibleId) {
this.detailVisible = !this.detailVisible;
}
// await postSalaryPerformanceScheme(convertDataToBackend({
// ...this.formData,
// merchantBrandRefList: this.merchantBrandRefList,
// }));
},
// 取消按钮
handleCancelSubmit() {
......
  • @limin
    commented
    Owner

    你好,我是负责本次代码审查的工程师。你提交的代码主要涉及绩效配置页面的输入验证优化。代码结构清晰,提交信息规范,但在工程规范和边界情况处理上存在一些需要改进的地方。

    以下是我的审查意见:

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

    1. 代码中遗留调试语句(严重)

      • 问题描述:在 validateBeforeSave 方法中(第 490 行),遗留了 console.log(coefRaw, ...) 调试代码。
      • 影响分析:这是生产环境代码禁忌。不仅污染浏览器控制台输出,还可能暴露内部变量逻辑,属于典型的工程疏忽。
      • 优化建议:务必删除该行代码。建议在 IDE 中配置 ESLint 规则(如 no-console)以在提交前自动拦截此类问题。
    2. 输入验证逻辑健壮性下降

      • 问题描述:移除了原有的 String(...).trim() 处理。
      • 影响分析:如果不进行 trim(),用户若误输入纯空格(如 " "),JavaScript 中非空字符串被视为 true,从而绕过 if (!coefRaw ...) 的非空校验。这会导致“看似有值实际为空”的脏数据存入数据库。
      • 优化建议:恢复去除首尾空格的逻辑。 javascript // 建议修改为: const coefRaw = String(r.rewardCoefficient || "").trim(); // 或者如果确定类型: const coefRaw = (r.rewardCoefficient ?? "").toString().trim();
    3. 数值 0 的逻辑判断存在隐患

      • 问题描述:代码使用了 const scoreRaw = r.scoreNumericValue || r.scoreSymbolValue。
      • 影响分析:在 JavaScript 中,数字 0 是 falsy 值。如果 r.scoreNumericValue 的有效值为 0,逻辑运算符 || 会将其判定为假,从而错误地回退取 r.scoreSymbolValue 的值。这可能导致取值逻辑与预期不符(取决于业务逻辑是否允许 scoreNumericValue 为 0)。
      • 优化建议:如果 0 是有效值,应使用空值合并运算符(Nullish Coalescing)??(需确认项目构建环境是否支持 ES2020),或显式判断 undefined/null。 javascript // 建议修改为(优先取数值,仅当数值为 null/undefined 时取符号值): const scoreRaw = (r.scoreNumericValue !== null && r.scoreNumericValue !== undefined) ? r.scoreNumericValue : r.scoreSymbolValue;

    二、评分明细

    1. 功能实现的正确性与健壮性(32/40分)

      • 修复了 0 无法通过校验的 Bug,这点很好。
      • 扣分项:移除了 trim() 导致对空白字符的防御能力下降;|| 运算符处理 0 值存在潜在逻辑歧义。
    2. 安全性与潜在风险(28/30分)

      • 整体无明显 XSS/SQL 注入风险。
      • 扣分项:数据完整性校验变弱(允许纯空格提交)。
    3. 最佳实践与可维护性(12/20分)

      • 变量命名尚可。
      • 扣分项:严重扣分项为提交了 console.log 调试代码,这是代码审查中的红线之一。
    4. 性能与资源利用(5/5分)

      • 逻辑简单,无性能瓶颈。
    5. 提交信息质量(4/5分)

      • Commit Message 格式符合规范(feat: ...)。
      • 扣分项:Commit 内容中提到“添加调试日志”,说明在提交时已知包含脏代码,应当在 Push 前清理。

    三、总分

    总分:81分

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