77 lines
1.6 KiB
JavaScript
77 lines
1.6 KiB
JavaScript
// import base from "@/config/baseUrl";
|
||
// let baseUrl = 'https://ceshi.excellentkk.cn/api';
|
||
// import store from '../store';
|
||
import {
|
||
config
|
||
} from '@/config/app';
|
||
import store from "@/store/index.js"
|
||
let header = {};
|
||
|
||
|
||
function uploads(src, type) {
|
||
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)
|
||
}
|
||
});
|
||
})
|
||
}
|
||
|
||
function Uploads(src, type) {
|
||
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: 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
|
||
} |