| | |
| | | <script setup lang="ts"> |
| | | import { onMounted, reactive, ref } from 'vue' |
| | | import { ElMessage } from 'element-plus' |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | | import { useRouter } from 'vue-router' |
| | | import { getTestList } from '@/api/tests' |
| | | import { deleteTests, getTestList } from '@/api/tests' |
| | | import { getTestTypeList } from '@/api/testTypes' |
| | | import type { TestRecord, TestStatus } from '@/stores/tests' |
| | | |
| | |
| | | const appliedFilters = ref<FilterState>({ name: '', typeId: null, status: '', batteryNo: '', dateRange: null }) |
| | | const currentPage = ref(1) |
| | | const pageSize = ref(10) |
| | | const deletingTestId = ref<number | null>(null) |
| | | |
| | | async function loadTestTypes() { |
| | | try { |
| | |
| | | router.push(`/test-list/${item.id}/edit`) |
| | | } |
| | | |
| | | function unavailableAction(action: string) { |
| | | ElMessage.info(`${action}接口尚未对接`) |
| | | async function removeTest(item: TestRecord) { |
| | | try { |
| | | await ElMessageBox.confirm(`删除测试“${item.name}”后无法恢复,是否继续?`, '确认删除测试', { |
| | | confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning', confirmButtonClass: 'danger-confirm', |
| | | }) |
| | | deletingTestId.value = item.id |
| | | await deleteTests([item.id]) |
| | | ElMessage.success('测试已删除') |
| | | if (records.value.length === 1 && currentPage.value > 1) currentPage.value -= 1 |
| | | await loadTests() |
| | | } catch (error) { |
| | | if (error === 'cancel' || error === 'close') return |
| | | ElMessage.error(error instanceof Error ? error.message : '测试删除失败') |
| | | } finally { |
| | | deletingTestId.value = null |
| | | } |
| | | } |
| | | |
| | | function downloadTests() { |
| | |
| | | <div class="row-actions"> |
| | | <button type="button" @click="openConsole(item)">控制台</button> |
| | | <button v-if="item.editable" type="button" @click="editTest(item)">编辑</button> |
| | | <button class="delete-action" type="button" @click="unavailableAction('删除')">删除</button> |
| | | <button v-if="item.editable" class="delete-action" type="button" :disabled="deletingTestId !== null" @click="removeTest(item)">{{ deletingTestId === item.id ? '删除中...' : '删除' }}</button> |
| | | </div> |
| | | </td> |
| | | </tr> |