Commit 7bc12e52d3a2076574192ec4b9c108e50f8d251b

Authored by ww
1 parent 68d9de5f

fix: 修复温度计无法动态更新刻度

@@ -15,6 +15,7 @@ export const option: PublicPresetOptions = { @@ -15,6 +15,7 @@ export const option: PublicPresetOptions = {
15 [ComponentConfigFieldEnum.SHOW_TIME]: false, 15 [ComponentConfigFieldEnum.SHOW_TIME]: false,
16 [ComponentConfigFieldEnum.FONT_SIZE]: 14, 16 [ComponentConfigFieldEnum.FONT_SIZE]: 14,
17 [ComponentConfigFieldEnum.VALUE_SIZE]: 20, 17 [ComponentConfigFieldEnum.VALUE_SIZE]: 20,
  18 + [ComponentConfigFieldEnum.MAX_NUMBER]: 120,
18 }; 19 };
19 20
20 export default class Config extends PublicConfigClass implements CreateComponentType { 21 export default class Config extends PublicConfigClass implements CreateComponentType {
@@ -18,16 +18,38 @@ @@ -18,16 +18,38 @@
18 18
19 const time = ref<Nullable<number>>(null); 19 const time = ref<Nullable<number>>(null);
20 20
  21 + const POSITIVE_NUMBER = 6;
  22 +
  23 + const ALL_PART = 7;
  24 +
  25 + const DEFAULT_PART_VALUE = 20;
  26 +
  27 + const partValue = computed(() => {
  28 + const { config } = props;
  29 + const { option } = config;
  30 + const { componentInfo } = option;
  31 + const { maxNumber = 120 } = componentInfo || {};
  32 + let value = maxNumber / POSITIVE_NUMBER;
  33 + return value % 10 > 0 ? Math.floor(value / 10) * 10 + 10 : value + 10;
  34 + });
  35 +
  36 + const maxValueScale = computed(() => unref(partValue) / DEFAULT_PART_VALUE);
  37 +
21 const getValue = computed(() => { 38 const getValue = computed(() => {
22 const maxHeight = 190; 39 const maxHeight = 190;
23 const minHeight = 15; 40 const minHeight = 15;
  41 +
24 const height = maxHeight - minHeight; 42 const height = maxHeight - minHeight;
25 - const rangeNumber = 7;  
26 - const itemRange = 20;  
27 - const itemHeight = height / (rangeNumber * itemRange); 43 +
  44 + const itemHeight = height / (ALL_PART * (DEFAULT_PART_VALUE * unref(maxValueScale)));
  45 +
28 const value = unref(currentValue); 46 const value = unref(currentValue);
29 - const transformValue =  
30 - maxHeight - (value >= 0 ? value + 20 : itemRange - Math.abs(value)) * itemHeight; 47 + let transformValue =
  48 + maxHeight -
  49 + (value >= 0
  50 + ? value + unref(DEFAULT_PART_VALUE * unref(maxValueScale))
  51 + : DEFAULT_PART_VALUE * unref(maxValueScale) - Math.abs(value)) *
  52 + itemHeight;
31 53
32 return transformValue >= maxHeight 54 return transformValue >= maxHeight
33 ? maxHeight 55 ? maxHeight
@@ -184,7 +206,9 @@ @@ -184,7 +206,9 @@
184 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px" 206 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
185 /> 207 />
186 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20"> 208 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20">
187 - <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">-20</div> 209 + <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">
  210 + {{ partValue * -1 }}
  211 + </div>
188 </foreignObject> 212 </foreignObject>
189 </g> 213 </g>
190 <g class="tick" opacity="1" transform="translate(0,165)"> 214 <g class="tick" opacity="1" transform="translate(0,165)">
@@ -204,7 +228,9 @@ @@ -204,7 +228,9 @@
204 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px" 228 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
205 /> 229 />
206 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20"> 230 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20">
207 - <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">20</div> 231 + <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">
  232 + {{ partValue }}
  233 + </div>
208 </foreignObject> 234 </foreignObject>
209 </g> 235 </g>
210 <g class="tick" opacity="1" transform="translate(0,115)"> 236 <g class="tick" opacity="1" transform="translate(0,115)">
@@ -214,7 +240,9 @@ @@ -214,7 +240,9 @@
214 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px" 240 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
215 /> 241 />
216 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20"> 242 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20">
217 - <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">40</div> 243 + <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">
  244 + {{ partValue * 2 }}
  245 + </div>
218 </foreignObject> 246 </foreignObject>
219 </g> 247 </g>
220 <g class="tick" opacity="1" transform="translate(0,90)"> 248 <g class="tick" opacity="1" transform="translate(0,90)">
@@ -224,7 +252,9 @@ @@ -224,7 +252,9 @@
224 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px" 252 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
225 /> 253 />
226 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20"> 254 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20">
227 - <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">60</div> 255 + <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">
  256 + {{ partValue * 3 }}
  257 + </div>
228 </foreignObject> 258 </foreignObject>
229 </g> 259 </g>
230 <g class="tick" opacity="1" transform="translate(0,65)"> 260 <g class="tick" opacity="1" transform="translate(0,65)">
@@ -234,7 +264,9 @@ @@ -234,7 +264,9 @@
234 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px" 264 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
235 /> 265 />
236 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20"> 266 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20">
237 - <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">80</div> 267 + <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">
  268 + {{ partValue * 4 }}
  269 + </div>
238 </foreignObject> 270 </foreignObject>
239 </g> 271 </g>
240 <g class="tick" opacity="1" transform="translate(0,40)"> 272 <g class="tick" opacity="1" transform="translate(0,40)">
@@ -244,7 +276,9 @@ @@ -244,7 +276,9 @@
244 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px" 276 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
245 /> 277 />
246 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20"> 278 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20">
247 - <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">100</div> 279 + <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">
  280 + {{ partValue * 5 }}
  281 + </div>
248 </foreignObject> 282 </foreignObject>
249 </g> 283 </g>
250 <g class="tick" opacity="1" transform="translate(0,15)"> 284 <g class="tick" opacity="1" transform="translate(0,15)">
@@ -254,7 +288,9 @@ @@ -254,7 +288,9 @@
254 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px" 288 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
255 /> 289 />
256 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20"> 290 <foreignObject xmlns="http://www.w3.org/2000/svg" x="-55" y="-10" width="45" height="20">
257 - <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">120</div> 291 + <div class="tick-label" xmlns="http://www.w3.org/1999/xhtml">
  292 + {{ partValue * 6 }}
  293 + </div>
258 </foreignObject> 294 </foreignObject>
259 </g> 295 </g>
260 </g> 296 </g>