TraceabilityAPP/api/upload.js

77 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2023-11-25 16:18:54 +08:00
// import base from "@/config/baseUrl";
// let baseUrl = 'https://ceshi.excellentkk.cn/api';
// import store from '../store';
2023-11-30 17:51:39 +08:00
import {
config
} from '@/config/app';
2023-11-27 18:23:17 +08:00
import store from "@/store/index.js"
2023-11-25 16:18:54 +08:00
let header = {};
2023-11-27 18:23:17 +08:00
2023-11-25 16:18:54 +08:00
function uploads(src, type) {
2023-11-30 17:51:39 +08:00
if (store.state.userInfo) {
header.TOKEN = store.state.userInfo.token
}
return new Promise((resolve, reject) => {
// //console.log('上传', type === 'img' ? '图片' : '视频', '', src)
let a = uni.uploadFile({
// url: base.baseUrl + '/upload?token=',
url: HTTP_REQUEST_URL_TWO + '/api' + '/upload?token=',
filePath: src,
name: 'file',
success: (res) => {
let data = JSON.parse(res.data)
if (data.code != 1) {
uni.$u.toast(data.msg)
return false
} else {
resolve(data.data.url) // 返回线上地址
}
},
fail: (err) => {
reject(err)
//console.log('upload-上传失败', err)
}
});
})
2023-11-25 16:18:54 +08:00
}
function Uploads(src, type) {
2023-11-30 17:51:39 +08:00
if (store.state.userInfo) {
header.TOKEN = store.state.userInfo.token
}
2023-11-25 16:18:54 +08:00
2023-11-30 17:51:39 +08:00
return new Promise((resolve, reject) => {
// //console.log('上传', type === 'img' ? '图片' : '视频', '', src)
let a = uni.uploadFile({
url: config.HTTP_REQUEST_URL + 'api/upload/image',
filePath: src,
name: 'file',
header: header,
success: (res) => {
let data = JSON.parse(res.data)
if (data.code == 1) {
resolve(data) // 返回线上地址
} else {
uni.$u.toast(data.msg)
return false
}
},
fail: (err) => {
reject(err)
//console.log('upload-上传失败', err)
}
});
})
2023-11-25 16:18:54 +08:00
}
export {
2023-11-30 17:51:39 +08:00
uploads,
Uploads
}