Skip to content

Commit 74b3c57

Browse files
committed
chroe: add methods of components and optimization of code
1 parent 9bc2d13 commit 74b3c57

19 files changed

+830
-236
lines changed

README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ interface ClickConfig {
7575
showTheme?: boolean;
7676
title?: string;
7777
buttonText?: string;
78+
iconSize?: number;
79+
dotSize?: number;
7880
}
7981

8082
// data = {}
@@ -88,7 +90,15 @@ interface ClickEvents {
8890
click?: (x: number, y: number) => void;
8991
refresh?: () => void;
9092
close?: () => void;
91-
confirm?: (dots: Array<ClickDot>) => boolean;
93+
confirm?: (dots: Array<ClickDot>, reset: ()=>void) => boolean;
94+
}
95+
96+
// component method
97+
interface PublicMethods {
98+
reset: () => void,
99+
clear: () => void,
100+
refresh: () => void,
101+
close: () => void,
92102
}
93103
```
94104

@@ -120,6 +130,8 @@ interface SlideConfig {
120130
horizontalPadding?: number;
121131
showTheme?: boolean;
122132
title?: string;
133+
iconSize?: number;
134+
scope ?: boolean;
123135
}
124136

125137
// data = {}
@@ -137,7 +149,15 @@ interface SlideEvents {
137149
move?: (x: number, y: number) => void;
138150
refresh?: () => void;
139151
close?: () => void;
140-
confirm?: (point: SlidePoint) => boolean;
152+
confirm?: (point: SlidePoint, reset: () => void) => boolean;
153+
}
154+
155+
// component method
156+
interface PublicMethods {
157+
reset: () => void,
158+
clear: () => void,
159+
refresh: () => void,
160+
close: () => void,
141161
}
142162
```
143163

@@ -152,6 +172,8 @@ interface SlideRegionConfig {
152172
horizontalPadding?: number;
153173
showTheme?: boolean;
154174
title?: string;
175+
iconSize?: number;
176+
scope ?: boolean;
155177
}
156178

157179
// data = {}
@@ -169,7 +191,15 @@ interface SlideRegionEvents {
169191
move?: (x: number, y: number) => void;
170192
refresh?: () => void;
171193
close?: () => void;
172-
confirm?: (point: SlideRegionPoint) => boolean;
194+
confirm?: (point: SlideRegionPoint, reset: ()=>void) => boolean;
195+
}
196+
197+
// component method
198+
interface PublicMethods {
199+
reset: () => void,
200+
clear: () => void,
201+
refresh: () => void,
202+
close: () => void,
173203
}
174204
```
175205

@@ -196,6 +226,8 @@ interface RotateConfig {
196226
horizontalPadding?: number;
197227
showTheme?: boolean;
198228
title?: string;
229+
iconSize?: number;
230+
scope ?: boolean;
199231
}
200232

201233
// data = {}
@@ -210,7 +242,15 @@ interface RotateEvents {
210242
rotate?: (angle: number) => void;
211243
refresh?: () => void;
212244
close?: () => void;
213-
confirm?: (angle: number) => boolean;
245+
confirm?: (angle: number, reset: ()=>void) => boolean;
246+
}
247+
248+
// component method
249+
interface PublicMethods {
250+
reset: () => void,
251+
clear: () => void,
252+
refresh: () => void,
253+
close: () => void,
214254
}
215255
```
216256

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "go-captcha-angular",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "This is the angular package for go-captcha",
55
"private": false,
66
"email": "[email protected]",

projects/example/src/app/app.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@
22
<go-captcha-click
33
[data]="clickData"
44
[events]="clickEvents"
5+
[config]="clickConfig"
6+
#clickRef
57
></go-captcha-click>
68
<br/>
79
<go-captcha-slide
810
[data]="slideData"
911
[events]="slideEvents"
12+
[config]="slideConfig"
13+
#slideRef
1014
></go-captcha-slide>
1115
<br/>
1216
<go-captcha-slide-region
1317
[data]="slideRegionData"
1418
[events]="slideRegionEvents"
19+
[config]="slideRegionConfig"
20+
#slideRegionRef
1521
></go-captcha-slide-region>
1622
<br/>
1723
<go-captcha-rotate
1824
[data]="rotateData"
1925
[events]="rotateEvents"
26+
[config]="rotateConfig"
27+
#rotateRef
2028
></go-captcha-rotate>
2129
<br/>
2230
<go-captcha-button [clickEvent]="handleEvent"></go-captcha-button>

projects/example/src/app/app.component.ts

Lines changed: 147 additions & 22 deletions
Large diffs are not rendered by default.

projects/go-captcha-angular/src/lib/helper/helper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ export function checkTargetFather(that: any, e: any) {
3838

3939
return parent !== that
4040
}
41+
42+
export function mergeTo(src: any, dest: any) {
43+
for (const ccKey in src) {
44+
if (!dest.hasOwnProperty(ccKey)) {
45+
dest[ccKey] = src[ccKey]
46+
}
47+
}
48+
}

projects/go-captcha-angular/src/lib/modules/click/click-instance.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
export interface ClickRef {
3+
reset: () => void,
4+
clear: () => void,
5+
refresh: () => void,
6+
close: () => void,
7+
}
8+
29
export interface ClickConfig {
310
width?: number;
411
height?: number;
@@ -9,6 +16,8 @@ export interface ClickConfig {
916
showTheme?: boolean;
1017
title?: string;
1118
buttonText?: string;
19+
iconSize?: number;
20+
dotSize?: number;
1221
}
1322

1423
export const defaultClickConfig = ():ClickConfig => ({
@@ -20,7 +29,9 @@ export const defaultClickConfig = ():ClickConfig => ({
2029
horizontalPadding: 12,
2130
showTheme: true,
2231
title: "请在下图依次点击",
23-
buttonText: "确认"
32+
buttonText: "确认",
33+
iconSize: 22,
34+
dotSize: 24,
2435
})
2536

2637
export interface ClickData {
Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,78 @@
11
<div
22
class="go-captcha gc-wrapper"
3-
[class]="{'gc-theme': config.showTheme}"
3+
[class]="{'gc-theme': localConfig.showTheme}"
44
[style]="{
5-
width: (config.width || 0) + ( config.horizontalPadding * 2) + (config.showTheme ? 2 : 0) + 'px',
6-
paddingLeft: config.horizontalPadding + 'px',
7-
paddingRight: config.horizontalPadding + 'px',
8-
paddingTop: config.verticalPadding + 'px',
9-
paddingBottom: config.verticalPadding + 'px',
5+
width: (localConfig.width || 0) + ( localConfig.horizontalPadding * 2) + (localConfig.showTheme ? 2 : 0) + 'px',
6+
paddingLeft: localConfig.horizontalPadding + 'px',
7+
paddingRight: localConfig.horizontalPadding + 'px',
8+
paddingTop: localConfig.verticalPadding + 'px',
9+
paddingBottom: localConfig.verticalPadding + 'px',
10+
display: hasDisplayWrapperState ? 'block' : 'none'
1011
}"
1112
>
1213
<div class="gc-header">
13-
<span>{{ config.title }}</span>
14-
<img [class]="{'gc-hide': data.thumb == ''}"
15-
[style]="{width: config.thumbWidth + 'px', height: config.thumbHeight + 'px'}"
16-
[attr.src]="data.thumb"
17-
alt="..."/>
14+
<span>{{ localConfig.title }}</span>
15+
<img
16+
[class]="{'gc-hide': localData.thumb == ''}"
17+
[style]="{
18+
width: localConfig.thumbWidth + 'px',
19+
height: localConfig.thumbHeight + 'px'
20+
}"
21+
[attr.src]="localData.thumb"
22+
alt=""
23+
/>
1824
</div>
19-
<div class="gc-body" [style]="{width: config.width + 'px', height: config.height + 'px'}">
25+
<div
26+
class="gc-body"
27+
[style]="{
28+
width: localConfig.width + 'px',
29+
height: localConfig.height + 'px',
30+
}"
31+
>
2032
<div class="gc-loading">
2133
<loading-icon></loading-icon>
2234
</div>
2335
<img
2436
class="gc-picture"
25-
[class]="{'gc-hide': data.image == ''}"
26-
[style]="{width: config.width + 'px', height: config.height + 'px'}"
27-
[attr.src]="data.image"
28-
alt="..."
37+
[class]="{'gc-hide': localData.image == ''}"
38+
[style]="{
39+
width: localConfig.width + 'px',
40+
height: localConfig.height + 'px',
41+
display: hasDisplayImageState ? 'block' : 'none'
42+
}"
43+
[attr.src]="localData.image"
44+
alt=""
2945
(click)="clickEvent($event)"
3046
/>
3147
<div class="gc-dots">
32-
<div class="gc-dot" *ngFor="let dot of dots;" [style]="{
48+
<div
49+
class="gc-dot"
50+
*ngFor="let dot of dots;"
51+
[style]="{
3352
top: (dot.y - 11) + 'px',
3453
left: (dot.x - 11) + 'px',
35-
}">{{dot.index}}</div>
54+
}"
55+
>{{dot.index}}</div>
3656
</div>
3757
</div>
3858
<div class="gc-footer">
3959
<div class="gc-icon-block gc-icon-block2">
40-
<close-icon [width]="22" [height]="22" (click)="closeEvent($event)"></close-icon>
41-
<refresh-icon [width]="22" [height]="22" (click)="refreshEvent($event)"></refresh-icon>
60+
<close-icon
61+
[width]="localConfig.iconSize"
62+
[height]="localConfig.iconSize"
63+
(click)="closeEvent($event)"
64+
></close-icon>
65+
<refresh-icon
66+
[width]="localConfig.iconSize"
67+
[height]="localConfig.iconSize"
68+
(click)="refreshEvent($event)"
69+
></refresh-icon>
4270
</div>
4371
<div class="gc-button-block">
44-
<button (click)="confirmEvent($event)">{{ config.buttonText }}</button>
72+
<button
73+
[class]="{'disabled': !hasDisplayImageState}"
74+
(click)="confirmEvent($event)"
75+
>{{ localConfig.buttonText }}</button>
4576
</div>
4677
</div>
4778
</div>

projects/go-captcha-angular/src/lib/modules/click/click.component.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
.gc-dot {
1313
position: absolute;
1414
z-index: 2;
15-
width: 20px;
16-
height: 20px;
15+
width: 22px;
16+
height: 22px;
1717
color: #cedffe;
1818
background: #3e7cff;
19-
border: 2px solid #f7f9fb;
19+
border: 3px solid #f7f9fb;
2020
display:-webkit-box;
2121
display:-webkit-flex;
2222
display:-ms-flexbox;

0 commit comments

Comments
 (0)