-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
107 lines (102 loc) · 3.02 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>weather</title>
<link rel="stylesheet" href="libs/bootstrap.css">
<style type="text/css">
header a {
display: inline-block;
}
header a img {
display: block;
}
h1 {
display: inline-block;
color: orange;
vertical-align: 10px;
}
.item {
border: solid 1px #eee;
margin-bottom: 20px;
}
</style>
</head>
<body ng-app="Weather">
<div class="container" ng-controller="MainCtrl">
<div class="row title">
<header class="col-xs-12 text-center">
<a href="#"><img src="images/loginlogo.png" alt="" class="img-responsive"></a>
<h1>天气应用</h1>
</header>
<div class="col-xs-12 col-md-12">
<div class="text-center">
<p>{{ Data.today.city }}</p>
<p>{{ Data.today.week }}</p>
<p>{{ Data.today.date_y }}</p>
<hr>
<h4>今天天气</h4>
<p>{{ Data.today.weather }}</p>
<p>{{ Data.today.temperature }}</p>
<p>湿度: {{ Data.sk.humidity }}</p>
<p>{{ Data.today.wind }}</p>
<p>穿衣指数: {{ Data.today.dressing_index }}</p>
<p>洗车指数: {{ Data.today.wash_index }}</p>
<p>旅行指数: {{ Data.today.travel_index }}</p>
<p>锻炼指数: {{ Data.today.exercise_index }}</p>
<p>紫外线指数: {{ Data.today.uv_index }}</p>
</div>
<hr>
</div>
<h4 class="text-center">未来6天天气</h4>
<div class="col-xs-4 col-md-2" ng-repeat="item in items">
<div class="text-center item">
<h5>{{ item.week }}</h5>
<p>{{ item.temperature }}</p>
<p>{{ item.weather }}</p>
<p>{{ item.wind }}</p>
</div>
</div>
</div>
</div>
<!-- js -->
<script type="text/javascript" src="libs/jquery.js"></script>
<!-- <script type="text/javascript" src="libs/angular.js"></script> -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("Weather", []);
app.factory("WeatherApi", function ($http) {
var obj = {};
// 获取当前位置
obj.getIP = function () {
return $http.jsonp("http://ipinfo.io/json?callback=JSON_CALLBACK");
}
//
obj.getCurrent = function (ip) {
var api = "http://v.juhe.cn/weather/ip?format=1";
var APPkey = "&key=4b77aef93545c80f9b02d99d342c6e7d&ip=";
var cb = "&callback=JSON_CALLBACK";
return $http.jsonp(api + APPkey + ip + cb);
}
return obj;
});
app.controller("MainCtrl", function ($scope, WeatherApi) {
$scope.Data = {};
WeatherApi.getIP().then(function (data) {
var ip = data.data.ip;
WeatherApi.getCurrent(ip).then(function (data) {
console.log(data.data.result);
$scope.Data = data.data.result;
$scope.items = data.data.result.future;
// delete
delete $scope.items[Object.keys($scope.items)[0]];
}, function (err) {
console.log(err);
})
})
})
</script>
</body>
</html>