deviceList.vue 5.9 KB

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