DNSChallenge.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <script setup lang="ts">
  2. import type { SelectProps } from 'ant-design-vue'
  3. import type { Ref } from 'vue'
  4. import type { DNSProvider } from '@/api/auto_cert'
  5. import auto_cert from '@/api/auto_cert'
  6. const providers = ref([]) as Ref<DNSProvider[]>
  7. // This data is provided by the Top StdCurd component,
  8. // is the object that you are trying to modify it
  9. const data = inject('data') as DNSProvider
  10. const code = computed(() => {
  11. return data.code
  12. })
  13. const provider_idx = ref()
  14. function init() {
  15. if (!data.configuration) {
  16. data.configuration = {
  17. credentials: {},
  18. additional: {},
  19. }
  20. }
  21. providers.value?.forEach((v: { code?: string }, k: number) => {
  22. if (v?.code === code.value)
  23. provider_idx.value = k
  24. })
  25. }
  26. auto_cert.get_dns_providers().then(r => {
  27. providers.value = r
  28. }).then(() => {
  29. init()
  30. })
  31. const current = computed(() => {
  32. return providers.value?.[provider_idx.value]
  33. })
  34. watch(code, init)
  35. watch(current, () => {
  36. data.code = current.value.code
  37. data.provider = current.value.name
  38. auto_cert.get_dns_provider(current.value.code!).then(r => {
  39. Object.assign(current.value, r)
  40. })
  41. })
  42. const options = computed<SelectProps['options']>(() => {
  43. const list: SelectProps['options'] = []
  44. providers.value.forEach((v: DNSProvider, k: number) => {
  45. list!.push({
  46. value: k,
  47. label: v.name,
  48. })
  49. })
  50. return list
  51. })
  52. const filterOption = (input: string, option: { label: string }) => {
  53. return option.label.toLowerCase().includes(input.toLowerCase())
  54. }
  55. </script>
  56. <template>
  57. <AForm layout="vertical">
  58. <AFormItem :label="$gettext('DNS Provider')">
  59. <ASelect
  60. v-model:value="provider_idx"
  61. show-search
  62. :options="options"
  63. :filter-option="filterOption"
  64. />
  65. </AFormItem>
  66. <AFormItem>
  67. <p v-if="current?.links?.api">
  68. {{ $gettext('API Document') }}: <a
  69. :href="current.links.api"
  70. target="_blank"
  71. rel="noopener noreferrer"
  72. >{{ current.links.api }}</a>
  73. </p>
  74. <p v-if="current?.links?.go_client">
  75. {{ $gettext('SDK') }}: <a
  76. :href="current.links.go_client"
  77. target="_blank"
  78. rel="noopener noreferrer"
  79. >{{ current.links.go_client }}</a>
  80. </p>
  81. </AFormItem>
  82. <template v-if="current?.configuration?.credentials">
  83. <h4>{{ $gettext('Credentials') }}</h4>
  84. <AFormItem
  85. v-for="(v, k) in current?.configuration?.credentials"
  86. :key="k"
  87. :label="k"
  88. :extra="v"
  89. >
  90. <AInput v-model:value="data.configuration.credentials[k]" />
  91. </AFormItem>
  92. </template>
  93. <template v-if="current?.configuration?.additional">
  94. <h4>{{ $gettext('Additional') }}</h4>
  95. <AFormItem
  96. v-for="(v, k) in current?.configuration?.additional"
  97. :key="k"
  98. :label="k"
  99. :extra="v"
  100. >
  101. <AInput v-model:value="data.configuration.additional[k]" />
  102. </AFormItem>
  103. </template>
  104. </AForm>
  105. </template>
  106. <style lang="less" scoped>
  107. </style>