huangxz
2026-08-17 a8a671b41187d8c63b52ec24f695f2baca8fa4c4
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
549
550
551
552
553
554
555
<script setup lang="tsx">
import noDataImg from '@/assets/element-img/no-data.png'
import type { DataTableColumns } from 'naive-ui'
import { NButton, NSpace, NTag, useDialog, useMessage } from 'naive-ui'
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useBoolean } from '@/hooks'
import { closeTestPlanDispatch, deleteTestPlan, fetchTestPlanPageList, interruptTestPlanDispatch, resumeTestPlanDispatch } from '@/service/api/testPlanManagement'
import { getTestPlanDisplayStatus, TEST_PLAN_STATUS_CRUISING_VALUE, TEST_PLAN_STATUS_OPTIONS } from './constants'
import CruiseDialog from './components/CruiseDialog.vue'
 
const router = useRouter()
const dialog = useDialog()
const message = useMessage()
 
const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false)
 
interface TestPlanRow {
  id: number
  planName: string
  pointNum: number
  vehicleNum: number
  orderNum: number
  status: number
  cruiseStatus: number
}
 
const initialModel = {
  planName: '',
  status: null as number | null,
  minPointCount: null as number | null,
  maxPointCount: null as number | null,
  minVehicleCount: null as number | null,
  maxVehicleCount: null as number | null,
  minOrderCount: null as number | null,
  maxOrderCount: null as number | null,
  plateNumber: '',
  pointName: '',
}
const model = ref({ ...initialModel })
 
const pageParams = ref({
  pageNum: 1,
  pageSize: 10,
})
const count = ref(0)
const listData = ref<TestPlanRow[]>([])
 
const tableScrollX = 1200
 
function handleResetSearch() {
  model.value = { ...initialModel }
  pageParams.value.pageNum = 1
  getList()
}
 
function renderRange(minKey: keyof typeof initialModel, maxKey: keyof typeof initialModel) {
  return (
    <div class="flex items-center gap-8px">
      <n-input-number
        v-model:value={model.value[minKey]}
        placeholder="请输入最小值"
        clearable
        precision={0}
        show-button={false}
        class="flex-1"
      />
      <span>~</span>
      <n-input-number
        v-model:value={model.value[maxKey]}
        placeholder="请输入最大值"
        clearable
        precision={0}
        show-button={false}
        class="flex-1"
      />
    </div>
  )
}
 
function validateRange(minVal: number | null, maxVal: number | null, label: string): boolean {
  if (minVal !== null && maxVal !== null && minVal > maxVal) {
    message.warning(`${label}的最小值不能大于最大值`)
    return false
  }
  return true
}
 
function buildQueryParams() {
  // 「巡游中」是 status=2 + cruiseStatus=1 的组合状态,前端用哨兵值 -1 表示。
  // 命中时只传 cruiseStatus=1,让后端返回所有 cruiseStatus=1 的计划。
  const rawStatus = model.value.status
  const isCruising = rawStatus === TEST_PLAN_STATUS_CRUISING_VALUE
  return {
    ...pageParams.value,
    planName: model.value.planName?.trim() || undefined,
    status: isCruising ? undefined : (rawStatus || undefined),
    cruiseStatus: isCruising ? 1 : undefined,
    minPointCount: model.value.minPointCount ?? undefined,
    maxPointCount: model.value.maxPointCount ?? undefined,
    minVehicleCount: model.value.minVehicleCount ?? undefined,
    maxVehicleCount: model.value.maxVehicleCount ?? undefined,
    minOrderCount: model.value.minOrderCount ?? undefined,
    maxOrderCount: model.value.maxOrderCount ?? undefined,
    plateNumber: model.value.plateNumber?.trim() || undefined,
    pointName: model.value.pointName?.trim() || undefined,
  }
}
 
async function getList() {
  startLoading()
  try {
    const res = await fetchTestPlanPageList(buildQueryParams())
 
    if (res.code !== 200 && res.code !== 0) {
      throw new Error(res.msg || '获取测试计划列表失败')
    }
 
    // 列表接口字段名可能仍在调整,这里对常见返回字段做一层兼容映射。
    const records = Array.isArray(res.data?.records) ? res.data.records : []
    listData.value = records.map((item: any) => ({
      id: item.id,
      planName: item.planName || '-',
      pointCount: Number(item.pointCount ?? 0),
      vehicleCount: Number(item.vehicleCount ?? 0),
      orderCount: Number(item.orderCount ?? 0),
      status: Number(item.status ?? 0),
      cruiseStatus: Number(item.cruiseStatus ?? 0),
    }))
    count.value = Number(res.data?.total ?? records.length ?? 0)
  }
  catch (e: any) {
    listData.value = []
    count.value = 0
    // message.error(e?.message || '获取测试计划列表失败')
  }
  finally {
    endLoading()
  }
}
 
function changePage(page: number, size: number) {
  pageParams.value.pageNum = page
  pageParams.value.pageSize = size
  getList()
}
 
function handleSearch() {
  if (!validateRange(model.value.minPointCount, model.value.maxPointCount, '关联点位'))
    return
  if (!validateRange(model.value.minVehicleCount, model.value.maxVehicleCount, '关联车辆数'))
    return
  if (!validateRange(model.value.minOrderCount, model.value.maxOrderCount, '测试订单数'))
    return
  pageParams.value.pageNum = 1
  getList()
}
 
function handleAdd() {
  router.push({ name: 'testPlanManagementAdd' })
}
 
const showOperationLogModal = ref(false)
 
function handleOpenOperationLog() {
  showOperationLogModal.value = true
}
 
function handleDetail(row: TestPlanRow) {
  router.push({ name: 'testPlanManagementDetail', query: { id: String(row.id) } })
}
 
function handleEdit(row: TestPlanRow) {
  router.push({ name: 'testPlanManagementEdit', query: { id: String(row.id), mode: 'edit' } })
}
 
function handleCopy(row: TestPlanRow) {
  // 复制改为“预填新增表单”,不立即落库;用户完善并保存后才真正创建,
  // 避免复制后未完善就残留一条不完整的测试计划。
  router.push({ name: 'testPlanManagementAdd', query: { copyFrom: String(row.id) } })
}
 
function handleDelete(row: TestPlanRow) {
  dialog.create({
    title: '确认删除该测试计划吗?',
    content: '删除后无法恢复',
    positiveText: '确定',
    negativeText: '取消',
    maskClosable: false,
    autoFocus: false,
    onPositiveClick: async () => {
      try {
        const res = await deleteTestPlan(row.id)
        if (res.code !== 200 && res.code !== 0) {
          throw new Error(res.msg || '删除失败')
        }
        message.success('删除成功')
        await getList()
      }
      catch (error: any) {
        // message.error(error?.message || '删除失败')
        throw error
      }
    },
  })
}
 
function handleInterrupt(row: TestPlanRow) {
  dialog.warning({
    maskClosable: false,
    title: '是否确认中断下发',
    content: '中断后,系统将暂停下发剩余订单',
    positiveText: '确定',
    negativeText: '取消',
    onPositiveClick: async () => {
      try {
        const res = await interruptTestPlanDispatch(row.id)
        if (res.code !== 200 && res.code !== 0) {
          // throw new Error(res.msg || '中断测试失败')
        }
        message.success('已中断')
        await getList()
      }
      catch (error: any) {
        // message.error(error?.message || '中断测试失败')
        throw error
      }
    },
  })
}
 
function handleClose(row: TestPlanRow) {
  dialog.warning({
    maskClosable: false,
    title: '确认关闭测试吗?',
    content: '关闭后测试计划将终止',
    positiveText: '确定',
    negativeText: '取消',
    onPositiveClick: async () => {
      try {
        const res = await closeTestPlanDispatch(row.id)
        if (res.code !== 200 && res.code !== 0) {
          throw new Error(res.msg || '关闭测试失败')
        }
        message.success('已关闭')
        await getList()
      }
      catch (error: any) {
        // message.error(error?.message || '关闭测试失败')
        throw error
      }
    },
  })
}
 
function handleContinue(row: TestPlanRow) {
  dialog.info({
    maskClosable: false,
    title: '确认继续测试吗?',
    content: '测试计划将继续执行',
    positiveText: '确定',
    negativeText: '取消',
    onPositiveClick: async () => {
      try {
        const res = await resumeTestPlanDispatch(row.id)
        if (res.code !== 200 && res.code !== 0) {
          throw new Error(res.msg || '继续测试失败')
        }
        message.success('已继续')
        await getList()
      }
      catch (error: any) {
        // message.error(error?.message || '继续测试失败')
        throw error
      }
    },
  })
}
 
const showCruiseDialog = ref(false)
const cruiseRow = ref<TestPlanRow | null>(null)
 
function handleCruise(row: TestPlanRow) {
  cruiseRow.value = row
  showCruiseDialog.value = true
}
 
function handleCruiseSuccess() {
  getList()
}
 
const columns = computed<DataTableColumns<TestPlanRow>>(() => [
  {
    title: '序号',
    key: 'index',
    width: 80,
    align: 'left',
    render: (_, index) => (pageParams.value.pageNum - 1) * pageParams.value.pageSize + index + 1,
  },
  {
    title: '测试计划名称',
    key: 'planName',
    width: 260,
    align: 'left',
    resizable: true,
    ellipsis: true,
    // render(row) {
    //   return (
    //     <NTooltip trigger="hover">
    //       {{
    //         trigger: () => (
    //           <div
    //             class="cursor-pointer text-ellipsis whitespace-nowrap w-full overflow-hidden text-[#0068FF]"
    //             onClick={() => handleDetail(row)}
    //           >
    //             {row.planName}
    //           </div>
    //         ),
    //         default: () => row.planName,
    //       }}
    //     </NTooltip>
    //   )
    // },
  },
  {
    title: '关联点位',
    key: 'pointCount',
    width: 140,
    align: 'left',
    resizable: true,
    ellipsis: true,
  },
  {
    title: '关联车辆数',
    key: 'vehicleCount',
    width: 140,
    align: 'left',
    resizable: true,
    ellipsis: true,
  },
  {
    title: '测试订单数',
    key: 'orderCount',
    width: 140,
    align: 'left',
    resizable: true,
    ellipsis: true,
  },
  {
    title: '状态',
    key: 'status',
    width: 120,
    align: 'left',
    render: (row) => {
      const { label, ...color } = getTestPlanDisplayStatus(row.status, row.cruiseStatus)
      return <NTag color={color} bordered={false} size="small" style="border-radius: 4px;">{label}</NTag>
    },
  },
  {
    title: '操作',
    key: 'actions',
    width: 280,
    align: 'left',
    fixed: 'right',
    render: (row: TestPlanRow) => {
      // 操作项跟随计划状态变化,避免在模板里堆叠过多条件分支。
      const actions = []
 
      if (row.status === 1) { // 待下发
        actions.push(<NButton text type="primary" onClick={() => handleCopy(row)}>复制</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleEdit(row)} v-permission="2026061522">编辑</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleDelete(row)} v-permission="2026061524">删除</NButton>)
      }
      if (row.status === 2) { // 测试中
        actions.push(<NButton text type="primary" onClick={() => handleCopy(row)}>复制</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleDetail(row)} v-permission="2026061523">详情</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleInterrupt(row)} v-permission="2026061525">中断测试</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleCruise(row)} v-permission="2026061525">{row.cruiseStatus === 1 ? '停止巡游' : '巡游策略'}</NButton>)
      }
      if (row.status === 3) { // 已暂停
        actions.push(<NButton text type="primary" onClick={() => handleCopy(row)}>复制</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleDetail(row)} v-permission="2026061523">详情</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleClose(row)} v-permission="2026061526">关闭测试</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleContinue(row)} v-permission="2026061527">继续测试</NButton>)
      }
      if (row.status === 4 || row.status === 5) { // 已完成 / 关闭测试
        actions.push(<NButton text type="primary" onClick={() => handleCopy(row)}>复制</NButton>)
        actions.push(<NButton text type="primary" onClick={() => handleDetail(row)} v-permission="2026061523">详情</NButton>)
      }
 
      return (
        <NSpace justify="start" size={12} wrap={false}>
          {actions}
        </NSpace>
      )
    },
  },
])
 
const isStatusSelectOpen = ref(false)
 
// 顺序经过排布校验:SearchPanel 按容器宽度取 2~6 列,区间筛选占 2 列。
// 先放两个 span=2 区间项再放 span=1 项,保证常见 5/6 列宽度下
// 「测试订单数、车牌号、点位名称」始终落在同一行(QA 报排版错位即源于旧顺序)。
const filterItems = computed(() => [
  {
    label: '关联点位',
    path: 'pointCount',
    span: 2,
    render: () => renderRange('minPointCount', 'maxPointCount'),
  },
  {
    label: '关联车辆数',
    path: 'vehicleCount',
    span: 2,
    render: () => renderRange('minVehicleCount', 'maxVehicleCount'),
  },
  {
    label: '计划名称',
    path: 'planName',
    render: () => <n-input v-model:value={model.value.planName} placeholder="请输入" clearable />,
  },
  {
    label: '计划状态',
    path: 'status',
    render: () => (
      <n-select
        v-model:value={model.value.status}
        options={TEST_PLAN_STATUS_OPTIONS}
        placeholder="请选择"
        clearable
        onUpdate:show={(val: boolean) => isStatusSelectOpen.value = val}
      >
        {{
          arrow: () => (
            <img
              src="https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/e120f81c-9f15-4e1a-9938-22252898edf9.png"
              class={`arrow-icon ${isStatusSelectOpen.value ? 'arrow-icon--open' : ''}`}
              style={{ width: '16px', height: '16px' }}
              alt="arrow"
            />
          ),
          empty: () => (
            <div class="flex-center">
              <img
                src={noDataImg}
                style={{ width: '50%' }}
                alt="no-data"
              />
            </div>
          ),
        }}
      </n-select>
    ),
  },
  {
    label: '测试订单数',
    path: 'orderCount',
    span: 2,
    render: () => renderRange('minOrderCount', 'maxOrderCount'),
  },
  {
    label: '车牌号',
    path: 'plateNumber',
    render: () => <n-input v-model:value={model.value.plateNumber} placeholder="请输入" clearable />,
  },
  {
    label: '点位名称',
    path: 'pointName',
    render: () => <n-input v-model:value={model.value.pointName} placeholder="请输入" clearable />,
  },
])
 
onMounted(() => {
  getList()
})
</script>
 
<template>
  <div class="roboTaxi">
    <div class="roboTaxi-form-card mb-12px">
      <n-form :model="model" label-placement="left" inline :show-feedback="false">
        <SearchPanel>
          <n-gi v-for="item in filterItems" :key="item.path" :span="item.span || 1" class="n-grid-item">
            <n-form-item :label="item.label" :path="item.path">
              <component :is="item.render" />
            </n-form-item>
          </n-gi>
          <template #action>
            <NButton @click="handleResetSearch">
              重置
            </NButton>
            <NButton type="primary" @click="handleSearch">
              查询
            </NButton>
          </template>
        </SearchPanel>
      </n-form>
    </div>
 
    <n-card
      class="flex-1 robotaxi-table-card"
      content-style="display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0;"
    >
      <template #header>
        <n-flex justify="flex-end">
         <NButton v-permission="2026061521" @click="handleOpenOperationLog">
            操作日志
          </NButton>
          <NButton v-permission="2026061520" type="primary" secondary style="background-color: #E6F4FF; border-color: #7ABDFF; color: #0068FF;" @click="handleAdd">
            添加测试计划
          </NButton>
           
        </n-flex>
      </template>
 
      <div class="flex-1 flex flex-col h-full" style="min-width: 0; overflow: hidden">
        <n-data-table
          class="flex-1"
          :columns="columns"
          :data="listData"
          :loading="loading"
          flex-height
          :bordered="false"
          :scroll-x="tableScrollX"
          :header-height="18"
          :row-height="18"
        >
          <template #empty>
            <div class="flex-center">
              <img :src="noDataImg" style="width:123px;height:125px" alt="no-data">
            </div>
          </template>
        </n-data-table>
        <Pagination
          :count="count"
          :page="pageParams.pageNum"
          :page-size="pageParams.pageSize"
          class="robotaxi-pagination mt-12px"
          @change="changePage"
        />
      </div>
    </n-card>
 
    <OperationLogModal v-model:show="showOperationLogModal" :business-type="57" />
    <CruiseDialog
      v-model:visible="showCruiseDialog"
      :plan-id="cruiseRow?.id"
      :cruise-status="cruiseRow?.cruiseStatus"
      @success="handleCruiseSuccess"
    />
  </div>
</template>
 
<style scoped></style>