Commit 7bc12e52d3a2076574192ec4b9c108e50f8d251b

Authored by ww
1 parent 68d9de5f

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

... ... @@ -15,6 +15,7 @@ export const option: PublicPresetOptions = {
15 15 [ComponentConfigFieldEnum.SHOW_TIME]: false,
16 16 [ComponentConfigFieldEnum.FONT_SIZE]: 14,
17 17 [ComponentConfigFieldEnum.VALUE_SIZE]: 20,
  18 + [ComponentConfigFieldEnum.MAX_NUMBER]: 120,
18 19 };
19 20
20 21 export default class Config extends PublicConfigClass implements CreateComponentType {
... ...
... ... @@ -18,16 +18,38 @@
18 18
19 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 38 const getValue = computed(() => {
22 39 const maxHeight = 190;
23 40 const minHeight = 15;
  41 +
24 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 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 54 return transformValue >= maxHeight
33 55 ? maxHeight
... ... @@ -184,7 +206,9 @@
184 206 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
185 207 />
186 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 212 </foreignObject>
189 213 </g>
190 214 <g class="tick" opacity="1" transform="translate(0,165)">
... ... @@ -204,7 +228,9 @@
204 228 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
205 229 />
206 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 234 </foreignObject>
209 235 </g>
210 236 <g class="tick" opacity="1" transform="translate(0,115)">
... ... @@ -214,7 +240,9 @@
214 240 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
215 241 />
216 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 246 </foreignObject>
219 247 </g>
220 248 <g class="tick" opacity="1" transform="translate(0,90)">
... ... @@ -224,7 +252,9 @@
224 252 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
225 253 />
226 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 258 </foreignObject>
229 259 </g>
230 260 <g class="tick" opacity="1" transform="translate(0,65)">
... ... @@ -234,7 +264,9 @@
234 264 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
235 265 />
236 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 270 </foreignObject>
239 271 </g>
240 272 <g class="tick" opacity="1" transform="translate(0,40)">
... ... @@ -244,7 +276,9 @@
244 276 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
245 277 />
246 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 282 </foreignObject>
249 283 </g>
250 284 <g class="tick" opacity="1" transform="translate(0,15)">
... ... @@ -254,7 +288,9 @@
254 288 style="stroke: rgb(136, 136, 136); shape-rendering: crispEdges; stroke-width: 1px"
255 289 />
256 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 294 </foreignObject>
259 295 </g>
260 296 </g>
... ...