IssueCert.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script setup lang="ts">
  2. import {useGettext} from 'vue3-gettext'
  3. import {computed, nextTick, provide, ref, watch} from 'vue'
  4. import ObtainCert from '@/views/domain/cert/components/ObtainCert.vue'
  5. const {$gettext, interpolate} = useGettext()
  6. const props = defineProps(['config_name', 'directivesMap', 'current_server_directives',
  7. 'enabled', 'ngx_config'])
  8. const emit = defineEmits(['callback', 'update:enabled'])
  9. const issuing_cert = ref(false)
  10. const obtain_cert: any = ref()
  11. const enabled = computed({
  12. get() {
  13. return props.enabled
  14. },
  15. set(value) {
  16. emit('update:enabled', value)
  17. }
  18. })
  19. const no_server_name = computed(() => {
  20. if (props.directivesMap['server_name'] === undefined) {
  21. return true
  22. }
  23. return props.directivesMap['server_name'].length === 0
  24. })
  25. provide('no_server_name', no_server_name)
  26. provide('props', props)
  27. provide('issuing_cert', issuing_cert)
  28. watch(no_server_name, () => emit('update:enabled', false))
  29. const update = ref(0)
  30. async function onchange() {
  31. update.value++
  32. await nextTick(() => {
  33. obtain_cert.value.toggle(enabled.value)
  34. })
  35. }
  36. </script>
  37. <template>
  38. <obtain-cert ref="obtain_cert" :key="update"/>
  39. <div class="issue-cert">
  40. <a-form-item :label="$gettext('Encrypt website with Let\'s Encrypt')">
  41. <a-switch
  42. :loading="issuing_cert"
  43. :checked="enabled"
  44. :disabled="no_server_name"
  45. @change="onchange"
  46. />
  47. </a-form-item>
  48. </div>
  49. </template>
  50. <style lang="less">
  51. .issue-cert-log-container {
  52. height: 320px;
  53. overflow: scroll;
  54. background-color: #f3f3f3;
  55. border-radius: 4px;
  56. margin-top: 15px;
  57. padding: 10px;
  58. p {
  59. font-size: 12px;
  60. line-height: 1.3;
  61. }
  62. }
  63. </style>
  64. <style lang="less" scoped>
  65. .ant-tag {
  66. margin: 0;
  67. }
  68. .issue-cert {
  69. margin: 15px 0;
  70. }
  71. .switch-wrapper {
  72. position: relative;
  73. .text {
  74. position: absolute;
  75. top: 50%;
  76. transform: translateY(-50%);
  77. margin-left: 10px;
  78. }
  79. }
  80. </style>