forked from drone/command-center-dashboard

罗广辉
2025-04-21 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7
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
<template>
  <div class="search-box-test" :class="{ 'is-expand': isExpand }">
    <el-form :model="searchForm" inline>
      <div class="search-first">
        <el-form-item>
          <el-input class="ztzf-input" v-model="searchForm.key_word" placeholder="请输入任务/机巢名称" clearable />
        </el-form-item>
        <el-form-item label="行政区划:">
          <el-select :teleported="false" class="ztzf-select" v-model="searchForm.area_code" @change="deptChange" placeholder="请选择部门" clearable>
            <el-option v-for="item in deptTreeData" :key="item.area_code" :label="item.area_name" :value="item.area_code" />
          </el-select>
        </el-form-item>
        <el-form-item label="所属机巢:">
          <el-select :teleported="false" class="ztzf-select" v-model="searchForm.device_sn" placeholder="请选择机巢" clearable>
            <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"
                        class="ztzf-date-picker"
                        v-model="dateRange"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="YYYY-MM-DD"
                        @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"
              @click="timeClick(item,index)"
            >
              {{ timeListStr[index] }}
            </div>
          </div>
        </el-form-item>
        <el-form-item label="任务算法:" v-if="isExpand">
          <TaskAlgorithmBusiness :setWidth="186" :showAlgorithm="true" @algorithmChange="algorithmChange"/>
        </el-form-item>
        <el-form-item label="所属部门:" v-if="isExpand">
          <el-select :teleported="false" class="ztzf-select" 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 :teleported="false" class="ztzf-select" v-model="searchForm.status" placeholder="请选择状态" clearable>
            <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">
          <TaskAlgorithmBusiness :setWidth="186" :showBusiness="true" @businessChange="businessChange"/>
        </el-form-item>
        <div class="more" v-if="isExpand" @click="toggleExpand">收起</div>
        <div class="more" v-else @click="toggleExpand">更多</div>
        <div class="search-btn">
          <img @click="handleReset" src="@/assets/images/task/reset.png" alt="">
          <img @click="handleSearch" src="@/assets/images/task/search.png" alt="">
          <img @click="addTask" src="@/assets/images/task/create.png" alt="">
        </div>
      </div>
    </el-form>
  </div>
</template>
<script setup>
import { pxToRem } from '@/utils/rem'
import { ElMessage } from 'element-plus'
import { deptsByAreaCode, getDockInfo } from '@/api/home/common';
import TaskAlgorithmBusiness from './components/TaskAlgorithmBusiness.vue';
import dayjs from 'dayjs';
import { useStore } from 'vuex'
 
const store = useStore()
const isExpand = ref(false);
const toggleExpand = () => {
  isExpand.value = !isExpand.value;
};
 
const dateRange = ref([]);
const searchForm = reactive({
  ai_types: [], // 算法类型
  area_code: '', // 区域code
  create_dept: '', // 创建部门
  date_enum: 'TODAY', // 日期枚举,可用值:TODAY,CURRENT_WEEK,CURRENT_MONTH,CURRENT_YEAR
  device_sn: '', // 设备编号
  end_date: null, // 结束时间
  industry_type: '', // 行业key
  key_word: '', // 模糊搜索关键词(匹配名称/昵称/设备sn)
  start_date: null, // 开始时间
  status: '' // 作业状态
});
 
const statusOptions = [
  { label: '待执行', value: 1 },
  { label: '执行中', value: 2 },
  { label: '已完成', value: 3 },
  { label: '已取消', value: 4 },
  { label: '执行失败', value: 5 }
];
 
const emit = defineEmits(['search','addTask']);
 
const algorithmChange = (val) => {
  searchForm.ai_types = val;
};
 
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 = () => {
  getDockInfo().then((res) => {
    if (res.data.code !== 0) return;
    // handleDeptData(res.data.data);
    deptTreeData.value = res.data.data;
  });
};
const deptChange = (value) => {
  // 处理机巢数据
  searchForm.device_sn = '';
  machineData.value = '';
  machineData.value = deptTreeData.value.find(item => item.area_code === value)?.devices || [];
  // 所属部门重新请求值
  searchForm.create_dept = '';
  deptData.value = [];
  getDeptsByAreaCode();
};
 
// 日期 和周期
let timeList = ['today', 'week', 'month', 'year'];
let timeListStr = ['今日', '本周', '本月', '本年'];
let timeListEnum = ['TODAY', 'CURRENT_WEEK', 'CURRENT_MONTH', 'CURRENT_YEAR'];
let checked = ref('today');
 
const getDateRange = unit => {
  if (unit === 'today') {
    return [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')];
  }
  return [dayjs().startOf(unit).format('YYYY-MM-DD'), dayjs().endOf(unit).format('YYYY-MM-DD')];
};
 
const dateRanges = {
  today: getDateRange('today'),
  week: getDateRange('week'),
  month: getDateRange('month'),
  year: getDateRange('year'),
};
 
let timeClick = (item,index) => {
  checked.value = item;
  // dateRange.value = dateRanges[item];
  dateRange.value = [];
  // emit('change', dateRanges[item],timeListEnum[index]);
  searchForm.date_enum = timeListEnum[index];
  handleSearch();
};
// 搜索
const handleSearch = () => {
  if (!dateRange.value) { dateRange.value = []; }
  if (dateRange.value && dateRange.value.length) {
      // 有值时 清除 日 本周 本月 本年状态
      checked.value = '';
  }
  // 提交至store
  let params = {
    ...searchForm,
    start_date: dateRange.value.length ? `${dateRange?.value[0]} 00:00:00` : null,
    end_date: dateRange.value.length ? `${dateRange?.value[1]} 23:59:59` : null
  }
  store.commit('setTaskSearchParams', params);
  emit('search', params);
};
const handleDateChange = (val) => {
  if (val && val.length === 2) {
    const start = dayjs(val[0])
    const end = dayjs(val[1])
    const diff = end.diff(start, 'day')
    
    if (diff > 30) {
      ElMessage.warning('日期范围不能超过30天')
      dateRange.value = []
      return
    }
  }
  handleSearch()
};
// 重置
const handleReset = () => {
  dateRange.value = [];
  Object.keys(searchForm).forEach(key => {
    searchForm[key] = '';
  });
  searchForm.ai_types = [];
  searchForm.date_enum = 'TODAY';
  checked.value = 'today';
  handleSearch();
};
 
// 新增任务
const addTask = () => {
  emit('addTask');
};
 
onMounted(() => {
  getDeptsByAreaCode();
  requestDockInfo();
  // 查询一次
  handleSearch();
});
</script>
<style lang="scss">
/* 修改日期单元格背景色 */
.custom-date-picker .el-picker-panel__body {
    background: #012350 !important;
    color: #fff !important;
}
</style>
<style lang="scss" scoped>
.search-box-test {
  transition: all 0.3s;
  .search-first {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px 12px;  // 设置行间距和列间距
    .more {
      cursor: pointer;
      width: 32px;
      height: 32px;
      color: #60B2FF;
      line-height: 32px;
      font-size: 16px;
    }
    .search-btn {
      position: absolute;
      right: 0;
      bottom: 2px;
      cursor: pointer;
      img {
        width: 82px;
        height: 32px;
        margin-right: 10px;
      }
    }
    .time-card {
      text-align: center;
      background: linear-gradient(270deg, #195bad 0%, rgba(25, 91, 173, 0) 100%);
      border: 1px solid #306fca;
      font-family: Source Han Sans CN, Source Han Sans CN, serif;
      font-weight: 400;
      font-size: 14px;
      color: #ffffff;
      display: flex;
      height: 32px;
 
      .card-item {
        width: 66px;
        height: 100%;
        line-height: 32px;
        cursor: pointer;
      }
 
      .active {
        background: linear-gradient(270deg, #19ad8d 0%, rgba(25, 173, 141, 0) 100%);
        box-shadow: inset 0px 0px 8px 0px rgba(0, 255, 200, 0.6);
        border-radius: 0px 0px 0px 0px;
      }
    }
  }
  :deep(.el-form) {
    :deep(.el-input__wrapper.is-disabled) {
      background-color: #021740;
      box-shadow: 0 0 0 1px #026AD6;
    }
    .el-form-item {
      margin-bottom: 0;
      margin-right: 20px;
      width: 260px;
 
      .el-form-item__label {
        color: #fff;
        line-height: 32px;
      }
 
    }
  }
}
</style>