更新 Vite 配置中的 API 目标地址为本地地址,新增按状态批量删除链接的功能,包含相关对话框和表单验证逻辑,优化移动端样式以提升用户体验。
This commit is contained in:
@@ -32,4 +32,10 @@ export function getLinkStatus(codeNo) {
|
||||
return http.get(`/api/link/${codeNo}/status`)
|
||||
}
|
||||
|
||||
// 按状态批量删除链接
|
||||
export function batchDeleteByStatus(payload) {
|
||||
// payload: { statusList: string[], confirmDelete: boolean }
|
||||
return http.post('/api/link/batch-delete-by-status', payload)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -155,6 +155,15 @@
|
||||
>
|
||||
导出CSV
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
size="small"
|
||||
@click="showBatchDeleteByStatusDialog"
|
||||
:disabled="!linkList.length"
|
||||
:icon="Delete"
|
||||
>
|
||||
按状态删除
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -178,6 +187,15 @@
|
||||
<el-icon><Download /></el-icon>
|
||||
导出CSV
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
@click="showBatchDeleteByStatusDialog"
|
||||
:disabled="!linkList.length"
|
||||
class="mobile-action-btn"
|
||||
>
|
||||
<el-icon><Delete /></el-icon>
|
||||
按状态删除
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -414,6 +432,54 @@
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 按状态批量删除对话框 -->
|
||||
<el-dialog
|
||||
v-model="batchDeleteByStatusDialog.visible"
|
||||
title="按状态批量删除链接"
|
||||
width="500px"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
class="batch-delete-dialog"
|
||||
>
|
||||
<el-form
|
||||
ref="batchDeleteFormRef"
|
||||
:model="batchDeleteByStatusDialog.form"
|
||||
:rules="batchDeleteByStatusDialog.rules"
|
||||
label-width="120px"
|
||||
>
|
||||
<el-form-item label="选择状态" prop="statusList" required>
|
||||
<el-checkbox-group v-model="batchDeleteByStatusDialog.form.statusList">
|
||||
<el-checkbox
|
||||
v-for="status in statusOptions"
|
||||
:key="status.value"
|
||||
:label="status.value"
|
||||
>
|
||||
{{ status.label }}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
<div class="form-tip">选择要删除的链接状态,可多选</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="confirmDelete" required>
|
||||
<el-checkbox v-model="batchDeleteByStatusDialog.form.confirmDelete">
|
||||
我确认要删除选中状态的所有链接,此操作不可恢复
|
||||
</el-checkbox>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="closeBatchDeleteByStatusDialog">取消</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
@click="handleBatchDeleteByStatus"
|
||||
:loading="batchDeleteByStatusDialog.loading"
|
||||
>
|
||||
确认删除
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
@@ -425,7 +491,7 @@ import {
|
||||
Plus, Minus, Connection, Refresh, Download,
|
||||
DocumentCopy, Delete
|
||||
} from '@element-plus/icons-vue'
|
||||
import { generateLinks, fetchLinks, deleteLink, batchDeleteLinks } from '@/api/links'
|
||||
import { generateLinks, fetchLinks, deleteLink, batchDeleteLinks, batchDeleteByStatus } from '@/api/links'
|
||||
import { formatLinkStatus, getLinkStatusType, generateQRCodeUrl, downloadImage, copyToClipboard as copyText, exportToCSV as exportCSV, exportToExcel } from '@/utils/links'
|
||||
import { LINK_CONFIG, STATUS_CONFIG, EXPORT_CONFIG } from '@/config/links'
|
||||
|
||||
@@ -447,6 +513,46 @@ const selectedRows = ref([])
|
||||
const showBatchActions = computed(() => selectedRows.value.length > 0)
|
||||
const tableRef = ref()
|
||||
|
||||
// 按状态批量删除相关状态
|
||||
const batchDeleteFormRef = ref()
|
||||
const batchDeleteByStatusDialog = reactive({
|
||||
visible: false,
|
||||
loading: false,
|
||||
form: {
|
||||
statusList: [],
|
||||
confirmDelete: false
|
||||
},
|
||||
rules: {
|
||||
statusList: [
|
||||
{ required: true, message: '请选择要删除的状态', trigger: 'change' },
|
||||
{ type: 'array', min: 1, message: '至少选择一个状态', trigger: 'change' }
|
||||
],
|
||||
confirmDelete: [
|
||||
{ required: true, message: '请确认删除操作', trigger: 'change' },
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
if (!value) {
|
||||
callback(new Error('必须确认删除操作'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ value: 'NEW', label: '新建' },
|
||||
{ value: 'USING', label: '使用中' },
|
||||
{ value: 'LOGGED_IN', label: '已登錄' },
|
||||
{ value: 'COMPLETED', label: '已完成' },
|
||||
{ value: 'REFUNDED', label: '已退款' },
|
||||
{ value: 'EXPIRED', label: '已過期' }
|
||||
]
|
||||
|
||||
// 生成表单
|
||||
const generateForm = reactive({
|
||||
times: null,
|
||||
@@ -810,6 +916,77 @@ const toggleSelection = (item) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 按状态批量删除相关方法
|
||||
const showBatchDeleteByStatusDialog = () => {
|
||||
batchDeleteByStatusDialog.visible = true
|
||||
batchDeleteByStatusDialog.form.statusList = []
|
||||
batchDeleteByStatusDialog.form.confirmDelete = false
|
||||
}
|
||||
|
||||
const closeBatchDeleteByStatusDialog = () => {
|
||||
batchDeleteByStatusDialog.visible = false
|
||||
batchDeleteByStatusDialog.loading = false
|
||||
batchDeleteByStatusDialog.form.statusList = []
|
||||
batchDeleteByStatusDialog.form.confirmDelete = false
|
||||
batchDeleteFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleBatchDeleteByStatus = async () => {
|
||||
try {
|
||||
// 表单验证
|
||||
await batchDeleteFormRef.value.validate()
|
||||
|
||||
const { statusList, confirmDelete } = batchDeleteByStatusDialog.form
|
||||
|
||||
// 二次确认
|
||||
await ElMessageBox.confirm(
|
||||
`確定要刪除狀態為 "${statusList.map(s => statusOptions.find(opt => opt.value === s)?.label).join('、')}" 的所有鏈接嗎?此操作不可恢復!`,
|
||||
'批量刪除確認',
|
||||
{
|
||||
confirmButtonText: '確定刪除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
)
|
||||
|
||||
batchDeleteByStatusDialog.loading = true
|
||||
|
||||
// 調用API
|
||||
const response = await batchDeleteByStatus({
|
||||
statusList,
|
||||
confirmDelete
|
||||
})
|
||||
|
||||
const result = response.data
|
||||
|
||||
// 顯示結果
|
||||
if (result.allSuccess) {
|
||||
ElMessage.success(`成功刪除 ${result.successCount} 個鏈接`)
|
||||
} else {
|
||||
ElMessage.warning(
|
||||
`刪除完成:成功 ${result.successCount} 個,失敗 ${result.failedCount} 個`
|
||||
)
|
||||
|
||||
// 如果有失敗的,顯示詳細信息
|
||||
if (result.failedCount > 0 && result.failedReasons.length > 0) {
|
||||
console.warn('刪除失敗的原因:', result.failedReasons)
|
||||
}
|
||||
}
|
||||
|
||||
// 關閉對話框並刷新列表
|
||||
closeBatchDeleteByStatusDialog()
|
||||
await getLinkList()
|
||||
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('按狀態批量刪除失敗:', error)
|
||||
ElMessage.error(error.response?.data?.message || '批量刪除失敗')
|
||||
}
|
||||
} finally {
|
||||
batchDeleteByStatusDialog.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时获取数据
|
||||
onMounted(() => {
|
||||
checkMobile()
|
||||
@@ -1259,6 +1436,26 @@ onUnmounted(() => {
|
||||
padding: 0 20px 20px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 按状态删除对话框移动端优化 */
|
||||
.batch-delete-dialog :deep(.el-checkbox-group) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.batch-delete-dialog :deep(.el-checkbox) {
|
||||
margin-right: 0;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 8px;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.batch-delete-dialog :deep(.el-checkbox.is-checked) {
|
||||
background: #ecf5ff;
|
||||
border-color: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
|
||||
Reference in New Issue
Block a user