eventList.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="_eventList">
  3. <HeadlineTag type="right" value="维护计划列表" style="flex-shrink: 0;"></HeadlineTag>
  4. <div class="scroll-view" ref="scrollViewRef" @mouseenter="onMouseenter" @mouseleave="onMouseleave">
  5. <div ref="listRef" class="list" v-for="(p, n) in count" :key="n">
  6. <div class="item" v-for="(item, index) in data" :key="index">
  7. <div class="_eventList_mains_item_text">
  8. <div :class="item.DeviceStatus === 0 ? '_success' : '_warning'"
  9. class="_eventList_mains_item_text_flag"></div>
  10. <el-text class="w-150px mb-2" truncated style="color: white;margin-left: 10px;">
  11. {{ item.DeviceName }}
  12. </el-text>
  13. </div>
  14. <el-text class="w-150px mb-2" truncated style="color: white;">
  15. {{ item.EventDate }}
  16. </el-text>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script setup>
  23. import { ref, onMounted, onUnmounted } from "vue";
  24. import HeadlineTag from '@/components/HeadlineTag'
  25. const props = defineProps({
  26. resultData: {
  27. type: Array,
  28. default: []
  29. }
  30. })
  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 lang="scss" scoped>
  94. ._success {
  95. background: #15acaa;
  96. }
  97. ._warning {
  98. background: #FFC107;
  99. }
  100. ._eventList {
  101. overflow: hidden;
  102. display: flex;
  103. flex-direction: column;
  104. &_mains {
  105. margin: 10px 30px;
  106. overflow: hidden; // 隐藏溢出内容
  107. // 鼠标移入时改变手势
  108. cursor: pointer;
  109. &_item {
  110. display: flex;
  111. justify-content: space-between;
  112. align-items: center;
  113. padding: 10px 0;
  114. &_text {
  115. display: flex;
  116. justify-content: space-between;
  117. align-items: center;
  118. &_flag {
  119. width: 10px;
  120. height: 10px;
  121. border-radius: 50%;
  122. margin-left: 10px;
  123. }
  124. &_p {
  125. margin-left: 10px;
  126. }
  127. }
  128. }
  129. &_item:hover {
  130. background-image: linear-gradient(to right, #168cdb, transparent);
  131. }
  132. }
  133. }
  134. .header-view {
  135. margin-top: 10px;
  136. width: 100%;
  137. display: flex;
  138. align-items: center;
  139. justify-content: space-between;
  140. padding: 10px 10px 10px 20px;
  141. background-color: rgba(16, 40, 92, 1);
  142. }
  143. .view_item {
  144. flex: 1;
  145. // display: flex;
  146. // align-items: center;
  147. // justify-content: flex-start;
  148. white-space: nowrap;
  149. text-overflow: ellipsis;
  150. overflow: hidden;
  151. }
  152. .warning-view {
  153. width: 100%;
  154. height: calc(100% - 51px);
  155. display: flex;
  156. flex-direction: column;
  157. }
  158. .label {
  159. color: #fff;
  160. padding: 20px;
  161. font-size: 22px;
  162. }
  163. .scroll-view {
  164. flex: 1;
  165. height: 0;
  166. width: 100%;
  167. overflow-y: auto;
  168. }
  169. .list {
  170. width: 100%;
  171. box-sizing: border-box;
  172. }
  173. .item {
  174. padding: 0px 10px 0px 20px;
  175. width: 100%;
  176. height: 50px;
  177. min-height: 50px;
  178. font-size: 15px;
  179. display: flex;
  180. align-items: center;
  181. justify-content: space-between;
  182. color: #eee;
  183. }
  184. .item:nth-child(even) {
  185. background: rgba(16, 40, 92, 0.4);
  186. }
  187. .item:hover {
  188. cursor: pointer;
  189. background-image: linear-gradient(to right, #168cdb, transparent);
  190. }
  191. /*隐藏滚动条
  192. */
  193. ::-webkit-scrollbar {
  194. display: none;
  195. }
  196. .blue_title {
  197. color: #67C23A;
  198. }
  199. .red_title {
  200. color: #F56C6C;
  201. }
  202. </style>