Commit 362e5e4ade147b305c38e6d6a78e5fe7eb32e0c1

Authored by fengwotao
1 parent 5ab7dc1d

perf(external/Composes): 小组件下新增天气

... ... @@ -5,7 +5,7 @@ import cloneDeep from 'lodash/cloneDeep'
5 5 import { chartInitConfig } from '@/settings/designSetting'
6 6
7 7 //第三方 天气接口key值和api配置(高德)
8   -export class ThirdPartyWeather {
  8 +export class ThirdPartyWeatherConnfig {
9 9 static ak = '0551a87b45e0363ae6c7a2242e8ac944'
10 10 static api = 'https://restapi.amap.com/v3/weather/weatherInfo'
11 11 // ((all,预报天气),(base,实况天气))
... ...
1 1 <script lang="ts" setup name="Weather">
2 2 import { PropType, toRefs, onMounted, reactive, watch } from 'vue'
3 3 import { CreateComponentType } from '@/packages/index.d'
4   -import { option, ThirdPartyWeather } from './config'
  4 +import { option, ThirdPartyWeatherConnfig } from './config'
5 5 import axios from 'axios'
6 6 import WeatherContent from './componnets/WeatherContent.vue'
7 7 import { useUtils } from './hooks/useUtils'
... ... @@ -17,35 +17,22 @@ const { loadWeatherImg, loadWeatherLevel } = useUtils()
17 17
18 18 const { w, h } = toRefs(props.chartConfig.attr)
19 19
20   -const {
21   - temperatureTextSize,
22   - temperatureTextColor,
23   - cityTextSize,
24   - cityTextColor,
25   - weatherIconSizeWidth,
26   - weatherIconSizeHeight,
27   - airSpeedTextSize,
28   - airSpeedTextColor,
29   - airSpeedLevelTextSize,
30   - airSpeedLevelTextColor,
31   - backgroundColor,
32   - borderRadius
33   -} = toRefs(props.chartConfig.option.weatherCss)
  20 +const { weatherCss } = toRefs(props.chartConfig.option)
34 21
35   -const weatherInfoValues: any = reactive({
  22 +const weatherInfoValues = reactive<any>({
36 23 weatherInfo: []
37 24 })
38 25
39   -const getWeatherInfos = async (cityObj: any) => {
40   - const { cityValue, countyValue } = cityObj || props.chartConfig.option.dataset
  26 +const getWeatherInfos = async (area: any) => {
  27 + const { cityValue, countyValue } = area || props.chartConfig.option.dataset
41 28 const params = {
42   - key: ThirdPartyWeather.ak,
  29 + key: ThirdPartyWeatherConnfig.ak,
43 30 city: !countyValue ? cityValue : countyValue,
44   - extensions: ThirdPartyWeather.extensions
45   - } as any
  31 + extensions: ThirdPartyWeatherConnfig.extensions
  32 + }
46 33 const {
47 34 data: { forecasts }
48   - } = await axios.get(ThirdPartyWeather.api, { params })
  35 + } = await axios.get(ThirdPartyWeatherConnfig.api, { params })
49 36 if (!forecasts) return
50 37 weatherInfoValues.weatherInfo = forecasts
51 38 }
... ... @@ -99,34 +86,34 @@ const onHandleSelectValues = (values: any) => {
99 86 .card {
100 87 width: v-bind('w+"px"');
101 88 height: v-bind('h+"px"');
102   - background-color: v-bind('backgroundColor');
103   - border-radius: v-bind('`${borderRadius}px`');
  89 + background-color: v-bind('weatherCss.backgroundColor');
  90 + border-radius: v-bind('`${weatherCss.borderRadius}px`');
104 91 .card-content {
105 92 display: flex;
106 93 justify-content: space-between;
107 94 .weather-temp {
108   - font-size: v-bind('`${temperatureTextSize}px`');
109   - color: v-bind('temperatureTextColor');
  95 + font-size: v-bind('`${weatherCss.temperatureTextSize}px`');
  96 + color: v-bind('weatherCss.temperatureTextColor');
110 97 }
111 98 .weather-city {
112 99 text-overflow: ellipsis;
113 100 overflow: hidden;
114 101 word-break: break-all;
115 102 white-space: nowrap;
116   - font-size: v-bind('`${cityTextSize}px`');
117   - color: v-bind('cityTextColor');
  103 + font-size: v-bind('`${weatherCss.cityTextSize}px`');
  104 + color: v-bind('weatherCss.cityTextColor');
118 105 }
119 106 .weather-img {
120   - width: v-bind('`${weatherIconSizeWidth}px`');
121   - height: v-bind('`${weatherIconSizeHeight}px`');
  107 + width: v-bind('`${weatherCss.weatherIconSizeWidth}px`');
  108 + height: v-bind('`${weatherCss.weatherIconSizeHeight}px`');
122 109 }
123 110 .weather-speed {
124   - font-size: v-bind('`${airSpeedTextSize}px`');
125   - color: v-bind('airSpeedTextColor');
  111 + font-size: v-bind('`${weatherCss.airSpeedTextSize}px`');
  112 + color: v-bind('weatherCss.airSpeedTextColor');
126 113 }
127 114 .weather-speed-level {
128   - font-size: v-bind('`${airSpeedLevelTextSize}px`');
129   - color: v-bind('airSpeedLevelTextColor');
  115 + font-size: v-bind('`${weatherCss.airSpeedLevelTextSize}px`');
  116 + color: v-bind('weatherCss.airSpeedLevelTextColor');
130 117 }
131 118 img {
132 119 width: 24px;
... ...