|
225 | 225 | <p class="font-semibold text-md">Nginx</p> |
226 | 226 | </el-radio> |
227 | 227 | <el-radio |
228 | | - v-if="!userStore.isAdmin" |
229 | 228 | class="rounded-md !border-[2px] !h-[120px] flex justify-center" |
230 | 229 | size="large" |
231 | 230 | label="docker" |
232 | | - disabled |
| 231 | + @click="fetchDockerTemplates" |
233 | 232 | border |
234 | 233 | > |
235 | 234 | <SvgIcon |
236 | 235 | name="space_docker" |
237 | 236 | class="m-auto" |
238 | 237 | /> |
239 | 238 | <p class="font-semibold text-md">Docker</p> |
240 | | - <p class="text-xs">11 templates</p> |
| 239 | + <!-- <p class="text-xs">11 templates</p> --> |
241 | 240 | </el-radio> |
242 | 241 | <el-radio |
243 | 242 | disabled |
|
255 | 254 | </el-radio> |
256 | 255 | </el-radio-group> |
257 | 256 | </el-form-item> |
| 257 | + <div v-if="dataForm.sdk === 'docker'"> |
| 258 | + <p class="text-gray-600 mb-1.5 font-light"> |
| 259 | + {{ $t('application_spaces.new.chooseTemplate') }} |
| 260 | + </p> |
| 261 | + |
| 262 | + <el-radio-group |
| 263 | + v-model="dockerTemplate" |
| 264 | + class="flex flex-wrap gap-2 mb-6" |
| 265 | + > |
| 266 | + <el-radio-button v-for="template in dockerTemplates" |
| 267 | + :label="template.name" |
| 268 | + :value="template.name" |
| 269 | + size="large" |
| 270 | + border |
| 271 | + /> |
| 272 | + </el-radio-group> |
| 273 | + |
| 274 | + <div v-if="dockerTemplate" class="mb-6"> |
| 275 | + <div v-if="currentDockerTemplates.secrets"> |
| 276 | + <p class="text-gray-700 text-sm leading-5">{{ t('application_spaces.new.spaceSecrets') }}</p> |
| 277 | + <div |
| 278 | + v-for="secret in JSON.parse(currentDockerTemplates.secrets)" |
| 279 | + :key="secret.name"> |
| 280 | + <div class="flex justify-between items-center my-2 pl-4"> |
| 281 | + <label :for="secret.name" class="text-gray-600 mb-1.5 font-light text-xs w-[40%]">{{ secret.name }}</label> |
| 282 | + <el-input v-model="dockerSecrets[secret.name]" size="small"></el-input> |
| 283 | + </div> |
| 284 | + </div> |
| 285 | + </div> |
| 286 | + |
| 287 | + <div v-if="currentDockerTemplates.variables"> |
| 288 | + <p class="text-gray-700 text-sm leading-5">{{ t('application_spaces.new.spaceVariables') }}</p> |
| 289 | + <div v-for="variable in JSON.parse(currentDockerTemplates.variables)" :key="variable.name"> |
| 290 | + <div class="flex justify-between items-center my-2 pl-4"> |
| 291 | + <label :for="variable.name" class="text-gray-600 mb-1.5 font-light text-xs w-[40%]">{{ variable.name }}</label> |
| 292 | + <el-input v-model="dockerVariables[variable.name]" size="small"></el-input> |
| 293 | + </div> |
| 294 | + </div> |
| 295 | + </div> |
| 296 | + </div> |
| 297 | + </div> |
258 | 298 | <el-form-item |
259 | 299 | :label="t('endpoints.new.cluster')" |
260 | 300 | class="w-full" |
|
332 | 372 | </template> |
333 | 373 |
|
334 | 374 | <script setup> |
335 | | - import { ref, onMounted, inject } from 'vue' |
| 375 | + import { ref, onMounted, inject, computed } from 'vue' |
336 | 376 | import { ElInput, ElMessage } from 'element-plus' |
337 | 377 | import { useI18n } from 'vue-i18n' |
338 | 378 | import useFetchApi from '../../packs/useFetchApi' |
|
349 | 389 | const images = ref([]) |
350 | 390 | const { t } = useI18n() |
351 | 391 | const nameRule = inject('nameRule') |
| 392 | + const dockerTemplates = ref([]) |
| 393 | + const dockerTemplate = ref('') |
| 394 | + const dockerVariables = ref({}) |
| 395 | + const dockerSecrets = ref({}) |
| 396 | +
|
| 397 | + const currentDockerTemplates = computed(() => { |
| 398 | + const currentTemplate = dockerTemplates.value.find((template) => template.name === dockerTemplate.value) |
| 399 | + if (currentTemplate && currentTemplate.variables) { |
| 400 | + dockerVariables.value = JSON.parse(currentTemplate.variables).reduce((accumulator, current) => { |
| 401 | + accumulator[current.name] = current.value |
| 402 | + return accumulator |
| 403 | + }, {}) |
| 404 | + } |
| 405 | + if (currentTemplate && currentTemplate.secrets) { |
| 406 | + dockerSecrets.value = JSON.parse(currentTemplate.secrets).reduce((accumulator, current) => { |
| 407 | + accumulator[current.name] = current.value |
| 408 | + return accumulator |
| 409 | + }, {}) |
| 410 | + } |
| 411 | + return (currentTemplate || {}) |
| 412 | + }) |
352 | 413 |
|
353 | 414 | const dataForm = ref({ |
354 | 415 | owner: '', |
|
511 | 572 | cluster_id: dataForm.value.space_cluster, |
512 | 573 | private: dataForm.value.visibility === 'private' |
513 | 574 | } |
| 575 | +
|
| 576 | + if (dataForm.value.sdk === 'docker') { |
| 577 | + params.template = dockerTemplate.value |
| 578 | + params.variables = JSON.stringify(dockerVariables.value) |
| 579 | + params.secrets = JSON.stringify(dockerSecrets.value) |
| 580 | + } |
| 581 | +
|
514 | 582 | const options = { |
515 | 583 | headers: { 'Content-Type': 'application/json' }, |
516 | 584 | body: JSON.stringify(params) |
|
531 | 599 | } |
532 | 600 | } |
533 | 601 |
|
| 602 | + const fetchDockerTemplates = async () => { |
| 603 | + try { |
| 604 | + const { data, error } = await useFetchApi('space_templates/docker').json() |
| 605 | + if (data.value) { |
| 606 | + dockerTemplates.value = data.value.data |
| 607 | + } else { |
| 608 | + ElMessage.warning(error.value.msg) |
| 609 | + } |
| 610 | + } catch (error) { |
| 611 | + ElMessage.warning(error) |
| 612 | + } |
| 613 | + } |
| 614 | +
|
534 | 615 | onMounted(() => { |
535 | 616 | fetchClusters() |
536 | 617 | }) |
|
0 commit comments