index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <!-- 气象环境检测列表 -->
  3. <view>
  4. <!-- 搜索框 -->
  5. <ui-search placeholder="请输入设备ID" @confirm="searchDevice"></ui-search>
  6. <!-- 搜索框end -->
  7. <!-- 气象列表 -->
  8. <block v-for="(item,index) in deviceList" :key="index">
  9. <view class="ui-card forecast-item" @click="openDeviceDetails(item)">
  10. <view class="flex-1 info">
  11. <view class="font-16 title on">设备名称:{{item.equip_name}}</view>
  12. <view class="text">设备ID:{{item.equip_id}}</view>
  13. <view class="text text-ellipsis">地址:{{item.address}}</view>
  14. <view class="text">最新上报时间:{{item.uptime | timeFrom('yyyy-mm-dd hh:MM:ss')}}</view>
  15. </view>
  16. <ui-state :state="item.is_online"></ui-state>
  17. </view>
  18. </block>
  19. <!-- 气象列表end -->
  20. </view>
  21. </template>
  22. <script>
  23. import {
  24. getWeatherDeviceList
  25. } from '@/api/weather.js'
  26. export default {
  27. data() {
  28. return {
  29. // 列表搜索条件
  30. params: {
  31. device_id: '', //筛选项 设备号、设备名称
  32. page: 1,
  33. page_size: 10,
  34. // device_status: // 筛选项 1在线 0离线
  35. device_type: 5, // 5气象站 8墒情站
  36. },
  37. deviceList: [], // 设备列表
  38. total: 0, // 设备总数
  39. };
  40. },
  41. onLoad() {
  42. this.getDeviceList();
  43. },
  44. // 触底请求
  45. onReachBottom(e) {
  46. if (this.deviceList.length >= this.total) {
  47. return;
  48. }
  49. this.params.page += 1;
  50. this.getDeviceList();
  51. },
  52. //下拉刷新
  53. onPullDownRefresh() {
  54. this.refreshDeviceList();
  55. uni.stopPullDownRefresh()
  56. },
  57. methods: {
  58. // 刷新设备列表
  59. refreshDeviceList(){
  60. this.params.page = 1;
  61. this.deviceList=[];
  62. this.getDeviceList();
  63. },
  64. /**
  65. * 打开设备详情
  66. * @param {Object} device 设备信息
  67. */
  68. openDeviceDetails(device) {
  69. let params={
  70. equip_name: device.equip_name, //设备名称
  71. equip_id: device.equip_id, //设备号
  72. address: device.address, //组织地址
  73. is_online: device.is_online, //在线状态 0离线 1在线
  74. uptime: device.uptime //数据更新时间 秒级时间戳
  75. }
  76. uni.navigateTo({
  77. url: `details?params=${JSON.stringify(params)}`
  78. })
  79. },
  80. // 获取设备列表
  81. async getDeviceList() {
  82. const {
  83. ids,
  84. nums
  85. } = await getWeatherDeviceList();
  86. this.deviceList = [...this.deviceList, ...ids];
  87. this.total = nums ?? 0;
  88. },
  89. /**
  90. * 搜索设备
  91. * @param {String} val 搜索内容
  92. */
  93. searchDevice(val) {
  94. this.params.device_id = val;
  95. this.refreshDeviceList();
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. </style>