Browse Source

fix: priceOptions allowZero

Roxas 4 years ago
parent
commit
ae2a0529c2

+ 2
- 1
eslib/PriceOptions/index.d.ts View File

@@ -7,6 +7,7 @@ interface Props {
7 7
     size: "small" | "normal" | "large";
8 8
     focusScroll: boolean;
9 9
     withTitle: boolean;
10
+    allowZero: boolean;
10 11
     titleText?: string | JSX.Element[] | JSX.Element;
11 12
     inputPlaceholderText?: string;
12 13
     priceOptions?: Array<any>;
@@ -19,5 +20,5 @@ interface Props {
19 20
     };
20 21
     inputRef: React.RefObject<any>;
21 22
 }
22
-declare const PriceOptions: ({ price, onPriceChange, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23
+declare const PriceOptions: ({ price, onPriceChange, allowZero, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23 24
 export { PriceOptions as default };

+ 5
- 0
eslib/PriceOptions/index.js View File

@@ -56,6 +56,7 @@ function _objectSpread(target) {
56 56
 var PriceOptions = function PriceOptions(_ref) {
57 57
   var price = _ref.price,
58 58
       onPriceChange = _ref.onPriceChange,
59
+      allowZero = _ref.allowZero,
59 60
       _ref$rowMode = _ref.rowMode,
60 61
       rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
61 62
       _ref$size = _ref.size,
@@ -139,6 +140,10 @@ var PriceOptions = function PriceOptions(_ref) {
139 140
         return;
140 141
       }
141 142
 
143
+      if (!allowZero && n === 0) {
144
+        return;
145
+      }
146
+
142 147
       setInputPrice("".concat(n * 100));
143 148
       onPriceChange(n * 100);
144 149
     },

+ 1
- 1
eslib/PriceOptions/index.js.map
File diff suppressed because it is too large
View File


+ 2
- 1
lib/PriceOptions/index.d.ts View File

@@ -7,6 +7,7 @@ interface Props {
7 7
     size: "small" | "normal" | "large";
8 8
     focusScroll: boolean;
9 9
     withTitle: boolean;
10
+    allowZero: boolean;
10 11
     titleText?: string | JSX.Element[] | JSX.Element;
11 12
     inputPlaceholderText?: string;
12 13
     priceOptions?: Array<any>;
@@ -19,5 +20,5 @@ interface Props {
19 20
     };
20 21
     inputRef: React.RefObject<any>;
21 22
 }
22
-declare const PriceOptions: ({ price, onPriceChange, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23
+declare const PriceOptions: ({ price, onPriceChange, allowZero, rowMode, size, focusScroll, withTitle, titleText, inputPlaceholderText, priceOptions, priceRender, inputPriceRender, inputSuffix, injectOptions, inputRef }: Props) => JSX.Element;
23 24
 export { PriceOptions as default };

+ 5
- 0
lib/PriceOptions/index.js View File

@@ -63,6 +63,7 @@ function _objectSpread(target) {
63 63
 var PriceOptions = function PriceOptions(_ref) {
64 64
   var price = _ref.price,
65 65
       onPriceChange = _ref.onPriceChange,
66
+      allowZero = _ref.allowZero,
66 67
       _ref$rowMode = _ref.rowMode,
67 68
       rowMode = _ref$rowMode === void 0 ? "single" : _ref$rowMode,
68 69
       _ref$size = _ref.size,
@@ -146,6 +147,10 @@ var PriceOptions = function PriceOptions(_ref) {
146 147
         return;
147 148
       }
148 149
 
150
+      if (!allowZero && n === 0) {
151
+        return;
152
+      }
153
+
149 154
       setInputPrice("".concat(n * 100));
150 155
       onPriceChange(n * 100);
151 156
     },

+ 1
- 1
lib/PriceOptions/index.js.map
File diff suppressed because it is too large
View File


+ 5
- 0
src/components/Payment/PriceOptions/index.tsx View File

@@ -28,6 +28,7 @@ interface Props {
28 28
   size: "small" | "normal" | "large";
29 29
   focusScroll: boolean;
30 30
   withTitle: boolean;
31
+  allowZero: boolean;
31 32
   titleText?: string | JSX.Element[] | JSX.Element;
32 33
   inputPlaceholderText?: string;
33 34
   priceOptions?: Array<any>;
@@ -44,6 +45,7 @@ interface Props {
44 45
 const PriceOptions = ({
45 46
   price,
46 47
   onPriceChange,
48
+  allowZero,
47 49
   rowMode = "single",
48 50
   size = "normal",
49 51
   focusScroll = true,
@@ -110,6 +112,9 @@ const PriceOptions = ({
110 112
             if (Number.isNaN(n)) {
111 113
               return;
112 114
             }
115
+            if (!allowZero && n === 0) {
116
+              return;
117
+            }
113 118
             // 测试暂时改成1分
114 119
             setInputPrice(`${n * 100}`);
115 120
             onPriceChange(n * 100);

+ 1
- 1
stats.html
File diff suppressed because it is too large
View File