LocationEditor.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script setup lang="ts">
  2. import CodeEditor from '@/components/CodeEditor'
  3. import {useGettext} from 'vue3-gettext'
  4. import {reactive, ref} from 'vue'
  5. import {DeleteOutlined, HolderOutlined} from '@ant-design/icons-vue'
  6. import draggable from 'vuedraggable'
  7. const {$gettext} = useGettext()
  8. const props = defineProps(['locations', 'readonly'])
  9. let location = reactive({
  10. comments: '',
  11. path: '',
  12. content: ''
  13. })
  14. const adding = ref(false)
  15. function add() {
  16. adding.value = true
  17. location.comments = ''
  18. location.path = ''
  19. location.content = ''
  20. }
  21. function save() {
  22. adding.value = false
  23. props.locations?.push({
  24. ...location
  25. })
  26. }
  27. function remove(index: number) {
  28. props.locations?.splice(index, 1)
  29. }
  30. </script>
  31. <template>
  32. <h2 v-translate>Locations</h2>
  33. <a-empty v-if="!locations"/>
  34. <draggable
  35. :list="locations"
  36. item-key="name"
  37. class="list-group"
  38. ghost-class="ghost"
  39. handle=".ant-card-head"
  40. >
  41. <template #item="{ element: v, index }">
  42. <a-card :key="index" size="small">
  43. <template #title>
  44. <HolderOutlined/>
  45. {{ $gettext('Location') }}
  46. </template>
  47. <template #extra v-if="!readonly">
  48. <a-popconfirm @confirm="remove(index)"
  49. :title="$gettext('Are you sure you want to remove this location?')"
  50. :ok-text="$gettext('Yes')"
  51. :cancel-text="$gettext('No')">
  52. <a-button type="text">
  53. <template #icon>
  54. <DeleteOutlined style="font-size: 14px;"/>
  55. </template>
  56. </a-button>
  57. </a-popconfirm>
  58. </template>
  59. <a-form layout="vertical">
  60. <a-form-item :label="$gettext('Comments')">
  61. <a-textarea v-model:value="v.comments" :bordered="false"/>
  62. </a-form-item>
  63. <a-form-item :label="$gettext('Path')">
  64. <a-input addon-before="location" v-model:value="v.path"/>
  65. </a-form-item>
  66. <a-form-item :label="$gettext('Content')">
  67. <code-editor v-model:content="v.content" default-height="200px" style="width: 100%;"/>
  68. </a-form-item>
  69. </a-form>
  70. </a-card>
  71. </template>
  72. </draggable>
  73. <a-modal :title="$gettext('Add Location')" v-model:visible="adding" @ok="save">
  74. <a-form layout="vertical">
  75. <a-form-item :label="$gettext('Comments')">
  76. <a-textarea v-model:value="location.comments"/>
  77. </a-form-item>
  78. <a-form-item :label="$gettext('Path')">
  79. <a-input addon-before="location" v-model:value="location.path"/>
  80. </a-form-item>
  81. <a-form-item :label="$gettext('Content')">
  82. <code-editor v-model:content="location.content" default-height="200px"/>
  83. </a-form-item>
  84. </a-form>
  85. </a-modal>
  86. <div v-if="!readonly">
  87. <a-button block @click="add">{{ $gettext('Add Location') }}</a-button>
  88. </div>
  89. </template>
  90. <style lang="less" scoped>
  91. .ant-card {
  92. margin: 10px 0;
  93. box-shadow: unset;
  94. }
  95. </style>