1
|
<script lang="ts" setup name="Weather">
|
1
|
<script lang="ts" setup name="Weather">
|
2
|
import { PropType, toRefs, onMounted, reactive, watch } from 'vue'
|
2
|
import { PropType, toRefs, onMounted, reactive, watch } from 'vue'
|
3
|
import { CreateComponentType } from '@/packages/index.d'
|
3
|
import { CreateComponentType } from '@/packages/index.d'
|
4
|
-import { option, ThirdPartyWeather } from './config'
|
4
|
+import { option, ThirdPartyWeatherConnfig } from './config'
|
5
|
import axios from 'axios'
|
5
|
import axios from 'axios'
|
6
|
import WeatherContent from './componnets/WeatherContent.vue'
|
6
|
import WeatherContent from './componnets/WeatherContent.vue'
|
7
|
import { useUtils } from './hooks/useUtils'
|
7
|
import { useUtils } from './hooks/useUtils'
|
|
@@ -17,35 +17,22 @@ const { loadWeatherImg, loadWeatherLevel } = useUtils() |
|
@@ -17,35 +17,22 @@ const { loadWeatherImg, loadWeatherLevel } = useUtils() |
17
|
|
17
|
|
18
|
const { w, h } = toRefs(props.chartConfig.attr)
|
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
|
weatherInfo: []
|
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
|
const params = {
|
28
|
const params = {
|
42
|
- key: ThirdPartyWeather.ak,
|
29
|
+ key: ThirdPartyWeatherConnfig.ak,
|
43
|
city: !countyValue ? cityValue : countyValue,
|
30
|
city: !countyValue ? cityValue : countyValue,
|
44
|
- extensions: ThirdPartyWeather.extensions
|
|
|
45
|
- } as any
|
31
|
+ extensions: ThirdPartyWeatherConnfig.extensions
|
|
|
32
|
+ }
|
46
|
const {
|
33
|
const {
|
47
|
data: { forecasts }
|
34
|
data: { forecasts }
|
48
|
- } = await axios.get(ThirdPartyWeather.api, { params })
|
35
|
+ } = await axios.get(ThirdPartyWeatherConnfig.api, { params })
|
49
|
if (!forecasts) return
|
36
|
if (!forecasts) return
|
50
|
weatherInfoValues.weatherInfo = forecasts
|
37
|
weatherInfoValues.weatherInfo = forecasts
|
51
|
}
|
38
|
}
|
|
@@ -99,34 +86,34 @@ const onHandleSelectValues = (values: any) => { |
|
@@ -99,34 +86,34 @@ const onHandleSelectValues = (values: any) => { |
99
|
.card {
|
86
|
.card {
|
100
|
width: v-bind('w+"px"');
|
87
|
width: v-bind('w+"px"');
|
101
|
height: v-bind('h+"px"');
|
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
|
.card-content {
|
91
|
.card-content {
|
105
|
display: flex;
|
92
|
display: flex;
|
106
|
justify-content: space-between;
|
93
|
justify-content: space-between;
|
107
|
.weather-temp {
|
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
|
.weather-city {
|
98
|
.weather-city {
|
112
|
text-overflow: ellipsis;
|
99
|
text-overflow: ellipsis;
|
113
|
overflow: hidden;
|
100
|
overflow: hidden;
|
114
|
word-break: break-all;
|
101
|
word-break: break-all;
|
115
|
white-space: nowrap;
|
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
|
.weather-img {
|
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
|
.weather-speed {
|
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
|
.weather-speed-level {
|
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
|
img {
|
118
|
img {
|
132
|
width: 24px;
|
119
|
width: 24px;
|