access.vue 5.5 KB

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