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';
104120import { Rules , checkNumberRange } from ' @/global/form-rules' ;
105121import { canEditPort } from ' @/global/business' ;
106122import { FormInstance , FormRules } from ' element-plus' ;
107- import { reactive , ref } from ' vue' ;
123+ import { onMounted , reactive , ref } from ' vue' ;
108124import { useRouter } from ' vue-router' ;
109125import Params from ' ../params/index.vue' ;
110126import Header from ' @/components/drawer-header/index.vue' ;
@@ -113,6 +129,8 @@ import { javascript } from '@codemirror/lang-javascript';
113129import { oneDark } from ' @codemirror/theme-one-dark' ;
114130import i18n from ' @/lang' ;
115131import { MsgError } from ' @/utils/message' ;
132+ import { Container } from ' @/api/interface/container' ;
133+ import { loadResourceLimit } from ' @/api/modules/container' ;
116134
117135const extensions = [javascript (), oneDark ];
118136const router = useRouter ();
@@ -154,12 +172,25 @@ const initData = () => ({
154172 dockerCompose: ' ' ,
155173});
156174const 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
158181const 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+
163194const 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+
213259defineExpose ({
214260 acceptParams ,
215261});
262+
263+ onMounted (() => {
264+ loadLimit ();
265+ });
216266 </script >
0 commit comments