ui-state.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <!-- 全局设备状态 -->
  3. <view class="w-state" :class="classNmae(state)">{{states[state]}}</view>
  4. </template>
  5. <script>
  6. /**
  7. * 设备状态
  8. * @property {String|Number} state 状态值 1: 在线,0:离线
  9. * @description 设备状态通用组件
  10. * @example <w-state state="1"></w-state>
  11. */
  12. export default {
  13. name: 'io-state',
  14. data() {
  15. return {
  16. // 状态键值对
  17. states: {
  18. 1: '在线',
  19. 0: '离线'
  20. }
  21. }
  22. },
  23. props: {
  24. state: {
  25. type: [String, Number],
  26. default: 1,
  27. }
  28. },
  29. methods: {
  30. // 設置狀態類名
  31. classNmae() {
  32. const names = {
  33. 1: 'on',
  34. 0: 'off'
  35. }
  36. return names[this.state];
  37. }
  38. }
  39. }
  40. </script>
  41. <style lang="scss" scoped>
  42. .w-state {
  43. width: 94rpx;
  44. height: 40rpx;
  45. line-height: 1;
  46. display: flex;
  47. align-items: center;
  48. justify-content: center;
  49. border-radius: 4rpx;
  50. font-size: 28rpx;
  51. &.on {
  52. background-color: rgba(49, 122, 253, .3);
  53. color: #3377FE;
  54. }
  55. &.off {
  56. background-color: rgba(233, 63, 39, .3);
  57. color: #E93F27;
  58. }
  59. }
  60. </style>