ConfigEdit.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <a-card :title="$gettext('Edit Configuration')">
  3. <vue-itextarea v-model="configText"/>
  4. <footer-tool-bar>
  5. <a-space>
  6. <a-button @click="$router.go(-1)"><translate>Cancel</translate></a-button>
  7. <a-button type="primary" @click="save"><translate>Save</translate></a-button>
  8. </a-space>
  9. </footer-tool-bar>
  10. </a-card>
  11. </template>
  12. <script>
  13. import FooterToolBar from '@/components/FooterToolbar/FooterToolBar'
  14. import VueItextarea from '@/components/VueItextarea/VueItextarea'
  15. import {$gettext, $interpolate} from "@/lib/translate/gettext"
  16. export default {
  17. name: 'DomainEdit',
  18. components: {FooterToolBar, VueItextarea},
  19. data() {
  20. return {
  21. name: this.$route.params.name,
  22. configText: ''
  23. }
  24. },
  25. watch: {
  26. '$route'() {
  27. this.init()
  28. },
  29. config: {
  30. handler() {
  31. this.unparse()
  32. },
  33. deep: true
  34. }
  35. },
  36. created() {
  37. this.init()
  38. },
  39. methods: {
  40. init() {
  41. if (this.name) {
  42. this.$api.config.get(this.name).then(r => {
  43. this.configText = r.config
  44. }).catch(r => {
  45. console.log(r)
  46. this.$message.error($gettext('Server error'))
  47. })
  48. } else {
  49. this.configText = ''
  50. }
  51. },
  52. save() {
  53. this.$api.config.save(this.name ? this.name : this.config.name, {content: this.configText}).then(r => {
  54. this.configText = r.config
  55. this.$message.success($gettext('Saved successfully'))
  56. }).catch(r => {
  57. console.log(r)
  58. this.$message.error($interpolate($gettext('Save error %{msg}'), {msg: r.message ?? ""}))
  59. })
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="less" scoped>
  65. .ant-card {
  66. margin: 10px;
  67. @media (max-width: 512px) {
  68. margin: 10px 0;
  69. }
  70. }
  71. </style>