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

feat: 安装网站增加提示

This commit is contained in:
zhengkunwang223 2022-12-04 17:45:54 +08:00 committed by zhengkunwang223
parent 92e7617304
commit 26039cc19d
14 changed files with 181 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package v1
import (
"errors"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant"
@ -255,3 +254,17 @@ func (b *BaseApi) UpdateHTTPSConfig(c *gin.Context) {
}
helper.SuccessWithData(c, res)
}
func (b *BaseApi) CreateWebsiteCheck(c *gin.Context) {
var req dto.WebsiteInstallCheckReq
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
data, err := websiteService.PreInstallCheck(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, data)
}

View File

@ -110,3 +110,14 @@ type WebsiteNginxConfig struct {
Enable bool `json:"enable"`
Params []NginxParam `json:"params"`
}
type WebsitePreInstallCheck struct {
Name string `json:"name"`
Status string `json:"status"`
Version string `json:"version"`
AppName string `json:"appName"`
}
type WebsiteInstallCheckReq struct {
InstallIds []uint `json:"InstallIds"`
}

View File

@ -112,7 +112,7 @@ type RootInfo struct {
Version string `json:"version"`
}
func (u *AppInstallRepo) LoadBaseInfoByKey(key string) (*RootInfo, error) {
func (a *AppInstallRepo) LoadBaseInfoByKey(key string) (*RootInfo, error) {
var (
app model.App
appInstall model.AppInstall

View File

@ -48,6 +48,7 @@ func (a AppInstallService) Page(req dto.AppInstalledRequest) (int64, []dto.AppIn
}
func (a AppInstallService) CheckExist(key string) (*dto.CheckInstalled, error) {
res := &dto.CheckInstalled{
IsExist: false,
}
@ -60,6 +61,10 @@ func (a AppInstallService) CheckExist(key string) (*dto.CheckInstalled, error) {
if reflect.DeepEqual(appInstall, model.AppInstall{}) {
return res, nil
}
if err := syncById(appInstall.ID); err != nil {
return nil, err
}
res.ContainerName = appInstall.ContainerName
res.Name = appInstall.Name
res.Version = appInstall.Version

View File

@ -511,6 +511,55 @@ func (w WebsiteService) OpWebsiteHTTPS(req dto.WebsiteHTTPSOp) (dto.WebsiteHTTPS
return res, nil
}
func (w WebsiteService) PreInstallCheck(req dto.WebsiteInstallCheckReq) ([]dto.WebsitePreInstallCheck, error) {
var (
res []dto.WebsitePreInstallCheck
checkIds []uint
showErr = false
)
app, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
if err != nil {
return nil, err
}
appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithAppId(app.ID))
if reflect.DeepEqual(appInstall, model.AppInstall{}) {
res = append(res, dto.WebsitePreInstallCheck{
Name: appInstall.Name,
AppName: app.Name,
Status: buserr.WithMessage(constant.ErrNotInstall, app.Name, nil).Error(),
Version: appInstall.Version,
})
showErr = true
} else {
checkIds = append(req.InstallIds, appInstall.ID)
}
for _, id := range checkIds {
if err := syncById(id); err != nil {
return nil, err
}
}
if len(checkIds) > 0 {
installList, _ := appInstallRepo.GetBy(commonRepo.WithIdsIn(checkIds))
for _, install := range installList {
res = append(res, dto.WebsitePreInstallCheck{
Name: install.Name,
Status: install.Status,
Version: install.Version,
AppName: install.App.Name,
})
if install.Status != constant.StatusRunning {
showErr = true
}
}
}
if showErr {
return res, nil
} else {
return nil, nil
}
}
type WebSiteInfo struct {
WebsiteName string `json:"websiteName"`
WebsiteType string `json:"websiteType"`

View File

@ -51,10 +51,10 @@ var (
ErrAppRequired = "ErrAppRequired"
ErrFileCanNotRead = "ErrFileCanNotRead"
ErrFileToLarge = "ErrFileToLarge"
ErrNotInstall = "ErrNotInstall"
)
//website
var (
ErrDomainIsExist = "ErrDomainIsExist"
ErrAliasIsExist = "ErrAliasIsExist"

View File

@ -22,6 +22,7 @@ ErrNameIsExist: "Name is already exist"
ErrPortInUsed: "{{ .detail }} port already in use"
ErrAppLimit: "App exceeds install limit"
ErrAppRequired: "{{ .detail }} app is required"
ErrNotInstall: "App not installed"
#file

View File

@ -22,6 +22,7 @@ ErrNameIsExist: "名称已存在"
ErrPortInUsed: "{{ .detail }} 端口已被占用!"
ErrAppLimit: "应用超出安装数量限制"
ErrAppRequired: "请先安装 {{ .detail }} 应用"
ErrNotInstall: "应用未安装"
#file

View File

@ -16,6 +16,7 @@ func (a *WebsiteRouter) InitWebsiteRouter(Router *gin.RouterGroup) {
baseApi := v1.ApiGroupApp.BaseApi
{
groupRouter.POST("", baseApi.CreateWebsite)
groupRouter.POST("/check", baseApi.CreateWebsiteCheck)
groupRouter.GET("/options", baseApi.GetWebsiteOptions)
groupRouter.POST("/backup/:domain", baseApi.BackupWebsite)
groupRouter.POST("/recover", baseApi.RecoverWebsite)

View File

@ -201,4 +201,15 @@ export namespace WebSite {
enable: boolean;
SSL: SSL;
}
export interface CheckReq {
installIds?: number[];
}
export interface CheckRes {
name: string;
status: string;
version: string;
appName: string;
}
}

View File

@ -144,3 +144,7 @@ export const GetHTTPSConfig = (id: number) => {
export const UpdateHTTPSConfig = (req: WebSite.HTTPSReq) => {
return http.post<WebSite.HTTPSConfig>(`/websites/${req.websiteId}/https`, req);
};
export const PreCheck = (req: WebSite.CheckReq) => {
return http.post<WebSite.CheckRes[]>(`/websites/check`, req);
};

View File

@ -712,6 +712,7 @@ export default {
},
app: {
app: '应用',
installName: '安装名称',
installed: '已安装',
all: '全部',
version: '版本',
@ -826,6 +827,8 @@ export default {
protocol: '协议',
setDefault: '设为默认',
default: '默认',
deleteHelper: '相关应用状态不正常请检查',
toApp: '去已安装列表',
},
nginx: {
serverNamesHashBucketSizeHelper: '服务器名字的hash表大小',

View File

@ -0,0 +1,61 @@
<template>
<el-dialog
v-model="open"
:title="$t('app.checkTitle')"
width="50%"
:close-on-click-modal="false"
:destroy-on-close="true"
>
<el-row>
<el-alert type="warning" :description="$t('website.deleteHelper')" center show-icon :closable="false" />
<el-col :span="24">
<br />
<el-table :data="items" style="width: 100%">
<el-table-column prop="name" :label="$t('app.installName')" />
<el-table-column prop="appName" :label="$t('app.appName')" />
<el-table-column prop="version" :label="$t('app.version')" />
<el-table-column prop="status" :label="$t('app.status')" />
</el-table>
</el-col>
</el-row>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="toPage">
{{ $t('website.toApp') }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
interface InstallRrops {
items: WebSite.CheckRes[];
}
let open = ref(false);
let items = ref([]);
const acceptParams = async (props: InstallRrops) => {
items.value = props.items;
open.value = true;
console.log(items);
};
const handleClose = () => {
open.value = false;
};
const toPage = () => {
router.push({ name: 'AppInstalled' });
};
defineExpose({
acceptParams,
});
</script>

View File

@ -115,6 +115,7 @@
</el-button>
</span>
</template>
<Check ref="preCheckRef"></Check>
</el-dialog>
</template>
@ -122,12 +123,13 @@
import { App } from '@/api/interface/app';
import { WebSite } from '@/api/interface/website';
import { GetApp, GetAppDetail, SearchApp, GetAppInstalled } from '@/api/modules/app';
import { CreateWebsite, ListGroups } from '@/api/modules/website';
import { CreateWebsite, ListGroups, PreCheck } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
import { ElDialog, ElForm, FormInstance, ElMessage } from 'element-plus';
import { reactive, ref } from 'vue';
import Params from '@/views/app-store/detail/params/index.vue';
import Check from '../check/index.vue';
const websiteForm = ref<FormInstance>();
const website = ref({
@ -175,6 +177,7 @@ let appVersions = ref<string[]>([]);
let appDetail = ref<App.AppDetail>();
let appParams = ref<App.AppParams>();
let paramKey = ref(1);
let preCheckRef = ref();
const em = defineEmits(['close']);
@ -248,14 +251,21 @@ const submit = async (formEl: FormInstance | undefined) => {
return;
}
loading.value = true;
CreateWebsite(website.value)
.then(() => {
ElMessage.success(i18n.global.t('commons.msg.createSuccess'));
handleClose();
})
.finally(() => {
PreCheck({}).then((res) => {
if (res.data) {
loading.value = false;
});
preCheckRef.value.acceptParams({ items: res.data });
} else {
CreateWebsite(website.value)
.then(() => {
ElMessage.success(i18n.global.t('commons.msg.createSuccess'));
handleClose();
})
.finally(() => {
loading.value = false;
});
}
});
});
};