mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +08:00
feat: Swap 修改增加最大值限制 (#3175)
This commit is contained in:
parent
282c58ca86
commit
30c577dbaf
@ -12,6 +12,7 @@ type DeviceBaseInfo struct {
|
|||||||
SwapMemoryTotal uint64 `json:"swapMemoryTotal"`
|
SwapMemoryTotal uint64 `json:"swapMemoryTotal"`
|
||||||
SwapMemoryAvailable uint64 `json:"swapMemoryAvailable"`
|
SwapMemoryAvailable uint64 `json:"swapMemoryAvailable"`
|
||||||
SwapMemoryUsed uint64 `json:"swapMemoryUsed"`
|
SwapMemoryUsed uint64 `json:"swapMemoryUsed"`
|
||||||
|
MaxSize uint64 `json:"maxSize"`
|
||||||
|
|
||||||
SwapDetails []SwapHelper `json:"swapDetails"`
|
SwapDetails []SwapHelper `json:"swapDetails"`
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,10 @@ func (u *DeviceService) LoadBaseInfo() (dto.DeviceBaseInfo, error) {
|
|||||||
if baseInfo.SwapMemoryTotal != 0 {
|
if baseInfo.SwapMemoryTotal != 0 {
|
||||||
baseInfo.SwapDetails = loadSwap()
|
baseInfo.SwapDetails = loadSwap()
|
||||||
}
|
}
|
||||||
|
disks := loadDiskInfo()
|
||||||
|
for _, item := range disks {
|
||||||
|
baseInfo.MaxSize += item.Free
|
||||||
|
}
|
||||||
|
|
||||||
return baseInfo, nil
|
return baseInfo, nil
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ export namespace Toolbox {
|
|||||||
swapMemoryTotal: number;
|
swapMemoryTotal: number;
|
||||||
swapMemoryAvailable: number;
|
swapMemoryAvailable: number;
|
||||||
swapMemoryUsed: number;
|
swapMemoryUsed: number;
|
||||||
|
maxSize: number;
|
||||||
|
|
||||||
swapDetails: Array<SwapHelper>;
|
swapDetails: Array<SwapHelper>;
|
||||||
}
|
}
|
||||||
|
@ -910,7 +910,8 @@ const message = {
|
|||||||
saveHelper: 'Please save the current settings first!',
|
saveHelper: 'Please save the current settings first!',
|
||||||
saveSwap:
|
saveSwap:
|
||||||
'Saving the current configuration will adjust the Swap partition {0} size to {1}. Do you want to continue?',
|
'Saving the current configuration will adjust the Swap partition {0} size to {1}. Do you want to continue?',
|
||||||
saveSwapHelper: 'The minimum partition size is 40 KB. Please modify and try again!',
|
swapMin: 'The minimum partition size is 40 KB. Please modify and try again!',
|
||||||
|
swapMax: 'The maximum value for partition size is {0}. Please modify and try again!',
|
||||||
swapOff: 'The minimum partition size is 40 KB. Setting it to 0 will disable the Swap partition.',
|
swapOff: 'The minimum partition size is 40 KB. Setting it to 0 will disable the Swap partition.',
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
|
@ -866,7 +866,8 @@ const message = {
|
|||||||
swapDeleteHelper: '此操作將移除 Swap 分區 {0},出於系統安全考慮,不會自動刪除該文件,如需刪除請手動操作!',
|
swapDeleteHelper: '此操作將移除 Swap 分區 {0},出於系統安全考慮,不會自動刪除該文件,如需刪除請手動操作!',
|
||||||
saveHelper: '請先保存當前設置!',
|
saveHelper: '請先保存當前設置!',
|
||||||
saveSwap: '儲存當前配置將調整 Swap 分區 {0} 大小到 {1},是否繼續?',
|
saveSwap: '儲存當前配置將調整 Swap 分區 {0} 大小到 {1},是否繼續?',
|
||||||
saveSwapHelper: '分區大小最小值為 40 KB,請修改後重試!',
|
swapMin: '分區大小最小值為 40 KB,請修改後重試!',
|
||||||
|
swapMax: '分區大小最大值為 {0},請修改後重試!',
|
||||||
swapOff: '分區大小最小值為 40 KB,設置為 0 則關閉 Swap 分區。',
|
swapOff: '分區大小最小值為 40 KB,設置為 0 則關閉 Swap 分區。',
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
|
@ -867,7 +867,8 @@ const message = {
|
|||||||
swapDeleteHelper: '此操作将移除 Swap 分区 {0},出于系统安全考虑,不会自动删除该文件,如需删除请手动操作!',
|
swapDeleteHelper: '此操作将移除 Swap 分区 {0},出于系统安全考虑,不会自动删除该文件,如需删除请手动操作!',
|
||||||
saveHelper: '请先保存当前设置!',
|
saveHelper: '请先保存当前设置!',
|
||||||
saveSwap: '保存当前配置将调整 Swap 分区 {0} 大小到 {1},是否继续?',
|
saveSwap: '保存当前配置将调整 Swap 分区 {0} 大小到 {1},是否继续?',
|
||||||
saveSwapHelper: '分区大小最小值为 40 KB,请修改后重试!',
|
swapMin: '分区大小最小值为 40 KB,请修改后重试!',
|
||||||
|
swapMax: '分区大小最大值为 {0},请修改后重试!',
|
||||||
swapOff: '分区大小最小值为 40 KB,设置成 0 则关闭 Swap 分区。',
|
swapOff: '分区大小最小值为 40 KB,设置成 0 则关闭 Swap 分区。',
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
|
@ -120,12 +120,6 @@ const handleHostsDelete = (index: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSave = async () => {
|
const onSave = async () => {
|
||||||
for (const item of form.hosts) {
|
|
||||||
if (item.ip === '' || item.host === '') {
|
|
||||||
MsgError(i18n.global.t('toolbox.device.hostHelper'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
if (confShowType.value === 'base') {
|
if (confShowType.value === 'base') {
|
||||||
await updateDeviceHost(form.hosts)
|
await updateDeviceHost(form.hosts)
|
||||||
@ -140,6 +134,12 @@ const onSave = async () => {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
for (const item of form.hosts) {
|
||||||
|
if (item.ip === '' || item.host === '') {
|
||||||
|
MsgError(i18n.global.t('toolbox.device.hostHelper'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
await updateDeviceByConf('Hosts', hostsConf.value)
|
await updateDeviceByConf('Hosts', hostsConf.value)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('file.size')" min-width="150">
|
<el-table-column :label="$t('file.size')" min-width="150">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-input placeholder="1024" v-model.number="row.size">
|
<el-input placeholder="1024" type="number" v-model.number="row.size">
|
||||||
<template #append>
|
<template #append>
|
||||||
<el-select v-model="row.sizeUnit" style="width: 85px">
|
<el-select v-model="row.sizeUnit" style="width: 85px">
|
||||||
<el-option label="KB" value="KB" />
|
<el-option label="KB" value="KB" />
|
||||||
@ -101,10 +101,10 @@ import { computeSize, splitSize } from '@/utils/util';
|
|||||||
import { loadBaseDir } from '@/api/modules/setting';
|
import { loadBaseDir } from '@/api/modules/setting';
|
||||||
|
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
swapItem: '',
|
|
||||||
swapMemoryTotal: '',
|
swapMemoryTotal: '',
|
||||||
swapMemoryAvailable: '',
|
swapMemoryAvailable: '',
|
||||||
swapMemoryUsed: '',
|
swapMemoryUsed: '',
|
||||||
|
maxSize: 0,
|
||||||
|
|
||||||
swapDetails: [],
|
swapDetails: [],
|
||||||
});
|
});
|
||||||
@ -124,6 +124,7 @@ const search = async () => {
|
|||||||
form.swapMemoryUsed = computeSize(res.data.swapMemoryUsed);
|
form.swapMemoryUsed = computeSize(res.data.swapMemoryUsed);
|
||||||
form.swapMemoryAvailable = computeSize(res.data.swapMemoryAvailable);
|
form.swapMemoryAvailable = computeSize(res.data.swapMemoryAvailable);
|
||||||
form.swapDetails = res.data.swapDetails || [];
|
form.swapDetails = res.data.swapDetails || [];
|
||||||
|
form.maxSize = res.data.maxSize;
|
||||||
|
|
||||||
await loadBaseDir()
|
await loadBaseDir()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@ -158,8 +159,17 @@ const loadData = (path: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSave = async (row) => {
|
const onSave = async (row) => {
|
||||||
if (row.sizeUnit === 'KB' && row.size < 40 && row.size !== 0) {
|
if (row.size === '') {
|
||||||
MsgError(i18n.global.t('toolbox.swap.saveSwapHelper'));
|
MsgError(i18n.global.t('commons.msg.confirmNoNull', ['Swap ' + i18n.global.t('file.size')]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const itemSize = loadItemSize(row);
|
||||||
|
if (itemSize < 40 && row.size !== 0) {
|
||||||
|
MsgError(i18n.global.t('toolbox.swap.swapMin'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (itemSize * 1024 > form.maxSize) {
|
||||||
|
MsgError(i18n.global.t('toolbox.swap.swapMax', [computeSize(form.maxSize)]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ElMessageBox.confirm(
|
ElMessageBox.confirm(
|
||||||
@ -173,7 +183,7 @@ const onSave = async (row) => {
|
|||||||
).then(async () => {
|
).then(async () => {
|
||||||
let params = {
|
let params = {
|
||||||
path: row.path,
|
path: row.path,
|
||||||
size: row.size * 1024,
|
size: itemSize,
|
||||||
used: '0',
|
used: '0',
|
||||||
|
|
||||||
isNew: row.isNew,
|
isNew: row.isNew,
|
||||||
@ -191,6 +201,17 @@ const onSave = async (row) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadItemSize = (row: any) => {
|
||||||
|
switch (row.sizeUnit) {
|
||||||
|
case 'KB':
|
||||||
|
return row.size;
|
||||||
|
case 'MB':
|
||||||
|
return row.size * 1024;
|
||||||
|
case 'GB':
|
||||||
|
return row.size * 1024 * 1024;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
drawerVisible.value = false;
|
drawerVisible.value = false;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user