GridPointRainfall.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <Dialog custom-show title="格点雨量" :height="'1000px'" hide-footer @close="handleClose">
  3. <div class="gradient-text title">雨量统计:{{address}}({{location[0]}}, {{location[1]}})</div>
  4. <Chart :option="chartOption" style="height: 700px" />
  5. </Dialog>
  6. </template>
  7. <script lang="ts" setup name="GridPointRainfall">
  8. import { option9 } from '@/views/globalMap/RightMenu/echartOptions';
  9. import AMapLoader from '@amap/amap-jsapi-loader';
  10. import { getRainfallCode, getRainfallInfo } from '@/api/globalMap/gridPointRainfall';
  11. interface Props {
  12. modelValue: boolean;
  13. location?: string | number[];
  14. }
  15. const props = withDefaults(defineProps<Props>(), {});
  16. const emits = defineEmits(['update:modelValue']);
  17. let address = ref('');
  18. let chartOption = ref(option9);
  19. const handleClose = () => {
  20. emits('update:modelValue', false);
  21. };
  22. let AMap, geocoder;
  23. onMounted(() => {
  24. AMapLoader.load({
  25. key: '30d3d8448efd68cb0b284549fd41adcf', // 申请好的Web端开发者Key,首次调用 load 时必填
  26. version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  27. plugins: ['AMap.PlaceSearch', 'AMap.ContextMenu', 'AMap.PolygonEditor', 'AMap.Geocoder'] // 插件列表
  28. }).then((res) => {
  29. AMap = res;
  30. geocoder = new AMap.Geocoder({
  31. // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
  32. city: '010'
  33. });
  34. geocoder.getAddress(props.location, (status, result) => {
  35. if (status === 'complete' && result.info === 'OK') {
  36. address.value = result.regeocode.formattedAddress;
  37. }
  38. });
  39. });
  40. getRainfallCode({
  41. longitude: props.location[0],
  42. latitude: props.location[1]
  43. }).then((res) => {
  44. getRainfallInfo(res.rows[0].code).then((res2) => {
  45. const data = res2.data.rainfallHistory;
  46. const data2 = res2.data.rainfallFuture;
  47. const data3 = [];
  48. data.forEach(() => {
  49. data3.push('');
  50. });
  51. data3[data3.length - 1] = data[data2.length - 1].value;
  52. data2.forEach((item) => {
  53. data3.push(item.hour);
  54. });
  55. chartOption.value.series[0].data = res2.data.rainfallHistory;
  56. chartOption.value.series[1].data = data3;
  57. });
  58. });
  59. });
  60. onMounted(() => {
  61. });
  62. </script>
  63. <style lang="scss" scoped></style>