123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- const weather = 'https://free-api.heweather.net/s6/weather'
- const future = 'http://v.juhe.cn/weather/index'
- const air = 'https://free-api.heweather.net/s6/air/now'
- const locl = 'http://apis.juhe.cn/geo/'
- const QQ_MAP_KEY1 = '630ac2e3d80941b48c80fe3a8ed1a042'
- const QQ_MAP_KEY2 = 'c649beb3621c84ee57c365f45a9a6ed4'
- const QQ_MAP_KEY3 = 'dd35eaa26348f268f1f02b4a8fbe4aaf'
- //添加finally事件
- Promise.prototype.finally = function (callback) {
- var Promise = this.constructor;
- return this.then(
- function (value) {
- Promise.resolve(callback()).then(
- function () {
- return value;
- }
- );
- },
- function (reason) {
- Promise.resolve(callback()).then(
- function () {
- throw reason;
- }
- );
- }
- );
- }
- // 实况天气
- function getWeather(location) {
- return new Promise((resolve, reject) => {
- uni.request({
- url: weather+"/now",
- data: {
- location:location,
- key: QQ_MAP_KEY1
- },
- success: (res) => {
- resolve({result: res.data})
- },
- fail: (e) => {
- reject(e)
- },
- complete: (e) => {
-
- }
- })
- })
- }
- // 未来天气
- function getFuture(location) {
- return new Promise((resolve, reject) => {
- uni.request({
- url: weather+"/forecast",
- data: {
- location:location,
- key: QQ_MAP_KEY1
- },
- success: (res) => {
- resolve({result: res.data})
- },
- fail: (e) => {
- reject(e)
- },
- complete: (e) => {
-
- }
- })
- })
- }
- // 生活指数
- function getLift(location) {
- return new Promise((resolve, reject) => {
- uni.request({
- url: weather+"/lifestyle",
- data: {
- location:location,
- key: QQ_MAP_KEY1,
- },
- success: (res) => {
- resolve({result:res.data})
- },
- fail: (e) => {
- reject(e)
- }
- })
- })
- }
- // 空气质量---废弃
- function getAir(location) {
- return new Promise((resolve, reject) => {
- uni.request({
- url: air,
- data: {
- location:location,
- key: QQ_MAP_KEY1,
- },
- success: (res) => {
- resolve({result:res.data})
- },
- fail: (e) => {
- reject(e)
- }
- })
- })
- }
- // 經緯度逆解析
- function gelocation(obj) {
- return new Promise((resolve, reject) => {
- uni.request({
- url: "/api/geo/",
- data: {
- key: QQ_MAP_KEY3,
- lat:obj.lat,
- lng:obj.lng,
- type:1
- },
- success: (res) => {
- resolve({result:res.data})
- },
- fail: (e) => {
- reject(e)
- }
- })
- })
- }
- export {
- getWeather,
- getFuture,
- getLift,
- getAir,
- gelocation
- }
- // export const getWeather = (location) => {
- // return new Promise((resolve, reject) => {
- // wx.request({
- // url: 'https://free-api.heweather.net/s6/weather/now',
- // data: {
- // location:location,
- // key: QQ_MAP_KEY1
- // },
- // success: (res) => {
- // resolve({result: res.data})
- // },
- // fail: (e) => {
- // reject(e)
- // },
- // complete: (e) => {
- //
- // }
- // })
- // })
- // }
- // 未来七天天气
- // export const getFuture = (location) => {
- // return new Promise((resolve, reject) => {
- // wx.request({
- // url: 'http://v.juhe.cn/weather/index',
- // data: {
- // cityname:location,
- // key: QQ_MAP_KEY2
- // },
- // success: (res) => {
- // console.log(res)
- // resolve({result: res.data})
- // },
- // fail: (e) => {
- // console.log("haha chucuo 2 ")
- // reject(e)
- // }
- // })
- // })
- // }
- // 生活指数
- // export const getLift = (location) => {
- // return new Promise((resolve, reject) => {
- // wx.request({
- // url: 'https://free-api.heweather.net/s6/weather/lifestyle',
- // data: {
- // location:location,
- // key: QQ_MAP_KEY1,
- // },
- // success: (res) => {
- // resolve({result:res.data})
- // },
- // fail: (e) => {
- // reject(e)
- // }
- // })
- // })
- // }
- // 获取空气质量
- // export const getAir = (location) => {
- // return new Promise((resolve, reject) => {
- // wx.request({
- // url: 'https://free-api.heweather.net/s6/air/now',
- // data: {
- // location:location,
- // key: QQ_MAP_KEY1,
- // },
- // success: (res) => {
- // resolve({result:res.data})
- // },
- // fail: (e) => {
- // reject(e)
- // }
- // })
- // })
- // }
- // 经纬度逆向解析
- // export const gelocation = (obj) => {
- // return new Promise((resolve, reject) => {
- // wx.request({
- // url: 'http://apis.juhe.cn/geo/',
- // data: {
- // key: QQ_MAP_KEY3,
- // lat:obj.lat,
- // lng:obj.lng,
- // type:1
- // },
- // success: (res) => {
- // resolve({result:res.data})
- // },
- // fail: (e) => {
- // reject(e)
- // }
- // })
- // })
- // }
|