topBar.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div id="top-bar">
  3. <div :class="$style.bar">
  4. <div
  5. v-for="(item, index) in topBarData"
  6. :key="index"
  7. :class="$style.item"
  8. >
  9. <div :class="$style.title">{{ item.title }}</div>
  10. <div
  11. v-for="(v, i) in item.children"
  12. :key="i"
  13. :class="$style.box"
  14. >
  15. <div :class="$style.label">{{ v.label }}</div>
  16. <div :class="$style.count">
  17. <dv-digital-flop
  18. :config="v.data"
  19. :class="$style.flop"
  20. />
  21. <div :class="$style.unit">{{ v.unit }}</div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <dv-decoration-10 />
  27. </div>
  28. </template>
  29. <script>
  30. import { getRandomColor } from '../data.js'
  31. export default {
  32. name: 'topBar',
  33. props: {
  34. info: {
  35. type: Array,
  36. default: []
  37. },
  38. color: {
  39. type: Array,
  40. default: []
  41. }
  42. },
  43. components: {},
  44. watch: {
  45. info(v) {
  46. this.update()
  47. }
  48. },
  49. data() {
  50. return {
  51. topBarData: []
  52. }
  53. },
  54. created() {
  55. this.update()
  56. },
  57. methods: {
  58. // 数据更新
  59. update() {
  60. const fontColor = [...this.color].sort(() => Math.random() - 0.5)
  61. const colorGenerator = getRandomColor(fontColor)
  62. this.info.forEach(item => {
  63. item.children.forEach(i => {
  64. i.data = {
  65. number: [i.value],
  66. content: '{nt}',
  67. textAlign: 'right',
  68. style: {
  69. fill: colorGenerator.next().value,
  70. fontWeight: 'bold'
  71. }
  72. }
  73. i.unit = item.unit
  74. })
  75. })
  76. this.topBarData = JSON.parse(JSON.stringify(this.info))
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" module>
  82. .bar {
  83. position: relative;
  84. height: 90%;
  85. margin: 20px 2%;
  86. display: flex;
  87. // flex-shrink: 0;
  88. justify-content: space-between;
  89. align-items: center;
  90. background-color: rgba(6, 30, 93, 0.5);
  91. .item {
  92. width: 20%;
  93. // width: calc(100% / 13);
  94. height: 60%;
  95. padding: 12px 20px;
  96. border-left: 5px solid rgb(6, 30, 93);
  97. &:first-child{
  98. width: 33.3%;
  99. .box{
  100. width: 20%;
  101. }
  102. }
  103. &:last-child{
  104. width: 26.6%;
  105. .box{
  106. width: 25%;
  107. }
  108. }
  109. .title {
  110. text-align: center;
  111. font-size: 20px;
  112. font-weight: bold;
  113. margin-bottom: 20px;
  114. }
  115. .box{
  116. display: inline-block;
  117. width: 33%;
  118. .label{
  119. text-align: center;
  120. font-size: 14px;
  121. }
  122. .count {
  123. display: flex;
  124. align-items: center;
  125. justify-content: center;
  126. .flop {
  127. width: 60px;
  128. height: 40px;
  129. font-size: 18px;
  130. }
  131. .unit {
  132. margin-left: 10px;
  133. box-sizing: border-box;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. :global {
  140. #top-bar{
  141. height: 150px;
  142. }
  143. .dv-decoration-10 {
  144. width: 96%;
  145. margin: -7px 2% 0;
  146. height: 5px;
  147. }
  148. }
  149. </style>