2023-11-25 16:18:54 +08:00
|
|
|
|
// import base from "@/config/baseUrl";
|
|
|
|
|
// let baseUrl = 'https://ceshi.excellentkk.cn/api';
|
|
|
|
|
// import store from '../store';
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
if (store.state.userInfo){
|
|
|
|
|
header.token = store.state.userInfo.token;
|
2023-11-25 16:18:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uploads(src, type) {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Uploads(src, type) {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
uploads,
|
|
|
|
|
Uploads
|
|
|
|
|
}
|