ConfigName.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <script setup lang="ts">
  2. import config from '@/api/config'
  3. import use2FAModal from '@/components/TwoFA/use2FAModal'
  4. const name = defineModel<string>('name', { default: '' })
  5. const route = useRoute()
  6. const router = useRouter()
  7. const { message } = useGlobalApp()
  8. const modify = ref(false)
  9. const buffer = ref('')
  10. const loading = ref(false)
  11. function clickModify() {
  12. buffer.value = name.value
  13. modify.value = true
  14. }
  15. const { open: openOtpModal } = use2FAModal()
  16. function save() {
  17. loading.value = true
  18. openOtpModal().then(() => {
  19. config.rename(route.query.basePath as string, name.value, buffer.value).then(() => {
  20. modify.value = false
  21. message.success($gettext('Renamed successfully'))
  22. router.push({
  23. path: `/config/${encodeURIComponent(buffer.value)}/edit`,
  24. query: {
  25. basePath: encodeURIComponent(route.query.basePath as string),
  26. },
  27. })
  28. }).finally(() => {
  29. loading.value = false
  30. })
  31. })
  32. }
  33. </script>
  34. <template>
  35. <div>
  36. <div v-if="!modify" class="flex items-center">
  37. <div class="mr-2">
  38. {{ name }}
  39. </div>
  40. <div>
  41. <AButton type="link" size="small" @click="clickModify">
  42. {{ $gettext('Rename') }}
  43. </AButton>
  44. </div>
  45. </div>
  46. <div v-else>
  47. <AInput v-model:value="buffer">
  48. <template #suffix>
  49. <AButton :disabled="buffer === name" type="link" size="small" :loading @click="save">
  50. {{ $gettext('Save') }}
  51. </AButton>
  52. </template>
  53. </AInput>
  54. </div>
  55. </div>
  56. </template>
  57. <style scoped lang="less">
  58. </style>