From 6d290f6a7384892a9cb8fbb290762a18c7c9671c Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Tue, 3 Jan 2023 14:57:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=B7=B2=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=BA=94=E7=94=A8=E7=9A=84=E8=AF=A6=E6=83=85=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/app_install.go | 25 ++++++----- backend/app/dto/app.go | 15 ++++--- backend/app/dto/response/app.go | 5 +++ backend/app/service/app_install.go | 39 ++++++++++++++++ backend/router/ro_app.go | 1 + frontend/src/api/interface/app.ts | 5 +++ frontend/src/api/modules/app.ts | 4 ++ frontend/src/lang/modules/zh.ts | 1 + .../views/app-store/installed/check/index.vue | 8 +--- .../app-store/installed/detail/index.vue | 45 +++++++++++++++++++ .../src/views/app-store/installed/index.vue | 16 ++++--- .../src/views/website/ssl/detail/index.vue | 37 --------------- 12 files changed, 134 insertions(+), 67 deletions(-) create mode 100644 frontend/src/views/app-store/installed/detail/index.vue diff --git a/backend/app/api/v1/app_install.go b/backend/app/api/v1/app_install.go index 3404233e2..0c0ea0d60 100644 --- a/backend/app/api/v1/app_install.go +++ b/backend/app/api/v1/app_install.go @@ -25,7 +25,6 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, dto.PageResult{ Items: list, Total: total, @@ -36,7 +35,6 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, list) } } @@ -89,7 +87,6 @@ func (b *BaseApi) DeleteCheck(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) return } - checkData, err := appInstallService.DeleteCheck(appInstallId) if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) @@ -117,7 +114,6 @@ func (b *BaseApi) SearchInstalledBackup(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, dto.PageResult{ Items: list, Total: total, @@ -134,7 +130,6 @@ func (b *BaseApi) OperateInstalled(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, nil) } @@ -158,7 +153,6 @@ func (b *BaseApi) GetServices(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, services) } @@ -168,13 +162,11 @@ func (b *BaseApi) GetUpdateVersions(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) return } - versions, err := appInstallService.GetUpdateVersions(appInstallId) if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, versions) } @@ -188,12 +180,10 @@ func (b *BaseApi) ChangeAppPort(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) return } - if err := appInstallService.ChangeAppPort(req); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, nil) } @@ -203,7 +193,6 @@ func (b *BaseApi) GetDefaultConfig(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) return } - content, err := appInstallService.GetDefaultConfigByKey(key) if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) @@ -212,3 +201,17 @@ func (b *BaseApi) GetDefaultConfig(c *gin.Context) { helper.SuccessWithData(c, content) } + +func (b *BaseApi) GetParams(c *gin.Context) { + appInstallId, err := helper.GetIntParamByKey(c, "appInstallId") + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + return + } + content, err := appInstallService.GetParams(appInstallId) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, content) +} diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index a0fe5b7b5..4278ae98e 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -62,16 +62,17 @@ type Tag struct { } type AppForm struct { - FormFields []AppFormFields `json:"form_fields"` + FormFields []AppFormFields `json:"formFields"` } type AppFormFields struct { - Type string `json:"type"` - LabelZh string `json:"label_zh"` - LabelEn string `json:"label_en"` - Required string `json:"required"` - Default string `json:"default"` - EnvKey string `json:"env_variable"` + Type string `json:"type"` + LabelZh string `json:"labelZh"` + LabelEn string `json:"labelEn"` + Required bool `json:"required"` + Default interface{} `json:"default"` + EnvKey string `json:"envKey"` + Disabled bool `json:"disabled"` } type AppResource struct { diff --git a/backend/app/dto/response/app.go b/backend/app/dto/response/app.go index f169f22d9..103d81837 100644 --- a/backend/app/dto/response/app.go +++ b/backend/app/dto/response/app.go @@ -52,3 +52,8 @@ type AppService struct { Value string `json:"value"` Config interface{} `json:"config"` } + +type AppParam struct { + Label string `json:"label"` + Value interface{} `json:"value"` +} diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index af1c11b52..724cf10d2 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -350,6 +350,45 @@ func (a AppInstallService) GetDefaultConfigByKey(key string) (string, error) { return string(contentByte), nil } +func (a AppInstallService) GetParams(id uint) ([]response.AppParam, error) { + var ( + res []response.AppParam + appForm dto.AppForm + envs = make(map[string]interface{}) + ) + install, err := appInstallRepo.GetFirst(commonRepo.WithByID(id)) + if err != nil { + return nil, err + } + detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(install.AppDetailId)) + if err != nil { + return nil, err + } + if err := json.Unmarshal([]byte(detail.Params), &appForm); err != nil { + return nil, err + } + if err := json.Unmarshal([]byte(install.Env), &envs); err != nil { + return nil, err + } + for _, form := range appForm.FormFields { + if v, ok := envs[form.EnvKey]; ok { + if form.Type == "service" { + appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithServiceName(v.(string))) + res = append(res, response.AppParam{ + Label: form.LabelZh, + Value: appInstall.Name, + }) + } else { + res = append(res, response.AppParam{ + Label: form.LabelZh, + Value: v, + }) + } + } + } + return res, nil +} + func syncById(installId uint) error { appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId)) if err != nil { diff --git a/backend/router/ro_app.go b/backend/router/ro_app.go index 75d291fd8..ab497230b 100644 --- a/backend/router/ro_app.go +++ b/backend/router/ro_app.go @@ -33,5 +33,6 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) { appRouter.POST("/installed/port/change", baseApi.ChangeAppPort) appRouter.GET("/services/:key", baseApi.GetServices) appRouter.GET("/installed/conf/:key", baseApi.GetDefaultConfig) + appRouter.GET("/installed/params/:appInstallId", baseApi.GetParams) } } diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 94ac0f12b..304d45afb 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -142,4 +142,9 @@ export namespace App { version: string; detailId: number; } + + export interface InstallParams { + label: string; + value: string; + } } diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index 0d1e3f126..0d0eb92f1 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -77,3 +77,7 @@ export const GetAppUpdateVersions = (id: number) => { export const GetAppDefaultConfig = (key: string) => { return http.get(`apps/installed/conf/${key}`); }; + +export const GetAppInstallParams = (id: number) => { + return http.get(`apps/installed/params/${id}`); +}; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 148955062..117faba6b 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -811,6 +811,7 @@ export default { deleteBackupHelper: '同时删除应用备份', noService: '无{0}', toInstall: '去安装', + param: '参数配置', }, website: { website: '网站', diff --git a/frontend/src/views/app-store/installed/check/index.vue b/frontend/src/views/app-store/installed/check/index.vue index 5467bdb86..a696b42cc 100644 --- a/frontend/src/views/app-store/installed/check/index.vue +++ b/frontend/src/views/app-store/installed/check/index.vue @@ -1,11 +1,5 @@ + diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 8ebe216ba..1bad0ea6e 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -18,7 +18,9 @@ @@ -32,6 +34,7 @@ + @@ -120,8 +124,8 @@ import { ElMessage, ElMessageBox } from 'element-plus'; import Backups from './backups.vue'; import AppResources from './check/index.vue'; import AppDelete from './delete/index.vue'; +import AppParams from './detail/index.vue'; import { App } from '@/api/interface/app'; -// import { useDeleteData } from '@/hooks/use-delete-data'; import Status from '@/components/status/index.vue'; let data = ref(); @@ -142,6 +146,7 @@ let versions = ref(); const backupRef = ref(); const checkRef = ref(); const deleteRef = ref(); +const appParamRef = ref(); let searchName = ref(''); const sync = () => { @@ -187,9 +192,6 @@ const openOperate = (row: any, op: string) => { checkRef.value.acceptParams({ items: items }); } else { deleteRef.value.acceptParams(row); - - // await useDeleteData(InstalledOp, operateReq, 'app.deleteWarn'); - // search(); } }); } else { @@ -281,6 +283,10 @@ const openBackups = (installId: number, installName: string) => { backupRef.value.acceptParams(params); }; +const openParam = (installId: number) => { + appParamRef.value.acceptParams({ id: installId }); +}; + onMounted(() => { search(); timer = setInterval(() => { diff --git a/frontend/src/views/website/ssl/detail/index.vue b/frontend/src/views/website/ssl/detail/index.vue index cd3d27bc5..cfba76e12 100644 --- a/frontend/src/views/website/ssl/detail/index.vue +++ b/frontend/src/views/website/ssl/detail/index.vue @@ -98,43 +98,6 @@ const copyText = async (msg) => { } }; -// const copyText = async (text: string) => { -// try { -// try { -// await navigator.clipboard.writeText(text); -// ElMessage.success(i18n.global.t('commons.msg.copySuccess')); -// return await Promise.resolve(); -// } catch (err) { -// return await Promise.reject(err); -// } -// } catch (e) { -// let input = document.createElement('input'); -// input.style.position = 'fixed'; -// input.style.top = '-10000px'; -// input.style.zIndex = '-999'; -// document.body.appendChild(input); -// console.log('input', input); -// input.value = text; -// input.focus(); -// input.select(); -// try { -// let result = document.execCommand('copy'); -// document.body.removeChild(input); -// if (!result) { -// ElMessage.error(i18n.global.t('commons.msg.copyfailed')); -// return Promise.reject(); -// } else { -// ElMessage.success(i18n.global.t('commons.msg.copySuccess')); -// return Promise.resolve(); -// } -// } catch (e) { -// document.body.removeChild(input); -// ElMessage.error(i18n.global.t('commons.msg.copyfailed')); -// return Promise.reject(); -// } -// } -// }; - defineExpose({ acceptParams, });