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.

67 lines
1.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
  1. <template>
  2. <form-import :error-message="errorMessage" @clear="clearErrorMessage" @upload="upload" />
  3. </template>
  4. <script lang="ts">
  5. import Vue from 'vue'
  6. import FormImport from '~/components/label/FormImport.vue'
  7. export default Vue.extend({
  8. components: {
  9. FormImport
  10. },
  11. layout: 'project',
  12. middleware: ['check-auth', 'auth', 'setCurrentProject', 'isProjectAdmin'],
  13. validate({ params, query, store }) {
  14. if (!['category', 'span', 'relation'].includes(query.type as string)) {
  15. return false
  16. }
  17. if (/^\d+$/.test(params.id)) {
  18. const project = store.getters['projects/project']
  19. return project.canDefineLabel
  20. }
  21. return false
  22. },
  23. data() {
  24. return {
  25. errorMessage: ''
  26. }
  27. },
  28. computed: {
  29. projectId(): string {
  30. return this.$route.params.id
  31. },
  32. service(): any {
  33. const type = this.$route.query.type
  34. if (type === 'category') {
  35. return this.$services.categoryType
  36. } else if (type === 'span') {
  37. return this.$services.spanType
  38. } else {
  39. return this.$services.relationType
  40. }
  41. }
  42. },
  43. methods: {
  44. async upload(file: File) {
  45. try {
  46. await this.service.upload(this.projectId, file)
  47. this.$router.push(`/projects/${this.projectId}/labels`)
  48. } catch (e: any) {
  49. this.errorMessage = e.message
  50. }
  51. },
  52. clearErrorMessage() {
  53. this.errorMessage = ''
  54. }
  55. }
  56. })
  57. </script>