mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 增加删除功能
This commit is contained in:
parent
c6219707ec
commit
c3274af4cd
@ -87,6 +87,7 @@ var (
|
||||
Up AppOperate = "up"
|
||||
Down AppOperate = "down"
|
||||
Restart AppOperate = "restart"
|
||||
Delete AppOperate = "delete"
|
||||
)
|
||||
|
||||
type AppInstallOperate struct {
|
||||
|
@ -21,11 +21,20 @@ func (a AppInstallRepo) Create(install *model.AppInstall) error {
|
||||
db := global.DB.Model(&model.AppInstall{})
|
||||
return db.Create(&install).Error
|
||||
}
|
||||
|
||||
func (a AppInstallRepo) Save(install model.AppInstall) error {
|
||||
db := global.DB.Model(&model.AppInstall{})
|
||||
return db.Save(&install).Error
|
||||
}
|
||||
|
||||
func (a AppInstallRepo) Delete(opts ...DBOption) error {
|
||||
db := global.DB.Model(&model.AppInstall{})
|
||||
for _, opt := range opts {
|
||||
db = opt(db)
|
||||
}
|
||||
return db.Delete(&model.AppInstall{}).Error
|
||||
}
|
||||
|
||||
func (a AppInstallRepo) Page(page, size int, opts ...DBOption) (int64, []model.AppInstall, error) {
|
||||
var apps []model.AppInstall
|
||||
db := global.DB.Model(&model.AppInstall{})
|
||||
|
@ -154,7 +154,7 @@ func (a AppService) Operate(req dto.AppInstallOperate) error {
|
||||
return err
|
||||
}
|
||||
if len(appInstall) == 0 {
|
||||
return errors.New("not found")
|
||||
return errors.New("req not found")
|
||||
}
|
||||
|
||||
install := appInstall[0]
|
||||
@ -175,6 +175,20 @@ func (a AppService) Operate(req dto.AppInstallOperate) error {
|
||||
if err != nil {
|
||||
return handleErr(install, err, out)
|
||||
}
|
||||
case dto.Delete:
|
||||
op := files.NewFileOp()
|
||||
appDir := path.Join(global.CONF.System.AppDir, install.App.Key, install.ContainerName)
|
||||
dir, _ := os.Stat(appDir)
|
||||
if dir == nil {
|
||||
_ = appInstallRepo.Delete(commonRepo.WithByID(install.ID))
|
||||
break
|
||||
}
|
||||
_ = op.DeleteDir(appDir)
|
||||
out, err := compose.Rmf(dockerComposePath)
|
||||
if err != nil {
|
||||
return handleErr(install, err, out)
|
||||
}
|
||||
_ = appInstallRepo.Delete(commonRepo.WithByID(install.ID))
|
||||
default:
|
||||
return errors.New("operate not support")
|
||||
}
|
||||
|
@ -28,3 +28,12 @@ func Restart(filePath string) (string, error) {
|
||||
}
|
||||
return string(stdout), nil
|
||||
}
|
||||
|
||||
func Rmf(filePath string) (string, error) {
|
||||
cmd := exec.Command("docker-compose", "-f", filePath, "rm", "-f")
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(stdout), nil
|
||||
}
|
||||
|
@ -408,11 +408,12 @@ export default {
|
||||
sync: 'sync',
|
||||
appName: 'App Name',
|
||||
status: 'status',
|
||||
container: 'container',
|
||||
restart: 'restart',
|
||||
up: 'start',
|
||||
down: 'stop',
|
||||
name: 'name',
|
||||
description: 'description',
|
||||
container: 'Container',
|
||||
restart: 'Restart',
|
||||
up: 'Start',
|
||||
down: 'Stop',
|
||||
name: 'Name',
|
||||
description: 'Description',
|
||||
delete: 'Delete',
|
||||
},
|
||||
};
|
||||
|
@ -406,5 +406,6 @@ export default {
|
||||
down: '停止',
|
||||
name: '名称',
|
||||
description: '描述',
|
||||
delete: '删除',
|
||||
},
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<ComplexTable :pagination-config="paginationConfig" :data="data" @search="search" v-loading="loading">
|
||||
<el-table-column :label="$t('app.name')" prop="name"></el-table-column>
|
||||
<el-table-column :label="$t('app.description')" prop="description"></el-table-column>
|
||||
<!-- <el-table-column :label="$t('app.description')" prop="description"></el-table-column> -->
|
||||
<el-table-column :label="$t('app.appName')" prop="appName"></el-table-column>
|
||||
<el-table-column :label="$t('app.version')" prop="version"></el-table-column>
|
||||
<el-table-column :label="$t('app.container')">
|
||||
@ -41,7 +41,7 @@ import { onMounted, reactive, ref } from 'vue';
|
||||
import ComplexTable from '@/components/complex-table/index.vue';
|
||||
import { dateFromat } from '@/utils/util';
|
||||
import i18n from '@/lang';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
|
||||
let data = ref<any>();
|
||||
let loading = ref(false);
|
||||
@ -77,7 +77,10 @@ const operate = async (row: any, op: string) => {
|
||||
}).then(async () => {
|
||||
loading.value = true;
|
||||
InstalledOp(req)
|
||||
.then(() => {})
|
||||
.then(() => {
|
||||
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
||||
search();
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
@ -103,6 +106,12 @@ const buttons = [
|
||||
operate(row, 'down');
|
||||
},
|
||||
},
|
||||
{
|
||||
label: i18n.global.t('app.delete'),
|
||||
click: (row: any) => {
|
||||
operate(row, 'delete');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
onMounted(() => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user