You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.9 KiB

  1. <template>
  2. <base-card
  3. :disabled="!valid"
  4. :title="$t('labels.importTitle')"
  5. :agree-text="$t('generic.upload')"
  6. :cancel-text="$t('generic.cancel')"
  7. @agree="$emit('upload', file)"
  8. @cancel="cancel"
  9. >
  10. <template #content>
  11. <v-form
  12. ref="form"
  13. v-model="valid"
  14. >
  15. <h2>{{ $t('labels.importMessage1') }}</h2>
  16. <v-sheet
  17. v-if="exampleFormat"
  18. :dark="!$vuetify.theme.dark"
  19. :light="$vuetify.theme.dark"
  20. class="mb-5 pa-5"
  21. >
  22. <pre>{{ exampleFormat }}</pre>
  23. </v-sheet>
  24. <h2>{{ $t('labels.importMessage2') }}</h2>
  25. <v-file-input
  26. v-model="file"
  27. accept=".json"
  28. :error-messages="errorMessage"
  29. :label="$t('labels.filePlaceholder')"
  30. :rules="uploadSingleFileRules($t('rules.uploadFileRules'))"
  31. @change="$emit('clear')"
  32. @click:clear="$emit('clear')"
  33. />
  34. </v-form>
  35. </template>
  36. </base-card>
  37. </template>
  38. <script lang="ts">
  39. import Vue from 'vue'
  40. import BaseCard from '@/components/utils/BaseCard.vue'
  41. import { uploadSingleFileRules } from '@/rules/index'
  42. export default Vue.extend({
  43. components: {
  44. BaseCard
  45. },
  46. props: {
  47. errorMessage: {
  48. type: String,
  49. default: ''
  50. }
  51. },
  52. data() {
  53. return {
  54. file: null,
  55. valid: false,
  56. uploadSingleFileRules,
  57. }
  58. },
  59. computed: {
  60. exampleFormat() {
  61. const data = [
  62. {
  63. text: 'Dog',
  64. suffix_key: 'a',
  65. background_color: '#FF0000',
  66. text_color: '#ffffff'
  67. },
  68. {
  69. text: 'Cat',
  70. suffix_key: 'c',
  71. background_color: '#FF0000',
  72. text_color: '#ffffff'
  73. }
  74. ]
  75. return JSON.stringify(data, null, 4)
  76. }
  77. },
  78. methods: {
  79. cancel() {
  80. (this.$refs.form as HTMLFormElement).reset()
  81. this.$emit('cancel')
  82. }
  83. }
  84. })
  85. </script>