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.

70 lines
1.4 KiB

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