he wei
2024-11-18 90954f2940dde0bb3ea44b4442648733b92811d6
U 添加电芯串数验证
2个文件已修改
2个文件已添加
55 ■■■■■ 已修改文件
src/assets/js/testVal.js 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/test/const_params.js 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/test/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/test/paramContent.vue 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/js/testVal.js
New file
@@ -0,0 +1,32 @@
/**
 * 校验数据
 *
 * @param   {[Number,String]}  val     [val description]
 * @param   {[Object]}  option  [option description]
 *
 * @return  {[Object]}          [return description]
 */
function testVal(rules, val, callback, option) {
    let result = {
        code: 1,
        msg: option.msg
    };
    // 根据正则验证数据
    result.code = option.pattern.test(val)?1:0;
    if(result.code == 1 && option.regVal) {
        let min = option.min;
        let max =option.max;
        if(min > val || max < val) {
            result.code = 0;
        }
    }
    if(result.code == 0) {
        callback(new Error(option.msg));
    }else {
        callback()
    }
}
export default testVal;
src/views/test/const_params.js
New file
@@ -0,0 +1,12 @@
export default {
  Rules: {
    batteryNumber: {
      // 电芯串数
      pattern: /^[0-9]{1,3}$/,
      regVal: true,
      min: 1,
      max: 100,
      msg: "取值范围1~100(整数)",
    },
  },
};
src/views/test/index.vue
@@ -234,7 +234,7 @@
        <template v-if="1 == devType">
          <el-button
            size="small"
            :disabled="!currentDev.devOnline"
            :disabled="!!currentDev.devOnline"
            class="btn-start"
            v-if="!currentDev.state?.isTesting"
            @click="test(false)"
src/views/test/paramContent.vue
@@ -8,6 +8,9 @@
  startA200ParamPl,
} from "./api";
import useElement from "@/hooks/useElement.js";
import testVal from "@/assets/js/testVal.js";
import const_params from "./const_params.js";
const { $alert, $loading, $message, $confirm } = useElement();
const $emit = defineEmits(["update:model-value"]);
@@ -92,6 +95,12 @@
      message: "不能为空",
      trigger: "blur",
    },
    {
      validator(rule, value, callback) {
        testVal(rule, value, callback, const_params.Rules.batteryNumber);
      },
      trigger: ['blur', 'change'],
    },
  ],
  diffBatteryVoltage: [
    {