Browse Source

dev: 修改README.md;替换支付图标为体积更小的图片;追加Modal形式的悬赏页面

thewinsword 4 years ago
parent
commit
6782c06a78

+ 1
- 0
.gitignore View File

@@ -21,3 +21,4 @@
21 21
 npm-debug.log*
22 22
 yarn-debug.log*
23 23
 yarn-error.log*
24
+/.idea/

+ 31
- 33
README.md View File

@@ -1,44 +1,42 @@
1
-This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
1
+# bilingo-ui
2 2
 
3
-## Available Scripts
3
+[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
4 4
 
5
-In the project directory, you can run:
5
+双语帮UI库
6 6
 
7
-### `yarn start`
7
+## Table of Contents
8 8
 
9
-Runs the app in the development mode.<br />
10
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
9
+- [Install](#install)
10
+- [Usage](#usage)
11
+- [Maintainers](#maintainers)
11 12
 
12
-The page will reload if you make edits.<br />
13
-You will also see any lint errors in the console.
13
+## Install
14 14
 
15
-### `yarn test`
15
+```
16
+yarn
17
+```
18
+```
19
+npm install
20
+```
16 21
 
17
-Launches the test runner in the interactive watch mode.<br />
18
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
22
+## Usage
19 23
 
20
-### `yarn build`
24
+Build UI
25
+```
26
+yarn run build:lib
27
+```
28
+```
29
+npm run build:lib
30
+```
21 31
 
22
-Builds the app for production to the `build` folder.<br />
23
-It correctly bundles React in production mode and optimizes the build for the best performance.
32
+Preview or Develop
33
+```
34
+yarn run storybook
35
+```
36
+```
37
+npm run storybook
38
+```
24 39
 
25
-The build is minified and the filenames include the hashes.<br />
26
-Your app is ready to be deployed!
40
+## Maintainers
27 41
 
28
-See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29
-
30
-### `yarn eject`
31
-
32
-**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33
-
34
-If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35
-
36
-Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37
-
38
-You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39
-
40
-## Learn More
41
-
42
-You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43
-
44
-To learn React, check out the [React documentation](https://reactjs.org/).
42
+[@Roxas](https://github.com/thewindsword)

+ 10
- 0
src/components/Payment/WantedPublishModal/WantedPublishModal.less View File

@@ -0,0 +1,10 @@
1
+.modalBg {
2
+  background: white;
3
+  display: flex;
4
+  justify-content: center;
5
+  flex-direction: column;
6
+  align-items: center;
7
+  padding: 16px;
8
+  text-align: center;
9
+  border-radius: 4px;
10
+}

+ 106
- 0
src/components/Payment/WantedPublishModal/index.tsx View File

@@ -0,0 +1,106 @@
1
+import React, { Component } from "react";
2
+
3
+import Modal, { ModalProps } from "../../Common/Modal";
4
+import WantedPublishView from "../WantedPublishView";
5
+import styles from "./WantedPublishModal.less";
6
+
7
+interface WantedPublishModalProps {
8
+  modalConfig?: ModalProps;
9
+  handleConfirm?: Function;
10
+}
11
+
12
+interface WantedPublishModalState {
13
+  modalVisible: boolean;
14
+  current_wanted: number | string | null;
15
+}
16
+
17
+export class WantedPublishModal extends Component<
18
+  WantedPublishModalProps,
19
+  WantedPublishModalState
20
+> {
21
+  constructor(props: WantedPublishModalProps) {
22
+    super(props);
23
+    this.state = {
24
+      modalVisible: false,
25
+      current_wanted: null
26
+    };
27
+  }
28
+
29
+  handleModalShow = () => {};
30
+
31
+  handleClose = () => {
32
+    const { handleConfirm } = this.props;
33
+    if (handleConfirm) {
34
+      this.handleUpdateCurrentWanted(
35
+        this.state.current_wanted,
36
+        (value: string) => {
37
+          handleConfirm(Number(value).toFixed(2));
38
+        }
39
+      );
40
+    }
41
+    this.setState({ modalVisible: false });
42
+  };
43
+
44
+  handleUpdateCurrentWanted = (
45
+    value: string | number | null,
46
+    afterUpdate?: Function
47
+  ) => {
48
+    if (!value) return;
49
+    let result: string | number;
50
+    result = value;
51
+    if (parseInt(`${value}`, 10) === value) {
52
+      // 无小数判断
53
+      result = Number(value);
54
+    }
55
+    if (!result) return;
56
+    if (result > 10000) result = 10000;
57
+    if (result < 5) result = 5;
58
+    this.setState(
59
+      { current_wanted: result },
60
+      () => afterUpdate && afterUpdate(result)
61
+    );
62
+  };
63
+
64
+  clearCurrentWanted = (cb: Function) => {
65
+    this.setState(
66
+      {
67
+        current_wanted: null
68
+      },
69
+      () => cb()
70
+    );
71
+  };
72
+
73
+  renderMain() {
74
+    const { current_wanted } = this.state;
75
+    return (
76
+      <WantedPublishView
77
+        wrapperClass={styles.modalBg}
78
+        current_wanted={current_wanted}
79
+        InputWantedValueChange={(v: string) =>
80
+          this.setState({ current_wanted: v })
81
+        }
82
+        InputWantedPressEnter={(v: string) =>
83
+          this.handleUpdateCurrentWanted(v, this.handleClose)
84
+        }
85
+        InputWantedOnBlur={(v: string) => this.handleUpdateCurrentWanted(v)}
86
+        InputWantedClear={() => this.clearCurrentWanted(this.handleClose)}
87
+        CloseFunction={this.handleClose}
88
+      />
89
+    );
90
+  }
91
+
92
+  render() {
93
+    return (
94
+      <>
95
+        <div onClick={() => this.setState({ modalVisible: true })}>
96
+          {this.props.children}
97
+        </div>
98
+        <Modal visible={this.state.modalVisible} onCancel={this.handleClose}>
99
+          {this.renderMain()}
100
+        </Modal>
101
+      </>
102
+    );
103
+  }
104
+}
105
+
106
+export default WantedPublishModal;

BIN
src/components/Payment/assets/kcxq_popovers_icon_alipay@2x.png View File


BIN
src/components/Payment/assets/kcxq_popovers_icon_paypal@2x.png View File


BIN
src/components/Payment/assets/kcxq_popovers_icon_wechatpay@2x.png View File


+ 81
- 54
stories/Payment.stories.tsx View File

@@ -25,7 +25,8 @@ import WaitPayInfoView from "@/components/Payment/WaitPayInfoView";
25 25
 import WaitPayInfoViewDoc from "@components/Payment/WaitPayInfoView/README.md";
26 26
 import AllocWantedModal from "@/components/Payment/AllocWantedModal";
27 27
 import WantedPublishView from "@/components/Payment/WantedPublishView";
28
-import WantedPublishPopover from '@/components/Payment/WantedPublishPopover';
28
+import WantedPublishPopover from "@/components/Payment/WantedPublishPopover";
29
+import WantedPublishModal from "@/components/Payment/WantedPublishModal";
29 30
 import { formatMoney } from "@components/Payment/Utils/utils";
30 31
 
31 32
 import { consumeList } from "./data/consumeList.json";
@@ -126,7 +127,11 @@ stories.add(
126 127
       <div style={{ width: text("style_width", "auto") }}>
127 128
         <PriceOptions
128 129
           price={price}
129
-          rowMode={select("rowMode", { single: 'single', multi: 'multi' }, "single")}
130
+          rowMode={select(
131
+            "rowMode",
132
+            { single: "single", multi: "multi" },
133
+            "single"
134
+          )}
130 135
           onPriceChange={v => setPrice(v)}
131 136
           size={select(
132 137
             "size",
@@ -185,9 +190,9 @@ stories.add(
185 190
           console.log(args);
186 191
         }}
187 192
         sendGiftData={{
188
-          answerId: text("answerId", '1'),
189
-          questionId: text("questionId", '1'),
190
-          toUserId: text("toUserId", '1')
193
+          answerId: text("answerId", "1"),
194
+          questionId: text("questionId", "1"),
195
+          toUserId: text("toUserId", "1")
191 196
         }}
192 197
         handleVisibleChange={visiable => {
193 198
           console.log(visiable);
@@ -210,78 +215,100 @@ stories.add(
210 215
     return (
211 216
       <>
212 217
         <WantedPublishView
213
-          type={select("type", {
214
-            POP: "pop",
215
-            Modal: 'modal',
216
-          }, "pop")}
218
+          type={select(
219
+            "type",
220
+            {
221
+              POP: "pop",
222
+              Modal: "modal"
223
+            },
224
+            "pop"
225
+          )}
217 226
           wrapperClass="test_wrapper"
218 227
           current_wanted={currentWanted}
219 228
           InputWantedValueChange={(value: any) => setCurrentWanted(value)}
220 229
           InputWantedOnBlur={(blurValue: any) => setCurrentWanted(blurValue)}
221 230
           InputWantedClear={() => setCurrentWanted(0)}
222
-          InputWantedPressEnter={(enterValue: any) => setCurrentWanted(enterValue)}
223
-          CloseFunction={() => { console.log("Close Button"); }}
231
+          InputWantedPressEnter={(enterValue: any) =>
232
+            setCurrentWanted(enterValue)
233
+          }
234
+          CloseFunction={() => {
235
+            console.log("Close Button");
236
+          }}
224 237
         />
225 238
         <Divider />
226
-        <div>
227
-          currentWanted: {currentWanted}
228
-        </div>
239
+        <div>currentWanted: {currentWanted}</div>
229 240
       </>
230
-    )
241
+    );
231 242
   },
232 243
   {
233 244
     info: { inline: true },
234 245
     notes: "A very simple example of addon notes"
235 246
   }
236
-)
247
+);
237 248
 
238 249
 stories.add(
239
-  "WantedPublishPopover",
250
+  "WantedPublishPopover And Modal",
240 251
   () => {
241
-    const [wanted, setWanted] = React.useState('');
252
+    const [wanted, setWanted] = React.useState("");
242 253
     return (
243 254
       <div>
244
-        <WantedPublishPopover
245
-          popoverConfig={{
246
-            placement: select("popoverConfigPlacement", {
247
-              Undefined: undefined,
248
-              Left: "left",
249
-              Right: "right",
250
-              Top: "top",
251
-              Bottom: "bottom",
252
-              TopLeft: "topLeft",
253
-              TopRight: "topRight",
254
-              BottomLeft: "bottomLeft",
255
-              BottomRight: "bottomRight",
256
-              LeftTop: "leftTop",
257
-              LeftBottom: "leftBottom",
258
-              RightTop: "rightTop",
259
-              RightBottom: "rightBottom",
260
-            }, undefined),
261
-            trigger: select("popoverConfigTrigger", {
262
-              Undefined: undefined,
263
-              Hover: "hover",
264
-              Click: "click",
265
-              Focus: "focus",
266
-              ContextMenu: "contextMenu",
267
-            }, undefined),
268
-          }}
269
-          handleConfirm={(value: any) => {
270
-            setWanted(value);
271
-          }}
272
-        >
273
-          <Button>HoverIt{wanted}</Button>
274
-        </WantedPublishPopover>
255
+        <div>
256
+          <WantedPublishModal>
257
+            <div>ModalClick</div>
258
+          </WantedPublishModal>
259
+        </div>
260
+        <Divider />
261
+        <div>
262
+          <WantedPublishPopover
263
+            popoverConfig={{
264
+              placement: select(
265
+                "popoverConfigPlacement",
266
+                {
267
+                  Undefined: undefined,
268
+                  Left: "left",
269
+                  Right: "right",
270
+                  Top: "top",
271
+                  Bottom: "bottom",
272
+                  TopLeft: "topLeft",
273
+                  TopRight: "topRight",
274
+                  BottomLeft: "bottomLeft",
275
+                  BottomRight: "bottomRight",
276
+                  LeftTop: "leftTop",
277
+                  LeftBottom: "leftBottom",
278
+                  RightTop: "rightTop",
279
+                  RightBottom: "rightBottom"
280
+                },
281
+                undefined
282
+              ),
283
+              trigger: select(
284
+                "popoverConfigTrigger",
285
+                {
286
+                  Undefined: undefined,
287
+                  Hover: "hover",
288
+                  Click: "click",
289
+                  Focus: "focus",
290
+                  ContextMenu: "contextMenu"
291
+                },
292
+                undefined
293
+              )
294
+            }}
295
+            handleConfirm={(value: any) => {
296
+              setWanted(value);
297
+            }}
298
+          >
299
+            <Button>HoverIt{wanted}</Button>
300
+          </WantedPublishPopover>
301
+        </div>
275 302
         <Divider />
276 303
         {/* 下面用于分割wanted值的渲染,防止Error */}
277
-        {
278
-          ((wanted) => <div>wanted{wanted}</div>)(wanted)
279
-        }
304
+        {(wanted => (
305
+          <div>wanted{wanted}</div>
306
+        ))(wanted)}
280 307
       </div>
281
-    )
308
+    );
282 309
   },
283 310
   {
284 311
     info: { inline: true },
285 312
     notes: "A very simple example of addon notes"
286 313
   }
287
-)
314
+);