DNSChallenge.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script setup lang="ts">
  2. import {computed, inject, ref, watch} from 'vue'
  3. import auto_cert from '@/api/auto_cert'
  4. import {useGettext} from 'vue3-gettext'
  5. import {SelectProps} from 'ant-design-vue'
  6. const {$gettext} = useGettext()
  7. const providers: any = ref([])
  8. const data: any = inject('data')!
  9. const code = computed(() => {
  10. return data.code
  11. })
  12. function init() {
  13. providers.value?.forEach((v: any, k: number) => {
  14. if (v.code === code.value) {
  15. provider_idx.value = k
  16. }
  17. })
  18. }
  19. auto_cert.get_dns_providers().then(r => {
  20. providers.value = r
  21. }).then(() => {
  22. init()
  23. })
  24. const provider_idx = ref()
  25. const current: any = computed(() => {
  26. return providers.value?.[provider_idx.value]
  27. })
  28. watch(code, init)
  29. watch(current, () => {
  30. data.code = current.value.code
  31. data.provider = current.value.name
  32. auto_cert.get_dns_provider(current.value.code).then(r => {
  33. Object.assign(current.value, r)
  34. })
  35. })
  36. const options = computed<SelectProps['options']>(() => {
  37. let list: SelectProps['options'] = []
  38. providers.value.forEach((v: any, k: number) => {
  39. list!.push({
  40. value: k,
  41. label: v.name
  42. })
  43. })
  44. return list
  45. })
  46. const filterOption = (input: string, option: any) => {
  47. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
  48. }
  49. </script>
  50. <template>
  51. <a-form layout="vertical">
  52. <a-form-item :label="$gettext('DNS Provider')">
  53. <a-select v-model:value="provider_idx" show-search :options="options" :filter-option="filterOption"/>
  54. </a-form-item>
  55. <template v-if="current?.configuration?.credentials">
  56. <h4>{{ $gettext('Credentials') }}</h4>
  57. <a-form-item :label="k" v-for="(v,k) in current?.configuration?.credentials"
  58. :extra="v" :rules="[{ required: true }]">
  59. <a-input v-model:value="data.configuration.credentials[k]"/>
  60. </a-form-item>
  61. </template>
  62. <template v-if="current?.configuration?.additional">
  63. <h4>{{ $gettext('Additional') }}</h4>
  64. <a-form-item :label="k" v-for="(v,k) in current?.configuration?.additional" :extra="v">
  65. <a-input v-model:value="data.configuration.additional[k]"/>
  66. </a-form-item>
  67. </template>
  68. </a-form>
  69. </template>
  70. <style lang="less" scoped>
  71. </style>