无人机管理后台前端(已迁走)
张含笑
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<template>
  <div class="search-box-test" :class="{ 'is-expand': isExpand }">
    <el-form :model="searchForm" inline>
      <div class="search-first">
        <el-form-item>
          <el-input v-model="searchForm.key_word" placeholder="请输入任务编号/名称" clearable />
        </el-form-item>
        <el-form-item label="行政区划:">
          <el-tree-select
            popper-class="custom-tree-select"
            v-model="searchForm.area_code"
            :data="deptTreeData"
            :default-expanded-keys="[searchForm.area_code]"
            check-strictly
            node-key="id"
            :props="treeProps"
            @node-click="handleNodeClick"
          />
        </el-form-item>
        <el-form-item label="所属机巢:">
          <el-select
            :teleported="false"
            v-model="searchForm.device_sn"
            placeholder="请选择"
            clearable
            @change="handleSearch"
          >
            <el-option
              v-for="item in machineData"
              :key="item.device_sn"
              :label="item.nickname"
              :value="item.device_sn"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            popper-class="custom-date-picker"
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :value-format="timeFormat"
            @change="handleDateChange"
          />
        </el-form-item>
        <el-form-item>
          <div class="time-card">
            <div
              class="card-item"
              :class="item === checked ? 'active' : ''"
              v-for="(item, index) in timeList"
              :key="index"
              @click="timeClick(item, index)"
            >
              {{ timeListStr[index] }}
            </div>
          </div>
        </el-form-item>
        <div class="more" v-if="isExpand" @click="toggleExpand">收起</div>
        <div class="more" v-else @click="toggleExpand">更多</div>
        <div class="search-btn" :style="{ bottom: isExpand ? '5px' : '-3px' }">
          
          <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="handleReset">清空</el-button>
        </div>
        <el-form-item label="任务算法:" v-if="isExpand" class="taskAlgorithm">
          <!-- <TaskAlgorithmBusiness
          ref="algorithmRef"
            :setWidth="160"
            :showAlgorithm="true"
            @algorithmChange="algorithmChange"
          /> -->
          <el-tree-select
          style="z-index: 1000"
            :teleported="false"
            class="custom-tree-select"
            :style="{ width: pxToRem(186) }"
            v-model="dictKey"
            :data="dataList"
            :default-expanded-keys="[dictKey]"
            :props="treePropsSF"
            :render-after-expand="false"
            :default-checked-keys="checkedKeys"
            node-key="id"
            multiple
            show-checkbox
            collapse-tags
            collapse-tags-tooltip
            clearable
            @node-click="handleNodeClick"
            @check="handleCheck"
            @clear="handleClear"
          />
        </el-form-item>
        <!-- <el-form-item label="所属部门:" v-if="isExpand">
          <el-select
            :teleported="false"
            v-model="searchForm.create_dept"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in deptData"
              :key="item.id"
              :label="item.deptName"
              :value="item.id"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="任务状态:" v-if="isExpand">
          <el-select
          style="z-index: 1000"
            :teleported="false"
            v-model="searchForm.status"
            placeholder="请选择"
            clearable
            multiple
            collapse-tags
            collapse-tags-tooltip
              @change="handleSearch"
          >
            <el-option
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="任务类型:" v-if="isExpand">
          <el-select
            :teleported="false"
            v-model="searchForm.is_circle_job"
            placeholder="请选择"
            clearable
            @change="handleSearch"
          >
            <el-option label="周期任务" :value="1" />
            <el-option label="临时任务" :value="0" />
          </el-select>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script setup>
import { pxToRem } from '@/utils/rem';
import { ElMessage } from 'element-plus';
import { deptsByAreaCode, getSFDictionaryTree  } from '@/api/job/task';
// import TaskAlgorithmBusiness from './TaskAlgorithmBusiness.vue';
import dayjs from 'dayjs';
import { useStore } from 'vuex';
import { getRegionTreeAll } from '@/api/job/task';
import { getDeviceRegion } from '@/api/job/task';
const route = useRoute();
const store = useStore();
const userAreaCode = computed(() => store.getters.userInfo.detail.areaCode);
const selectedAreaCode = computed(() => store.state.user.selectedAreaCode);
 
const algorithmRef = ref(null)
const isExpand = ref(false);
const toggleExpand = () => {
  isExpand.value = !isExpand.value;
};
const timeFormat = 'YYYY-MM-DD HH:mm:ss';
 
const dateRange = ref([]);
 
const treeProps = {
  label: 'name',
  value: 'id',
  children: 'childrens',
};
const searchForm = reactive({
  ai_types: [], // 算法类型
  area_code: userAreaCode.value, // 区域code
  create_dept: '', // 创建部门
  date_enum: 'CURRENT_MONTH', // 日期枚举,可用值:TODAY,CURRENT_WEEK,CURRENT_MONTH,CURRENT_YEAR
  device_sn: '', // 设备编号
  end_date: null, // 结束时间
  industry_type: '', // 行业key
  key_word: '', // 模糊搜索关键词(匹配名称/昵称/设备sn)
  start_date: null, // 开始时间
  status: [], // 作业状态
  is_circle_job: null, // 任务类型
});
 
// 从单机巢任务传参值
const signDevice_sn = ref('');
 
const statusOptions = [
  { label: '待执行', value: 1 },
  { label: '执行中', value: 2 },
  { label: '已执行', value: 3 },
  // { label: '已取消', value: 4 },
  { label: '执行失败', value: 5 },
  { label: '取消执行', value: 7 },
];
 
const emit = defineEmits(['search', 'addTask']);
 
const algorithmChange = val => {
  searchForm.ai_types = val;
  handleSearch()
};
 
const businessChange = val => {
  searchForm.industry_type = val;
};
 
let deptData = ref([]);
// 所属部门信息
const getDeptsByAreaCode = () => {
  deptsByAreaCode(searchForm.area_code).then(res => {
    if (res.code !== 0) {
      deptData.value = res.data.data;
    }
  });
};
 
// 部门
let deptTreeData = ref([]);
// 机巢
let machineData = ref([]);
 
// 部门下得机巢
const requestDockInfo = () => {
  getRegionTreeAll({ parentCode: userAreaCode.value }).then(res => {
    deptTreeData.value = res.data.data ? [res.data.data] : [];
 
    handleNodeClick({ id: userAreaCode.value });
  });
};
 
// 算法
const treePropsSF = {
    label: 'dictValue',
    value: 'id',
    children: 'children',
}
const dictKey = ref('')
const dataList = ref([])
function getAlgorithmList() {
  getSFDictionaryTree({code:'SF'}).then((res) => {
      if (res.data.code === 200) {
          const result = res.data.data[0].children
          // 过滤第一层数据
          const filteredData = result.map(item => {
              // 过滤第二层数据
              const children = item.children?.map(child => ({
                  ...child,
                  children: [] // 清空第三层数据
              }))
              return {
                  ...item,
                  children: children || []
              }
          })
          dataList.value = filteredData
      }
  })
}
 
function handleSFNodeClick(data) {
    if (data.children && data.children.length) {
        // 获取子节点dictKey
        const childDictKeys = data.children.map(child => child.dictKey)
        searchForm.ai_types = childDictKeys
    } else {
        searchForm.ai_types = [data.dictKey]
    }
    // 更新列表
    handleSearch()
}
function handleClear() {
    dictKey.value = ''
    searchForm.ai_types = []
    handleSearch()
}
 
const handleNodeClick = async data => {
  // 处理机巢数据
  searchForm.device_sn = '';
  machineData.value = '';
 
  const droneList = await getDeviceRegion({ areaCode: data.id });
 
  machineData.value = droneList?.data?.data;
  // 默认选中值
  if (signDevice_sn.value) {
    searchForm.device_sn = signDevice_sn.value;
  }
  // 所属部门重新请求值
  searchForm.create_dept = '';
  deptData.value = [];
  getDeptsByAreaCode();
  handleSearch();
};
 
// 日期 和周期
let timeList = ['today', 'week', 'month', 'year'];
let timeListStr = ['今日', '本周', '本月', '本年'];
let timeListEnum = ['TODAY', 'CURRENT_WEEK', 'CURRENT_MONTH', 'CURRENT_YEAR'];
let checked = ref('month');
 
let timeClick = (item, index) => {
  if (checked.value === item){
    checked.value = null
    searchForm.date_enum = undefined
  }else{
    checked.value = item
    searchForm.date_enum = timeListEnum[index]
  }
  dateRange.value = []
  handleSearch()
};
// 搜索
const handleSearch = () => {
  if (!dateRange.value) {
    dateRange.value = [];
  }
  if (dateRange.value && dateRange.value.length) {
    // 有值时 清除 日 本周 本月 本年状态
    checked.value = '';
    searchForm.date_enum = '';
  }
  // 提交至store
  let params = {
    ...searchForm,
    start_date: dateRange.value.length
      ? dayjs(dateRange?.value[0]).startOf('day').format(timeFormat)
      : null,
    end_date: dateRange.value.length
      ? dayjs(dateRange?.value[1]).endOf('day').format(timeFormat)
      : null,
  };
  store.commit('setTaskSearchParams', params);
  emit('search', params);
};
const handleDateChange = val => {
  checked.value = null
  searchForm.date_enum = undefined
  handleSearch()
};
 
// 重置
const handleReset = () => {
  dateRange.value = [];
  Object.keys(searchForm).forEach(key => {
    searchForm[key] = '';
  });
  searchForm.ai_types = [];
  searchForm.date_enum = 'CURRENT_MONTH';
  searchForm.area_code = userAreaCode.value;
  checked.value = 'month';
  signDevice_sn.value = ''
  // 清除算法
  dictKey.value = '';
    // algorithmRef.value?.clear()
  handleNodeClick({ id: userAreaCode.value });
  handleSearch();
};
 
// 新增任务
const addTask = () => {
  emit('addTask');
};
 
// 监听从巡检任务概况提交的数据
// watch(
//   () => store.state.task.jumpTask,
//   newVal => {
 
//     if (newVal && Object.keys(newVal).length) {
//       // 兼容当日任务 计划任务 历史任务传参
//       if (newVal.clickValue) {
//         checked.value = newVal.clickValue;
//         searchForm.date_enum = newVal.date_enum;
//       }
//       if (newVal.date_value) {
//         dateRange.value = newVal.date_value;
//       }
//       if (newVal.status) {
//         searchForm.status = newVal.status;
//       }
//       if (newVal.device_sn) {
//         searchForm.device_sn = newVal.device_sn;
//         // 不直接赋值的原因: 回选会被清空值
//         signDevice_sn.value = newVal.device_sn;
//       }
//     } else {
//       checked.value = 'today';
//       searchForm.date_enum = 'TODAY';
//     }
//     handleSearch();
//   },
//   { immediate: true, deep: true }
// );
 
const checkedKeys = ref([])
 
const handleCheck = (data, { checkedKeys, checkedNodes }) => {
    dictKey.value = checkedKeys
    // 获取所有选中节点的 dictKey
    const selectedDictKeys = checkedNodes.map(node => node.dictKey).filter(Boolean)
  searchForm.ai_types = selectedDictKeys
  handleSearch()
}
 
onBeforeUnmount(() => {
  checked.value = 'today';
  searchForm.date_enum = 'TODAY';
});
 
onMounted(() => {
  requestDockInfo();
  getAlgorithmList();
  // 日历传值
  const calendarday = ref(route.query.day);
 
  if (calendarday.value) {
    const date = dayjs(calendarday.value).format(timeFormat);
 
    const dateArray = [date, date];
 
    dateRange.value = dateArray;
    const find = store.state.tags.bsTagList.find(i => i.path === '/job/jobstatistics')
          find && (find.query = {})
  }
      // 查询一次
    handleSearch()
});
</script>
<style lang="scss"></style>
<style lang="scss" scoped>
// .taskAlgorithm {
//     :deep() {
//         .task-algorithm > div {
//             width: 233px !important;
//         }
//     }
// }
.search-box-test {
  transition: all 0.3s;
 
  .search-first {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px 15px; // 设置行间距和列间距
 
    .more {
      cursor: pointer;
      width: 32px;
      height: 32px;
      color: #1c5cff;
      line-height: 32px;
      font-size: 16px;
      margin: 0 28px;
    }
 
    .search-btn {
      // position: absolute;
      // right: 0;
      display: flex;
      justify-content: space-between;
      cursor: pointer;
      font-size: 14px;
 
      .btn {
        width: 80px;
        height: 32px;
        border-radius: 4px 4px 4px 4px;
        line-height: 32px;
        display: flex;
        justify-content: center;
        align-items: center;
        // margin-left: px;
        img {
          width: 14px;
          height: 14px;
        }
      }
      .search {
        background: #409eff;
        color: #fff;
        margin-right: 10px;
      }
      .clear {
        border: 1px solid #d2d1d1;
        color: #676767;
        margin-right: 10px;
      }
      .add {
        background: #ff9243;
        color: #fff;
      }
    }
 
    .time-card {
      text-align: center;
      background: #ffffff;
      border-radius: 4px 0px 0px 4px;
      border: 1px solid #e5e5e5;
      font-family: Source Han Sans CN, Source Han Sans CN;
      font-weight: 400;
      font-size: 14px;
      color: #7c8091;
      display: flex;
      height: 32px;
 
      .card-item {
        width: 60px;
        height: 100%;
        line-height: 32px;
        cursor: pointer;
      }
 
      .active {
        background: #ffffff;
        border-radius: 0px 0px 0px 0px;
        border: 1px solid #1c5cff;
        color: #1441ff;
      }
    }
  }
 
  :deep(.el-form) {
    :deep(.el-input__wrapper.is-disabled) {
      box-shadow: 0 0 0 1px #026ad6;
    }
 
    .el-form-item {
      margin-bottom: 0;
      width: 233px;
          margin-right: 20px;
 
      .el-form-item__label {
        color: #363636;
        line-height: 32px;
      }
    }
  }
}
</style>