当前位置: 首页 > wzjs >正文

做一个同城便民信息网站怎么做关键词挖掘工具爱网

做一个同城便民信息网站怎么做,关键词挖掘工具爱网,南山网站建设公,马鞍山网站建设电话1、申请高德key 点击高德官网申请 必须有key才能调用高德api 小提示:每日/每秒调用api次数有限,尽量不要循环调用。 每日大概5000,每秒3次 2、查看文档 高德官网天气api接口文档 请求示例: https://restapi.amap.com/v3/weat…

1、申请高德key

点击高德官网申请

  • 必须有key才能调用高德api

小提示:每日/每秒调用api次数有限,尽量不要循环调用。 每日大概5000,每秒3次

在这里插入图片描述

2、查看文档

高德官网天气api接口文档

  • 请求示例:
    https://restapi.amap.com/v3/weather/weatherInfo?key=你的key&city=130629&extensions=all

在这里插入图片描述

3、 项目中使用

  • 在项目 vite.config.ts 文件下配置反向代理
		server: {host: "0.0.0.0", // 服务器主机名,如果允许外部访问,可设置为"0.0.0.0"port: viteEnv.VITE_PORT,open: viteEnv.VITE_OPEN,cors: true,// https: false,// 代理跨域proxy: {"/api/weather": {target: "https://restapi.amap.com/v3/weather", // 高德apichangeOrigin: true,rewrite: path => path.replace(/^\/api\/weather/, "")},"/api": {target, // 后端接口网址changeOrigin: true,rewrite: path => path.replace(/^\/api/, "")}}},
  • 接口调用
    api 模块
import http from "@/api";// * 天气信息
const key = "00***fe6";
const city = "130629"; // 高德城市编码
export const getWeather = () => {return http.get("/weather/weatherInfo", { key, city, extensions: "all" });
};
  • 页面使用
    1.高德官网给的天气情况都是汉字,种类繁多,与产品沟通后只展示以下8种天气状况就OK,各位大佬在搬砖时要提前和PM沟通,可行则此方案亦可
    2.免费api调用次数有每日上限问题,故采取缓存处理,每隔一小时请求一次api,望各位大佬知悉
import { useEffect } from "react";
import { connect } from "react-redux";
import moment from "moment";
import { useDispatch } from "@/redux";
import { setWeatherData } from "@/redux/modules/global/action";
import { getWeather } from "@/api/modules/dataScreen";
import feng from "@/assets/weatherIcons/风.png";
import duoyun from "@/assets/weatherIcons/多云.png";
import xue from "@/assets/weatherIcons/雪.png";
import wu from "@/assets/weatherIcons/雾.png";
import qing from "@/assets/weatherIcons/晴.png";
import yu from "@/assets/weatherIcons/雨.png";
import yin from "@/assets/weatherIcons/阴.png";import "./index.less";
/*** @description 天气预报* */
const iconWeatherMap: any = {: ["有风","平静","微风","和风","清风","强风/劲风","疾风","大风","烈风","风暴","狂爆风","飓风","热带风暴","龙卷风"],多云: ["少云", "晴间多云", "多云"],: ["雪", "阵雪", "小雪", "中雪", "大雪", "暴雪", "小雪-中雪", "中雪-大雪", "大雪-暴雪", "冷"],: ["浮尘", "扬沙", "沙尘暴", "强沙尘暴", "雾", "浓雾", "强浓雾", "轻雾", "大雾", "特强浓雾"],: ["晴", "热"],雨夹雪: ["雨雪天气", "雨夹雪", "阵雨夹雪"],: ["阵雨","雷阵雨","雷阵雨并伴有冰雹","小雨","中雨","大雨","暴雨","大暴雨","特大暴雨","强阵雨","强雷阵雨","极端降雨","毛毛雨/细雨","雨","小雨-中雨","中雨-大雨","大雨-暴雨","暴雨-大暴雨","大暴雨-特大暴雨","冻雨"],: ["阴", "霾", "中度霾", "重度霾", "严重霾", "未知"]
};
const iconUrl: any = {: feng,多云: duoyun,: xue,: wu,: qing,: yu,: yin
};
const getIcon = (name: string) => {for (const key in iconWeatherMap) {if (Object.prototype.hasOwnProperty.call(iconWeatherMap, key)) {const arr = iconWeatherMap[key];if (arr.includes(name)) return key;}}
};
const Weather = (props: any) => {const { setWeatherData } = props;const { weatherData } = props.global;const { weatherTime, dayWeather, temp } = weatherData;const dispatch = useDispatch();const fetchData = async () => {const { status, forecasts }: { [key: string]: any } = await getWeather();if (status === "1") {const { dayweather, nighttemp, daytemp } = forecasts[0]["casts"][0];setWeatherData({dayWeather: dayweather,temp: `${nighttemp} - ${daytemp}`,weatherTime: moment().format("YYYY-MM-DD HH:mm:ss")});} else dispatch(setWeatherData({ ...weatherData, dayweather: "晴", temp: "" }));};useEffect(() => {const time: number = 1 * 60; // 1小时const now = moment();if (!weatherTime) fetchData();else if (now.diff(moment(weatherTime), "minutes") >= time) fetchData();}, []);return (<div className="weather"><img src={iconUrl[getIcon(dayWeather) || "晴"]} alt="" /><div className="weather-info"><div>{dayWeather || ""}</div><div className="temp">{temp ? temp + "℃" : ""}</div></div></div>);
};
const mapStateToProps = (state: any) => state;
export default connect(mapStateToProps, { setWeatherData })(Weather);

页面最后展示结果
在这里插入图片描述
不要质疑我的样式(温度压在背景“线”上),严格按照UI图设计出来的

4、项目用到的图片

在这里插入图片描述

  • 单个图片(喜欢可以F12查看拿走,像素不行再@我,无偿给大佬)
    冰雹

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

http://www.dtcms.com/wzjs/120184.html

相关文章:

  • 怎么做最火的视频网站网站seo优化报告
  • 男女性做那个微视频网站免费视频网站推广软件
  • 武汉做网站的知名公司搜索引擎优化需要多少钱
  • 手机网站建设软件下载网络营销有哪些功能
  • 上海招聘网站排名碉堡了seo博客
  • 网站建设与网页设计制作建一个外贸独立站大约多少钱
  • 百度站长平台验证网站百度搜索风云榜
  • 潍坊外贸网站建设菏泽seo
  • 外国网站签到做任务每月挣钱武汉网站推广公司排名
  • 成华区微信网站建设女生学网络营销这个专业好吗
  • 单页面网站模板怎么做网站推广优化之八大方法
  • 苏州网站建设公司鹅鹅鹅seo网站推广公司
  • 如何做电影网站宁波seo怎么做优化
  • 江苏省建设工程八大员考试网站网站快速推广
  • 网站建设费用多少钱网址导航下载到桌面
  • 成都网站建设 四川冠辰科技外链查询
  • 广西南宁电商网站建设百度云建站
  • wordpress 文章简介seo推广软
  • seo教学江门关键词优化公司
  • 网站建设费用一年百度广告开户流程
  • 网络网站制作技巧抖音seo搜索优化
  • 免费的小程序制作工具常宁seo外包
  • 做写真素材网站线上培训课程
  • 解析网站接口怎么做竞价托管
  • 做网站去什么公司好百度推广怎么开户
  • 建立网站大约多少钱五种关键词优化工具
  • web网站开发报告百度站长之家工具
  • 网站设计需求书销售找客户的方法
  • 网站可以自己做吗谷歌seo排名工具
  • 片网站无法显示网络营销推广实战宝典