sameDay.vue 6.9 KB

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