index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div class="robotbar" @click="changeRobot">
  3. <div class="name">{{ deviceInfo.name }}</div>
  4. <div class="online-state">
  5. <div class="light" :style="{ backgroundColor: getOnlineColor }"></div>
  6. <div class="text">{{ getOnlineState }}</div>
  7. </div>
  8. <div class="alarm-state">
  9. <div class="light" :style="{ backgroundColor: getAlarmColor }"></div>
  10. <div class="text">{{ getAlarmState }}</div>
  11. </div>
  12. <div></div>
  13. </div>
  14. </template>
  15. <script>
  16. import lodash from 'lodash'
  17. export default {
  18. props: {
  19. deviceInfo: {
  20. type: Object,
  21. default: {
  22. id: '1',
  23. name: '机器人1#',
  24. onlineState: '1',
  25. alarmState: '0',
  26. },
  27. },
  28. },
  29. data() {
  30. return {
  31. onlineStateOptions: [
  32. { code: '0', text: '离线', color: '#526891' },
  33. { code: '1', text: '运行', color: '#28b973' },
  34. { code: '2', text: '急停', color: '#f32727' },
  35. ],
  36. alarmStateOptions: [
  37. { code: '0', text: '正常', color: '#28b973' },
  38. { code: '1', text: '故障', color: '#f32727' },
  39. ],
  40. }
  41. },
  42. computed: {
  43. getOnlineState() {
  44. return lodash.find(this.onlineStateOptions, (o) => {
  45. return o.code == this.deviceInfo.onlineState
  46. }).text
  47. },
  48. getAlarmState() {
  49. return lodash.find(this.alarmStateOptions, (o) => {
  50. return o.code == this.deviceInfo.alarmState
  51. }).text
  52. },
  53. getOnlineColor() {
  54. return lodash.find(this.onlineStateOptions, (o) => {
  55. return o.code == this.deviceInfo.onlineState
  56. }).color
  57. },
  58. getAlarmColor() {
  59. return lodash.find(this.alarmStateOptions, (o) => {
  60. return o.code == this.deviceInfo.alarmState
  61. }).color
  62. },
  63. },
  64. methods: {
  65. //回传选中设备
  66. changeRobot() {
  67. this.$emit('changeRobot', this.deviceInfo)
  68. },
  69. },
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .robotbar {
  74. background-color: #1278e1;
  75. color: white;
  76. height: 47px;
  77. display: flex;
  78. gap: 10px;
  79. width: 100%;
  80. border-radius: 5px !important;
  81. .name {
  82. margin-top: 10px;
  83. width: 150px;
  84. height: 27px;
  85. min-width: 80px;
  86. line-height: 27px;
  87. font-size: 16px;
  88. display: inline-block;
  89. vertical-align: middle;
  90. text-align: center;
  91. }
  92. .online-state {
  93. margin-top: 10px;
  94. width: 82px;
  95. min-width: 82px;
  96. height: 27px;
  97. display: inline-block;
  98. border-radius: 15px;
  99. background-color: #063e92;
  100. .light {
  101. width: 12px;
  102. height: 12px;
  103. display: inline-block;
  104. margin-left: 12px;
  105. margin-top: 8px;
  106. border-radius: 5px;
  107. }
  108. .text {
  109. display: inline-block;
  110. margin-left: 12px;
  111. font-size: 14px;
  112. height: 10px;
  113. }
  114. }
  115. .alarm-state {
  116. margin-top: 10px;
  117. width: 82px;
  118. min-width: 82px;
  119. height: 27px;
  120. display: inline-block;
  121. border-radius: 15px;
  122. background-color: #063e92;
  123. .light {
  124. width: 12px;
  125. height: 12px;
  126. display: inline-block;
  127. margin-left: 12px;
  128. margin-top: 8px;
  129. border-radius: 5px;
  130. }
  131. .text {
  132. display: inline-block;
  133. margin-left: 12px;
  134. font-size: 14px;
  135. height: 10px;
  136. }
  137. }
  138. }
  139. </style>