LocationEditor.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script setup lang="ts">
  2. import CodeEditor from '@/components/CodeEditor'
  3. import {useGettext} from 'vue3-gettext'
  4. import {reactive} from 'vue'
  5. const {$gettext} = useGettext()
  6. const {locations} = defineProps<{
  7. locations?: any[]
  8. }>()
  9. let location = reactive({})
  10. function add() {
  11. adding.value = true
  12. location = reactive({})
  13. }
  14. function save() {
  15. this.adding = false
  16. if (this.locations) {
  17. this.locations.push(this.location)
  18. } else {
  19. this.locations = [this.location]
  20. }
  21. }
  22. function remove(index) {
  23. this.locations.splice(index, 1)
  24. }
  25. </script>
  26. <template>
  27. <h2 v-translate>Locations</h2>
  28. <a-empty v-if="!locations"/>
  29. <a-card v-for="(v,k) in locations" :key="k"
  30. :title="$gettext('Location')" size="small">
  31. <a-form-item :label="$gettext('Comments')" v-if="v.comments">
  32. <p style="white-space: pre-wrap;">{{ v.comments }}</p>
  33. </a-form-item>
  34. <a-form-item :label="$gettext('Path')">
  35. <a-input addon-before="location" v-model="v.path"/>
  36. </a-form-item>
  37. <a-form-item :label="$gettext('Content')">
  38. <code-editor v-model:content="v.content" default-height="200px"/>
  39. </a-form-item>
  40. </a-card>
  41. <a-modal :title="$gettext('Add Location')" v-model:visible="adding" @ok="save">
  42. <a-form-item :label="$gettext('Comments')">
  43. <a-textarea v-model="location.comments"></a-textarea>
  44. </a-form-item>
  45. <a-form-item :label="$gettext('Path')">
  46. <a-input addon-before="location" v-model="location.path"/>
  47. </a-form-item>
  48. <a-form-item :label="$gettext('Content')">
  49. <vue-itextarea v-model:content="location.content" default-height="200px"/>
  50. </a-form-item>
  51. </a-modal>
  52. <div>
  53. <a-button block @click="add">{{ $gettext('Add Location') }}</a-button>
  54. </div>
  55. </template>
  56. <style lang="less" scoped>
  57. .ant-card {
  58. margin: 10px 0;
  59. box-shadow: unset;
  60. }
  61. </style>