import Vue from "vue"; import axios from "axios"; // import md5 from "js-md5"; const instance = axios.create({ baseURL: process.env.VUE_APP_BASE_API, timeout: 30000, withCredentials: true }); // const appKey = "cd72c223-923f-44a3-aede-b9f07dcd56b8"; // const plat = "steelfurniture"; // const v = "1.0"; instance.interceptors.request.use( ({ headers: { timestamp = Date.now(), token = "", ...h }, ...x }) => ({ headers: { timestamp, // appKey, // plat, // v, // sign: md5(`timestamp${timestamp}plat${plat}v${v}appKey${appKey}`), token, ...h }, ...x }) ); instance.interceptors.response.use( x => x, err => ({ data: { code: -100, data: err } }) ); const getResult: (x: IBaseResult) => IResult = ({ data, code, msg }: IBaseResult) => { if (code === 0) return [null, data]; // Message.error(getErrMsg(code)); return [{ code, msg }, (data || {}) as T]; }; export const post: IRequest = async (url: string, params: any) => { params.datedate= new Date().getTime(); const { data } = await instance.post>(url, params); return getResult(data); }; export const get: IRequest = async (url: string, params: any) => { params.datedate= new Date().getTime(); const {data} = await instance.get>(url, {params}); return getResult(data); }; export default { install(vue: typeof Vue) { Object.assign(vue.prototype, { $get: get, $post: post }); } };