fix: Fix the issue of abnormal display of recommended applications on… (#7914)

This commit is contained in:
ssongliu 2025-02-19 17:08:34 +08:00 committed by GitHub
parent 33e23655d3
commit 736200bd57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 58 additions and 17 deletions

View file

@ -61,6 +61,19 @@ func (b *BaseApi) LoadAppLauncherOption(c *gin.Context) {
helper.SuccessWithData(c, data)
}
func (b *BaseApi) SyncAppLauncher(c *gin.Context) {
var req dto.SyncFromMaster
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
if err := dashboardService.Sync(req); err != nil {
helper.BadRequest(c, err)
return
}
helper.SuccessWithOutData(c)
}
// @Tags Dashboard
// @Summary Load dashboard base info
// @Accept json

View file

@ -96,16 +96,27 @@ func (u *CronjobService) SearchRecords(search dto.SearchRecord) (int64, interfac
func (u *CronjobService) LoadNextHandle(specStr string) ([]string, error) {
spec := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)
now := time.Now()
var nexts [5]string
if strings.HasPrefix(specStr, "@every ") {
duration := time.Minute
if strings.HasSuffix(specStr, "s") {
duration = time.Second
}
for i := 0; i < 5; i++ {
nextTime := now.Add(duration)
nexts[i] = nextTime.Format(constant.DateTimeLayout)
now = nextTime
}
return nexts[:], nil
}
sched, err := spec.Parse(specStr)
if err != nil {
return nil, err
}
now := time.Now()
var nexts [5]string
for i := 0; i < 5; i++ {
nextTime := sched.Next(now)
nexts[i] = nextTime.Format("2006-01-02 15:04:05")
fmt.Println(nextTime)
nexts[i] = nextTime.Format(constant.DateTimeLayout)
now = nextTime
}
return nexts[:], nil

View file

@ -13,6 +13,7 @@ func (s *DashboardRouter) InitRouter(Router *gin.RouterGroup) {
{
cmdRouter.GET("/base/os", baseApi.LoadDashboardOsInfo)
cmdRouter.GET("/app/launcher", baseApi.LoadAppLauncher)
cmdRouter.POST("/app/launcher/sync", baseApi.SyncAppLauncher)
cmdRouter.POST("/app/launcher/option", baseApi.LoadAppLauncherOption)
cmdRouter.GET("/base/:ioOption/:netOption", baseApi.LoadDashboardBaseInfo)
cmdRouter.GET("/current/node", baseApi.LoadCurrentInfoForNode)

View file

@ -39,6 +39,7 @@ func (u *LauncherService) ChangeShow(req dto.SettingUpdate) error {
launcher, _ := launcherRepo.Get(repo.WithByKey(req.Key))
if req.Value == constant.StatusEnable {
if launcher.ID != 0 {
go syncLauncherToAgent(launcher, "create")
return nil
}
launcher.Key = req.Key
@ -49,6 +50,7 @@ func (u *LauncherService) ChangeShow(req dto.SettingUpdate) error {
return nil
}
if launcher.ID == 0 {
go syncLauncherToAgent(launcher, "delete")
return nil
}
if err := launcherRepo.Delete(repo.WithByKey(req.Key)); err != nil {

View file

@ -84,6 +84,7 @@ const dialogVisible = computed({
const handleBeforeClose = () => {
emit('close');
dialogVisible.value = false;
};
const open = () => {
emit('open');

View file

@ -23,7 +23,7 @@
</el-popover>
</template>
<template #body>
<el-scrollbar height="525px" class="moz-height">
<el-scrollbar height="545px" class="moz-height">
<div class="h-app-card" v-for="(app, index) in apps" :key="index">
<el-row :gutter="5">
<el-col :span="5">
@ -64,16 +64,17 @@
<div class="h-app-content" v-else>
<div>
<el-dropdown trigger="hover">
<el-button plain size="small" link class="h-app-dropdown">
<el-button type="primary" plain size="small" link class="h-app-dropdown">
{{ app.currentRow.name }}
<el-icon class="el-icon--right"><ArrowDown /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu
v-for="(detailItem, index2) in app.detail"
:key="index2"
>
<el-dropdown-item @click="app.currentRow = detailItem">
<el-dropdown-menu>
<el-dropdown-item
v-for="(detailItem, index2) in app.detail"
:key="index2"
@click="app.currentRow = detailItem"
>
{{ detailItem.name + ' - ' + detailItem.version }}
</el-dropdown-item>
</el-dropdown-menu>
@ -90,7 +91,8 @@
size="small"
type="primary"
link
@click="onOperate('stop', app.currentRow)"
v-if="app.currentRow.status !== 'Running'"
@click="onOperate('start', app.currentRow)"
>
{{ $t('commons.button.start') }}
</el-button>
@ -99,10 +101,20 @@
size="small"
type="primary"
link
v-else
@click="onOperate('stop', app.currentRow)"
>
{{ $t('commons.button.stop') }}
</el-button>
<el-button
:style="mobile ? 'margin-left: -1px' : ''"
size="small"
type="primary"
link
@click="onOperate('restart', app.currentRow)"
>
{{ $t('commons.button.restart') }}
</el-button>
<el-button
:style="mobile ? 'margin-left: -1px' : ''"
size="small"
@ -244,6 +256,7 @@ const onChangeStatus = async (row: any) => {
await changeLauncherStatus(row.key, row.isShow ? 'Enable' : 'Disable')
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
search();
})
.catch(() => {
@ -266,8 +279,8 @@ const getConfig = async () => {
const onOperate = async (operation: string, row: any) => {
ElMessageBox.confirm(
i18n.global.t('app.operatorHelper', [i18n.global.t('app.' + operation)]),
i18n.global.t('app.' + operation),
i18n.global.t('app.operatorHelper', [i18n.global.t('commons.button.' + operation)]),
i18n.global.t('commons.button.' + operation),
{
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
@ -276,9 +289,9 @@ const onOperate = async (operation: string, row: any) => {
).then(async () => {
loading.value = true;
let params = {
installId: row.installId,
installId: row.installID,
operate: operation,
detailId: row.detailId,
detailId: row.detailID,
};
await installedOp(params)
.then(() => {
@ -353,7 +366,7 @@ defineExpose({
.h-app-dropdown {
font-weight: 600;
font-size: 16px;
color: #1f2329;
color: var(--panel-text-color);
}
.h-app-margin {