index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div>
  3. <template v-if="props.isSimple">
  4. <div v-if="props.pre">{{ props.pre }}</div>
  5. <div class="font-bold mr-spacd4" :class="props.valueClass">
  6. {{ func.convert.nullView(props.value) }}
  7. </div>
  8. <div v-if="props.unit">{{ props.unit }}</div>
  9. </template>
  10. <template v-else>
  11. <div v-if="props.pre">{{ props.pre }}</div>
  12. <div v-if="func.isnull(props.value)">
  13. {{ func.convert.nullView(props.value) }}
  14. </div>
  15. <div class="mr-spacd4" v-else>
  16. <div class="font-bold b-fz" v-if="numer.integer">{{ numer.integer }}</div>
  17. <div class="font-bold" v-if="numer.decimal">{{ numer.decimal }}</div>
  18. </div>
  19. <div v-if="numer.unit">{{ numer.unit }}</div>
  20. </template>
  21. </div>
  22. </template>
  23. <script lang="ts" setup>
  24. type Numer = { integer?: string; decimal?: string; unit: string }
  25. const props = withDefaults(
  26. defineProps<{
  27. isSimple?: boolean
  28. value?: number | string
  29. pre?: string
  30. unit?: string
  31. valueClass: string[]
  32. }>(),
  33. {
  34. value: '',
  35. unit: '',
  36. },
  37. )
  38. const numer = computed(() => {
  39. if (props.isSimple) return
  40. const arr = props.value.toString().split('.')
  41. return {
  42. integer: arr[0],
  43. decimal: arr[1] ? '.' + arr[1] : '',
  44. unit: props.unit,
  45. } as Numer
  46. })
  47. </script>
  48. <style lang="scss" scoped>
  49. div,
  50. view {
  51. display: inline-block;
  52. }
  53. </style>