Elements-SY

modify

...@@ -37,7 +37,15 @@ export const inputBlurValidate = { ...@@ -37,7 +37,15 @@ export const inputBlurValidate = {
37 } 37 }
38 // 最小重量有值的情况下 38 // 最小重量有值的情况下
39 if (target.value && Number(target.value) >= 0) { 39 if (target.value && Number(target.value) >= 0) {
40 + if (/^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(target.value))) {
41 + if (this.queryForm.maxWeight) {
40 if ( 42 if (
43 + Number(this.queryForm.maxWeight) <
44 + Number(this.queryForm.minWeight)
45 + ) {
46 + this.validateForm = false;
47 + this.$refs.minWeight.innerHTML = "最小重量不得大于最大重量";
48 + } else if (
41 /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.maxWeight)) 49 /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.maxWeight))
42 ) { 50 ) {
43 this.validateForm = true; 51 this.validateForm = true;
...@@ -45,25 +53,14 @@ export const inputBlurValidate = { ...@@ -45,25 +53,14 @@ export const inputBlurValidate = {
45 } else { 53 } else {
46 this.validateForm = false; 54 this.validateForm = false;
47 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位"; 55 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
48 - // this.msgError("请输入有效重量,小数保留5位");
49 } 56 }
50 - if (/^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(target.value))) { 57 + } else {
51 this.validateForm = true; 58 this.validateForm = true;
52 this.$refs.minWeight.innerHTML = ""; 59 this.$refs.minWeight.innerHTML = "";
60 + }
53 } else { 61 } else {
54 this.validateForm = false; 62 this.validateForm = false;
55 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位"; 63 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
56 - // this.msgError("请输入有效重量,小数保留5位");
57 - }
58 - }
59 - // 重量最小值和最大值都不为空的情况下
60 - if (this.queryForm.minWeight && this.queryForm.maxWeight) {
61 - if (
62 - Number(this.queryForm.maxWeight) < Number(this.queryForm.minWeight)
63 - ) {
64 - this.validateForm = false;
65 - this.$refs.minWeight.innerHTML = "最小重量不得大于最大重量";
66 - // this.msgError("最小重量不得大于最大重量");
67 } 64 }
68 } 65 }
69 }, 66 },
...@@ -87,9 +84,16 @@ export const inputBlurValidate = { ...@@ -87,9 +84,16 @@ export const inputBlurValidate = {
87 // this.msgError("请输入有效重量,小数保留5位"); 84 // this.msgError("请输入有效重量,小数保留5位");
88 } 85 }
89 } 86 }
90 - // 最大重量有值的情况下
91 if (target.value && Number(target.value) >= 0) { 87 if (target.value && Number(target.value) >= 0) {
88 + if (/^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(target.value))) {
89 + if (this.queryForm.minWeight) {
92 if ( 90 if (
91 + Number(this.queryForm.maxWeight) <
92 + Number(this.queryForm.minWeight)
93 + ) {
94 + this.validateForm = false;
95 + this.$refs.minWeight.innerHTML = "最小重量不得大于最大重量";
96 + } else if (
93 /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.minWeight)) 97 /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.minWeight))
94 ) { 98 ) {
95 this.validateForm = true; 99 this.validateForm = true;
...@@ -97,25 +101,14 @@ export const inputBlurValidate = { ...@@ -97,25 +101,14 @@ export const inputBlurValidate = {
97 } else { 101 } else {
98 this.validateForm = false; 102 this.validateForm = false;
99 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位"; 103 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
100 - // this.msgError("请输入有效重量,小数保留5位");
101 } 104 }
102 - if (/^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(target.value))) { 105 + } else {
103 this.validateForm = true; 106 this.validateForm = true;
104 this.$refs.minWeight.innerHTML = ""; 107 this.$refs.minWeight.innerHTML = "";
108 + }
105 } else { 109 } else {
106 this.validateForm = false; 110 this.validateForm = false;
107 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位"; 111 this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
108 - // this.msgError("请输入有效重量,小数保留5位");
109 - }
110 - }
111 - // 重量最小值和最大值都不为空的情况下
112 - if (this.queryForm.minWeight && this.queryForm.maxWeight) {
113 - if (
114 - Number(this.queryForm.maxWeight) < Number(this.queryForm.minWeight)
115 - ) {
116 - this.validateForm = false;
117 - this.$refs.minWeight.innerHTML = "最小重量不得大于最大重量";
118 - // this.msgError("最小重量不得大于最大重量");
119 } 112 }
120 } 113 }
121 }, 114 },
......
...@@ -48,8 +48,6 @@ ...@@ -48,8 +48,6 @@
48 <script> 48 <script>
49 import ElInput from 'element-ui/packages/input'; 49 import ElInput from 'element-ui/packages/input';
50 import Focus from 'element-ui/src/mixins/focus'; 50 import Focus from 'element-ui/src/mixins/focus';
51 - import RepeatClick from 'element-ui/src/directives/repeat-click';
52 -
53 export default { 51 export default {
54 name: 'YlElInputNumber', 52 name: 'YlElInputNumber',
55 mixins: [Focus('input')], 53 mixins: [Focus('input')],
...@@ -61,9 +59,6 @@ ...@@ -61,9 +59,6 @@
61 default: '' 59 default: ''
62 } 60 }
63 }, 61 },
64 - directives: {
65 - repeatClick: RepeatClick
66 - },
67 components: { 62 components: {
68 ElInput 63 ElInput
69 }, 64 },
...@@ -120,13 +115,11 @@ ...@@ -120,13 +115,11 @@
120 if (isNaN(newVal)) { 115 if (isNaN(newVal)) {
121 return; 116 return;
122 } 117 }
123 -
124 if (this.stepStrictly) { 118 if (this.stepStrictly) {
125 const stepPrecision = this.getPrecision(this.step); 119 const stepPrecision = this.getPrecision(this.step);
126 const precisionFactor = Math.pow(10, stepPrecision); 120 const precisionFactor = Math.pow(10, stepPrecision);
127 newVal = Math.round(newVal / this.step) * precisionFactor * this.step / precisionFactor; 121 newVal = Math.round(newVal / this.step) * precisionFactor * this.step / precisionFactor;
128 } 122 }
129 -
130 if (this.precision !== undefined) { 123 if (this.precision !== undefined) {
131 newVal = this.toPrecision(newVal, this.precision); 124 newVal = this.toPrecision(newVal, this.precision);
132 } 125 }
...@@ -174,9 +167,7 @@ ...@@ -174,9 +167,7 @@
174 if (this.userInput !== null) { 167 if (this.userInput !== null) {
175 return this.userInput; 168 return this.userInput;
176 } 169 }
177 -
178 let currentValue = this.currentValue; 170 let currentValue = this.currentValue;
179 -
180 if (typeof currentValue === 'number') { 171 if (typeof currentValue === 'number') {
181 if (this.stepStrictly) { 172 if (this.stepStrictly) {
182 const stepPrecision = this.getPrecision(this.step); 173 const stepPrecision = this.getPrecision(this.step);
...@@ -188,7 +179,6 @@ ...@@ -188,7 +179,6 @@
188 currentValue = currentValue.toFixed(this.precision); 179 currentValue = currentValue.toFixed(this.precision);
189 } 180 }
190 } 181 }
191 -
192 return currentValue; 182 return currentValue;
193 } 183 }
194 }, 184 },
...@@ -209,16 +199,12 @@ ...@@ -209,16 +199,12 @@
209 }, 199 },
210 _increase(val, step) { 200 _increase(val, step) {
211 if (typeof val !== 'number' && val !== undefined) return this.currentValue; 201 if (typeof val !== 'number' && val !== undefined) return this.currentValue;
212 -
213 const precisionFactor = Math.pow(10, this.numPrecision); 202 const precisionFactor = Math.pow(10, this.numPrecision);
214 - // Solve the accuracy problem of JS decimal calculation by converting the value to integer.
215 return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor); 203 return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor);
216 }, 204 },
217 _decrease(val, step) { 205 _decrease(val, step) {
218 if (typeof val !== 'number' && val !== undefined) return this.currentValue; 206 if (typeof val !== 'number' && val !== undefined) return this.currentValue;
219 -
220 const precisionFactor = Math.pow(10, this.numPrecision); 207 const precisionFactor = Math.pow(10, this.numPrecision);
221 -
222 return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor); 208 return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor);
223 }, 209 },
224 increase() { 210 increase() {
......