index.vue 2.9 KB

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