mirror of
https://github.com/XShengTech/MEGREZ.git
synced 2026-05-03 13:02:38 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fc2c3ec09 | |||
| 011827f5c7 | |||
| 69554b5e39 | |||
| a24fb8e8ad |
@@ -4,10 +4,36 @@ const layoutConfig = reactive({
|
||||
preset: 'Aura',
|
||||
primary: 'blue',
|
||||
surface: null,
|
||||
darkTheme: false,
|
||||
darkTheme: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches,
|
||||
menuMode: 'static'
|
||||
});
|
||||
|
||||
// Listen for changes to the prefers-color-scheme media query
|
||||
if (window.matchMedia) {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
||||
layoutConfig.darkTheme = e.matches;
|
||||
toggleDarkMode();
|
||||
});
|
||||
}
|
||||
|
||||
const toggleDarkMode = () => {
|
||||
if (!document.startViewTransition) {
|
||||
executeDarkModeToggle();
|
||||
return;
|
||||
}
|
||||
|
||||
document.startViewTransition(() => executeDarkModeToggle(event));
|
||||
};
|
||||
|
||||
if (layoutConfig.darkTheme) {
|
||||
toggleDarkMode()
|
||||
}
|
||||
|
||||
const executeDarkModeToggle = () => {
|
||||
layoutConfig.darkTheme = !layoutConfig.darkTheme;
|
||||
document.documentElement.classList.toggle('app-dark');
|
||||
};
|
||||
|
||||
const layoutState = reactive({
|
||||
staticMenuDesktopInactive: false,
|
||||
overlayMenuActive: false,
|
||||
@@ -39,21 +65,6 @@ export function useLayout() {
|
||||
layoutConfig.menuMode = mode;
|
||||
};
|
||||
|
||||
const toggleDarkMode = () => {
|
||||
if (!document.startViewTransition) {
|
||||
executeDarkModeToggle();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
document.startViewTransition(() => executeDarkModeToggle(event));
|
||||
};
|
||||
|
||||
const executeDarkModeToggle = () => {
|
||||
layoutConfig.darkTheme = !layoutConfig.darkTheme;
|
||||
document.documentElement.classList.toggle('app-dark');
|
||||
};
|
||||
|
||||
const onMenuToggle = () => {
|
||||
if (layoutConfig.menuMode === 'overlay') {
|
||||
layoutState.overlayMenuActive = !layoutState.overlayMenuActive;
|
||||
|
||||
@@ -121,13 +121,13 @@
|
||||
</Fieldset>
|
||||
<Fieldset legend="GPU">
|
||||
<span v-if="instanceDetail.gpu_count !== 0">{{ instanceDetail.gpu_type }} * {{ instanceDetail.gpu_count
|
||||
}}</span>
|
||||
}}</span>
|
||||
<span v-else>无卡模式</span>
|
||||
</Fieldset>
|
||||
<div class="flex flex-col md:flex-row gap-4">
|
||||
<Fieldset class="flex flex-wrap gap-2 w-full" legend="CPU">
|
||||
<span v-if="instanceDetail.gpu_count !== 0">{{ instanceDetail.cpu_count_per_gpu * instanceDetail.gpu_count
|
||||
}}
|
||||
}}
|
||||
核</span>
|
||||
<span v-else>1 核</span>
|
||||
</Fieldset>
|
||||
@@ -498,6 +498,9 @@ const instanceModify = async () => {
|
||||
setTimeout(() => {
|
||||
getInstances()
|
||||
}, 100);
|
||||
if (instanceConfiguration.value.cpu_only) {
|
||||
delete instanceConfiguration.value.gpu_count
|
||||
}
|
||||
await api.AdminInstancesModify(instanceDetail.value.id, instanceConfiguration.value).then(async (res) => {
|
||||
toast.add({ severity: 'success', summary: '调整配置', detail: '已调整配置', life: 3000 });
|
||||
instanceModifyVisible.value = false
|
||||
|
||||
@@ -125,13 +125,13 @@
|
||||
</Fieldset>
|
||||
<Fieldset legend="GPU">
|
||||
<span v-if="instanceDetail.gpu_count !== 0">{{ instanceDetail.gpu_type }} * {{ instanceDetail.gpu_count
|
||||
}}</span>
|
||||
}}</span>
|
||||
<span v-else>无卡模式</span>
|
||||
</Fieldset>
|
||||
<div class="flex flex-col md:flex-row gap-4">
|
||||
<Fieldset class="flex flex-wrap gap-2 w-full" legend="CPU">
|
||||
<span v-if="instanceDetail.gpu_count !== 0">{{ instanceDetail.cpu_count_per_gpu * instanceDetail.gpu_count
|
||||
}}
|
||||
}}
|
||||
核</span>
|
||||
<span v-else>1 核</span>
|
||||
</Fieldset>
|
||||
@@ -501,6 +501,9 @@ const instanceModify = async () => {
|
||||
setTimeout(() => {
|
||||
getInstances()
|
||||
}, 100);
|
||||
if (instanceConfiguration.value.cpu_only) {
|
||||
delete instanceConfiguration.value.gpu_count
|
||||
}
|
||||
await api.UserInstancesModify(instanceDetail.value.id, instanceConfiguration.value).then(async (res) => {
|
||||
toast.add({ severity: 'success', summary: '调整配置', detail: '已调整配置', life: 3000 });
|
||||
instanceModifyVisible.value = false
|
||||
|
||||
@@ -33,6 +33,10 @@ func modifyHandler(ctx iris.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.CpuOnly {
|
||||
req.GpuCount = nil
|
||||
}
|
||||
|
||||
if req.GpuCount != nil {
|
||||
if *req.GpuCount < 0 {
|
||||
middleware.Error(ctx, middleware.CodeBadRequest, iris.StatusBadRequest)
|
||||
@@ -62,7 +66,17 @@ func modifyHandler(ctx iris.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.CpuOnly == instance.CpuOnly && req.CpuOnly {
|
||||
hasChanges := false
|
||||
if req.CpuOnly != instance.CpuOnly {
|
||||
hasChanges = true
|
||||
}
|
||||
if req.GpuCount != nil && *req.GpuCount != instance.GpuCount {
|
||||
hasChanges = true
|
||||
}
|
||||
if req.VolumeSize != nil && *req.VolumeSize != instance.VolumeSize {
|
||||
hasChanges = true
|
||||
}
|
||||
if !hasChanges {
|
||||
middleware.Error(ctx, middleware.CodeBadRequest, iris.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ func modifyHandler(ctx iris.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.CpuOnly {
|
||||
req.GpuCount = nil
|
||||
}
|
||||
|
||||
if req.GpuCount != nil {
|
||||
if *req.GpuCount < 0 {
|
||||
middleware.Error(ctx, middleware.CodeBadRequest, iris.StatusBadRequest)
|
||||
@@ -68,7 +72,17 @@ func modifyHandler(ctx iris.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.CpuOnly == instance.CpuOnly && req.CpuOnly {
|
||||
hasChanges := false
|
||||
if req.CpuOnly != instance.CpuOnly {
|
||||
hasChanges = true
|
||||
}
|
||||
if req.GpuCount != nil && *req.GpuCount != instance.GpuCount {
|
||||
hasChanges = true
|
||||
}
|
||||
if req.VolumeSize != nil && *req.VolumeSize != instance.VolumeSize {
|
||||
hasChanges = true
|
||||
}
|
||||
if !hasChanges {
|
||||
middleware.Error(ctx, middleware.CodeBadRequest, iris.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -43,9 +43,19 @@ func modify(serverID uint, data Data) (err error) {
|
||||
return errors.New("instance status error")
|
||||
}
|
||||
|
||||
if data.CpuOnly == instance.CpuOnly && data.CpuOnly {
|
||||
lc.Error("instance already cpu_only mode")
|
||||
return errors.New("instance already cpu_only mode")
|
||||
hasChanges := false
|
||||
if data.CpuOnly != instance.CpuOnly {
|
||||
hasChanges = true
|
||||
}
|
||||
if data.GpuCount != nil && *data.GpuCount != instance.GpuCount {
|
||||
hasChanges = true
|
||||
}
|
||||
if data.VolumeSize != nil && *data.VolumeSize != instance.VolumeSize {
|
||||
hasChanges = true
|
||||
}
|
||||
if !hasChanges {
|
||||
lc.Error("no changes")
|
||||
return errors.New("no changes")
|
||||
}
|
||||
|
||||
oldVolumeSize := instance.VolumeSize
|
||||
|
||||
@@ -45,6 +45,15 @@ func patchGpu(ip string, port int, apikey string,
|
||||
Dest: "/root/megrez-tmp",
|
||||
},
|
||||
}
|
||||
data.GpuPatch = &gpuPatchStruct{
|
||||
GpuCount: gpuCount,
|
||||
}
|
||||
data.CpuPatch = &cpuPatchStruct{
|
||||
CpuCount: cpuCountPerGpu * gpuCount,
|
||||
}
|
||||
data.MemoryPatch = &MemoryPatchStruct{
|
||||
Memory: strconv.Itoa(memoryPerGpu*gpuCount) + "GB",
|
||||
}
|
||||
}
|
||||
|
||||
reqBytes, err := json.Marshal(data)
|
||||
|
||||
Reference in New Issue
Block a user