index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. async onLoad(options) {
  43. await this.$onLaunched;
  44. //获取类型 5气象站 8墒情站
  45. this.params.device_type=options.type ?? 5;
  46. this.getDeviceList();
  47. },
  48. // 触底请求
  49. onReachBottom(e) {
  50. if (this.deviceList.length >= this.total) {
  51. return;
  52. }
  53. this.params.page += 1;
  54. this.getDeviceList();
  55. },
  56. //下拉刷新
  57. onPullDownRefresh() {
  58. this.refreshDeviceList();
  59. uni.stopPullDownRefresh()
  60. },
  61. methods: {
  62. // 刷新设备列表
  63. refreshDeviceList(){
  64. this.params.page = 1;
  65. this.deviceList=[];
  66. this.getDeviceList();
  67. },
  68. /**
  69. * 打开设备详情
  70. * @param {Object} device 设备信息
  71. */
  72. openDeviceDetails(device) {
  73. let params={
  74. equip_name: device.equip_name, //设备名称
  75. equip_id: device.equip_id, //设备号
  76. address: device.address, //组织地址
  77. is_online: device.is_online, //在线状态 0离线 1在线
  78. uptime: device.uptime ,//数据更新时间 秒级时间戳
  79. device_type: this.params.device_type, // 5气象站 8墒情站
  80. }
  81. uni.navigateTo({
  82. url: `details?params=${JSON.stringify(params)}`
  83. })
  84. },
  85. // 获取设备列表
  86. async getDeviceList() {
  87. this.$api.loading('加载中...');
  88. const {
  89. ids,
  90. nums
  91. } = await getWeatherDeviceList(this.params);
  92. this.$api.hide();
  93. this.deviceList = [...this.deviceList, ...ids];
  94. this.total = nums ?? 0;
  95. },
  96. /**
  97. * 搜索设备
  98. * @param {String} val 搜索内容
  99. */
  100. searchDevice(val) {
  101. this.params.device_id = val;
  102. this.refreshDeviceList();
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss">
  108. </style>