Skip to content

Commit 1f8c6a7

Browse files
feat: 应用创建增加 cpu 和内存最大值提示
1 parent a0ceb62 commit 1f8c6a7

File tree

5 files changed

+76
-30
lines changed

5 files changed

+76
-30
lines changed

backend/app/service/website_ssl.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ func (w WebsiteSSLService) Search(search request.WebsiteSSLSearch) ([]response.W
6666
opts []repo.DBOption
6767
result []response.WebsiteSSLDTO
6868
)
69-
opts = append(opts, commonRepo.WithOrderBy("created_at desc"))
70-
if search.AcmeAccountID >= 0 {
71-
opts = append(opts, websiteSSLRepo.WithByAcmeAccountId(search.AcmeAccountID))
72-
}
69+
opts = append(opts, commonRepo.WithOrderBy("created_at desc"), websiteSSLRepo.WithByAcmeAccountId(search.AcmeAccountID))
7370
sslList, err := websiteSSLRepo.List(opts...)
7471
if err != nil {
7572
return nil, err

frontend/src/lang/modules/en.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,7 @@ const message = {
11751175
containerName: 'Container Name',
11761176
containerNameHelper: 'can be empty, it will be automatically generated',
11771177
allowPort: 'Port external access',
1178-
allowPortHelper:
1179-
'Allowing external port access will release the firewall port, please do not release the php operating environment',
1178+
allowPortHelper: 'Allowing external port access will release the firewall port',
11801179
appInstallWarn:
11811180
'The application does not release the external access port by default, you can choose to release it in the advanced settings',
11821181
upgradeStart: 'Start upgrading! Please refresh the page later',

frontend/src/lang/modules/tw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ const message = {
11161116
containerName: '容器名稱',
11171117
containerNameHelper: '可以為空,為空自動生成',
11181118
allowPort: '端口外部訪問',
1119-
allowPortHelper: '允許端口外部訪問會放開防火墻端口,php運行環境請勿放開',
1119+
allowPortHelper: '允許端口外部訪問會放開防火墻端口',
11201120
appInstallWarn: '應用端口默認不允許外部訪問,可以在下方高級設置中選擇放開',
11211121
upgradeStart: '開始升級!請稍後刷新頁面',
11221122
toFolder: '進入安裝目錄',

frontend/src/lang/modules/zh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ const message = {
11221122
containerName: '容器名称',
11231123
containerNameHelper: '可以为空,为空自动生成',
11241124
allowPort: '端口外部访问',
1125-
allowPortHelper: '允许端口外部访问会放开防火墙端口,php运行环境请勿放开',
1125+
allowPortHelper: '允许端口外部访问会放开防火墙端口',
11261126
appInstallWarn: '应用端口默认不允许外部访问,可以在下方高级设置中选择放开',
11271127
upgradeStart: '开始升级!请稍后刷新页面',
11281128
toFolder: '进入安装目录',
@@ -1133,7 +1133,7 @@ const message = {
11331133
allReadyInstalled: '已安装',
11341134
installHelper: '配置镜像加速可以解决镜像拉取失败的问题',
11351135
upgradeHelper: '异常应用需要先同步到正常状态',
1136-
installWarn: '未开启端口外部访问,无法通过外网IP:端口访问,是否继续?',
1136+
installWarn: '当前未开启端口外部访问,将无法通过外网IP:端口访问,是否继续?',
11371137
restoreWarn: '恢复操作将删除该应用当前数据并重启。此操作不可回滚,是否继续?',
11381138
},
11391139
website: {

frontend/src/views/app-store/detail/install/index.vue

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,39 @@
4141
:placeholder="$t('app.containerNameHelper')"
4242
></el-input>
4343
</el-form-item>
44-
<el-form-item :label="$t('container.cpuQuota')" prop="cpuQuota">
44+
<el-form-item
45+
:label="$t('container.cpuQuota')"
46+
prop="cpuQuota"
47+
:rules="checkNumberRange(0, limits.cpu)"
48+
>
4549
<el-input type="number" style="width: 40%" v-model.number="req.cpuQuota" maxlength="5">
4650
<template #append>{{ $t('app.cpuCore') }}</template>
4751
</el-input>
48-
<span class="input-help">{{ $t('container.limitHelper') }}</span>
52+
<span class="input-help">
53+
{{ $t('container.limitHelper', [limits.cpu]) }}{{ $t('commons.units.core') }}
54+
</span>
4955
</el-form-item>
50-
<el-form-item :label="$t('container.memoryLimit')" prop="memoryLimit">
56+
<el-form-item
57+
:label="$t('container.memoryLimit')"
58+
prop="memoryLimit"
59+
:rules="checkNumberRange(0, limits.memory)"
60+
>
5161
<el-input style="width: 40%" v-model.number="req.memoryLimit" maxlength="10">
5262
<template #append>
53-
<el-select v-model="req.memoryUnit" placeholder="Select" style="width: 85px">
54-
<el-option label="KB" value="K" />
63+
<el-select
64+
v-model="req.memoryUnit"
65+
placeholder="Select"
66+
style="width: 85px"
67+
@change="chnageUnit"
68+
>
5569
<el-option label="MB" value="M" />
5670
<el-option label="GB" value="G" />
5771
</el-select>
5872
</template>
5973
</el-input>
60-
<span class="input-help">{{ $t('container.limitHelper') }}</span>
74+
<span class="input-help">
75+
{{ $t('container.limitHelper', [limits.memory]) }}{{ req.memoryUnit }}B
76+
</span>
6177
</el-form-item>
6278
<el-form-item prop="allowPort" v-if="canEditPort(installData.app)">
6379
<el-checkbox v-model="req.allowPort" :label="$t('app.allowPort')" size="large" />
@@ -104,7 +120,7 @@ import { InstallApp } from '@/api/modules/app';
104120
import { Rules, checkNumberRange } from '@/global/form-rules';
105121
import { canEditPort } from '@/global/business';
106122
import { FormInstance, FormRules } from 'element-plus';
107-
import { reactive, ref } from 'vue';
123+
import { onMounted, reactive, ref } from 'vue';
108124
import { useRouter } from 'vue-router';
109125
import Params from '../params/index.vue';
110126
import Header from '@/components/drawer-header/index.vue';
@@ -113,6 +129,8 @@ import { javascript } from '@codemirror/lang-javascript';
113129
import { oneDark } from '@codemirror/theme-one-dark';
114130
import i18n from '@/lang';
115131
import { MsgError } from '@/utils/message';
132+
import { Container } from '@/api/interface/container';
133+
import { loadResourceLimit } from '@/api/modules/container';
116134
117135
const extensions = [javascript(), oneDark];
118136
const router = useRouter();
@@ -154,12 +172,25 @@ const initData = () => ({
154172
dockerCompose: '',
155173
});
156174
const req = reactive(initData());
175+
const limits = ref<Container.ResourceLimit>({
176+
cpu: null as number,
177+
memory: null as number,
178+
});
179+
const oldMemory = ref<number>(0);
157180
158181
const handleClose = () => {
159182
open.value = false;
160183
resetForm();
161184
};
162185
186+
const chnageUnit = () => {
187+
if (req.memoryUnit == 'M') {
188+
limits.value.memory = oldMemory.value;
189+
} else {
190+
limits.value.memory = oldMemory.value / 1024;
191+
}
192+
};
193+
163194
const resetForm = () => {
164195
if (paramForm.value) {
165196
paramForm.value.clearValidate();
@@ -193,24 +224,43 @@ const submit = async (formEl: FormInstance | undefined) => {
193224
if (req.memoryLimit < 0) {
194225
req.memoryLimit = 0;
195226
}
196-
ElMessageBox.confirm(i18n.global.t('app.installWarn'), i18n.global.t('app.checkTitle'), {
197-
confirmButtonText: i18n.global.t('commons.button.confirm'),
198-
cancelButtonText: i18n.global.t('commons.button.cancel'),
199-
}).then(async () => {
200-
loading.value = true;
201-
InstallApp(req)
202-
.then(() => {
203-
handleClose();
204-
router.push({ path: '/apps/installed' });
205-
})
206-
.finally(() => {
207-
loading.value = false;
208-
});
209-
});
227+
if (req.advanced && !req.allowPort) {
228+
ElMessageBox.confirm(i18n.global.t('app.installWarn'), i18n.global.t('app.checkTitle'), {
229+
confirmButtonText: i18n.global.t('commons.button.confirm'),
230+
cancelButtonText: i18n.global.t('commons.button.cancel'),
231+
}).then(async () => {
232+
install();
233+
});
234+
} else {
235+
install();
236+
}
210237
});
211238
};
212239
240+
const install = () => {
241+
loading.value = true;
242+
InstallApp(req)
243+
.then(() => {
244+
handleClose();
245+
router.push({ path: '/apps/installed' });
246+
})
247+
.finally(() => {
248+
loading.value = false;
249+
});
250+
};
251+
252+
const loadLimit = async () => {
253+
const res = await loadResourceLimit();
254+
limits.value = res.data;
255+
limits.value.memory = Number((limits.value.memory / 1024 / 1024).toFixed(2));
256+
oldMemory.value = limits.value.memory;
257+
};
258+
213259
defineExpose({
214260
acceptParams,
215261
});
262+
263+
onMounted(() => {
264+
loadLimit();
265+
});
216266
</script>

0 commit comments

Comments
 (0)