diff --git a/web/client/assets/images/weather/baoxue.png b/web/client/assets/images/weather/baoxue.png new file mode 100644 index 0000000..c6791b4 Binary files /dev/null and b/web/client/assets/images/weather/baoxue.png differ diff --git a/web/client/assets/images/weather/dayu.png b/web/client/assets/images/weather/dayu.png new file mode 100644 index 0000000..3c7aef6 Binary files /dev/null and b/web/client/assets/images/weather/dayu.png differ diff --git a/web/client/assets/images/weather/duoyun.png b/web/client/assets/images/weather/duoyun.png new file mode 100644 index 0000000..1d0dc7d Binary files /dev/null and b/web/client/assets/images/weather/duoyun.png differ diff --git a/web/client/assets/images/weather/fucheng.png b/web/client/assets/images/weather/fucheng.png new file mode 100644 index 0000000..b614c9a Binary files /dev/null and b/web/client/assets/images/weather/fucheng.png differ diff --git a/web/client/assets/images/weather/leizhengyu.png b/web/client/assets/images/weather/leizhengyu.png new file mode 100644 index 0000000..d1818ca Binary files /dev/null and b/web/client/assets/images/weather/leizhengyu.png differ diff --git a/web/client/assets/images/weather/mai.png b/web/client/assets/images/weather/mai.png new file mode 100644 index 0000000..ebb2a4b Binary files /dev/null and b/web/client/assets/images/weather/mai.png differ diff --git a/web/client/assets/images/weather/qiangshachengbao.png b/web/client/assets/images/weather/qiangshachengbao.png new file mode 100644 index 0000000..19e76e4 Binary files /dev/null and b/web/client/assets/images/weather/qiangshachengbao.png differ diff --git a/web/client/assets/images/weather/qing.png b/web/client/assets/images/weather/qing.png new file mode 100644 index 0000000..0ec8841 Binary files /dev/null and b/web/client/assets/images/weather/qing.png differ diff --git a/web/client/assets/images/weather/shachengbao.png b/web/client/assets/images/weather/shachengbao.png new file mode 100644 index 0000000..ea3f6d6 Binary files /dev/null and b/web/client/assets/images/weather/shachengbao.png differ diff --git a/web/client/assets/images/weather/tedabaoyu.png b/web/client/assets/images/weather/tedabaoyu.png new file mode 100644 index 0000000..a6737e2 Binary files /dev/null and b/web/client/assets/images/weather/tedabaoyu.png differ diff --git a/web/client/assets/images/weather/weizhi.png b/web/client/assets/images/weather/weizhi.png new file mode 100644 index 0000000..9ae6864 Binary files /dev/null and b/web/client/assets/images/weather/weizhi.png differ diff --git a/web/client/assets/images/weather/wu.png b/web/client/assets/images/weather/wu.png new file mode 100644 index 0000000..fe7b233 Binary files /dev/null and b/web/client/assets/images/weather/wu.png differ diff --git a/web/client/assets/images/weather/xiaoxue.png b/web/client/assets/images/weather/xiaoxue.png new file mode 100644 index 0000000..53800ff Binary files /dev/null and b/web/client/assets/images/weather/xiaoxue.png differ diff --git a/web/client/assets/images/weather/xiaoyu.png b/web/client/assets/images/weather/xiaoyu.png new file mode 100644 index 0000000..3d2f22a Binary files /dev/null and b/web/client/assets/images/weather/xiaoyu.png differ diff --git a/web/client/assets/images/weather/yangsha.png b/web/client/assets/images/weather/yangsha.png new file mode 100644 index 0000000..b8ae80c Binary files /dev/null and b/web/client/assets/images/weather/yangsha.png differ diff --git a/web/client/assets/images/weather/yingtian.png b/web/client/assets/images/weather/yingtian.png new file mode 100644 index 0000000..61c5876 Binary files /dev/null and b/web/client/assets/images/weather/yingtian.png differ diff --git a/web/client/assets/images/weather/yujiaxue.png b/web/client/assets/images/weather/yujiaxue.png new file mode 100644 index 0000000..a3e049e Binary files /dev/null and b/web/client/assets/images/weather/yujiaxue.png differ diff --git a/web/client/assets/images/weather/zhenyu.png b/web/client/assets/images/weather/zhenyu.png new file mode 100644 index 0000000..36de494 Binary files /dev/null and b/web/client/assets/images/weather/zhenyu.png differ diff --git a/web/client/assets/images/weather/zhongxue.png b/web/client/assets/images/weather/zhongxue.png new file mode 100644 index 0000000..0e713e8 Binary files /dev/null and b/web/client/assets/images/weather/zhongxue.png differ diff --git a/web/client/assets/images/weather/zhongyu.png b/web/client/assets/images/weather/zhongyu.png new file mode 100644 index 0000000..3309cd0 Binary files /dev/null and b/web/client/assets/images/weather/zhongyu.png differ diff --git a/web/client/src/sections/bigScreen/components/header.js b/web/client/src/sections/bigScreen/components/header.js index a546e28..de265d4 100644 --- a/web/client/src/sections/bigScreen/components/header.js +++ b/web/client/src/sections/bigScreen/components/header.js @@ -3,6 +3,7 @@ import { connect } from 'react-redux'; import { Spin, Card, Modal, TreeSelect, message } from 'antd'; import ProForm, { ProFormText, ModalForm, ProFormSwitch, ProFormTreeSelect } from '@ant-design/pro-form'; import Title from 'antd/lib/skeleton/Title'; +import Weather from './public/weather'; const Header = ({ dispatch, actions, user, module, setModule, history }) => { @@ -14,7 +15,7 @@ const Header = ({ dispatch, actions, user, module, setModule, history }) => { justifyContent: 'space-between', alignItems: 'center' }}> -
天气
+
{ + const icon = `/assets/images/weather/${key}.png`; + ICONSMAP[lbl] = icon; +}); + +function Weather() { + const [time, setTime] = useState(new Date().toLocaleTimeString()); + const [weather, setWeather] = useState(''); + const [temp, setTemp] = useState(0); + + useEffect(() => { + const timeUpdate = setInterval(() => { + setTime(new Date().toLocaleTimeString()); + }, 1000); + return () => { + clearInterval(timeUpdate); + }; + }, []); + + const queryWeather = () => { + RouteRequest.get(`/query/weather?cname=南昌市`).then((doc) => { + console.log(doc, 'weather'); + const w = doc?.text || '未知'; + const temp = doc?.temp || 0; + setWeather(w); + setTemp(temp); + }); + }; + + useEffect(() => { + queryWeather(); + const timeUpdate = setInterval(() => { + queryWeather(); + }, WEATHERMARGIN); + return () => { + clearInterval(timeUpdate); + }; + }, []); + + const iconSrc = useMemo(() => { + const icon = ICONSMAP[weather]; + if (icon) return icon; + const rgx = new RegExp(weather); + for (const k in ICONSMAP) { + if (rgx.test(k)) { + return ICONSMAP[k]; + } + } + return ''; + }, [weather]); + + return ( +
+
+
{time}
+
+ {moment().format( + 'YYYY-MM-DD' + )} +
+
+
+ icon +
+
{weather}
+
{temp}℃
+
+
+
+ ); +} + +export default Weather; diff --git a/web/config.js b/web/config.js index ea80bd4..8268c7c 100644 --- a/web/config.js +++ b/web/config.js @@ -21,7 +21,7 @@ args.option(['u', 'api-url'], 'webapi的URL'); const flags = args.parse(process.argv); const FS_UNIAPP_API = process.env.FS_UNIAPP_API || flags.apiUrl; - +const weatherUrl = process.env.ANXINCLOUD_WEATHERAPP_API || "https://weatherssj.anxinyun.cn/weatherApp/weather/getImmeData" if ( !FS_UNIAPP_API @@ -54,7 +54,7 @@ const product = { }, { entry: require('./routes').entry, opts: { - + weatherUrl, } }, { entry: require('./client').entry,// 静态信息 diff --git a/web/routes/weather/index.js b/web/routes/weather/index.js new file mode 100644 index 0000000..26145df --- /dev/null +++ b/web/routes/weather/index.js @@ -0,0 +1,55 @@ +const request = require('superagent'); + +let _weatherUrl = ''; +module.exports.entry = function (app, router, opts) { + const { weatherUrl } = opts; + console.log(weatherUrl, '天气'); + _weatherUrl = weatherUrl; + // _weatherUrl = "https://weatherssj.anxinyun.cn/weatherApp/weather/getImmeData" + + router.get('/query/weather', weather); +}; + +async function weather(ctx) { + try { + const { cname } = ctx.query; + const reg = /.+?(省|市|自治区|自治州|县|区)/g; + const arr = cname.match(reg); + if (Array.isArray(arr)) { + let cityName = arr[0]; + if (arr[1]) { + cityName = arr[1]; + } + const weatherRes = await request.post(_weatherUrl).send({ cityName }); + const { body } = weatherRes; + if (body && body.data) { + ctx.status = 200; + ctx.body = { ...body.data, cname, texta: _weatherUrl }; + } else { + ctx.status = 400; + ctx.body = { msg: '获取天气错误' }; + } + } else { + ctx.status = 400; + ctx.body = { msg: '地址解析错误' }; + } + } catch (error) { + console.log('[*err]', error); + ctx.status = 400; + ctx.body = error; + } +} + +// ip地址识别库 +// 淘宝IP地址查询接口:http://ip.taobao.com/service/getIpInfo.php?ip=1.1.35.57 +// 腾讯IP地址查询接口:http://fw.qq.com/ipaddress +// 新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js +// 新浪多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42 +// 搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson +// 搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8 +// 搜狐另外的IP地址查询接口:http://txt.go.sohu.com/ip/soip +// 谷歌IP地址查询接口:http://j.maxmind.com/app/geoip.js +// 1616 IP地址查询接口:http://w.1616.net/chaxun/iptolocal.php +// 126 http://ip.ws.126.net/ipquery hao123 +// http://app.hao123.com/ipquery/getcity.php?rtype=2 +// 太平洋电脑网 http://whois.pconline.com.cn/