eventList.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="_eventList">
  3. <HeadlineTag type="right" value="终端日志" style="flex-shrink: 0;"></HeadlineTag>
  4. <div class="scroll-view" ref="scrollViewRef" v-if="data && data.length > 0" @mouseenter="onMouseenter"
  5. @mouseleave="onMouseleave">
  6. <div ref="listRef" class="list" v-for="(p, n) in count" :key="n">
  7. <div class="item" v-for="(item, index) in data" :key="index">
  8. <div class="_eventList_mains_item_text">
  9. <div :class="item.store === 'on' ? '_warning' : '_success'"
  10. class="_eventList_mains_item_text_flag"></div>
  11. <el-text class="w-150px mb-2" truncated style="color: white;margin-left: 10px;">
  12. {{ index + 1 }}#{{ item.TerminalLog }}
  13. </el-text>
  14. </div>
  15. <div class="_eventList_mains_item_btn">
  16. {{ item.TerminalTime }}
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. <Empty :bottom="true" v-else></Empty>
  22. </div>
  23. </template>
  24. <script setup>
  25. import { ref, onBeforeMount, onMounted, onBeforeUnmount, nextTick } from "vue";
  26. import HeadlineTag from '@/components/HeadlineTag'
  27. import Empty from '@/components/Empty'
  28. const props = defineProps({
  29. resultData: {
  30. type: Array,
  31. default: []
  32. }
  33. })
  34. const headerList = ref(['名称', '使用状态', '状态'])
  35. const data = ref([]); //列表数据
  36. const listRef = ref(); //列表dom
  37. const scrollViewRef = ref(); //滚动区域dom
  38. const count = ref(1); //列表个数
  39. let intervalId = null;
  40. let isAutoScrolling = true; //是否自动滚动标识
  41. //获取列表数据
  42. const getData = () => {
  43. //模拟接口请求列表数据
  44. return new Promise((resolve, reject) => {
  45. setTimeout(() => {
  46. //生成10条数据
  47. let list = new Array(30).fill().map((item, index) => index);
  48. resolve(list);
  49. }, 100);
  50. });
  51. };
  52. watch(() => props.resultData, (newVal) => {
  53. if (newVal) {
  54. // data.value = await getData();
  55. data.value = newVal;
  56. intervalId && clearInterval(intervalId);
  57. nextTick(() => {
  58. //判断列表是否生成滚动条
  59. count.value = hasScrollBar() ? 2 : 1;
  60. //有滚动条开始自动滚动
  61. if (count.value == 2) {
  62. autoScrolling();
  63. }
  64. });
  65. }
  66. }, { deep: true, immediate: true } // 开启深度监听
  67. )
  68. onMounted(() => {
  69. })
  70. //判断列表是否有滚动条
  71. const hasScrollBar = () => {
  72. return scrollViewRef.value.scrollHeight > scrollViewRef.value.clientHeight;
  73. };
  74. //设置自动滚动
  75. const autoScrolling = () => {
  76. intervalId = setInterval(() => {
  77. if (scrollViewRef.value.scrollTop < listRef.value[0].clientHeight) {
  78. scrollViewRef.value.scrollTop += isAutoScrolling ? 1 : 0;
  79. } else {
  80. scrollViewRef.value.scrollTop = 0;
  81. }
  82. }, 20);
  83. };
  84. onBeforeUnmount(() => {
  85. //离开页面清理定时器
  86. intervalId && clearInterval(intervalId);
  87. });
  88. //鼠标进入,停止滚动
  89. const onMouseenter = () => {
  90. isAutoScrolling = false;
  91. };
  92. //鼠标移出,继续滚动
  93. const onMouseleave = () => {
  94. isAutoScrolling = true;
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. ._success {
  99. background: #15acaa;
  100. }
  101. ._warning {
  102. background: #FFC107;
  103. }
  104. ._eventList {
  105. overflow: hidden;
  106. display: flex;
  107. flex-direction: column;
  108. &_mains {
  109. // margin: 10px 30px;
  110. overflow: hidden; // 隐藏溢出内容
  111. cursor: pointer;
  112. &_item {
  113. display: flex;
  114. justify-content: space-between;
  115. align-items: center;
  116. padding: 10px 0;
  117. &_text {
  118. display: flex;
  119. justify-content: space-between;
  120. align-items: center;
  121. &_flag {
  122. width: 10px;
  123. height: 10px;
  124. border-radius: 50%;
  125. margin-left: 10px;
  126. }
  127. &_p {
  128. margin-left: 10px;
  129. }
  130. }
  131. &_btn {
  132. color: #fff;
  133. display: flex;
  134. font-size: 14px;
  135. gap: 20px;
  136. &_item {
  137. border-radius: 5px;
  138. cursor: pointer;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. .page {
  145. width: 100%;
  146. height: 100%;
  147. display: flex;
  148. flex-direction: column;
  149. justify-content: center;
  150. align-items: center;
  151. overflow: hidden;
  152. }
  153. .header-view {
  154. margin-top: 10px;
  155. width: 100%;
  156. display: flex;
  157. align-items: center;
  158. justify-content: space-between;
  159. // padding: 10px 10px 10px 20px;
  160. background-color: rgba(16, 40, 92, 1);
  161. }
  162. .view_item {
  163. flex: 1;
  164. // display: flex;
  165. // align-items: center;
  166. // justify-content: flex-start;
  167. white-space: nowrap;
  168. text-overflow: ellipsis;
  169. overflow: hidden;
  170. color: #ffffff;
  171. }
  172. .view_item:first-child {
  173. flex: 2;
  174. }
  175. .warning-view {
  176. width: 100%;
  177. height: calc(100% - 51px);
  178. display: flex;
  179. flex-direction: column;
  180. }
  181. .label {
  182. color: #fff;
  183. padding: 20px;
  184. font-size: 22px;
  185. }
  186. .scroll-view {
  187. flex: 1;
  188. height: 0;
  189. width: 100%;
  190. overflow-y: auto;
  191. }
  192. .list {
  193. width: 100%;
  194. box-sizing: border-box;
  195. }
  196. .item {
  197. padding: 0px 10px 0px 0px;
  198. width: 100%;
  199. height: 50px;
  200. min-height: 50px;
  201. font-size: 15px;
  202. display: flex;
  203. align-items: center;
  204. justify-content: space-between;
  205. color: #eee;
  206. }
  207. .item:nth-child(even) {
  208. background: rgba(16, 40, 92, 0.4);
  209. }
  210. .item:hover {
  211. cursor: pointer;
  212. background-image: linear-gradient(to right, #168cdb, transparent);
  213. }
  214. /*隐藏滚动条
  215. */
  216. ::-webkit-scrollbar {
  217. display: none;
  218. }
  219. </style>