feiyu02
2025-03-03 7eb2abf43167d9db3fca2e7958b90ff1bea0cead
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<template>
  <el-form
    :inline="true"
    :model="formObj"
    :rules="rules"
    ref="formRef"
    label-position="right"
    label-width="80px"
  >
    <SatelliteSearchBar
      label-width="80px"
      :loading="loading"
      @search="onSearchAOD"
    ></SatelliteSearchBar>
    <OptionAOD ref="optionAODRef" v-model="aodData"></OptionAOD>
    <el-form-item label="产品记录">
      <el-text :type="historyGridData ? 'warning' : 'success'">{{
        historyGridData ? '已生成' : '未生成'
      }}</el-text>
    </el-form-item>
    <el-form-item label="拟合公式">
      <div>
        y =
        <el-input-number
          v-model="a"
          :precision="2"
          controls-position="right"
          :controls="false"
          placeholder="请输入系数a"
          size="small"
        />
        x +
        <el-input-number
          v-model="b"
          :precision="2"
          controls-position="right"
          :controls="false"
          placeholder="请输入系数b"
          size="small"
        />
      </div>
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        class="el-button-custom"
        size="small"
        @click="handleShowAODClick"
      >
        {{ '显示AOD数据' }}
      </el-button>
      <el-button
        type="primary"
        class="el-button-custom"
        size="small"
        @click="handlePreviewClick"
      >
        {{ '拟合预览' }}
      </el-button>
      <el-button
        type="primary"
        class="el-button-custom"
        size="small"
        @click="handleSaveClick"
      >
        {{ '保存拟合结果' }}
      </el-button>
    </el-form-item>
  </el-form>
</template>
<script setup>
import { ref, watch } from 'vue';
import gridApi from '@/api/gridApi';
import aodApi from '@/api/aodApi';
import moment from 'moment';
import SatelliteSearchBar from '@/views/satellitetelemetry/component/SatelliteSearchBar.vue';
import { SatelliteProxy } from '@/views/satellitetelemetry/SatelliteProxy';
 
const satelliteProxy = new SatelliteProxy();
 
const optionAODRef = ref(null);
 
const gridGroup = ref(null);
const aodData = ref(null);
const aodDataDetail = ref(null);
const historyGridData = ref(null);
const a = ref(null);
const b = ref(null);
const tempGridDataDetailList = ref(null);
 
function handleShowAODClick() {
  if (aodDataDetail.value) {
    showAOD(aodDataDetail.value);
  } else {
    _fetchAODDetail().then((res) => {
      showAOD(res);
    });
  }
}
 
// 计算PM2.5结果,后续应该在后端实现
function calculatePM25(aod) {
  return Math.round((a.value * aod + b.value) * 100) / 100;
}
 
function handlePreviewClick() {
  if (aodDataDetail.value) {
    showPreview(aodDataDetail.value);
  } else {
    _fetchAODDetail().then((res) => {
      showPreview(res);
    });
  }
}
 
function showAOD(data) {
  const _aod = data.map((v, i) => {
    return {
      groupId: v.groupId,
      cellId: v.cellId,
      pm25: v.aod,
      rank: i + 1
    };
  });
  satelliteProxy.drawGrid({
    gridDataDetail: _aod,
    showDataTxt: true,
    showRankTxt: true
  });
}
 
function showPreview(data) {
  tempGridDataDetailList.value = data.map((v, i) => {
    return {
      groupId: v.groupId,
      cellId: v.cellId,
      pm25: calculatePM25(v.aod),
      rank: i + 1
    };
  });
  tempGridDataDetailList.value.sort((a, b) => {
    return b.pm25 - a.pm25;
  });
  satelliteProxy.drawGrid({
    gridDataDetail: tempGridDataDetailList.value,
    showDataTxt: true,
    showRankTxt: true
  });
}
 
function handleSaveClick() {}
 
function _fetchAODDetail() {
  return aodApi
    .fetchAODDetail(aodData.value.id, gridGroup.value.id)
    .then((res) => {
      res.data.sort((a, b) => {
        return b.aod - a.aod;
      });
      aodDataDetail.value = res.data;
      return res.data;
    });
}
 
function onSearchAOD(options) {
  gridGroup.value = options;
  gridApi.fetchGridCell(options.id).then((res) => {
    satelliteProxy.gridPrepare(res.data);
  });
  optionAODRef.value.fetchAOD(options.id);
}
 
function checkHistoryGridData() {
  if (aodData.value) {
    const groupId = gridGroup.value.id;
    const dataTime = moment(aodData.value.dataTime).format(
      'YYYY-MM-DD HH:mm:ss'
    );
    // 原始卫星数据
    const type = 0;
    return gridApi.fetchGridData(groupId, dataTime, type).then((res) => {
      if (res.data.length > 0) {
        historyGridData.value = res.data[0];
      } else {
        historyGridData.value = null;
      }
    });
  } else {
    historyGridData.value = null;
  }
}
 
watch(aodData, (nv, ov) => {
  if (nv != ov) {
    aodDataDetail.value = null;
    checkHistoryGridData();
  }
});
</script>