ConfigEdit.vue 2.1 KB

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