|
| 1 | +<template> |
| 2 | + <button class="ui button toggle mybtn" :class="[btnColour, 'mybtn']"></button> |
| 3 | +</template> |
| 4 | +<script> |
| 5 | +export default { |
| 6 | + name: 'LedComponent', |
| 7 | + props: { |
| 8 | + id: { type: String, default: '' }, |
| 9 | + onColour: { type: String, default: 'green' }, |
| 10 | + offColour: { type: String, default: 'white' }, |
| 11 | + errColour: { type: String, default: 'amber' }, |
| 12 | + ledValue: { type: Boolean, default: false }, |
| 13 | + isSolidLed: { type: Boolean, default: false }, |
| 14 | + isServiceLed: { type: Boolean, default: false }, |
| 15 | + issysAttentionLed: { type: Boolean, default: false }, |
| 16 | + issysidentifyLed: { type: Boolean, default: false }, |
| 17 | + health: { type: String, default: '' }, |
| 18 | + }, |
| 19 | + data() { |
| 20 | + return { |
| 21 | + checkbox: false, |
| 22 | + blinkcolour: false, |
| 23 | + btnColour: 'white', |
| 24 | + intervalId: 0, |
| 25 | + onColours: this.onColour, |
| 26 | + offColours: this.offColour, |
| 27 | + errColours: 'red', |
| 28 | + cid: this.id, |
| 29 | + }; |
| 30 | + }, |
| 31 | + mounted() { |
| 32 | + if (this.isServiceLed && this.isSolidLed) { |
| 33 | + clearInterval(this.intervalId); |
| 34 | + if (this.ledValue === `global.status.on`) { |
| 35 | + this.turnon(); |
| 36 | + } else { |
| 37 | + this.startBlinking(); |
| 38 | + } |
| 39 | + } else if (this.isServiceLed) { |
| 40 | + if (this.isServiceLed && this.issysidentifyLed) { |
| 41 | + this.issysidentifyLed ? this.turnon() : this.turnoff(); |
| 42 | + } else if (this.isServiceLed && this.issysAttentionLed) { |
| 43 | + this.issysAttentionLed ? this.turnon() : this.turnoff(); |
| 44 | + } |
| 45 | + } else { |
| 46 | + if (!(this.health === 'Critical')) { |
| 47 | + if (this.ledValue) { |
| 48 | + this.startBlinking(); |
| 49 | + } else { |
| 50 | + this.stopBlinking(); |
| 51 | + } |
| 52 | + } else { |
| 53 | + this.turnon(); |
| 54 | + } |
| 55 | + } |
| 56 | + }, |
| 57 | + methods: { |
| 58 | + myFunction() { |
| 59 | + if (this.blinkcolour) { |
| 60 | + this.turnoff(); |
| 61 | + } else { |
| 62 | + this.turnon(); |
| 63 | + } |
| 64 | + }, |
| 65 | + turnoff() { |
| 66 | + this.blinkcolour = false; |
| 67 | + this.btnColour = this.offColour; |
| 68 | + }, |
| 69 | + turnon() { |
| 70 | + this.blinkcolour = true; |
| 71 | + this.btnColour = this.onColour; |
| 72 | + }, |
| 73 | +
|
| 74 | + toggleCheckbox() { |
| 75 | + this.checkbox = true; |
| 76 | + if (this.blinkcolour) { |
| 77 | + this.turnoff(); |
| 78 | + this.blinkcolour = false; |
| 79 | + } else { |
| 80 | + this.turnon(); |
| 81 | + this.blinkcolour = true; |
| 82 | + } |
| 83 | + this.intervalId = setInterval(this.myFunction, 500); |
| 84 | + }, |
| 85 | +
|
| 86 | + turnErrorColor() { |
| 87 | + if (this.checkbox) { |
| 88 | + this.stopBlinking(); |
| 89 | + } |
| 90 | + this.blinkcolour = true; |
| 91 | + this.btnColour = this.errColours; |
| 92 | + }, |
| 93 | +
|
| 94 | + stopBlinking() { |
| 95 | + clearInterval(this.intervalId); |
| 96 | + this.turnoff(); |
| 97 | + this.checkbox = false; |
| 98 | + }, |
| 99 | + startBlinking() { |
| 100 | + if (!this.checkbox) this.toggleCheckbox(); |
| 101 | + }, |
| 102 | + }, |
| 103 | +}; |
| 104 | +</script> |
| 105 | + |
| 106 | +<style scoped> |
| 107 | +.mybtn { |
| 108 | + border-radius: 50%; |
| 109 | + padding: 12px; |
| 110 | + border-color: black; |
| 111 | + color: black; |
| 112 | + outline-color: black; |
| 113 | +} |
| 114 | +
|
| 115 | +.green { |
| 116 | + background-color: green; |
| 117 | +} |
| 118 | +.blue { |
| 119 | + background-color: #0029e0; |
| 120 | +} |
| 121 | +.amber { |
| 122 | + background-color: #ffb300; |
| 123 | +} |
| 124 | +.red { |
| 125 | + background-color: red; |
| 126 | +} |
| 127 | +.white { |
| 128 | + background-color: white; |
| 129 | +} |
| 130 | +.lightgrey { |
| 131 | + background-color: lightgrey; |
| 132 | +} |
| 133 | +</style> |
0 commit comments