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