equipment.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="page">
  3. <div class="header-view">
  4. <div class="view_item" v-for="(item, index) in headerList" :key="index">{{ item }}</div>
  5. </div>
  6. <div class="warning-view">
  7. <div class="scroll-view" ref="scrollViewRef" @mouseenter="onMouseenter" @mouseleave="onMouseleave">
  8. <div ref="listRef" class="list" v-for="(p, n) in count" :key="n">
  9. <div class="item" v-for="(item, index) in data" :key="index">
  10. <div class="content view_item">{{ item.Name }}</div>
  11. <!-- 运行/停止/故障 -->
  12. <div class="time view_item" :class="item.State == 0 ? 'blue_title' : 'red_title'">
  13. {{ item.State == 0 ? '运行' : '停止' }}
  14. </div>
  15. <div class="time view_item">{{ item.Date }}</div>
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script setup>
  23. import { ref, onBeforeMount, onMounted, onBeforeUnmount, nextTick } from "vue";
  24. const props = defineProps({
  25. resultData: {
  26. type: Array,
  27. default: []
  28. }
  29. })
  30. const headerList = ref(['名称', '状态', '时间'])
  31. const data = ref(); //列表数据
  32. const listRef = ref(); //列表dom
  33. const scrollViewRef = ref(); //滚动区域dom
  34. const count = ref(1); //列表个数
  35. let intervalId = null;
  36. let isAutoScrolling = true; //是否自动滚动标识
  37. //获取列表数据
  38. const getData = () => {
  39. //模拟接口请求列表数据
  40. return new Promise((resolve, reject) => {
  41. setTimeout(() => {
  42. //生成10条数据
  43. let list = new Array(30).fill().map((item, index) => index);
  44. resolve(list);
  45. }, 100);
  46. });
  47. };
  48. watch(() => props.resultData, (newVal) => {
  49. if (newVal) {
  50. // data.value = await getData();
  51. data.value = newVal;
  52. intervalId && clearInterval(intervalId);
  53. nextTick(() => {
  54. //判断列表是否生成滚动条
  55. count.value = hasScrollBar() ? 2 : 1;
  56. //有滚动条开始自动滚动
  57. if (count.value == 2) {
  58. autoScrolling();
  59. }
  60. });
  61. }
  62. }, { deep: true, immediate: true } // 开启深度监听
  63. )
  64. onMounted(() => {
  65. })
  66. //判断列表是否有滚动条
  67. const hasScrollBar = () => {
  68. return scrollViewRef.value.scrollHeight > scrollViewRef.value.clientHeight;
  69. };
  70. //设置自动滚动
  71. const autoScrolling = () => {
  72. intervalId = setInterval(() => {
  73. if (scrollViewRef.value.scrollTop < listRef.value[0].clientHeight) {
  74. scrollViewRef.value.scrollTop += isAutoScrolling ? 1 : 0;
  75. } else {
  76. scrollViewRef.value.scrollTop = 0;
  77. }
  78. }, 20);
  79. };
  80. onBeforeUnmount(() => {
  81. //离开页面清理定时器
  82. intervalId && clearInterval(intervalId);
  83. });
  84. //鼠标进入,停止滚动
  85. const onMouseenter = () => {
  86. isAutoScrolling = false;
  87. };
  88. //鼠标移出,继续滚动
  89. const onMouseleave = () => {
  90. isAutoScrolling = true;
  91. };
  92. </script>
  93. <style scoped lang="scss">
  94. .page {
  95. width: 100%;
  96. height: 100%;
  97. display: flex;
  98. flex-direction: column;
  99. justify-content: center;
  100. align-items: center;
  101. overflow: hidden;
  102. }
  103. .header-view {
  104. margin-top: 10px;
  105. width: 100%;
  106. display: flex;
  107. align-items: center;
  108. justify-content: space-between;
  109. padding: 10px 10px 10px 20px;
  110. background-color: rgba(16, 40, 92, 1);
  111. }
  112. .view_item {
  113. flex: 1;
  114. // display: flex;
  115. // align-items: center;
  116. // justify-content: flex-start;
  117. white-space: nowrap;
  118. text-overflow: ellipsis;
  119. overflow: hidden;
  120. }
  121. .warning-view {
  122. width: 100%;
  123. height: calc(100% - 51px);
  124. display: flex;
  125. flex-direction: column;
  126. }
  127. .label {
  128. color: #fff;
  129. padding: 20px;
  130. font-size: 22px;
  131. }
  132. .scroll-view {
  133. flex: 1;
  134. height: 0;
  135. width: 100%;
  136. overflow-y: auto;
  137. }
  138. .list {
  139. width: 100%;
  140. box-sizing: border-box;
  141. }
  142. .item {
  143. padding: 0px 10px 0px 20px;
  144. width: 100%;
  145. height: 50px;
  146. min-height: 50px;
  147. font-size: 15px;
  148. display: flex;
  149. align-items: center;
  150. justify-content: space-between;
  151. color: #eee;
  152. }
  153. .item:nth-child(even) {
  154. background: rgba(16, 40, 92, 0.4);
  155. }
  156. .item:hover {
  157. cursor: pointer;
  158. background-image: linear-gradient(to right, #168cdb, transparent);
  159. }
  160. /*隐藏滚动条
  161. */
  162. ::-webkit-scrollbar {
  163. display: none;
  164. }
  165. .blue_title {
  166. color: #67C23A;
  167. }
  168. .red_title {
  169. color: #F56C6C;
  170. }
  171. </style>