diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/app.js" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/app.js" new file mode 100644 index 0000000000000000000000000000000000000000..1ed57c47fc86716c337dee0e196bdbbac27abfe5 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/app.js" @@ -0,0 +1,19 @@ +// app.js +App({ + onLaunch() { + // 展示本地存储能力 + const logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + } + }) + }, + globalData: { + userInfo: null + } +}) diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/app.json" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/app.json" new file mode 100644 index 0000000000000000000000000000000000000000..d90dbac23e5e4f0defc858c7aab5e5d96758de12 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/app.json" @@ -0,0 +1,20 @@ +{ + "pages":[ + "pages/index/index", + "pages/search/search", + "pages/logs/logs" + ], + "permission": { + "scope.userLocation": { + "desc": "你的位置信息将用于小程序位置接口的效果展示" + } + }, + "window":{ + "backgroundTextStyle":"light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "天气预报", + "navigationBarTextStyle":"black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/app.wxss" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/app.wxss" new file mode 100644 index 0000000000000000000000000000000000000000..60194c3c05e1208ab0d1b6b00f60cd0a0296ee7f --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/app.wxss" @@ -0,0 +1,2 @@ +/**app.wxss**/ + diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.js" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.js" new file mode 100644 index 0000000000000000000000000000000000000000..f970764095a36f1596fda6e7a31d80aec473f0db --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.js" @@ -0,0 +1,124 @@ +// index.js +// 获取应用实例 +const app = getApp() +Page({ + data: { + city:'龙岩', + rq:['2021-7-12','2021-7-13','2021-7-14','2021-7-15','2021-7-16'], + days:['今天','明天','后天'], + locationX:'', + locationY:'' + }, + + onLoad: function (option) { + if(option.lat&&option.lon){ + this.getCityByLocation(option.lat,option.lon) + }else{ + this.getLocationXY() + } + }, + //获得当前的坐标,通过百度地图API + // + getLocationXY: function () { + var that=this; + wx.getLocation({ + success: function(res) { + var locationX=res.latitude; + var locationY=res.longitude; + //通过坐标获得具体的位置 + that.getCityByLocation(locationX, locationY); + }, + }) + }, + //通过坐标获得具体的位置名称,关联腾讯地图API + + getCityByLocation: function (locationX,locationY) { + var that=this; + + wx.request({ + url: 'https://geoapi.qweather.com/v2/city/lookup', + data:{ + location:locationY+","+locationX, + key: '6c764218c0694a068da82b510b7a5ec8', + }, + success:function(res){ + // console.log(that.data.city) + var city=res.data.location[0].adm2; + that.setData({city:city}); + }, + fail:function(res){}, + complete:function(res){}, + + }); + var that=this; + console.log(that.data.city) + //和风api 获取天气 + wx.request({ + url: 'https://devapi.qweather.com/v7/weather/now', + data:{ + location:locationY+","+locationX, + key:'6c764218c0694a068da82b510b7a5ec8', + }, + success:function(res){ + console.log(res) + console.log(res.data.now); + var now = res.data.now + that.setData({ + info:{weather:now} + }) + + // }else if(now.text=='阴'){ + // document.getElementById('backgorund').className='cloudy' + // }else if(now.text=='小雨'||now.text=='大雨'||now.text=='雷阵雨'){ + // document.getElementById('backgorund').className='rain' + // } + }, + fail:function(res){}, + + }) + //和风天气天信息 + wx.request({ + url: 'https://devapi.qweather.com/v7/weather/3d?', + data:{ + location:locationY+","+locationX, + key:'c82edbacf76d4f0e8921b0fd3ffe7410', + }, + success:function(res){ + console.log(res.data.daily) + var future = res.data.daily + that.setData({ + future:future + }) + console.log('----',that.data.future); + }, + fail:function(res){}, + + }) + + }, + + onShow: function () { + + }, + + onHide: function () { + + }, + + onUnload: function () { + + }, + + onPullDownRefresh: function () { + + }, + + onReachBottom: function () { + + }, + + onShareAppMessage: function () { + + } +}) + diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.json" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.json" new file mode 100644 index 0000000000000000000000000000000000000000..8835af0699ccec004cbe685ef938cd2d63ea7037 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.json" @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.wxml" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.wxml" new file mode 100644 index 0000000000000000000000000000000000000000..48ba22d1ce86283e3f3d02c9ade239ae0b573978 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.wxml" @@ -0,0 +1,66 @@ + + + + ➣{{city}} + {{item.temp}}℃ + + + {{item.text}} + + + + 湿度 {{item.humidity}}% + + + + + + + + 未来天气预报 + + {{item.fxDate}} + {{days[index]}} + ☀ {{item.textDay}} + 🌦 {{item.textDay}} + 🌦 {{item.textDay}} + 🌦 {{item.textDay}} + 🌤 {{item.textDay}} + ⛈ {{item.textDay}} + ☁ {{item.textDay}} + {{item.tempMin}}℃/{{item.tempMax}}℃ + + + + + \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.wxss" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.wxss" new file mode 100644 index 0000000000000000000000000000000000000000..e288bd584558cc1e7f7ae510d045abe968728c14 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/index/index.wxss" @@ -0,0 +1,92 @@ +.sunny{ + background: url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20170717%2Fcd138e1e901b428b97ef8e2e94f32205.gif&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628668338&t=ade6809ad523c7baad9ab2815e74bfb1) no-repeat; +} +.cloudy{ + background: url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20180629%2F2c4019a426bf41fdb8799622c84807c1.gif&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628759006&t=445af0fd4d450e3999ece6c2a760831d + ) no-repeat; +} +.rain{ + background: url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F10183610447%2F0.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628758199&t=b125e946575b1bdc1e2a3c65bd018e49 + ) no-repeat; +} +.content{ + width: 100%; + height: auto; + position: absolute; + color: white; + font-size: 15px; + font-family: 微软雅黑,宋体; +} +.location{ + background-size: 100% 100%; + height: auto; + /* text-align: center; */ +} +.dq{ + font-size: 30px; + margin-bottom: 10px; + padding: 30rpx 0rpx 0rpx 20rpx; +} + +.tmp{ + font-size: 60px; + text-align: center; + width: 100%; +} +.other{ + padding-top:30px; + margin-left: 15px; + width: 100%; + flex-direction: row; + justify-content: space-around; + display: flex; +} +.x{ + font-size: 30px; +} + +.fgx{ + border: 1px solid white; +} +.bt{ + font-size: 20px; + padding: 30px 0px 0px 10px; + color: white; +} +.future{ + height: 100%; + flex-direction: row; + justify-content: space-around; + background-image: linear-gradient(to bottom right, rgb(0,44,130), skyblue); +} +.img{ + width: 60rpx; + height: 60rpx; +} + .day{ + padding: 30px; + font-size: 20px; + flex-direction: row; + justify-content: space-around; + display: flex; + border-bottom: 1px solid gray; + margin-left: 10px; +} +.future .x{ + font-size: 15px; +} +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} +.container { + height: 100%; + display: flex; + flex-direction: column; + box-sizing: border-box; +} \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.js" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.js" new file mode 100644 index 0000000000000000000000000000000000000000..85f6aac5ab16db728fa27cdf75c4ab2126b1105b --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.js" @@ -0,0 +1,18 @@ +// logs.js +const util = require('../../utils/util.js') + +Page({ + data: { + logs: [] + }, + onLoad() { + this.setData({ + logs: (wx.getStorageSync('logs') || []).map(log => { + return { + date: util.formatTime(new Date(log)), + timeStamp: log + } + }) + }) + } +}) diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.json" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.json" new file mode 100644 index 0000000000000000000000000000000000000000..3ee76c183c748834923c80f78292e46d739d556e --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.json" @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "查看启动日志", + "usingComponents": {} +} \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.wxml" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.wxml" new file mode 100644 index 0000000000000000000000000000000000000000..0b6b6456f7ac8b92181e8aff296890fd7d3d86a3 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.wxml" @@ -0,0 +1,6 @@ + + + + {{index + 1}}. {{log.date}} + + diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.wxss" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.wxss" new file mode 100644 index 0000000000000000000000000000000000000000..94d4b88a27dcea1fbaa6da8fc19c6a8821983924 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/logs/logs.wxss" @@ -0,0 +1,8 @@ +.log-list { + display: flex; + flex-direction: column; + padding: 40rpx; +} +.log-item { + margin: 10rpx; +} diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.js" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.js" new file mode 100644 index 0000000000000000000000000000000000000000..7a5a1370ee37c4f92f66567aeb68605bf4ac2399 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.js" @@ -0,0 +1,112 @@ + +const app = getApp(); +Page({ + data: { + isSearch: false, + result: [], + value: '', + hotCity: ['北京市', '深圳', '广州', '哈尔滨','厦门','上海'], + history: [] + }, + inputHandle(e) { + const { value } = e.detail + if (value) { + wx.request({ + url: 'https://geoapi.qweather.com/v2/poi/lookup', + data:{ + key:'7364f1d6588041229b5a69633d058c95', + location:value, + type:"scenic" + }, + success:function (res) { + console.log('--------',res.data) + var lat = res.data.poi[0].lat + var lon = res.data.poi[0].lon + wx.navigateTo({ + url: '/pages/index/index?lat='+lat+'&lon='+lon, + }) + } + }) + // wx.navigateTo({ + // url: '/page/index/index?vule', + // }) + } + }, + onLoad() { + this.setData({ + history: this.getLocal() + }) + // console.log("--------",app.globalData.hotCity); + }, + cancelHandle() { + wx.navigateBack() + }, + selectItem(e) { + const { lat, lng } = e.currentTarget.dataset + console.log('-----',e) + wx.navigateTo({ + url: `pages/index/index` + }) + }, + clearHandle() { + this.setData({ + value: '' + }) + }, + clearHistory() { + wx.removeStorage({ key: 'history'}) + this.setData({ + history: [] + }) + }, + dwHandle() { + wx.navigateTo({ + url: `/pages/index/index` + }) + }, + hotHandle(e) { + const { value } = e.currentTarget.dataset + this.setLocal(value) + wx.request({ + url: 'https://geoapi.qweather.com/v2/poi/lookup', + data:{ + key:'7364f1d6588041229b5a69633d058c95', + location:value, + type:"scenic" + }, + success:function (res) { + console.log('------------------------------------',res) + var lat = res.data.poi[0].lat + var lon = res.data.poi[0].lon + wx.navigateTo({ + url: '/pages/index/index?lat='+lat+'&lon='+lon, + }) + } + }) + }, + // 设置历史记录 + setLocal(val) { + const arr = this.getLocal() + if (!arr.includes(val)) { + console.log(arr) + arr.push(val) + wx.setStorageSync('history', arr) + } + }, + getLocal() { + return wx.getStorageSync('history') ? wx.getStorageSync('history') : [] + }, + delHandle(e) { + const { value } = e.currentTarget.dataset + const arr = this.getLocal() + if (arr.includes(value)) { + const index = arr.indexOf(value) + arr.splice(index, 1) + wx.setStorageSync('history', arr) + this.setData({ + history: arr + }) + + } + } +}) \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.json" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.json" new file mode 100644 index 0000000000000000000000000000000000000000..8835af0699ccec004cbe685ef938cd2d63ea7037 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.json" @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.wxml" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.wxml" new file mode 100644 index 0000000000000000000000000000000000000000..935aaced7b5e48589d940581f264d437d947e2ae --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.wxml" @@ -0,0 +1,44 @@ + + + + + + + + + + + + + {{item.title}}, + {{item.city}}, + {{item.province}} + + + + 热门城市 + + 定位 + {{item}} + + 历史搜索 + + + {{item}} + + + + 清空历史 + + \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.wxss" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.wxss" new file mode 100644 index 0000000000000000000000000000000000000000..026040bb50a3d9958705c6ddb322e07e0dce2bf0 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/pages/search/search.wxss" @@ -0,0 +1,93 @@ +.search-input { + padding: 10px; + display: flex; +} + +.search-input .input-wrap { + display: flex; + align-items: center; + justify-content: center; + margin: 0 10px; + font-size: 14px; + flex: 1; +} +.search-input .icon-search { + margin-right: 10px; +} +.search-input .icon-del { + color: #e9e9e9; +} +.search-input .input { + flex: 1; +} + +.search-input .cancel{ + font-size: 14px; + border: 0; +} + +.result .item { + font-size: 12px; + padding: 10px; +} + +.history .clear { + font-size: 14px; +} + +.default .title { + display: block; + padding: 10px; + font-size: 14px; +} + +.hot, +.history { + width:calc(100% - 20px); + margin: auto; +} +.hot .item.dw { + background: rgb(123, 180, 228); + border-radius: 5px; + color: #fff; +} + +.hot .item, +.history .item { + float: left; + font-size: 14px; + width:calc((100% - 30px) / 3); + margin-right: 10px; + margin-bottom: 10px; + text-align: center; + line-height: 30px; +} + +.hot .item:nth-child(3n), +.hot .history:nth-child(3n) { + margin-right: 10px; +} + +.history .icon-del { + padding: 10px; +} + +.clear-h { + color: rgb(211, 210, 210); + display: block; + font-size: 14px; + text-align: center; +} + +.clear { + zoom:1; +} + +.clear:after { + clear:both; + content:''; + display:block; + width:0; + height:0; + visibility:hidden; +} \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/project.config.json" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/project.config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e27668277b02a61b6e0fd8660132dc1102d2f7a0 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/project.config.json" @@ -0,0 +1,72 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "enhance": false, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": false, + "coverView": true, + "nodeModules": false, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": true, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "lazyloadPlaceholderEnable": false, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": false, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "enableEngineNative": false, + "useIsolateContext": true, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "showES6CompileOption": false + }, + "compileType": "miniprogram", + "libVersion": "2.17.0", + "appid": "wx7cc3e303d5902b33", + "projectname": "weatherSearch", + "debugOptions": { + "hidedInDevtools": [] + }, + "scripts": {}, + "isGameTourist": false, + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, + "condition": { + "search": { + "list": [] + }, + "conversation": { + "list": [] + }, + "game": { + "list": [] + }, + "plugin": { + "list": [] + }, + "gamePlugin": { + "list": [] + }, + "miniprogram": { + "list": [] + } + } +} \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/sitemap.json" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/sitemap.json" new file mode 100644 index 0000000000000000000000000000000000000000..ca02add20b581be471b8d17f887b8e8337070546 --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/sitemap.json" @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git "a/\345\272\204\346\230\255\345\261\261/weatherSearch/utils/util.js" "b/\345\272\204\346\230\255\345\261\261/weatherSearch/utils/util.js" new file mode 100644 index 0000000000000000000000000000000000000000..764bc2ce26ab9b55a21cbb069dcf084a8418dffd --- /dev/null +++ "b/\345\272\204\346\230\255\345\261\261/weatherSearch/utils/util.js" @@ -0,0 +1,19 @@ +const formatTime = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` +} + +const formatNumber = n => { + n = n.toString() + return n[1] ? n : `0${n}` +} + +module.exports = { + formatTime +}