wxapi/api.js
2020-02-14 14:15:38 +08:00

75 lines
1.8 KiB
JavaScript

// fetch.js
import axios from 'axios'
export const api = axios.create({
baseURL: 'https://chenmo1212.site/wxapi',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
},
timeout: 10 * 1000
})
//设置拦截器
api.interceptors.response.use(
(response) => {
// console.log('拦截器:请求成功', response)
return response
}, (error) => {
// console.log('拦截器:发生错误', error.response)
return Promise.reject(error)
}
)
// api.js
// 签名算法
// cnpm install crypto-js -s
var CryptoJS = require("crypto-js");
export function getKeywordLists() {
return api.get('/keyword/get')
}
// item 就是去掉row的关键词json
export function addKeywords(item) {
let data = { item }
let sign = CryptoJS.MD5(JSON.stringify(data).replace(/\"/g,"'")).toString().toUpperCase();
data.sign = sign
let params = new URLSearchParams();
params.append('data', JSON.stringify(data));
return api.post('/keyword/insert',params)
}
// id 就是关键词的 id
export function delKeywords(id) {
let data = { id }
let sign = CryptoJS.MD5(JSON.stringify(data).replace(/\"/g,"'")).toString().toUpperCase();
data.sign = sign
let params = new URLSearchParams();
params.append('data', JSON.stringify(data));
return api.post('/keyword/del',params)
}
// 上传excel
export function addExcel(file) {
let param = new FormData();
param.append('excel', file);
return api.put('/excel/add', param, {
headers: {
'Content-Type': 'multipart/form-data',
}
})
}
// 上传excel
export function resetExcel(file) {
let param = new FormData();
param.append('excel', file);
return api.put('/excel/reset', param, {
headers: {
'Content-Type': 'multipart/form-data',
}
})
}