DNSChallenge.vue 2.4 KB

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