ConfigEdit.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script setup lang="ts">
  2. import FooterToolBar from '@/components/FooterToolbar/FooterToolBar.vue'
  3. import gettext from '@/gettext'
  4. import {useRoute} from 'vue-router'
  5. import {computed, ref} from 'vue'
  6. import config from '@/api/config'
  7. import {message} from 'ant-design-vue'
  8. import CodeEditor from '@/components/CodeEditor/CodeEditor.vue'
  9. const {$gettext, interpolate} = gettext
  10. const route = useRoute()
  11. const name = computed(() => {
  12. const n = route.params.name
  13. if (typeof n === 'string') {
  14. return n
  15. }
  16. return n?.join('/')
  17. })
  18. const configText = ref('')
  19. function init() {
  20. if (name.value) {
  21. config.get(name.value).then(r => {
  22. configText.value = r.config
  23. }).catch(r => {
  24. message.error(r.message ?? $gettext('Server error'))
  25. })
  26. } else {
  27. configText.value = ''
  28. }
  29. }
  30. init()
  31. function save() {
  32. config.save(name.value, {content: configText.value}).then(r => {
  33. configText.value = r.config
  34. message.success($gettext('Saved successfully'))
  35. }).catch(r => {
  36. message.error(interpolate($gettext('Save error %{msg}'), {msg: r.message ?? ''}))
  37. })
  38. }
  39. </script>
  40. <template>
  41. <a-card :title="$gettext('Edit Configuration')">
  42. <code-editor v-model:content="configText"/>
  43. <footer-tool-bar>
  44. <a-space>
  45. <a-button @click="$router.go(-1)">
  46. <translate>Back</translate>
  47. </a-button>
  48. <a-button type="primary" @click="save">
  49. <translate>Save</translate>
  50. </a-button>
  51. </a-space>
  52. </footer-tool-bar>
  53. </a-card>
  54. </template>
  55. <style lang="less" scoped>
  56. .ant-card {
  57. margin: 10px;
  58. @media (max-width: 512px) {
  59. margin: 10px 0;
  60. }
  61. }
  62. </style>