无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<template>
  <basic-container>
    <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" v-model="form" ref="crud"
      @search-change="searchChange" @search-reset="searchReset" @current-change="currentChange"
      @size-change="sizeChange" @refresh-change="refreshChange">
    </avue-crud>
  </basic-container>
</template>
 
<script>
import { getWaylineFileByUser } from '@/api/resource/waylineFile'
import { getAirportList } from '@/api/device/device'
 
export default {
  name: 'WaylineFile',
  data () {
    const { defaultStartDate, defaultEndDate } = this.getDefaultDates()
    return {
      form: {},
      query: { name: '', dock_name: '', daterange: [defaultStartDate, defaultEndDate] },
      loading: false,
      page: { pageSize: 10, currentPage: 1, total: 0 },
      selectedWorkspaceId: null,
      data: [],
      option: {
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        menu: false,
        page: true,
 
        height: 'auto',
        calcHeight: 20,
        column: [
          {
            label: '机场选择',
            prop: 'dock_name',
            type: 'select',
            search: true,
            searchSpan: 5,
            dicData: [],
            props: { label: 'nickname', value: 'nickname' },
            hide: true,
             change: (value) => {
               this.searchChange({ ...this.query,dock_name:value.value}, () => {});
          }
          },
          {
            label: '航线名称',
            prop: 'name',
            search: true,
            searchSpan: 6,
          },
          {
            label: '时间范围',
            prop: 'daterange',
            type: 'daterange',
            search: true,
            searchRange: true,
            searchSpan: 6,
            format: 'YYYY-MM-DD',
            valueFormat: 'YYYY-MM-DD',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            searchValue: [defaultStartDate, defaultEndDate],
            hide: true,
             change: (value) => {
               this.searchChange({ ...this.query,daterange:value.value}, () => {});
          }
          },
          { label: '航线名称', prop: 'name' },
          {
            label: '航线类型',
            prop: 'wayline_type',
            formatter: (row) => this.formatWaylineType(row.wayline_type),
          },
          { label: '用户名', prop: 'user_name' },
          { label: '航线ID', prop: 'id' },
          {
            label: '更新时间',
            prop: 'update_time',
            formatter: (row) => this.formatTime(row.update_time),
          },
        ],
      },
    }
  },
  mounted () {
    this.fetchAirports()
    this.fetchData(this.page, this.query) // 初次加载包含默认时间范围
  },
  methods: {
    getDefaultDates () {
      const endDate = new Date()
      const startDate = new Date()
      startDate.setMonth(startDate.getMonth() - 1)
      // 结束时间设定为当天 23:59:59
      endDate.setHours(23, 59, 59, 999)
 
      return {
        defaultStartDate: `${startDate.getFullYear()}-${String(startDate.getMonth() + 1).padStart(2, '0')}-${String(startDate.getDate()).padStart(2, '0')}`,
        defaultEndDate: `${endDate.getFullYear()}-${String(endDate.getMonth() + 1).padStart(2, '0')}-${String(endDate.getDate()).padStart(2, '0')}`,
      }
    },
    async fetchAirports () {
      try {
        const res = await getAirportList()
        const airportData = res.data.data || []
        const airportColumn = this.option.column.find((col) => col.prop === 'dock_name')
        if (airportColumn) {
          airportColumn.dicData = airportData.map((item) => ({
            nickname: item.nickname,
            workspace_id: item.workspace_id,
          }))
        }
      } catch (error) {
        console.error('加载机场列表失败:', error)
      }
    },
    async fetchData (page, params = {}) {
      this.loading = true
      const { name, dock_name, daterange } = params
      const workspaceId = this.selectedWorkspaceId || null
 
      // 时间范围处理
      const startDate = new Date(daterange[0])
      let endDate = new Date(daterange[1])
      // 结束时间始终设定为当天 23:59:59
      endDate.setHours(23, 59, 59, 999)
 
      const startTime = isNaN(startDate.getTime()) ? null : startDate.getTime()
      const endTime = isNaN(endDate.getTime()) ? null : endDate.getTime()
 
      const requestParams = {
        workspaceId,
        waylineName: name || null,
        startTime,
        endTime,
        page: page.currentPage,
        pageSize: page.pageSize,
      }
 
      console.log('请求参数:', requestParams)
 
      try {
        const res = await getWaylineFileByUser(
          requestParams.workspaceId,
          requestParams.waylineName,
          requestParams.startTime,
          requestParams.endTime,
          requestParams.page,
          requestParams.pageSize
        )
        const responseData = res.data
 
        if (responseData?.code === 0 && Array.isArray(responseData.data?.list)) {
          this.data = responseData.data.list.map((item) => ({
            id: item.id,
            name: item.name,
            wayline_type: item.wayline_type,
            user_name: item.user_name,
            update_time: item.update_time,
          }))
          this.page.total = responseData.data.pagination?.total || responseData.data.list.length
          this.page.currentPage = page.currentPage
          console.log('返回数据条数:', this.data.length)
          console.log('当前页码:', this.page.currentPage)
          console.log('总条数:', this.page.total)
        } else {
          this.data = []
          this.page.total = 0
        }
      } catch (error) {
        console.error('加载数据失败:', error)
        this.data = []
        this.page.total = 0
      } finally {
        this.loading = false
      }
    },
    searchChange (params, done) {
      this.query = { ...params }
      const airportColumn = this.option.column.find((col) => col.prop === 'dock_name')
      const selectedAirport = airportColumn.dicData.find((item) => item.nickname === params.dock_name)
      this.selectedWorkspaceId = selectedAirport ? selectedAirport.workspace_id : null
      this.page.currentPage = 1
      this.fetchData(this.page, this.query)
      done()
    },
    searchReset () {
      const { defaultStartDate, defaultEndDate } = this.getDefaultDates()
      this.query = { name: '', dock_name: '', daterange: [defaultStartDate, defaultEndDate] }
      this.selectedWorkspaceId = null
      const daterangeColumn = this.option.column.find((col) => col.prop === 'daterange')
      daterangeColumn.searchValue = [defaultStartDate, defaultEndDate]
      this.page.currentPage = 1
      this.fetchData(this.page, this.query)
    },
    currentChange (currentPage) {
      console.log('切换页码至:', currentPage)
      this.page.currentPage = currentPage
      this.fetchData(this.page, this.query)
    },
    sizeChange (pageSize) {
      console.log('每页条数改为:', pageSize)
      this.page.pageSize = pageSize
      this.page.currentPage = 1
      this.fetchData(this.page, this.query)
    },
    refreshChange () {
      this.fetchData(this.page, this.query)
    },
    formatTime (time) {
      if (!time) return ''
      const date = new Date(time < 10000000000 ? time * 1000 : time)
      if (isNaN(date.getTime())) return '无效时间'
      return date.toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-')
    },
    formatWaylineType (type) {
      const typeMap = { '0': '普通航线', '1': '图斑举证航线', '2': '航测航线', '3': '航点航线', '4': '正射举证航线' }
      return typeMap[type] || '未知'
    },
  },
}
</script>
 
<style scoped lang="scss">
.avue-crud .el-table {
  max-height: none !important;
}
</style>