1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

feat: 增加删除功能

This commit is contained in:
zhengkunwang223 2022-09-26 22:54:38 +08:00 committed by zhengkunwang223
parent c6219707ec
commit c3274af4cd
7 changed files with 54 additions and 10 deletions

View File

@ -87,6 +87,7 @@ var (
Up AppOperate = "up" Up AppOperate = "up"
Down AppOperate = "down" Down AppOperate = "down"
Restart AppOperate = "restart" Restart AppOperate = "restart"
Delete AppOperate = "delete"
) )
type AppInstallOperate struct { type AppInstallOperate struct {

View File

@ -21,11 +21,20 @@ func (a AppInstallRepo) Create(install *model.AppInstall) error {
db := global.DB.Model(&model.AppInstall{}) db := global.DB.Model(&model.AppInstall{})
return db.Create(&install).Error return db.Create(&install).Error
} }
func (a AppInstallRepo) Save(install model.AppInstall) error { func (a AppInstallRepo) Save(install model.AppInstall) error {
db := global.DB.Model(&model.AppInstall{}) db := global.DB.Model(&model.AppInstall{})
return db.Save(&install).Error 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) { func (a AppInstallRepo) Page(page, size int, opts ...DBOption) (int64, []model.AppInstall, error) {
var apps []model.AppInstall var apps []model.AppInstall
db := global.DB.Model(&model.AppInstall{}) db := global.DB.Model(&model.AppInstall{})

View File

@ -154,7 +154,7 @@ func (a AppService) Operate(req dto.AppInstallOperate) error {
return err return err
} }
if len(appInstall) == 0 { if len(appInstall) == 0 {
return errors.New("not found") return errors.New("req not found")
} }
install := appInstall[0] install := appInstall[0]
@ -175,6 +175,20 @@ func (a AppService) Operate(req dto.AppInstallOperate) error {
if err != nil { if err != nil {
return handleErr(install, err, out) 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: default:
return errors.New("operate not support") return errors.New("operate not support")
} }

View File

@ -28,3 +28,12 @@ func Restart(filePath string) (string, error) {
} }
return string(stdout), nil 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
}

View File

@ -408,11 +408,12 @@ export default {
sync: 'sync', sync: 'sync',
appName: 'App Name', appName: 'App Name',
status: 'status', status: 'status',
container: 'container', container: 'Container',
restart: 'restart', restart: 'Restart',
up: 'start', up: 'Start',
down: 'stop', down: 'Stop',
name: 'name', name: 'Name',
description: 'description', description: 'Description',
delete: 'Delete',
}, },
}; };

View File

@ -406,5 +406,6 @@ export default {
down: '停止', down: '停止',
name: '名称', name: '名称',
description: '描述', description: '描述',
delete: '删除',
}, },
}; };

View File

@ -1,7 +1,7 @@
<template> <template>
<ComplexTable :pagination-config="paginationConfig" :data="data" @search="search" v-loading="loading"> <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.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.appName')" prop="appName"></el-table-column>
<el-table-column :label="$t('app.version')" prop="version"></el-table-column> <el-table-column :label="$t('app.version')" prop="version"></el-table-column>
<el-table-column :label="$t('app.container')"> <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 ComplexTable from '@/components/complex-table/index.vue';
import { dateFromat } from '@/utils/util'; import { dateFromat } from '@/utils/util';
import i18n from '@/lang'; import i18n from '@/lang';
import { ElMessageBox } from 'element-plus'; import { ElMessage, ElMessageBox } from 'element-plus';
let data = ref<any>(); let data = ref<any>();
let loading = ref(false); let loading = ref(false);
@ -77,7 +77,10 @@ const operate = async (row: any, op: string) => {
}).then(async () => { }).then(async () => {
loading.value = true; loading.value = true;
InstalledOp(req) InstalledOp(req)
.then(() => {}) .then(() => {
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
search();
})
.finally(() => { .finally(() => {
loading.value = false; loading.value = false;
}); });
@ -103,6 +106,12 @@ const buttons = [
operate(row, 'down'); operate(row, 'down');
}, },
}, },
{
label: i18n.global.t('app.delete'),
click: (row: any) => {
operate(row, 'delete');
},
},
]; ];
onMounted(() => { onMounted(() => {