upload.js 566 B

12345678910111213141516171819202122232425
  1. import store from '../store'
  2. import { baseURL } from '@/api/config'
  3. export function upload({ url, ...config }, loading = false) {
  4. if (loading) uni.showLoading({ title: '上传中' })
  5. return new Promise((resolve, reject) => {
  6. uni.uploadFile({
  7. url: baseURL + url,
  8. header: {
  9. token: store.state.token
  10. },
  11. name: 'file',
  12. ...config,
  13. success: res => {
  14. resolve(res.data)
  15. },
  16. fail: err => {
  17. reject(err)
  18. },
  19. complete: () => {
  20. if (loading) uni.hideLoading()
  21. }
  22. })
  23. })
  24. }