1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { getToken } from '@/utils/auth'
- import {
- store
- } from '@/store/index.js'
- // import baseURL from '@/api/base/path.js'
- function upload({url, data, method="POST"}) {
- let token = 'Bearer ' + getToken();
- let header = {
- Authorization: token
- }
- console.log(data)
- return new Promise((resolve, reject)=>{
- const urlList = uni.getStorageSync('baseUrl')
- uni.uploadFile({
- url: JSON.parse(urlList).baseUrl + url,
- method,
- header,
- timeout: 600000,
- filePath:data.filePath,
- name: 'file',
- sslVerify: false,
- success: (res) => {
- if (res.statusCode === 200) {
- //请求成功
- resolve(res.data);
- } else if (res.statusCode === 401) {
- uni.showToast({
- icon: 'none',
- title: "未登录或登录状态已超时",
- duration: 1500
- });
- } else if (res.statusCode === 405) {
- uni.showToast({
- icon: 'none',
- title: "请求方法错误",
- duration: 1500
- });
- } else {
- uni.showToast({
- icon: 'none',
- title: "请求错误:" + res.statusCode,
- duration: 1500
- });
- }
- },
- fail: (err) => {
- uni.showToast({
- icon: 'none',
- title: err.errMsg,
- duration: 1500
- });
- reject(err);
- }
- })
- })
- }
- export default {upload}
|