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.

53 lines
1.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import { reactive } from '@nuxtjs/composition-api'
  2. export const useTeacherList = (service: any) => {
  3. const state = reactive({
  4. teacherList: []
  5. })
  6. const getTeacherList = async (projectId: string, exampleId: number) => {
  7. state.teacherList = await service.list(projectId, exampleId)
  8. }
  9. const removeTeacher = async (projectId: string, exampleId: number, teacherId: number) => {
  10. await service.delete(projectId, exampleId, teacherId)
  11. await getTeacherList(projectId, exampleId)
  12. }
  13. const annotateLabel = async (projectId: string, exampleId: number, labelId: number) => {
  14. await service.create(projectId, exampleId, labelId)
  15. await getTeacherList(projectId, exampleId)
  16. }
  17. const clearTeacherList = async (projectId: string, exampleId: number) => {
  18. await service.clear(projectId, exampleId)
  19. await getTeacherList(projectId, exampleId)
  20. }
  21. const autoLabel = async (projectId: string, exampleId: number) => {
  22. await service.autoLabel(projectId, exampleId)
  23. await getTeacherList(projectId, exampleId)
  24. }
  25. const annotateOrRemoveLabel = async (projectId: string, exampleId: number, srcKey: string) => {
  26. const labelId = parseInt(srcKey, 10)
  27. // @ts-ignore
  28. const annotation = state.teacherList.find((item) => item.label === labelId)
  29. if (annotation) {
  30. // @ts-ignore
  31. await removeTeacher(projectId, exampleId, annotation.id)
  32. } else {
  33. await annotateLabel(projectId, exampleId, labelId)
  34. }
  35. }
  36. return {
  37. state,
  38. getTeacherList,
  39. annotateLabel,
  40. annotateOrRemoveLabel,
  41. removeTeacher,
  42. clearTeacherList,
  43. autoLabel
  44. }
  45. }