(function() { var sk, future, today, isOpen = false, WeatherIcon = [ { text: '多云', icon: './img/b1.png' }, { text: '晴', icon: './img/b0.png' }, { text: '阴', icon: './img/b2.png' }, { text: '雨', icon: './img/b8.png' } ]; var cityLitst = [ '合肥','蚌埠','六安','北京','南京' ], newList = []; var cityLists = localStorage.getItem("cityList") == null ? [] : JSON.parse(localStorage.getItem("cityList")); function getIp() { get({ url: '/ip', data: {}, callback (res) { var city = res.city; city.indexOf("省") > -1 ? city = city.split("省")[1] : city; getCityWeather(city) } }) } function getCityWeather(city) { get({ url: '/getWeather', data: { cityname : city }, callback (res) { sk = res.sk; future = res.future; today = res.today; $(".title_city").text(today.city) $(".content_top h2").text(`${sk.temp}°`) $(".content_top p").text(`${sk.humidity} | ${sk.wind_direction} | ${sk.wind_strength}`) RenderToday(); RenderFuture(); } }) } function RenderToday () { var list = [ { text: '温度: ', value: sk.temp, icons: '#icon-thermometer'}, { text: '湿度: ', value: sk.humidity, icons: '#icon-shidu'}, { text: '风力: ', value: sk.wind_strength, icons: '#icon-feng'}, { text: '天气: ', value: today.weather, icons: '#icon-tianqi'}, { text: '风向: ', value: sk.wind_direction, icons: '#icon-fangxiangpai'}, { text: '紫外线: ', value: today.uv_index, icons: '#icon-taiyangrichu'} ]; $('.content_today ul').empty() list.forEach(val => { $('.content_today ul').append(`
${val.text}${val.value}
${val.week}
没有数据...
`) }else { cityLists.forEach(val => { $(".his_info").append(`${val}`) }) BindClickCityList() } } function BindClickCityList() { $(".his_info span").on("click",function () { getCityWeather($(this).text()) $('.main').css({ right: '0' }) $('.menu').css({ right: '-100%' }) }) } function OnInput () { $(".menu_center input").on('input',function() { newList = [] var key = $(".menu_center input").val(); cityLitst.forEach(val => { if(val.indexOf(key) > -1) { newList.push(val) } }); $('.menu_center ul').empty() newList.forEach(val => { $('.menu_center ul').append(`