list.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="device-list">
  3. <up-search v-model="searchValue"></up-search>
  4. <view class="stat-ctl">
  5. <view class="u-page__tag-item" v-for="(item, index) in DeviceState" :key="index">
  6. <up-tag
  7. :text="item.label"
  8. :plain="selectTag === item.value"
  9. :plainFill="true"
  10. bgColor="#007aff"
  11. :name="item.value"
  12. @click="()=>radioClick(item)"
  13. >
  14. </up-tag>
  15. </view>
  16. </view>
  17. <view class="u-page-list" style="padding-bottom: 100rpx">
  18. <up-list @scrolltolower="scrolltolower">
  19. <up-list-item
  20. v-for="(item, index) in indexList"
  21. :key="item.id"
  22. >
  23. <view class="item-content">
  24. <up-image
  25. :showLoading="true"
  26. :src="getDevImg(item.devImg)"
  27. width="160rpx"
  28. height="150rpx"
  29. :lazy-load="true"
  30. >
  31. <template #error>
  32. <view style="font-size: 24rpx;">加载失败</view>
  33. </template>
  34. </up-image>
  35. <view class="content-info">
  36. <view>
  37. <up-text :lines="1" :text="`设备名称: ${formatTxt(item.deviceNickname)}`" size="24rpx"/>
  38. <up-tag :text="item.statusName" plain size="mini" :bgColor="valueToConst(DeviceState,item.status).color"
  39. class="tag-stat"></up-tag>
  40. <up-text text="详情>" color="#007aff" style="flex:none;width: auto"
  41. @click="()=>onDetailClick(item)"></up-text>
  42. </view>
  43. <view>
  44. <up-text :lines="1" :text="`设备编码:${formatTxt(item.name)}`" size="24rpx"/>
  45. </view>
  46. <view>
  47. <up-text :lines="1" :text="`上线时间:${formatTxt(item.lastOnlineTime)}`" size="24rpx"/>
  48. </view>
  49. </view>
  50. </view>
  51. </up-list-item>
  52. <up-loading-icon v-if="loading" text="加载中" textSize="12"></up-loading-icon>
  53. <up-text
  54. v-if="!loadmoreFlag" text="已经到底了" style="justify-content: center;"
  55. size="24rpx"
  56. color="gray"
  57. >
  58. </up-text>
  59. </up-list>
  60. </view>
  61. </view>
  62. </template>
  63. <script setup lang="ts">
  64. import {ref} from "vue"
  65. import {DeviceState} from '@/common/consts/DeviceConst.js'
  66. import {valueToConst} from '@/common/consts/CommonConst.js'
  67. import {onLoad} from '@dcloudio/uni-app';
  68. import {formatTxt, getDevImg, navigateTo,} from '@/util/index.js'
  69. import {getDeviceList} from "@/api/device.js";
  70. const page = ref(1)
  71. onLoad(() => {
  72. page.value = 1
  73. loading.value = true;
  74. loadmore();
  75. });
  76. let searchValue = ref("")
  77. let indexList = ref([])
  78. let selectTag = ref(DeviceState.ALL.value)
  79. let loadmoreFlag = ref(true)
  80. let loading = ref(false)
  81. function radioClick(item) {
  82. selectTag.value = item.value
  83. }
  84. const loadmore = async () => {
  85. const {records} = await getDeviceList({
  86. page: page.value,
  87. deviceNickName: searchValue.value,
  88. deviceState: selectTag.value,
  89. })
  90. if (records && records.length > 0) {
  91. indexList.value = indexList.value.concat(records)
  92. page.value += 1
  93. if (records.length < 10) {
  94. loadmoreFlag.value = false;
  95. }
  96. } else {
  97. loadmoreFlag.value = false;
  98. }
  99. loading.value = false;
  100. };
  101. const scrolltolower = () => {
  102. if (!loadmoreFlag.value) return;
  103. loading.value = true;
  104. loadmore();
  105. };
  106. const onDetailClick = (item) => {
  107. navigateTo({
  108. url: "/pages/workbenchsub/device/detail",
  109. param: item
  110. })
  111. }
  112. </script>
  113. <style lang="scss">
  114. .device-list {
  115. width: 680rpx;
  116. margin: 14rpx auto 0;
  117. .u-search__content {
  118. background: $uni-bg-color !important;
  119. .u-search__content__input {
  120. background-color: $uni-bg-color !important;
  121. }
  122. }
  123. .u-page-list {
  124. margin-top: 14rpx;
  125. }
  126. .item-content {
  127. width: 100%;
  128. border-radius: $comm-border-radius;
  129. display: flex;
  130. box-sizing: border-box;
  131. align-items: center;
  132. justify-content: flex-start;
  133. background: $uni-bg-color;
  134. margin-bottom: 14rpx;
  135. padding: 14rpx;
  136. .content-info {
  137. flex: 1;
  138. display: flex;
  139. flex-direction: column;
  140. align-items: flex-start;
  141. justify-content: flex-start;
  142. margin-left: 14rpx;
  143. > view {
  144. font-size: inherit;
  145. width: 100%;
  146. display: flex;
  147. align-items: center;
  148. justify-content: flex-start;
  149. .tag-stat {
  150. margin-left: auto;
  151. margin-right: 14rpx;
  152. .u-tag--mini {
  153. height: 35rpx;
  154. }
  155. .u-tag--primary--plain {
  156. border-color: transparent !important;
  157. .u-tag__text--primary--plain {
  158. color: $uni-bg-color !important;
  159. font-size: 18rpx !important;
  160. }
  161. }
  162. }
  163. .u-link {
  164. flex: none;
  165. }
  166. &:not(:first-child) {
  167. margin-top: 14rpx;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. </style>