courseWare.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {axios} from "@/requests/axios.config";
  2. const prefix = "/courseWare";
  3. function createCourseWare(data) {
  4. return axios.post(`${prefix}/create`, data);
  5. }
  6. function setCanDownloadById(id, canDownload) {
  7. return axios.post(`${prefix}/setCanDownloadById`, null, {params: {id, canDownload}});
  8. }
  9. function uploadCourseWareFile(name, file) {
  10. let data = new FormData();
  11. data.append("name", name);
  12. data.append("file", file);
  13. return axios.post(`${prefix}/uploadCourseWareFile`, data);
  14. }
  15. function deleteCourseWare(id) {
  16. return axios.delete(`${prefix}/delete`, {params: {id}});
  17. }
  18. function getCourseWaresByCourseId(courseId) {
  19. return axios.get(`${prefix}/getCourseWaresByCourseId`, {params: {courseId}});
  20. }
  21. function getCourseWareById(id) {
  22. return axios.get(`${prefix}/getById`, {params: {id}});
  23. }
  24. function checkCourseWareNameUnique(courseId, name) {
  25. return axios.get(`${prefix}/checkName`, {params: {courseId, name}});
  26. }
  27. function changeCourseWareName(id, newName) {
  28. return axios.post(`${prefix}/changeCourseWareName`, null, {
  29. params: {
  30. id,
  31. newName,
  32. }
  33. });
  34. }
  35. function getCourseWareUrlById(id) {
  36. return axios.get(`${prefix}/getUrlById`, {params: {id}});
  37. }
  38. function getCourseIdById(id) {
  39. return axios.get(`${prefix}/getCourseIdById`, {params: {id}});
  40. }
  41. function previewpdf(fileUrl) {
  42. return axios({
  43. methods: "get",
  44. url: "/courseWare/readPdfFile",
  45. params: {
  46. fileUrl: fileUrl
  47. },
  48. responseType: "blob",
  49. headers:{
  50. "Content-Type": "application/json"
  51. }
  52. });
  53. }
  54. function getCanDownloadById(id) {
  55. return axios.get(`${prefix}/getCanDownloadById`, {params: {id}});
  56. }
  57. const courseWareAPIs = {
  58. createCourseWare,
  59. setCanDownloadById,
  60. deleteCourseWare,
  61. getCourseWaresByCourseId,
  62. getCourseWareById,
  63. uploadCourseWareFile,
  64. checkCourseWareNameUnique,
  65. changeCourseWareName,
  66. getCourseWareUrlById,
  67. previewpdf,
  68. getCourseIdById,
  69. getCanDownloadById
  70. };
  71. export default courseWareAPIs;