mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +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"`
|
||||
SwapMemoryAvailable uint64 `json:"swapMemoryAvailable"`
|
||||
SwapMemoryUsed uint64 `json:"swapMemoryUsed"`
|
||||
MaxSize uint64 `json:"maxSize"`
|
||||
|
||||
SwapDetails []SwapHelper `json:"swapDetails"`
|
||||
}
|
||||
|
@ -59,6 +59,10 @@ func (u *DeviceService) LoadBaseInfo() (dto.DeviceBaseInfo, error) {
|
||||
if baseInfo.SwapMemoryTotal != 0 {
|
||||
baseInfo.SwapDetails = loadSwap()
|
||||
}
|
||||
disks := loadDiskInfo()
|
||||
for _, item := range disks {
|
||||
baseInfo.MaxSize += item.Free
|
||||
}
|
||||
|
||||
return baseInfo, nil
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ export namespace Toolbox {
|
||||
swapMemoryTotal: number;
|
||||
swapMemoryAvailable: number;
|
||||
swapMemoryUsed: number;
|
||||
maxSize: number;
|
||||
|
||||
swapDetails: Array<SwapHelper>;
|
||||
}
|
||||
|
@ -910,7 +910,8 @@ const message = {
|
||||
saveHelper: 'Please save the current settings first!',
|
||||
saveSwap:
|
||||
'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.',
|
||||
},
|
||||
device: {
|
||||
|
@ -866,7 +866,8 @@ const message = {
|
||||
swapDeleteHelper: '此操作將移除 Swap 分區 {0},出於系統安全考慮,不會自動刪除該文件,如需刪除請手動操作!',
|
||||
saveHelper: '請先保存當前設置!',
|
||||
saveSwap: '儲存當前配置將調整 Swap 分區 {0} 大小到 {1},是否繼續?',
|
||||
saveSwapHelper: '分區大小最小值為 40 KB,請修改後重試!',
|
||||
swapMin: '分區大小最小值為 40 KB,請修改後重試!',
|
||||
swapMax: '分區大小最大值為 {0},請修改後重試!',
|
||||
swapOff: '分區大小最小值為 40 KB,設置為 0 則關閉 Swap 分區。',
|
||||
},
|
||||
device: {
|
||||
|
@ -867,7 +867,8 @@ const message = {
|
||||
swapDeleteHelper: '此操作将移除 Swap 分区 {0},出于系统安全考虑,不会自动删除该文件,如需删除请手动操作!',
|
||||
saveHelper: '请先保存当前设置!',
|
||||
saveSwap: '保存当前配置将调整 Swap 分区 {0} 大小到 {1},是否继续?',
|
||||
saveSwapHelper: '分区大小最小值为 40 KB,请修改后重试!',
|
||||
swapMin: '分区大小最小值为 40 KB,请修改后重试!',
|
||||
swapMax: '分区大小最大值为 {0},请修改后重试!',
|
||||
swapOff: '分区大小最小值为 40 KB,设置成 0 则关闭 Swap 分区。',
|
||||
},
|
||||
device: {
|
||||
|
@ -120,12 +120,6 @@ const handleHostsDelete = (index: number) => {
|
||||
};
|
||||
|
||||
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;
|
||||
if (confShowType.value === 'base') {
|
||||
await updateDeviceHost(form.hosts)
|
||||
@ -140,6 +134,12 @@ const onSave = async () => {
|
||||
});
|
||||
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)
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
|
@ -56,7 +56,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('file.size')" min-width="150">
|
||||
<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>
|
||||
<el-select v-model="row.sizeUnit" style="width: 85px">
|
||||
<el-option label="KB" value="KB" />
|
||||
@ -101,10 +101,10 @@ import { computeSize, splitSize } from '@/utils/util';
|
||||
import { loadBaseDir } from '@/api/modules/setting';
|
||||
|
||||
const form = reactive({
|
||||
swapItem: '',
|
||||
swapMemoryTotal: '',
|
||||
swapMemoryAvailable: '',
|
||||
swapMemoryUsed: '',
|
||||
maxSize: 0,
|
||||
|
||||
swapDetails: [],
|
||||
});
|
||||
@ -124,6 +124,7 @@ const search = async () => {
|
||||
form.swapMemoryUsed = computeSize(res.data.swapMemoryUsed);
|
||||
form.swapMemoryAvailable = computeSize(res.data.swapMemoryAvailable);
|
||||
form.swapDetails = res.data.swapDetails || [];
|
||||
form.maxSize = res.data.maxSize;
|
||||
|
||||
await loadBaseDir()
|
||||
.then((res) => {
|
||||
@ -158,8 +159,17 @@ const loadData = (path: string) => {
|
||||
};
|
||||
|
||||
const onSave = async (row) => {
|
||||
if (row.sizeUnit === 'KB' && row.size < 40 && row.size !== 0) {
|
||||
MsgError(i18n.global.t('toolbox.swap.saveSwapHelper'));
|
||||
if (row.size === '') {
|
||||
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;
|
||||
}
|
||||
ElMessageBox.confirm(
|
||||
@ -173,7 +183,7 @@ const onSave = async (row) => {
|
||||
).then(async () => {
|
||||
let params = {
|
||||
path: row.path,
|
||||
size: row.size * 1024,
|
||||
size: itemSize,
|
||||
used: '0',
|
||||
|
||||
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 = () => {
|
||||
drawerVisible.value = false;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user