fix: remove package force #73
This commit is contained in:
@@ -188,6 +188,8 @@ func (c *DependencyController) Uninstall(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
force := ctx.Query("force") == "true"
|
||||||
|
|
||||||
// 获取依赖信息
|
// 获取依赖信息
|
||||||
deps, _ := c.service.List("", "")
|
deps, _ := c.service.List("", "")
|
||||||
var dep *models.Dependency
|
var dep *models.Dependency
|
||||||
@@ -204,11 +206,13 @@ func (c *DependencyController) Uninstall(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := c.service.Uninstall(dep); err != nil {
|
if err := c.service.Uninstall(dep); err != nil {
|
||||||
utils.ServerError(ctx, err.Error())
|
if !force {
|
||||||
return
|
utils.ServerError(ctx, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 卸载成功后从数据库删除
|
// 卸载成功(或强制删除)后从数据库删除
|
||||||
c.service.Delete(id)
|
c.service.Delete(id)
|
||||||
|
|
||||||
utils.SuccessMsg(ctx, "卸载成功")
|
utils.SuccessMsg(ctx, "卸载成功")
|
||||||
|
|||||||
@@ -242,7 +242,10 @@ export const api = {
|
|||||||
delete: (id: string) => request(`/deps/${id}`, { method: 'DELETE' }),
|
delete: (id: string) => request(`/deps/${id}`, { method: 'DELETE' }),
|
||||||
install: (data: any) => request<any>('/deps/install', { method: 'POST', body: JSON.stringify(data) }),
|
install: (data: any) => request<any>('/deps/install', { method: 'POST', body: JSON.stringify(data) }),
|
||||||
getInstallCmd: (data: any) => request<{ command: string }>('/deps/install-cmd', { method: 'POST', body: JSON.stringify(data) }),
|
getInstallCmd: (data: any) => request<{ command: string }>('/deps/install-cmd', { method: 'POST', body: JSON.stringify(data) }),
|
||||||
uninstall: (id: string) => request<any>(`/deps/uninstall/${id}`, { method: 'POST' }),
|
uninstall: (id: string, force?: boolean) => {
|
||||||
|
const query = force ? '?force=true' : ''
|
||||||
|
return request<any>(`/deps/uninstall/${id}${query}`, { method: 'POST' })
|
||||||
|
},
|
||||||
reinstall: (id: string) => request(`/deps/reinstall/${id}`, { method: 'POST' }),
|
reinstall: (id: string) => request(`/deps/reinstall/${id}`, { method: 'POST' }),
|
||||||
reinstallAll: (language: string, lang_version?: string) => {
|
reinstallAll: (language: string, lang_version?: string) => {
|
||||||
const query = new URLSearchParams({ language })
|
const query = new URLSearchParams({ language })
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent,
|
|||||||
import { Trash2, Package, Search, RefreshCw, Loader2, Download, FileText, RotateCw, ChevronLeft } from 'lucide-vue-next'
|
import { Trash2, Package, Search, RefreshCw, Loader2, Download, FileText, RotateCw, ChevronLeft } from 'lucide-vue-next'
|
||||||
import { api, type Dependency } from '@/api'
|
import { api, type Dependency } from '@/api'
|
||||||
import TextOverflow from '@/components/TextOverflow.vue'
|
import TextOverflow from '@/components/TextOverflow.vue'
|
||||||
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import { toast } from 'vue-sonner'
|
import { toast } from 'vue-sonner'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@@ -32,6 +33,7 @@ const newPkgRemark = ref('')
|
|||||||
|
|
||||||
// 删除确认
|
// 删除确认
|
||||||
const showDeleteDialog = ref(false)
|
const showDeleteDialog = ref(false)
|
||||||
|
const isForce = ref(false)
|
||||||
const depToDelete = ref<Dependency | null>(null)
|
const depToDelete = ref<Dependency | null>(null)
|
||||||
|
|
||||||
const showLogDialog = ref(false)
|
const showLogDialog = ref(false)
|
||||||
@@ -116,17 +118,40 @@ async function installPackage() {
|
|||||||
|
|
||||||
function confirmDelete(dep: Dependency) {
|
function confirmDelete(dep: Dependency) {
|
||||||
depToDelete.value = dep
|
depToDelete.value = dep
|
||||||
|
isForce.value = false
|
||||||
showDeleteDialog.value = true
|
showDeleteDialog.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uninstallPackage() {
|
async function uninstallPackage() {
|
||||||
if (!depToDelete.value) return
|
if (!depToDelete.value) return
|
||||||
|
const id = depToDelete.value.id
|
||||||
|
const name = depToDelete.value.name
|
||||||
|
const force = isForce.value
|
||||||
try {
|
try {
|
||||||
await api.deps.uninstall(depToDelete.value.id)
|
await api.deps.uninstall(id, force)
|
||||||
toast.success('卸载成功')
|
toast.success(force ? `"${name}" 记录已强制移除` : '卸载成功')
|
||||||
await loadDeps()
|
await loadDeps()
|
||||||
} catch (e: unknown) {
|
} catch (e: any) {
|
||||||
toast.error((e as Error).message || '卸载失败')
|
const errorMsg = e.message || '卸载失败'
|
||||||
|
toast.error(errorMsg, {
|
||||||
|
duration: 10000,
|
||||||
|
action: {
|
||||||
|
label: '强制删除记录',
|
||||||
|
onClick: async () => {
|
||||||
|
try {
|
||||||
|
await api.deps.uninstall(id, true)
|
||||||
|
toast.success(`已强制删除 "${name}" 记录`)
|
||||||
|
await loadDeps()
|
||||||
|
} catch (err: any) {
|
||||||
|
toast.error('强制删除失败: ' + err.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actionButtonStyle: {
|
||||||
|
backgroundColor: '#ef4444', // text-red-500 equivalent for background
|
||||||
|
color: 'white'
|
||||||
|
}
|
||||||
|
})
|
||||||
} finally {
|
} finally {
|
||||||
showDeleteDialog.value = false
|
showDeleteDialog.value = false
|
||||||
depToDelete.value = null
|
depToDelete.value = null
|
||||||
@@ -348,11 +373,19 @@ onMounted(async () => {
|
|||||||
确定要卸载 "{{ depToDelete?.name }}" 吗?
|
确定要卸载 "{{ depToDelete?.name }}" 吗?
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter class="flex-col sm:flex-row gap-3">
|
||||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
<div class="flex items-center gap-2 mr-auto mb-2 sm:mb-0">
|
||||||
<AlertDialogAction class="bg-destructive text-white hover:bg-destructive/90" @click="uninstallPackage">
|
<Checkbox id="force" v-model:checked="isForce" />
|
||||||
卸载
|
<Label for="force" class="text-sm font-medium text-red-500 cursor-pointer select-none">
|
||||||
</AlertDialogAction>
|
强制删除 (卸载失败时仍移除记录)
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||||
|
<AlertDialogAction class="bg-destructive text-white hover:bg-destructive/90" @click="uninstallPackage">
|
||||||
|
{{ isForce ? '强制删除' : '卸载' }}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</div>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user