Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Commit 041fc84

Browse files
committed
new discovery
1 parent c0fa970 commit 041fc84

28 files changed

+289
-124
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"axios": "^0.16.1",
1313
"fastclick": "^1.0.6",
14+
"jsonp": "^0.2.1",
1415
"leaflet": "^1.0.2",
1516
"leaflet.locatecontrol": "^0.60.0",
1617
"object-assign": "^4.1.1",

src/components/GridLink.vue

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<card :header="{title:'更多服务'}">
3+
<grid slot="content">
4+
<grid-item v-for="item in items" :label="item.label" :link="item.link">
5+
<img slot="icon" :src="item.img">
6+
</grid-item>
7+
</grid>
8+
</card>
9+
</template>
10+
11+
<script>
12+
import { mapMutations } from 'vuex'
13+
import { Grid, GridItem, Card } from 'vux'
14+
15+
export default {
16+
data() {
17+
return {
18+
items: [{
19+
label: "百度",
20+
link: "https://www.baidu.com",
21+
img: require("../assets/vux_logo.png"),
22+
}, {
23+
label: "滴滴",
24+
link: "https://common.diditaxi.com.cn/general/webEntry?code=031RcUHP1bDB5717NpHP1U6KHP1RcUHV&state=123#/",
25+
img: require("../assets/vux_logo.png"),
26+
}, {
27+
label: "美团外卖",
28+
link: "https://takeaway.dianping.com/waimai/wxwallet#!index/source=redir",
29+
img: require("../assets/vux_logo.png"),
30+
}]
31+
}
32+
},
33+
34+
components: {
35+
Grid,
36+
GridItem,
37+
Card
38+
},
39+
40+
mounted() {
41+
this.SET_TITLE(this.$t('Discovery'))
42+
this.SET_RIGHT_OPTION({show:false})
43+
},
44+
45+
methods: {
46+
...mapMutations(['SET_TITLE','SET_RIGHT_OPTION'])
47+
}
48+
}
49+
</script>

src/network/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export const WEATHERUID = 'U4B4E3B9B9'
12
export const WEATHERKEY = '5wetuvenll5qucca'
23
export const AMAPKEY = 'ea889682997a181fd6678d9aaf23693a'
34
export const weatherhost = 'https://api.thinkpage.cn/v3/weather'

src/network/getFutureWeather.js

Whitespace-only changes.

src/network/getNowWeather.js

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

src/network/getWeather.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import axios from 'axios'
2+
import { weatherhost } from './api'
3+
4+
export const getFutureWeather = (params) => axios.get(weatherhost + '/daily.json', {params})
5+
6+
export const getNowWeather = (params) => axios.get(weatherhost + '/now.json', {params})

src/network/jsonp.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import jsonp from 'jsonp'
2+
import querystring from 'querystring'
3+
4+
export default function(url, data, params) {
5+
return new Promise((resolve, reject) => {
6+
if (data) url += "?" + querystring.stringify(data)
7+
params = params || {timeout: 15000}
8+
if (!params.timeout) params.timeout = 15000
9+
jsonp(url, params, (err, data) => {
10+
if (err) {
11+
reject(err)
12+
} else {
13+
resolve(data)
14+
}
15+
})
16+
})
17+
}

src/pages/Discovery.vue

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,37 @@
11
<template>
2-
<grid>
3-
<grid-item v-for="item in items" :label="item.label" :link="item.link">
4-
<img slot="icon" :src="item.img">
5-
</grid-item>
6-
</grid>
2+
<panel header="我的博客" :footer="footer" :list="list" :type="type"></panel>
73
</template>
84

95
<script>
10-
import {mapMutations} from 'vuex'
11-
import { Grid, GridItem } from 'vux'
6+
import {Panel} from 'vux'
7+
8+
export default {
9+
components:{
10+
Panel,
11+
},
1212
13-
export default {
14-
data() {
15-
return {
16-
items: [{
17-
label: "百度",
18-
link: "https://www.baidu.com",
19-
img: require("../assets/vux_logo.png"),
20-
}, {
21-
label: "滴滴",
22-
link: "https://common.diditaxi.com.cn/general/webEntry?code=031RcUHP1bDB5717NpHP1U6KHP1RcUHV&state=123#/",
23-
img: require("../assets/vux_logo.png"),
24-
}, {
25-
label: "美团外卖",
26-
link: "https://takeaway.dianping.com/waimai/wxwallet#!index/source=redir",
27-
img: require("../assets/vux_logo.png"),
28-
}]
13+
data(){
14+
return {
15+
type:'1',
16+
list: [{
17+
src: 'http://placeholder.qiniudn.com/60x60/3cc51f/ffffff',
18+
title: '标题一',
19+
desc: '由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨道。',
20+
url: '/component/cell'
21+
}, {
22+
src: 'http://placeholder.qiniudn.com/60x60/3cc51f/ffffff',
23+
title: '标题二',
24+
desc: '由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨道。',
25+
url: {
26+
path: '/component/radio',
27+
replace: false
28+
}
29+
}],
30+
footer: {
31+
title: '查看更多',
32+
url: 'http://vux.li'
33+
}
34+
}
35+
}
2936
}
30-
},
31-
32-
components: {
33-
Grid,
34-
GridItem,
35-
},
36-
37-
mounted() {
38-
this.SET_TITLE(this.$t('Discovery'))
39-
this.SET_RIGHT_OPTION({show:false})
40-
},
41-
42-
methods: {
43-
...mapMutations(['SET_TITLE','SET_RIGHT_OPTION'])
44-
}
45-
}
4637
</script>

src/pages/Setting.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
<popup-picker :title="$t('Language')" :data="langs" v-model="currentLang" @on-change="onChange"></popup-picker>
1010
<cell :title="$t('About')" link="/about" is-link></cell>
1111
</group>
12+
<grid-link></grid-link>
1213
</div>
1314
</template>
1415

1516
<script>
1617
import { mapMutations } from 'vuex'
1718
import { Group, Cell, Blur, PopupPicker } from 'vux'
19+
import GridLink from '../components/GridLink'
1820
1921
export default {
2022
components: {
2123
Group,
2224
Cell,
2325
Blur,
2426
PopupPicker,
27+
GridLink,
2528
},
2629
2730
computed: {

src/pages/Weather.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<div class="vux-1px-t vux-1px-b future-box" v-for="item in future">
1010
<span class="future-text">{{item.day}}</span>
1111
<span class="future-text">日</span>
12-
<img class="future-img" :src="require(`../assets/weather/${item.codeDay}.png`)">
12+
<img class="future-img" :src="require(`../assets/weather/${item.code_day}.png`)">
1313
<span class="future-text">夜</span>
14-
<img class="future-img" :src="require(`../assets/weather/${item.codeNight}.png`)">
14+
<img class="future-img" :src="require(`../assets/weather/${item.code_night}.png`)">
1515
<span class="future-text">{{item.high}}</span>
1616
<span class="future-text">{{item.low}}</span>
1717
</div>
@@ -20,21 +20,28 @@
2020
</template>
2121

2222
<script>
23-
import { mapMutations, mapGetters} from 'vuex'
23+
24+
import { mapMutations, mapGetters, mapActions} from 'vuex'
2425
2526
export default {
2627
2728
computed:{
2829
...mapGetters(['now', 'future'])
2930
},
3031
32+
created(){
33+
const fetch = [this.loadNowWeather(), this.loadDailyWeather()]
34+
Promise.all(fetch)
35+
},
36+
3137
mounted() {
3238
this.SET_TITLE('天气')
3339
this.SET_RIGHT_OPTION({show:true,name:'城市',link:'cities'})
3440
},
3541
3642
methods: {
37-
...mapMutations(['SET_TITLE','SET_RIGHT_OPTION'])
43+
...mapMutations(['SET_TITLE','SET_RIGHT_OPTION']),
44+
...mapActions(['loadNowWeather','loadDailyWeather'])
3845
}
3946
}
4047
</script>

src/store/actions.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { makeAction } from '../utils/actionTools'
22
import * as types from './mutation-types'
3+
import { getNowWeather, getFutureWeather } from '@/network/getWeather'
4+
import { weatherhost, WEATHERKEY, WEATHERUID } from '@/network/api'
5+
import jsonp from '@/network/jsonp'
6+
import { base64 } from 'vux'
7+
const crypto = require('crypto')
8+
import querystring from 'querystring'
39

410
export const loadCoordinates = ({ commit }) => { }
511

@@ -11,4 +17,65 @@ export const toggleCity = makeAction(types.TOGGLE_CITY)
1117

1218
export const updateDirction = makeAction(types.UPDATE_DIRECTION)
1319

14-
// export const getNowWeather =
20+
export const loadNowWeather = ({commit}) => {
21+
getNowWeather({
22+
key:WEATHERKEY,
23+
location: 'shenzhen',
24+
language:'zh-Hans',
25+
unit:'c',
26+
}).then((res)=>{
27+
commit('SET_NOW_WEATHER', res.data.results[0].now)
28+
})
29+
}
30+
31+
export const loadDailyWeather = ({commit}) => {
32+
getFutureWeather({
33+
key:WEATHERKEY,
34+
location: 'shenzhen',
35+
language:'zh-Hans',
36+
unit:'c',
37+
start:0,
38+
days:5,
39+
}).then((res)=>{
40+
commit('SET_FUTURE_WEATHER', res.data.results[0].daily)
41+
})
42+
}
43+
44+
// export const loadNowWeather = ({ commit, state }) => {
45+
46+
// var params = {}
47+
// params.ts = Math.floor((new Date()).getTime() / 1000); // 当前时间戳
48+
// params.ttl = 300; // 过期时间
49+
// params.uid = WEATHERUID; // 用户ID
50+
51+
// var str = querystring.encode(params); // 构造请求字符串
52+
53+
// // 使用 HMAC-SHA1 方式,以API密钥(key)对上一步生成的参数字符串进行加密
54+
// params.sig = crypto.createHmac('sha1', WEATHERKEY)
55+
// .update(str)
56+
// .digest('base64'); // 将加密结果用 base64 编码,并做一个 urlencode,得到签名 sig
57+
58+
59+
// params.language = 'zh-Hans'
60+
// params.unit = 'c'
61+
// params.location = state.now.cityName
62+
63+
// jsonp(weatherhost + '/now.json', params).then((res) => {
64+
// commit('SET_NOW_WEATHER', res.data.results[0].now)
65+
// })
66+
// }
67+
// export const loadDailyWeather = ({ commit, state }) => {
68+
// const params = Object.assign({
69+
// uid: WEATHERUID,
70+
// ts: new Date().getTime(),
71+
// sig: crypto.createHmac("sha1", WEATHERKEY).digest().toString('base64'),
72+
// language: 'zh-Hans',
73+
// unit: 'c',
74+
// start: 0,
75+
// days: 3
76+
// }, { location: state.now.cityName })
77+
78+
// jsonp(weatherhost + '/daily.json', params).then((res) => {
79+
// commit('SET_FUTURE_WEATHER', res.data.results[0].daily)
80+
// })
81+
// }

src/store/mutations.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ export default {
3434
},
3535

3636
[types.SET_NOW_WEATHER](state, now){
37-
state.now = now
37+
state.now = Object.assign(state.now, now)
3838
},
3939

4040
[types.SET_FUTURE_WEATHER](state, future){
4141
state.future = future
42+
state.future[0].day = '今日'
43+
state.future[1].day = '明天'
44+
state.future[2].day = '后天'
4245
}
4346
}

src/store/store.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,30 @@ const state = {
3030
cityName: 'Shenzhen',
3131
text: 'Sunny',
3232
temperature: 20,
33+
code:'14',
3334
},
3435
future: [
3536
{
3637
day: '今日',
37-
codeDay: '1',
38-
codeNight: '2',
38+
date: '2017-05-13',
39+
code_day: '1',
40+
code_night: '2',
3941
high: 25,
4042
low: 20,
4143
},
4244
{
4345
day: '明天',
44-
codeDay: '1',
45-
codeNight: '2',
46+
date: '"2017-05-14"',
47+
code_day: '1',
48+
code_night: '2',
4649
high: 25,
4750
low: 20,
4851
},
4952
{
50-
day: '后天',
51-
codeDay: '1',
52-
codeNight: '2',
53+
day:'后天',
54+
date: '"2017-05-15"',
55+
code_day: '1',
56+
code_night: '2',
5357
high: 25,
5458
low: 20,
5559
},

www/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><title></title><meta name=format-detection content="telephone=no"><meta name=format-detection content="email=no"><meta name=apple-mobile-web-app-capable content=yes><meta name=apple-mobile-web-app-status-bar-style content=black><link href=static/css/app.c6cd963247f10bcd2bc803ef623e0506.css rel=stylesheet></head><body ontouchstart><div id=app></div><script type=text/javascript src=static/js/manifest.bfe82b42cf8a38e31fe7.js></script><script type=text/javascript src=static/js/vendor.e0d3a0d1c4d6e0fcae0e.js></script><script type=text/javascript src=static/js/app.39248fcefdfe65656f6a.js></script></body></html>
1+
<!DOCTYPE html><html><head><title></title><meta name=format-detection content="telephone=no"><meta name=format-detection content="email=no"><meta name=apple-mobile-web-app-capable content=yes><meta name=apple-mobile-web-app-status-bar-style content=black><link href=static/css/app.4991fa34f3c2b5f8f86172c9c2ae23e8.css rel=stylesheet></head><body ontouchstart><div id=app></div><script type=text/javascript src=static/js/manifest.e883c423124f145cf9eb.js></script><script type=text/javascript src=static/js/vendor.6ad37f95fe52935f074a.js></script><script type=text/javascript src=static/js/app.86e8f1bb15306bd55091.js></script></body></html>

www/static/css/app.4991fa34f3c2b5f8f86172c9c2ae23e8.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/static/css/app.4991fa34f3c2b5f8f86172c9c2ae23e8.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/static/css/app.c6cd963247f10bcd2bc803ef623e0506.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

www/static/css/app.c6cd963247f10bcd2bc803ef623e0506.css.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

www/static/js/app.39248fcefdfe65656f6a.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

www/static/js/app.39248fcefdfe65656f6a.js renamed to www/static/js/app.86e8f1bb15306bd55091.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/static/js/app.86e8f1bb15306bd55091.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/static/js/manifest.bfe82b42cf8a38e31fe7.js

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

www/static/js/manifest.e883c423124f145cf9eb.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)