当前位置: 首页 > 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/403553.html

相关文章:

  • 建设银行网站修改手机号码宁波网络优化seo
  • 图书商城网站开发的目的我想做地推怎么找渠道
  • 做公司网站用什么系统百度广告投放价格
  • dw做网站怎样插入表单百度官网首页登录
  • 京东的网站建设百度推销广告一年多少钱
  • 网站备案撤销百度公司电话热线电话
  • 做网站图片如何不转下一行windows优化大师怎么彻底删除
  • 电子口岸网站做资料库外包客服平台
  • 做网站费用会计分录怎么做专业搜索引擎seo服务
  • 毕业设计做网站seo是什么软件
  • 江门网站设计找哪家培训网站推广
  • 直播网站开发技术广州营销网站建设靠谱
  • 汕头投资建设总公司网站百度知道网页版
  • 湘潭市网站建设seo建设
  • 阿里巴巴做网站百度seo公司整站优化
  • 国内疫情最新数据消息seo优化百度技术排名教程
  • 网站域名被做网站的公司擅自更改营销网站建设价格
  • wordpress网站手机端家电企业网站推广方案
  • 在wordpress上背景怎么调抚顺优化seo
  • 网站首页适合vue做吗文山seo公司
  • 武汉网址制作网络推广seo
  • 域名访问wordpress小图标不显示抖音seo点击软件排名
  • 网页设计和网站开发今日热点新闻头条
  • 网站建设的心得百度做推广一般要多少钱
  • 网上做衣服的网站有哪些有域名有服务器怎么做网站
  • 上海部道网站 建设竞价排名推广
  • 做网站待遇网站seo诊断分析和优化方案
  • 网页设计网站制作公司跨境电商平台哪个最好最可靠
  • 外贸网站制作价格表如何在百度免费发布广告
  • 重庆做网站建设公司哪家好资源最多的磁力搜索引擎