api.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //所有的接口请求
  2. import axios from 'axios';
  3. const isProd =
  4. import.meta.env.BASE_URL.indexOf('https://assets.le5lecdn.com') === 0;
  5. export const cdn = isProd ? 'https://assets.le5lecdn.com' : '';
  6. export const upCdn = isProd ? 'https://drive.le5lecdn.com' : '';
  7. export const imageDrive = 'https://drive.le5lecdn.com';
  8. //https://v.le5le.com/file/2023/0828/1/1/thumb.07c0a78f.png
  9. export async function delImage(image: string) {
  10. if (image.startsWith('/file') || image.startsWith('/api')) {
  11. await axios.delete(`${image}`);
  12. } else if (image.startsWith(upCdn) || image.startsWith(imageDrive)) {
  13. await axios.delete('/api/file' + image.replace(upCdn || imageDrive, ''));
  14. } else {
  15. await axios.delete(`${image}`);
  16. }
  17. return true;
  18. }
  19. export async function getFolders(query: any) {
  20. const folder: any = await axios.post('/api/data/folders/get', {
  21. query,
  22. });
  23. if (folder.error) {
  24. return;
  25. } else {
  26. return folder;
  27. }
  28. }
  29. export async function updateFolders(data: any) {
  30. const folder: any = await axios.post('/api/data/folders/update', data);
  31. if (folder.error) {
  32. return;
  33. } else {
  34. return folder;
  35. }
  36. }
  37. export async function addCollection(collection: string, data: any) {
  38. return await axios.post(`/api/data/${collection}/add`, data);
  39. }
  40. export async function updateCollection(collection: string, data: any) {
  41. return await axios.post(`/api/data/${collection}/update`, data);
  42. }
  43. export async function getCollectionList(
  44. collection: string,
  45. data: any,
  46. config: any
  47. ) {
  48. return await axios.post(`/api/data/${collection}/list`, data, config);
  49. }
  50. export async function getLe5leV(id: string, projection?: any, historyId?: string) {
  51. const res = await axios.post('/api/data/v/get', {
  52. id,
  53. projection,
  54. historyId
  55. });
  56. res.data = JSON.parse(res.data);
  57. return res;
  58. }
  59. export async function getComponents(id: string) {
  60. const res = await axios.post(`/api/data/v.component/get`, {
  61. id,
  62. });
  63. res.data = JSON.parse(res.data);
  64. return res;
  65. }
  66. export async function getComponentsList(data: any, config: any) {
  67. return await axios.post('/api/data/v.component/list', data, config);
  68. }
  69. export async function getLe5le3d(id: string, projection?: any) {
  70. return await axios.post(`/api/data/3d/get`, {
  71. id,
  72. projection,
  73. });
  74. }
  75. export async function getProjectsList(data: any, config: any) {
  76. return await axios.post('/api/data/v/list', data, config);
  77. }
  78. export async function getLe5le2d(id: string, projection?: any) {
  79. return await axios.post('/api/data/2d/get', {
  80. id,
  81. projection,
  82. });
  83. }