123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import request from '@/common/request.js'
- import config from '../config.js'
- import {
- getToken
- } from '../common/auth.js'
- /**
- * 单一文件上传接口
- * @file 文件地址
- * @url 上传路径
- * @formData 上传数据
- */
- export function UploadOne(file, formData = {}) {
- let header = {}
- if (getToken()) {
- header['Authorization'] = 'Bearer ' + getToken()
- }
- return new Promise((resolve, reject) => {
- try {
- uni.uploadFile({
- url: '/api/file/upload',
- filePath: file,
- name: 'file',
- formData: formData,
- header: header,
- success: (res) => {
- let r = JSON.parse(res.data)
- resolve(r)
- },
- fail: (err) => {
- uni.showToast({
- title: '服务器休息中,请稍后再试',
- icon: "none",
- position: "center",
- duration: 3000
- });
- },
- complete: (e) => {
- }
- })
- } catch {
- uni.showToast({
- title: '网速不好哦!在试试',
- icon: "none",
- position: "center",
- duration: 3000
- })
- uni.hideLoading()
- }
- })
- }
- export function UploadSomeFile(file, formData = {}) {
- let header = {}
- if (getToken()) {
- header['Authorization'] = 'Bearer ' + getToken()
- }
- return new Promise((resolve, reject) => {
- try {
- uni.uploadFile({
- url: '/api/file/uploadForm',
- // filePath: file,
- // name: 'file',
- files:file,
- formData: formData,
- header: header,
- success: (res) => {
- let r = JSON.parse(res.data)
- resolve(r)
- },
- fail: (err) => {
- uni.showToast({
- title: '服务器休息中,请稍后再试',
- icon: "none",
- position: "center",
- duration: 3000
- });
- },
- complete: (e) => {
- }
- })
- } catch {
- uni.showToast({
- title: '网速不好哦!在试试',
- icon: "none",
- position: "center",
- duration: 3000
- })
- uni.hideLoading()
- }
- })
- }
- export function UploadSome(data) {
- return request({
- url: '/api/file/uploadMul',
- method: 'post',
- data: data
- })
- }
|