file.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { baseUrl, apiPath } from '@/sheep/config';
  2. const FileApi = {
  3. // 上传文件
  4. uploadFile: (file) => {
  5. // TODO 非繁人:访问令牌的接入;
  6. const token = uni.getStorageSync('token');
  7. uni.showLoading({
  8. title: '上传中',
  9. });
  10. return new Promise((resolve, reject) => {
  11. uni.uploadFile({
  12. url: baseUrl + apiPath + '/infra/file/upload',
  13. filePath: file,
  14. name: 'file',
  15. header: {
  16. // Accept: 'text/json',
  17. Accept : '*/*',
  18. 'tenant-id' :'1',
  19. // Authorization: 'Bearer test247',
  20. },
  21. success: (uploadFileRes) => {
  22. let result = JSON.parse(uploadFileRes.data);
  23. if (result.error === 1) {
  24. uni.showToast({
  25. icon: 'none',
  26. title: result.msg,
  27. });
  28. } else {
  29. return resolve(result);
  30. }
  31. },
  32. fail: (error) => {
  33. console.log('上传失败:', error);
  34. return resolve(false);
  35. },
  36. complete: () => {
  37. uni.hideLoading();
  38. },
  39. });
  40. });
  41. },
  42. };
  43. export default FileApi;