pagetype列表页删除记录增加确认对话框
This commit is contained in:
parent
0cfb0101a3
commit
fc74b761a9
@ -268,7 +268,7 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed, watch, shallowRef, markRaw } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { NPagination, useMessage } from 'naive-ui'
|
||||
import { NPagination, useMessage, useDialog } from 'naive-ui'
|
||||
import { Icon } from '@iconify/vue'
|
||||
import axios from 'axios'
|
||||
import { t } from '@/shared/i18n'
|
||||
@ -290,6 +290,7 @@ import { downloadImageToLocal } from '@/shared/api/common'
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const message = useMessage()
|
||||
const dialog = useDialog()
|
||||
|
||||
// 使用组合式函数处理URL slug
|
||||
const { pagetypeSlug, entity } = usePageTypeSlug(route)
|
||||
@ -992,14 +993,32 @@ function openDetail(name: string) {
|
||||
|
||||
async function handleDeleteSelected() {
|
||||
if (selectedKeys.value.length === 0) return
|
||||
const { deleteRecords } = await import('../../shared/api/common')
|
||||
const res = await deleteRecords(entity.value, selectedKeys.value)
|
||||
if (res.success) {
|
||||
selectedKeys.value = []
|
||||
await loadData()
|
||||
} else {
|
||||
message.error(res.message || t('Delete failed'))
|
||||
}
|
||||
|
||||
dialog.warning({
|
||||
title: t('Delete Selected Records'),
|
||||
content: t(`Are you sure you want to delete ${selectedKeys.value.length} selected record(s)? This action cannot be undone.`),
|
||||
positiveText: t('Delete'),
|
||||
negativeText: t('Cancel'),
|
||||
onPositiveClick: async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const { deleteRecords } = await import('../../shared/api/common')
|
||||
const res = await deleteRecords(entity.value, selectedKeys.value)
|
||||
if (res.success) {
|
||||
message.success(res.message || t('Deleted successfully'))
|
||||
selectedKeys.value = []
|
||||
await loadData()
|
||||
} else {
|
||||
message.error(res.message || t('Delete failed'))
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(t('Delete failed'))
|
||||
console.error('Delete error:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function createRecordHandler() {
|
||||
@ -1013,13 +1032,30 @@ function editRecord(row: any) {
|
||||
}
|
||||
|
||||
async function deleteRecord(name: string) {
|
||||
const { deleteRecords } = await import('@/shared/api/common')
|
||||
const res = await deleteRecords(entity.value, [name])
|
||||
if (res.success) {
|
||||
await loadData()
|
||||
} else {
|
||||
message.error(res.message || t('Delete failed'))
|
||||
}
|
||||
dialog.warning({
|
||||
title: t('Delete Record'),
|
||||
content: t('Are you sure you want to delete this record? This action cannot be undone.'),
|
||||
positiveText: t('Delete'),
|
||||
negativeText: t('Cancel'),
|
||||
onPositiveClick: async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const { deleteRecords } = await import('@/shared/api/common')
|
||||
const res = await deleteRecords(entity.value, [name])
|
||||
if (res.success) {
|
||||
message.success(res.message || t('Deleted successfully'))
|
||||
await loadData()
|
||||
} else {
|
||||
message.error(res.message || t('Delete failed'))
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(t('Delete failed'))
|
||||
console.error('Delete error:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user