Skip to content

Commit c23f2dc

Browse files
committed
1.0.5 支持TS
1 parent 7d01e1d commit c23f2dc

File tree

10 files changed

+503
-555
lines changed

10 files changed

+503
-555
lines changed

.babelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"presets": ["@babel/preset-env", "@babel/preset-react"],
3-
"plugins": ["@babel/plugin-transform-runtime", ["@babel/plugin-proposal-decorators", { "legacy": true }]]
3+
"plugins": [
4+
"@babel/plugin-transform-runtime",
5+
["@babel/plugin-proposal-decorators", { "legacy": true }]
6+
]
47
}

.eslintrc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"extends": [
5+
"plugin:react-hooks/recommended",
6+
"plugin:@typescript-eslint/eslint-recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
"prettier/@typescript-eslint"
9+
],
10+
"plugins": ["react", "react-hooks", "prettier"],
11+
"rules": {
12+
"semi": "warn",
13+
"no-unused-vars": "off",
14+
"no-cond-assign": "error",
15+
"no-debugger": "warn",
16+
"no-dupe-args": "error",
17+
"no-caller": "error",
18+
"no-unmodified-loop-condition": "error",
19+
"no-with": "error",
20+
"no-catch-shadow": "error",
21+
22+
"@typescript-eslint/camelcase": "off",
23+
"@typescript-eslint/no-unused-vars": "off",
24+
"@typescript-eslint/no-var-requires": "off",
25+
"@typescript-eslint/no-use-before-define": "off",
26+
"@typescript-eslint/explicit-function-return-type": "off",
27+
28+
"prettier/prettier": "warn"
29+
}
30+
}

example/src/index.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import React from 'react';
2-
import Vcode from '../../dist/index.js';
3-
import ReactDom from 'react-dom';
4-
import ImgTest1 from '../assets/test1.png';
5-
import ImgTest2 from '../assets/test2.png';
1+
import React from "react";
2+
import Vcode from "../../dist/index.js";
3+
import ReactDom from "react-dom";
4+
import ImgTest1 from "../assets/test1.png";
5+
import ImgTest2 from "../assets/test2.png";
66
class Test extends React.Component {
77
constructor(props) {
88
super(props);
99
this.state = {
1010
img: 1,
11-
input2: '', // 第2个input的值
12-
vcode2: '-1', // 第2个vcode的值
13-
code: '',
11+
input2: "", // 第2个input的值
12+
vcode2: "-1", // 第2个vcode的值
13+
code: "",
1414
width: 200,
1515
};
1616
}
@@ -22,7 +22,7 @@ class Test extends React.Component {
2222
}
2323

2424
onVcode2Change(v) {
25-
console.log('触发回调onChange', v);
25+
console.log("触发回调onChange", v);
2626
if (v) {
2727
this.setState({
2828
vcode2: v,
@@ -35,18 +35,18 @@ class Test extends React.Component {
3535
this.setState({
3636
img: imgindex,
3737
code: imgindex === 1 ? ImgTest1 : ImgTest2,
38-
vcode2: '1234',
38+
vcode2: imgindex === 1 ? "wow1" : "helloworld",
3939
});
4040
}
4141
onChangeStr() {
42-
const a = ['a', 'b', 'c', 'd'];
42+
const a = ["a", "b", "c", "d"];
4343
const d = [];
4444
for (let i = 0; i < 5; i++) {
4545
d.push(a[Math.round(Math.random() * 3)]);
4646
}
47-
console.log('code:', d);
47+
console.log("code:", d);
4848
this.setState({
49-
code: d.join(''),
49+
code: d.join(""),
5050
});
5151
}
5252

@@ -55,7 +55,7 @@ class Test extends React.Component {
5555
}
5656
onChangeWidth() {
5757
const l = Math.round(Math.random() * 800 + 400);
58-
console.log('改变width:', l);
58+
console.log("改变width:", l);
5959
this.setState({
6060
width: l,
6161
});
@@ -64,9 +64,21 @@ class Test extends React.Component {
6464
return (
6565
<div>
6666
<div>
67-
<input type="text" placeholder="请输入正确的验证码" value={this.state.input2} onChange={e => this.onInput2Change(e)} maxLength={20} />
68-
<Vcode onChange={v => this.onVcode2Change(v)} value={this.state.code} width={this.state.width} />
69-
<span>{this.state.input2 === this.state.vcode2 ? '输入正确' : '输入错误'}</span>
67+
<input
68+
type="text"
69+
placeholder="请输入正确的验证码"
70+
value={this.state.input2}
71+
onChange={(e) => this.onInput2Change(e)}
72+
maxLength={20}
73+
/>
74+
<Vcode
75+
onChange={(v) => this.onVcode2Change(v)}
76+
value={this.state.code}
77+
width={this.state.width}
78+
/>
79+
<span>
80+
{this.state.input2 === this.state.vcode2 ? "输入正确" : "输入错误"}
81+
</span>
7082
</div>
7183
<hr />
7284
<button onClick={() => this.onChangeImg()}>更换图片</button>
@@ -77,4 +89,4 @@ class Test extends React.Component {
7789
}
7890
}
7991

80-
ReactDom.render(<Test />, document.getElementById('root'));
92+
ReactDom.render(<Test />, document.getElementById("root"));

lib/index.js

Lines changed: 0 additions & 236 deletions
This file was deleted.

0 commit comments

Comments
 (0)