Initial commit: weather demo
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京·中国 未来3天温度变化</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
|
||||
<style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui,sans-serif}#c{width:100vw;height:100vh}</style></head>
|
||||
<body><div id="c"></div><script>
|
||||
const rows=[{"t":"2026-10-24 00:00","temp":10.2,"hum":82,"precip":0},{"t":"2026-10-24 01:00","temp":9.9,"hum":83,"precip":0},{"t":"2026-10-24 02:00","temp":9.1,"hum":88,"precip":0},{"t":"2026-10-24 03:00","temp":8.9,"hum":88,"precip":0},{"t":"2026-10-24 04:00","temp":8.7,"hum":89,"precip":0},{"t":"2026-10-24 05:00","temp":8.9,"hum":87,"precip":0},{"t":"2026-10-24 06:00","temp":9,"hum":86,"precip":0},{"t":"2026-10-24 07:00","temp":8.9,"hum":84,"precip":0},{"t":"2026-10-24 08:00","temp":10.2,"hum":83,"precip":0},{"t":"2026-10-24 09:00","temp":11.7,"hum":76,"precip":0},{"t":"2026-10-24 10:00","temp":13.1,"hum":73,"precip":0},{"t":"2026-10-24 11:00","temp":13.9,"hum":69,"precip":0},{"t":"2026-10-24 12:00","temp":14.6,"hum":68,"precip":0},{"t":"2026-10-24 13:00","temp":15.3,"hum":67,"precip":0},{"t":"2026-10-24 14:00","temp":15.6,"hum":66,"precip":0},{"t":"2026-10-24 15:00","temp":15.8,"hum":66,"precip":0},{"t":"2026-10-24 16:00","temp":15.8,"hum":68,"precip":0},{"t":"2026-10-24 17:00","temp":15.5,"hum":75,"precip":0},{"t":"2026-10-24 18:00","temp":15.1,"hum":76,"precip":0},{"t":"2026-10-24 19:00","temp":15,"hum":76,"precip":1},{"t":"2026-10-24 20:00","temp":14.5,"hum":80,"precip":2},{"t":"2026-10-24 21:00","temp":14.1,"hum":83,"precip":4},{"t":"2026-10-24 22:00","temp":13.7,"hum":84,"precip":7},{"t":"2026-10-24 23:00","temp":13.5,"hum":84,"precip":10},{"t":"2026-10-25 00:00","temp":13.3,"hum":86,"precip":14},{"t":"2026-10-25 01:00","temp":13.2,"hum":87,"precip":19},{"t":"2026-10-25 02:00","temp":13.1,"hum":90,"precip":25},{"t":"2026-10-25 03:00","temp":12.9,"hum":92,"precip":34},{"t":"2026-10-25 04:00","temp":12.7,"hum":94,"precip":44},{"t":"2026-10-25 05:00","temp":12.4,"hum":93,"precip":49},{"t":"2026-10-25 06:00","temp":12.1,"hum":93,"precip":43},{"t":"2026-10-25 07:00","temp":12.1,"hum":91,"precip":32},{"t":"2026-10-25 08:00","temp":12.3,"hum":89,"precip":22},{"t":"2026-10-25 09:00","temp":12.5,"hum":88,"precip":16},{"t":"2026-10-25 10:00","temp":12.7,"hum":88,"precip":12},{"t":"2026-10-25 11:00","temp":13,"hum":86,"precip":10},{"t":"2026-10-25 12:00","temp":13.1,"hum":83,"precip":9},{"t":"2026-10-25 13:00","temp":12.9,"hum":81,"precip":9},{"t":"2026-10-25 14:00","temp":12.9,"hum":79,"precip":12},{"t":"2026-10-25 15:00","temp":12.7,"hum":77,"precip":20},{"t":"2026-10-25 16:00","temp":12.3,"hum":78,"precip":32},{"t":"2026-10-25 17:00","temp":11.8,"hum":80,"precip":43},{"t":"2026-10-25 18:00","temp":11.3,"hum":83,"precip":54},{"t":"2026-10-25 19:00","temp":11.1,"hum":84,"precip":65},{"t":"2026-10-25 20:00","temp":10.8,"hum":86,"precip":71},{"t":"2026-10-25 21:00","temp":10.5,"hum":88,"precip":67},{"t":"2026-10-25 22:00","temp":10.3,"hum":87,"precip":58},{"t":"2026-10-25 23:00","temp":10.2,"hum":88,"precip":49},{"t":"2026-10-26 00:00","temp":10,"hum":89,"precip":43},{"t":"2026-10-26 01:00","temp":9.9,"hum":92,"precip":38},{"t":"2026-10-26 02:00","temp":9.8,"hum":93,"precip":33},{"t":"2026-10-26 03:00","temp":9.7,"hum":93,"precip":29},{"t":"2026-10-26 04:00","temp":9.6,"hum":93,"precip":25},{"t":"2026-10-26 05:00","temp":9.8,"hum":92,"precip":22},{"t":"2026-10-26 06:00","temp":9.8,"hum":92,"precip":21},{"t":"2026-10-26 07:00","temp":9.4,"hum":94,"precip":20},{"t":"2026-10-26 08:00","temp":9.9,"hum":92,"precip":18},{"t":"2026-10-26 09:00","temp":10.7,"hum":87,"precip":13},{"t":"2026-10-26 10:00","temp":11.8,"hum":80,"precip":7},{"t":"2026-10-26 11:00","temp":12.7,"hum":76,"precip":2},{"t":"2026-10-26 12:00","temp":13.9,"hum":71,"precip":0},{"t":"2026-10-26 13:00","temp":14.5,"hum":69,"precip":0},{"t":"2026-10-26 14:00","temp":14.9,"hum":68,"precip":0},{"t":"2026-10-26 15:00","temp":15.2,"hum":67,"precip":0},{"t":"2026-10-26 16:00","temp":14.9,"hum":71,"precip":0},{"t":"2026-10-26 17:00","temp":14,"hum":76,"precip":0},{"t":"2026-10-26 18:00","temp":13,"hum":80,"precip":0},{"t":"2026-10-26 19:00","temp":12.8,"hum":81,"precip":0},{"t":"2026-10-26 20:00","temp":12.6,"hum":70,"precip":0},{"t":"2026-10-26 21:00","temp":13.1,"hum":35,"precip":0},{"t":"2026-10-26 22:00","temp":13,"hum":30,"precip":0},{"t":"2026-10-26 23:00","temp":12.6,"hum":28,"precip":0}];
|
||||
const ch=echarts.init(document.getElementById('c'));
|
||||
ch.setOption({title:{text:"北京·中国 未来3天温度变化",left:'center',textStyle:{color:'#e2e8f0'}},
|
||||
tooltip:{trigger:'axis',formatter:p=>{const r=rows[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C<br>湿度 '+r.hum+'%<br>降水概率 '+r.precip+'%';}},
|
||||
grid:{left:55,right:40,top:80,bottom:55},
|
||||
xAxis:{type:'category',data:rows.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:5}},
|
||||
yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},
|
||||
series:[{name:'温度',type:'line',smooth:true,data:rows.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});
|
||||
window.addEventListener('resize',()=>ch.resize());
|
||||
</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const hours=[{"t":"10-24 00:00","temp":13},{"t":"10-24 03:00","temp":12},{"t":"10-24 06:00","temp":12},{"t":"10-24 09:00","temp":14},{"t":"10-24 12:00","temp":17},{"t":"10-24 15:00","temp":18},{"t":"10-24 18:00","temp":17},{"t":"10-24 21:00","temp":17},{"t":"10-25 00:00","temp":16},{"t":"10-25 03:00","temp":14},{"t":"10-25 06:00","temp":14},{"t":"10-25 09:00","temp":14},{"t":"10-25 12:00","temp":13},{"t":"10-25 15:00","temp":13},{"t":"10-25 18:00","temp":12},{"t":"10-25 21:00","temp":11},{"t":"10-26 00:00","temp":12},{"t":"10-26 03:00","temp":12},{"t":"10-26 06:00","temp":12},{"t":"10-26 09:00","temp":14},{"t":"10-26 12:00","temp":16},{"t":"10-26 15:00","temp":18},{"t":"10-26 18:00","temp":16},{"t":"10-26 21:00","temp":15}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis',formatter:p=>{const r=hours[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:hours.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:3}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{type:'line',smooth:true,data:hours.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const hours=[{"t":"10-24 00:00","temp":13},{"t":"10-24 03:00","temp":12},{"t":"10-24 06:00","temp":12},{"t":"10-24 09:00","temp":14},{"t":"10-24 12:00","temp":17},{"t":"10-24 15:00","temp":18},{"t":"10-24 18:00","temp":17},{"t":"10-24 21:00","temp":17},{"t":"10-25 00:00","temp":16},{"t":"10-25 03:00","temp":14},{"t":"10-25 06:00","temp":14},{"t":"10-25 09:00","temp":14},{"t":"10-25 12:00","temp":13},{"t":"10-25 15:00","temp":13},{"t":"10-25 18:00","temp":12},{"t":"10-25 21:00","temp":11},{"t":"10-26 00:00","temp":12},{"t":"10-26 03:00","temp":12},{"t":"10-26 06:00","temp":12},{"t":"10-26 09:00","temp":14},{"t":"10-26 12:00","temp":16},{"t":"10-26 15:00","temp":18},{"t":"10-26 18:00","temp":16},{"t":"10-26 21:00","temp":15}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis',formatter:p=>{const r=hours[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:hours.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:3}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{type:'line',smooth:true,data:hours.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const hours=[{"t":"10-24 00:00","temp":13},{"t":"10-24 03:00","temp":12},{"t":"10-24 06:00","temp":12},{"t":"10-24 09:00","temp":14},{"t":"10-24 12:00","temp":17},{"t":"10-24 15:00","temp":18},{"t":"10-24 18:00","temp":17},{"t":"10-24 21:00","temp":17},{"t":"10-25 00:00","temp":16},{"t":"10-25 03:00","temp":14},{"t":"10-25 06:00","temp":14},{"t":"10-25 09:00","temp":14},{"t":"10-25 12:00","temp":13},{"t":"10-25 15:00","temp":13},{"t":"10-25 18:00","temp":12},{"t":"10-25 21:00","temp":11},{"t":"10-26 00:00","temp":12},{"t":"10-26 03:00","temp":12},{"t":"10-26 06:00","temp":12},{"t":"10-26 09:00","temp":14},{"t":"10-26 12:00","temp":16},{"t":"10-26 15:00","temp":18},{"t":"10-26 18:00","temp":16},{"t":"10-26 21:00","temp":15}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis',formatter:p=>{const r=hours[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:hours.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:3}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{type:'line',smooth:true,data:hours.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>深圳 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":32,"min":22,"desc":"阴"},{"date":"2026-10-25","max":32,"min":22,"desc":"阴"},{"date":"2026-10-26","max":30,"min":23,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'深圳 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><title>深圳 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":32,"min":22,"desc":"阴"},{"date":"2026-10-25","max":32,"min":22,"desc":"阴"},{"date":"2026-10-26","max":30,"min":23,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'深圳 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||
@@ -0,0 +1,234 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>AI 天气工作流</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f4f6fb;
|
||||
--primary: #3b6ef6;
|
||||
--text: #1f2937;
|
||||
--muted: #6b7280;
|
||||
--border: #e5e9f0;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||
background: linear-gradient(160deg, #eef2ff, #f4f6fb 45%, #e6f7f5);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
color: var(--text);
|
||||
}
|
||||
.card {
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
background: #fff;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(31, 45, 90, .12);
|
||||
padding: 36px 32px;
|
||||
}
|
||||
.badge {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
color: var(--primary);
|
||||
background: #eef2ff;
|
||||
border: 1px solid #dbe3ff;
|
||||
padding: 4px 10px;
|
||||
border-radius: 999px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
h1 { font-size: 23px; }
|
||||
.subtitle { color: var(--muted); font-size: 14px; margin-top: 8px; line-height: 1.6; }
|
||||
.form { display: flex; gap: 10px; margin-top: 22px; }
|
||||
.form input {
|
||||
flex: 1;
|
||||
height: 48px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 0 16px;
|
||||
font-size: 15px;
|
||||
outline: none;
|
||||
}
|
||||
.form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 110, 246, .15); }
|
||||
.form button {
|
||||
height: 48px;
|
||||
padding: 0 22px;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.form button:disabled { opacity: .6; cursor: not-allowed; }
|
||||
.result { margin-top: 24px; display: none; }
|
||||
.result.show { display: block; }
|
||||
.days { display: flex; gap: 10px; margin-top: 14px; }
|
||||
.day {
|
||||
flex: 1;
|
||||
background: #f8fafc;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 14px 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.day .w { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
|
||||
.day .ico { font-size: 22px; margin-bottom: 6px; }
|
||||
.day .tmp { font-size: 15px; font-weight: 700; }
|
||||
.day .range { font-size: 12px; color: var(--muted); margin-top: 4px; }
|
||||
.link {
|
||||
margin-top: 18px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: #fff;
|
||||
background: #10b981;
|
||||
text-decoration: none;
|
||||
padding: 12px 20px;
|
||||
border-radius: 12px;
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
}
|
||||
.link:hover { background: #059669; }
|
||||
.err {
|
||||
margin-top: 18px;
|
||||
color: #c0392b;
|
||||
background: #fdf2f2;
|
||||
border: 1px solid #f5c6c6;
|
||||
border-radius: 12px;
|
||||
padding: 14px;
|
||||
font-size: 14px;
|
||||
display: none;
|
||||
}
|
||||
.load { margin-top: 18px; color: var(--muted); font-size: 14px; display: none; }
|
||||
.spin {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 2px solid #c7d2fe;
|
||||
border-top-color: var(--primary);
|
||||
border-radius: 50%;
|
||||
animation: s .7s linear infinite;
|
||||
vertical-align: -2px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
@keyframes s { to { transform: rotate(360deg); } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="card">
|
||||
<span class="badge">工作流:查天气 → 生成曲线图</span>
|
||||
<h1>未来3天天气曲线</h1>
|
||||
<p class="subtitle">输入城市提交后,系统自动查询未来3天天气并生成温度变化曲线图。</p>
|
||||
<form class="form" id="form">
|
||||
<input id="city" placeholder="例如:北京 / 上海 / 深圳" autocomplete="off">
|
||||
<button id="btn" type="submit">提交</button>
|
||||
</form>
|
||||
<div class="load" id="load"><span class="spin"></span>正在查询并生成曲线图…</div>
|
||||
<div class="err" id="err"></div>
|
||||
<div class="result" id="result"></div>
|
||||
</main>
|
||||
<script>
|
||||
const ICO = {
|
||||
晴: '☀️', 大致晴朗: '🌤️', 多云: '⛅', 阴: '☁️',
|
||||
雾: '🌫️', 雾凇: '🌫️', 小毛毛雨: '🌦️', 毛毛雨: '🌦️',
|
||||
强毛毛雨: '🌧️', 小雨: '🌧️', 中雨: '🌧️', 大雨: '🌧️',
|
||||
冻雨: '🌧️', 小雪: '🌨️', 中雪: '🌨️', 大雪: '❄️',
|
||||
小阵雨: '🌦️', 中阵雨: '🌧️', 强阵雨: '⛈️', 小阵雪: '🌨️',
|
||||
大阵雪: '❄️', 雷雨: '⛈️', 雷雨伴冰雹: '⛈️', 强雷雨伴冰雹: '⛈️',
|
||||
未知: '🌡️'
|
||||
};
|
||||
|
||||
const form = document.getElementById('form');
|
||||
const city = document.getElementById('city');
|
||||
const btn = document.getElementById('btn');
|
||||
const load = document.getElementById('load');
|
||||
const err = document.getElementById('err');
|
||||
const result = document.getElementById('result');
|
||||
|
||||
let summary = null;
|
||||
let chartUrl = null;
|
||||
|
||||
function render() {
|
||||
if (!summary && !chartUrl) return;
|
||||
let h = '';
|
||||
if (summary) {
|
||||
h += '<div class="days">' + summary.summary.map(s =>
|
||||
`<div class="day"><div class="w">${s.week} ${s.date.slice(5)}</div><div class="ico">${ICO[s.weather] || '🌡️'}</div><div class="tmp">${s.weather}</div><div class="range">${s.min}° ~ ${s.max}°</div></div>`
|
||||
).join('') + '</div>';
|
||||
}
|
||||
if (chartUrl) {
|
||||
h += '<a class="link" href="' + chartUrl + '" target="_blank">查看温度变化曲线图 →</a>';
|
||||
}
|
||||
result.innerHTML = h;
|
||||
result.classList.add('show');
|
||||
}
|
||||
|
||||
form.addEventListener('submit', async e => {
|
||||
e.preventDefault();
|
||||
const c = city.value.trim();
|
||||
if (!c) {
|
||||
err.textContent = '请输入城市名称';
|
||||
err.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
btn.disabled = true;
|
||||
err.style.display = 'none';
|
||||
result.classList.remove('show');
|
||||
result.innerHTML = '';
|
||||
summary = null;
|
||||
chartUrl = null;
|
||||
load.style.display = 'block';
|
||||
|
||||
try {
|
||||
const r = await fetch('/api/weather', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ city: c })
|
||||
});
|
||||
if (!r.ok) throw new Error('请求失败 HTTP ' + r.status);
|
||||
|
||||
const reader = r.body.getReader();
|
||||
const dec = new TextDecoder();
|
||||
let buf = '';
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
buf += dec.decode(value, { stream: true });
|
||||
let idx;
|
||||
while ((idx = buf.indexOf('\n\n')) >= 0) {
|
||||
const block = buf.slice(0, idx);
|
||||
buf = buf.slice(idx + 2);
|
||||
let ev = 'message';
|
||||
let data = '';
|
||||
for (const line of block.split('\n')) {
|
||||
if (line.startsWith('event:')) ev = line.slice(6).trim();
|
||||
else if (line.startsWith('data:')) data += line.slice(5).trim();
|
||||
}
|
||||
if (ev === 'meta') {
|
||||
try { load.innerHTML = '<span class="spin"></span>' + JSON.parse(data).message; } catch {}
|
||||
} else if (ev === 'summary') {
|
||||
try { summary = JSON.parse(data); render(); } catch {}
|
||||
} else if (ev === 'chart') {
|
||||
try { chartUrl = JSON.parse(data).chartUrl; render(); } catch {}
|
||||
} else if (ev === 'error') {
|
||||
try { err.textContent = '出错了:' + JSON.parse(data).message; err.style.display = 'block'; } catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e2) {
|
||||
err.textContent = '出错了:' + e2.message;
|
||||
err.style.display = 'block';
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
load.style.display = 'none';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user