mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 06:47:20 +08:00
feat(project): 添加项目自启动设置功能 (#1251)
* Initial plan * feat(project): 添加项目自启动设置功能 Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> * style(project): 为自启动开关添加 rubberBand: false Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> * fix: 项目列表宽度 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> Co-authored-by: 耗子 <haozi@loli.email>
This commit is contained in:
@@ -216,6 +216,11 @@ func (r *projectRepo) parseProjectDetail(project *biz.Project) (*types.ProjectDe
|
||||
detail.Uptime = info.Uptime
|
||||
}
|
||||
|
||||
// 获取是否自启动
|
||||
if enabled, err := systemctl.IsEnabled(project.Name); err == nil {
|
||||
detail.Enabled = enabled
|
||||
}
|
||||
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ type ProjectDetail struct {
|
||||
|
||||
// 运行状态
|
||||
Status string `json:"status"` // 运行状态
|
||||
Enabled bool `json:"enabled"` // 是否自启动
|
||||
PID int `json:"pid"` // 进程ID
|
||||
Memory int64 `json:"memory"` // 内存使用(字节)
|
||||
CPU float64 `json:"cpu"` // CPU使用率
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" setup>
|
||||
import { NButton, NDataTable, NFlex, NPopconfirm, NTag } from 'naive-ui'
|
||||
import { NButton, NDataTable, NFlex, NPopconfirm, NSwitch, NTag } from 'naive-ui'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
|
||||
import project from '@/api/panel/project'
|
||||
@@ -77,6 +77,19 @@ const columns: any = [
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $gettext('Autostart'),
|
||||
key: 'enabled',
|
||||
width: 100,
|
||||
render(row: any) {
|
||||
return h(NSwitch, {
|
||||
size: 'small',
|
||||
rubberBand: false,
|
||||
value: row.enabled,
|
||||
onUpdateValue: (value: boolean) => handleToggleAutostart(row, value)
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $gettext('Directory'),
|
||||
key: 'root_dir',
|
||||
@@ -183,6 +196,20 @@ const handleToggleStatus = (row: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleAutostart = (row: any, enabled: boolean) => {
|
||||
if (enabled) {
|
||||
useRequest(systemctl.enable(row.name)).onSuccess(() => {
|
||||
row.enabled = true
|
||||
window.$message.success($gettext('Autostart enabled'))
|
||||
})
|
||||
} else {
|
||||
useRequest(systemctl.disable(row.name)).onSuccess(() => {
|
||||
row.enabled = false
|
||||
window.$message.success($gettext('Autostart disabled'))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleShowLog = (row: any) => {
|
||||
logService.value = row.name
|
||||
logModal.value = true
|
||||
@@ -238,7 +265,7 @@ watch(type, () => {
|
||||
striped
|
||||
remote
|
||||
:loading="loading"
|
||||
:scroll-x="1200"
|
||||
:scroll-x="1300"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
:row-key="(row: any) => row.id"
|
||||
|
||||
Reference in New Issue
Block a user