SeparatorComponent.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <!-- 分离器 -->
  3. <div class="tank_body" :style="getTankBodyStyle">
  4. <i class="icon iconfont-hnyz-colour icon-hnyz-colourseparator tank " :style="getTankStyle">
  5. <!-- 标题 -->
  6. <div class="tank_title" v-if="title">{{ title }}</div>
  7. </i>
  8. </div>
  9. </template>
  10. <script setup>
  11. import { computed } from 'vue'
  12. const props = defineProps({
  13. iconSize: {//图标大小
  14. type: Number,
  15. default: 200,
  16. },
  17. title: {//罐名
  18. type: String,
  19. },
  20. iconWidth: {//图标宽度
  21. type: Number,
  22. },
  23. iconHeight: {//图标高度
  24. type: Number,
  25. },
  26. })
  27. //罐体样式
  28. const getTankBodyStyle = computed(() => ({
  29. width: `${props.iconWidth ?? props.iconSize}px`,
  30. height: `${props.iconHeight ?? props.iconSize}px`,
  31. fontSize: `${props.iconSize}px`,
  32. }))
  33. // 罐子样式
  34. const getTankStyle = computed(() => {
  35. const style = {
  36. fontSize: props.iconSize + 'px',
  37. display: 'inline-block'
  38. }
  39. //根据传进来的iconWidth和iconHeight来控制图标的大小
  40. const scaleX = props.iconWidth ? props.iconWidth / props.iconSize : 1
  41. const scaleY = props.iconHeight ? props.iconHeight / props.iconSize : 1
  42. if (scaleX !== 1 || scaleY !== 1) {
  43. style.transform = `scale(${scaleX}, ${scaleY})`
  44. }
  45. return style
  46. })
  47. </script>
  48. <style scoped lang="scss">
  49. //水位罐
  50. .tank_body {
  51. text-align: center;
  52. position: relative;
  53. .tank {
  54. position: relative;
  55. z-index: 10;
  56. //罐子名称
  57. .tank_title {
  58. position: absolute;
  59. top: 47%;
  60. left: 50%;
  61. transform: translate(-50%, -50%);
  62. font-size: 16px;
  63. color: #d3e600;
  64. font-weight: bold;
  65. }
  66. }
  67. }
  68. </style>