DigitalDashBoard.vue 2.27 KB
<script lang="ts" setup>
  import { computed } from 'vue';
  import { Space } from 'ant-design-vue';
  import type { DigitalDashBoardLayout, DigitalDashBoardValue } from './digitalDashBoard.config';
  import { dateUtil } from '/@/utils/dateUtil';

  const props = defineProps<{
    layout: DigitalDashBoardLayout;
    value: DigitalDashBoardValue;
  }>();

  const integerPart = computed(() => {
    const { value = 0 } = props.value;
    const { max = 5 } = props.layout;
    let _value = value?.toFixed(2).split('.')[0];
    if (_value.length < max) _value = _value.padStart(5, '0');

    if (_value.length > max) _value = ''.padStart(5, '9');

    return _value;
  });

  const decimalPart = computed(() => {
    const { value = 0 } = props.value;
    const { keepNumber = 2 } = props.layout;
    let _value = value?.toFixed(2).split('.')[1];
    if (_value.length < keepNumber) _value = _value.padStart(5, '0');

    if (_value.length > keepNumber) _value = ''.padStart(5, '0');

    return _value;
  });
</script>

<template>
  <section class="w-full h-full">
    <div class="flex flex-col w-full h-full">
      <div class="flex-1 flex justify-center items-center">
        <div class="flex flex-col">
          <Space justify="end" class="justify-end">
            <div
              v-for="number in integerPart"
              :key="number"
              class="border border-gray-400 p-2"
              :style="{ color: props.value.valueColor }"
            >
              {{ number }}
            </div>
          </Space>
          <Space justify="end" class="justify-end mt-2">
            <div
              v-for="number in decimalPart"
              :key="number"
              class="border border-gray-400 p-1"
              :style="{ color: props.value.valueColor }"
            >
              {{ number }}
            </div>
          </Space>
        </div>
      </div>

      <div class="text-center">
        <span>{{ props.value.name || '电表' }}</span>
        <span class="px-1">({{ props.value.unit || 'kw/h' }})</span>
      </div>
      <div class="text-center mt-1 text-gray-400 text-xs">
        <span class="mr-1">更新时间:</span>
        <span>{{ props.value.updateTime || dateUtil().format('YYYY-MM-DD HH:mm:ss') }}</span>
      </div>
    </div>
    <div></div>
  </section>
</template>