index.vue 2.7 KB

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