Deploy.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <script setup lang="ts">
  2. import { InfoCircleOutlined } from '@ant-design/icons-vue'
  3. import { Modal, notification } from 'ant-design-vue'
  4. import type { Ref } from 'vue'
  5. import domain from '@/api/domain'
  6. import NodeSelector from '@/components/NodeSelector/NodeSelector.vue'
  7. const node_map = ref({})
  8. const target = ref([])
  9. const overwrite = ref(false)
  10. const enabled = ref(false)
  11. const name = inject('name') as Ref<string>
  12. const [modal, ContextHolder] = Modal.useModal()
  13. function deploy() {
  14. modal.confirm({
  15. title: () => $ngettext('Do you want to deploy this file to remote server?',
  16. 'Do you want to deploy this file to remote servers?', target.value.length),
  17. mask: false,
  18. centered: true,
  19. okText: $gettext('OK'),
  20. cancelText: $gettext('Cancel'),
  21. onOk() {
  22. target.value.forEach(id => {
  23. const node_name = node_map.value[id]
  24. // get source content
  25. domain.get(name.value).then(r => {
  26. domain.save(name.value, {
  27. name: name.value,
  28. content: r.config,
  29. overwrite: overwrite.value,
  30. }, { headers: { 'X-Node-ID': id } }).then(async () => {
  31. notification.success({
  32. message: $gettext('Deploy successfully'),
  33. description:
  34. $gettext('Deploy %{conf_name} to %{node_name} successfully',
  35. { conf_name: name.value, node_name }),
  36. })
  37. if (enabled.value) {
  38. domain.enable(name.value, { headers: { 'X-Node-ID': id } }).then(() => {
  39. notification.success({
  40. message: $gettext('Enable successfully'),
  41. description:
  42. $gettext('Enable %{conf_name} in %{node_name} successfully',
  43. { conf_name: name.value, node_name }),
  44. })
  45. }).catch(e => {
  46. notification.error({
  47. message: $gettext('Enable %{conf_name} in %{node_name} failed', {
  48. conf_name: name.value,
  49. node_name,
  50. }),
  51. description: $gettext(e?.message ?? 'Server error'),
  52. })
  53. })
  54. }
  55. }).catch(e => {
  56. notification.error({
  57. message: $gettext('Deploy %{conf_name} to %{node_name} failed', {
  58. conf_name: name.value,
  59. node_name,
  60. }),
  61. description: $gettext(e?.message ?? 'Server error'),
  62. })
  63. })
  64. })
  65. })
  66. },
  67. })
  68. }
  69. </script>
  70. <template>
  71. <div>
  72. <ContextHolder />
  73. <NodeSelector
  74. v-model:target="target"
  75. v-model:map="node_map"
  76. hidden-local
  77. />
  78. <div class="node-deploy-control">
  79. <ACheckbox v-model:checked="enabled">
  80. {{ $gettext('Enable') }}
  81. </ACheckbox>
  82. <div class="overwrite">
  83. <ACheckbox v-model:checked="overwrite">
  84. {{ $gettext('Overwrite') }}
  85. </ACheckbox>
  86. <ATooltip placement="bottom">
  87. <template #title>
  88. {{ $gettext('Overwrite exist file') }}
  89. </template>
  90. <InfoCircleOutlined />
  91. </ATooltip>
  92. </div>
  93. <AButton
  94. :disabled="target.length === 0"
  95. type="primary"
  96. ghost
  97. @click="deploy"
  98. >
  99. {{ $gettext('Deploy') }}
  100. </AButton>
  101. </div>
  102. </div>
  103. </template>
  104. <style scoped lang="less">
  105. .overwrite {
  106. margin-right: 15px;
  107. span {
  108. color: #9b9b9b;
  109. }
  110. }
  111. .node-deploy-control {
  112. display: flex;
  113. justify-content: flex-end;
  114. margin-top: 10px;
  115. align-items: center;
  116. }
  117. </style>