access.vue 5.3 KB

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