index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div class="query-box">
  3. <div class="query-head">
  4. <div class="query-tbas">
  5. <div class="tbas-title" :class="activeKey == '1' ? 'active' : ''" @click="activeclick('1')">冷链采集器</div>
  6. <a-divider type="vertical" style="height: 15px; background-color: #f4f5f7; margin: 8px 20px" />
  7. <div class="tbas-title" :class="activeKey == '2' ? 'active' : ''" @click="activeclick('2')">冷链中继器</div>
  8. </div>
  9. </div>
  10. <div class="query-body">
  11. <Collector ref="collectorRef" v-if="activeKey == '1'" />
  12. <Repeater ref="repeaterRef" v-if="activeKey == '2'" />
  13. </div>
  14. </div>
  15. </template>
  16. <script setup>
  17. import Collector from './collector.vue'
  18. import Repeater from './repeater.vue'
  19. const activeKey = ref('1')
  20. const collectorRef = ref(null)
  21. const repeaterRef = ref(null)
  22. onMounted(() => {})
  23. onBeforeMount(() => {})
  24. // 点击标签
  25. const activeclick = (v) => {
  26. activeKey.value = v
  27. }
  28. // 监听
  29. watch(
  30. () => activeKey.value,
  31. (newValue) => {
  32. if (newValue === '1' && collectorRef.value) {
  33. collectorRef.value.loadData()
  34. } else if (newValue === '2' && repeaterRef.value) {
  35. repeaterRef.value.loadData()
  36. }
  37. },
  38. {
  39. immediate: true // 立即执行
  40. }
  41. )
  42. </script>
  43. <style lang="less" scoped>
  44. .query-box {
  45. width: 100%;
  46. height: 100vh;
  47. overflow: hidden;
  48. background-color: #fff;
  49. // 顶部
  50. .query-head {
  51. width: 100%;
  52. height: 50px;
  53. display: flex;
  54. justify-content: space-between;
  55. padding: 15px;
  56. border-bottom: 1px solid #e7e7e7;
  57. .query-tbas {
  58. width: 95%;
  59. display: flex;
  60. .tbas-title {
  61. height: 35px;
  62. line-height: 25px;
  63. color: #a7a7a7;
  64. font-size: 16px;
  65. cursor: pointer;
  66. }
  67. .active {
  68. color: #1b8fff;
  69. border-bottom: 2px solid #1b8fff;
  70. }
  71. }
  72. }
  73. }
  74. </style>