File tree 4 files changed +67
-114
lines changed
src/app/shared/components/weather 4 files changed +67
-114
lines changed Original file line number Diff line number Diff line change 1
1
< div class ="weather-wrap ">
2
2
< div class ="weather-content ">
3
- < i class ="icon iconfont icon-duoyun type "> </ i >
4
- < span class ="date "> 03-04</ span >
5
- < span class ="low-high "> 29.0℃ ~ 22.0℃</ span >
3
+ < i class ="icon iconfont icon-{{today.type}} type "> </ i >
4
+ < span class ="low-high "> {{today.low}} ~ {{today.high}}</ span >
6
5
< span class ="wind ">
7
6
< i class ="icon iconfont icon-tianqizitiku09 "> </ i >
8
- < 3 级 </ span >
7
+ {{today.fl}} </ span >
9
8
</ div >
10
9
< div class ="weather-bottom ">
11
- < div class ="forecast-item-wrap ">
12
- < i class ="icon iconfont icon-duoyun "> </ i >
13
- < span > 03-04</ span >
14
- </ div >
15
- < div class ="forecast-item-wrap ">
16
- < i class ="icon iconfont icon-duoyun "> </ i >
17
- < span > 03-05</ span >
18
- </ div >
19
- < div class ="forecast-item-wrap ">
20
- < i class ="icon iconfont icon-xiaoyu "> </ i >
21
- < span > 03-06</ span >
22
- </ div >
23
- < div class ="forecast-item-wrap ">
24
- < i class ="icon iconfont icon-xiaoyu "> </ i >
25
- < span > 03-07</ span >
26
- </ div >
27
- < div class ="forecast-item-wrap ">
28
- < i class ="icon iconfont icon-qing "> </ i >
29
- < span > 03-08</ span >
30
- </ div >
10
+ < button class ="switch-btn forecast-item-wrap " [ngClass] ="{'active':item.isSelect} " *ngFor ="let item of data;let i = index "
11
+ (click) ="switch(i) ">
12
+ < i class ="icon iconfont icon-{{item.type}} "> </ i >
13
+ < span > {{item.date}}</ span >
14
+ </ button >
31
15
</ div >
32
16
</ div >
Original file line number Diff line number Diff line change 2
2
.weather-wrap {
3
3
display : flex ;
4
4
flex-direction : column ;
5
+ background : url (https://api.dujin.org/bing/1366.php );
5
6
}
6
7
7
8
.weather-content {
8
9
flex : 1 ;
9
10
height : 200px ;
10
11
.type {
12
+ display : block ;
11
13
font-size : 10em ;
14
+ text-align : center ;
15
+ }
16
+ .low-high {
17
+ display : block ;
18
+ font-size : 2em ;
19
+ text-align : center ;
12
20
}
13
21
}
14
22
17
25
flex-direction : row ;
18
26
flex-wrap : nowrap ;
19
27
width : 100% ;
20
- height : 70px ;
28
+ height : 100px ;
29
+ background : rgba ($card-bg , .8 );
21
30
border-top : 1px solid $border-color ;
22
31
.forecast-item-wrap {
23
32
flex : 1 ;
33
+ background : transparent ;
34
+ border : none ;
24
35
border-right : 1px solid $border-color ;
36
+ outline : none ;
25
37
text-align : center ;
26
38
.icon {
27
39
font-size : 3em ;
31
43
font-size : $sm-text ;
32
44
}
33
45
& :last-child {
34
- border : none ;
46
+ border-right : none ;
35
47
}
36
48
}
49
+ .active {
50
+ border-top : 2px solid $primary ;
51
+ }
37
52
}
Original file line number Diff line number Diff line change @@ -9,14 +9,23 @@ import { WeatherService } from './weather.service';
9
9
} )
10
10
export class WeatherComponent implements OnInit {
11
11
12
+ today ;
12
13
data : Array < any > ;
13
14
constructor ( private _weatherService : WeatherService ) { }
14
15
15
16
ngOnInit ( ) {
16
17
/* this._weatherService.getJSON().subscribe(data => {
17
18
console.log(data);
18
19
}); */
19
- this . data = this . _weatherService . DATA . data . forecast ;
20
+ this . data = this . _weatherService . DATA ;
21
+ this . switch ( 0 ) ;
20
22
}
21
23
24
+ switch ( index ) {
25
+ this . data . forEach ( item => {
26
+ item . isSelect = false ;
27
+ } ) ;
28
+ this . data [ index ] . isSelect = true ;
29
+ this . today = this . data [ index ] ;
30
+ }
22
31
}
Original file line number Diff line number Diff line change @@ -17,91 +17,36 @@ export class WeatherService {
17
17
}
18
18
19
19
20
- DATA = {
21
- "date" : "20180404" ,
22
- "message" : "Success !" ,
23
- "status" : 200 ,
24
- "city" : "深圳" ,
25
- "count" : 410 ,
26
- "data" : {
27
- "shidu" : "87%" ,
28
- "pm25" : 28.0 ,
29
- "pm10" : 51.0 ,
30
- "quality" : "良" ,
31
- "wendu" : "21" ,
32
- "ganmao" : "极少数敏感人群应减少户外活动" ,
33
- "yesterday" : {
34
- "date" : "03日星期二" ,
35
- "sunrise" : "06:16" ,
36
- "high" : "高温 29.0℃" ,
37
- "low" : "低温 21.0℃" ,
38
- "sunset" : "18:40" ,
39
- "aqi" : 47.0 ,
40
- "fx" : "无持续风向" ,
41
- "fl" : "<3级" ,
42
- "type" : "多云" ,
43
- "notice" : "阴晴之间,谨防紫外线侵扰"
44
- } ,
45
- "forecast" : [ {
46
- "date" : "04日星期三" ,
47
- "sunrise" : "06:15" ,
48
- "high" : "高温 29.0℃" ,
49
- "low" : "低温 22.0℃" ,
50
- "sunset" : "18:40" ,
51
- "aqi" : 31.0 ,
52
- "fx" : "无持续风向" ,
53
- "fl" : "<3级" ,
54
- "type" : "多云" ,
55
- "notice" : "阴晴之间,谨防紫外线侵扰"
56
- } ,
57
- {
58
- "date" : "05日星期四" ,
59
- "sunrise" : "06:14" ,
60
- "high" : "高温 30.0℃" ,
61
- "low" : "低温 19.0℃" ,
62
- "sunset" : "18:40" ,
63
- "aqi" : 26.0 ,
64
- "fx" : "无持续风向" ,
65
- "fl" : "<3级" ,
66
- "type" : "多云" ,
67
- "notice" : "阴晴之间,谨防紫外线侵扰"
68
- } ,
69
- {
70
- "date" : "06日星期五" ,
71
- "sunrise" : "06:13" ,
72
- "high" : "高温 25.0℃" ,
73
- "low" : "低温 16.0℃" ,
74
- "sunset" : "18:41" ,
75
- "aqi" : 36.0 ,
76
- "fx" : "北风" ,
77
- "fl" : "3-4级" ,
78
- "type" : "阵雨" ,
79
- "notice" : "阵雨来袭,出门记得带伞"
80
- } ,
81
- {
82
- "date" : "07日星期六" ,
83
- "sunrise" : "06:13" ,
84
- "high" : "高温 21.0℃" ,
85
- "low" : "低温 15.0℃" ,
86
- "sunset" : "18:41" ,
87
- "aqi" : 74.0 ,
88
- "fx" : "无持续风向" ,
89
- "fl" : "<3级" ,
90
- "type" : "阵雨" ,
91
- "notice" : "阵雨来袭,出门记得带伞"
92
- } ,
93
- {
94
- "date" : "08日星期日" ,
95
- "sunrise" : "06:12" ,
96
- "high" : "高温 25.0℃" ,
97
- "low" : "低温 17.0℃" ,
98
- "sunset" : "18:42" ,
99
- "aqi" : 74.0 ,
100
- "fx" : "无持续风向" ,
101
- "fl" : "<3级" ,
102
- "type" : "晴" ,
103
- "notice" : "愿你拥有比阳光明媚的心情"
104
- } ]
105
- }
106
- }
20
+ DATA = [
21
+ {
22
+ "date" : "03-04" ,
23
+ "high" : "29.0℃" ,
24
+ "low" : "22.0℃" ,
25
+ "fl" : "<3级" ,
26
+ "type" : "dayu" ,
27
+ } , {
28
+ "date" : "03-05" ,
29
+ "high" : "29.0℃" ,
30
+ "low" : "22.0℃" ,
31
+ "fl" : "<3级" ,
32
+ "type" : "duoyun" ,
33
+ } , {
34
+ "date" : "03-06" ,
35
+ "high" : "29.0℃" ,
36
+ "low" : "22.0℃" ,
37
+ "fl" : "<3级" ,
38
+ "type" : "leidian" ,
39
+ } , {
40
+ "date" : "03-07" ,
41
+ "high" : "29.0℃" ,
42
+ "low" : "22.0℃" ,
43
+ "fl" : "<3级" ,
44
+ "type" : "qing" ,
45
+ } , {
46
+ "date" : "03-08" ,
47
+ "high" : "29.0℃" ,
48
+ "low" : "22.0℃" ,
49
+ "fl" : "<3级" ,
50
+ "type" : "yintian" ,
51
+ } ]
107
52
}
You can’t perform that action at this time.
0 commit comments