Browse Source

新增输入判断

695593266@qq.com 21 giờ trước cách đây
mục cha
commit
51926fb7a1
2 tập tin đã thay đổi với 40 bổ sung7 xóa
  1. 38 5
      src/views/material/product/detail.vue
  2. 2 2
      vue.config.js

+ 38 - 5
src/views/material/product/detail.vue

@@ -272,7 +272,11 @@
 
           <el-col :span="8">
             <el-form-item label="面积" prop="area">
-              <el-input v-model="form.area" :disabled="isReadOnly" />
+              <el-input
+                v-model="form.area"
+                @input="handleAreaInput"
+                :disabled="isReadOnly"
+              />
             </el-form-item>
           </el-col>
 
@@ -355,10 +359,10 @@
               <div class="form-line">
                 <el-input
                   v-model="form.volume"
+                  @input="handleInput"
                   style="width: calc(100% - 100px)"
                   :disabled="isReadOnly"
                 />
-                <!-- @input="handleInput1" -->
                 <DictSelection
                   dictName="体积单位"
                   clearable
@@ -1236,14 +1240,42 @@
       changeMeasureType() {
         this.setNetWeight();
       },
+      sanitizePositiveDecimalInput(value) {
+        if (value === null || value === undefined) return '';
+
+        const filteredValue = String(value).replace(/[^0-9.]/g, '');
+        if (!filteredValue) return '';
+
+        const [integerPart, ...decimalParts] = filteredValue.split('.');
+        if (!decimalParts.length) {
+          return integerPart;
+        }
+
+        return `${integerPart || '0'}.${decimalParts.join('')}`;
+      },
+      normalizeDecimalFields() {
+        ['area', 'roughWeight', 'netWeight', 'volume'].forEach((field) => {
+          const value = this.sanitizePositiveDecimalInput(this.form[field]);
+          this.$set(
+            this.form,
+            field,
+            value.endsWith('.') ? value.slice(0, -1) : value
+          );
+        });
+      },
+      handleAreaInput(value) {
+        this.form.area = this.sanitizePositiveDecimalInput(value);
+      },
       handleInput(value) {
-        // this.form.volume = this.$handleInputPublicHasPoint(value);
+        this.form.volume = this.sanitizePositiveDecimalInput(value);
       },
       handleInput2(value) {
-        this.form.roughWeight = this.$handleInputPublicHasPoint(value);
+        this.form.roughWeight = this.sanitizePositiveDecimalInput(value);
       },
       handleInput3(value) {
-        // this.form.netWeight = this.$handleInputPublicHasPoint(value);
+        this.form.netWeight = this.sanitizePositiveDecimalInput(
+          value === undefined ? this.form.netWeight : value
+        );
         if (this.form.weightUnit == this.form.measuringUnit) {
           this.$refs.warehouseRefs.changeNetWeight(this.form.netWeight);
         }
@@ -1665,6 +1697,7 @@
 
       // 保存
       submit() {
+        this.normalizeDecimalFields();
         this.$refs.manageForm.validate(async (valid) => {
           console.log(this.$refs.qualityRefs);
 

+ 2 - 2
vue.config.js

@@ -35,10 +35,10 @@ module.exports = {
         // target: 'http://192.168.1.3:18086',
         // target: 'http://192.168.1.158:18086',
         // target: 'http://192.168.1.176:18086',
-        target: 'http://192.168.1.125:18086',
+        // target: 'http://192.168.1.125:18086',
         // target: 'http://192.168.1.251:51005',
         // target: 'http://192.168.1.251:18186',
-        // target: 'http://192.168.1.251:18086',
+        target: 'http://192.168.1.251:18086',
         // target: 'http://192.168.1.251:18186',
         // target: 'http://192.168.1.3:18086',
         // target: 'http://192.168.1.251:18186', // 测试环境