OA/api/file.js

50 lines
1.2 KiB
JavaScript

import {
HTTP_REQUEST_URL_THREE,
HEADER,
TOKENNAME,
} from '@/config/app';
import {
Toast
} from '../libs/uniApi';
// import { checkLogin } from '../libs/login';
import store from '../store';
function toLogin() {
store.commit("LOGOUT");
uni.showToast({
title: '请登录',
icon: 'none',
duration: 1000
});
}
function upLoad(url, data) {
let Url = HTTP_REQUEST_URL_THREE,
header = {}
if (store.state.app.token) header[TOKENNAME] = store.state.app.token;
return new Promise((reslove, reject) => {
uni.uploadFile({
url: Url + '/api' + url,
filePath: data.filePath,
name: data.name,
success: (uploadFileRes) => {
uploadFileRes.data = JSON.parse(uploadFileRes.data)
if (uploadFileRes.data.code == 1) reslove(uploadFileRes.data)
else Toast('网络错误')
},
fail: (err) => {
Toast('网络错误')
}
})
});
}
export const upLoadImage = (data) => {
return upLoad('/upload/image', data)
}
export const VIDEO_URL = HTTP_REQUEST_URL_THREE + '/api/upload/video'
export const FILE_URL = HTTP_REQUEST_URL_THREE + '/api/home_index/upload'
// im文件上传
// export const VIDEO_URL_IM = HTTP_REQUEST_URL_THREE + '/api/upload/video'
export const FILE_URL_IM = HTTP_REQUEST_URL_THREE + '/common/im/sendFileMsg'