import axios from 'axios'; import Vue from 'vue'; import context from '../main'; // let loading; // axios.defaults.timeout = 3000000; // let loadinginstace; // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; axios.interceptors.request.use( config => { config.headers = { // "Content-Type": "application/json" // "Content-Type": "text/html" // "Content-Type":"multipart/form-data" } return config; }, error => { console.log('error', error); // loading.close(); if (error) { context.$alert('网络错误,请稍后再试!','提示',{ confirmButtonText: '确定' }); return Promise.reject(error); } } ); axios.interceptors.response.use( res => { // console.log('响应res', res); // loading.close(); if (res && res.data && res.data.code == 200) { return res.data; } else { if (res && res.data) { if (res.data.message) { context.$message({ message: res.data.message, type: 'warning' }); } if (res && res.data.code == 10014) { setTimeout(() => { context.$router.replace('/login') }, 2000) } } } }, err => { // console.log('err', err); // loading.close(); // if (err.message.includes('timeout')) { // err.message = '请求超时'; // context.$router.replace({path:'/login'}); // } // else // { // if (err && err.response) { // switch (err.response.status) { // case 400: err.message = '请求错误(400)'; break; // case 401: err.message = '未授权,请重新登录(401)'; break; // case 403: err.message = '拒绝访问(403)'; break; // case 404: err.message = '请求出错(404)'; break; // case 408: err.message = '请求超时(408)'; break; // case 500: err.message = '服务器错误(500)'; break; // case 501: err.message = '服务未实现(501)'; break; // case 502: err.message = '网络错误(502)'; break; // case 503: err.message = '服务不可用(503)'; break; // case 504: err.message = '网络超时(504)'; break; // case 505: err.message = 'HTTP版本不受支持(505)'; break; // default: err.message = `连接出错(${err.response.status})!`; // } // context.$router.replace({path:'/login'}); // } else { // err.message = '连接服务器失败!' // context.$router.replace({path:'/login'}); // } // } // context.$alert(err.message,'提示',{ // confirmButtonText: '确定' // }); return Promise.reject(err); }); Vue.prototype.$axios = axios; axios.defaults.headers.get['Pragma'] = 'no-cache'; axios.defaults.headers.get['Cache-Control'] = 'no-cache, no-store'; let requestLoading = (url, method, params) => { return axios({ method: method, url: url, params, withCredentials: true, data: params, timeout: 120000, }) }; // const Prefix = 'http://192.168.1.220/mchsrv/index.php?'; // const Prefix = 'http://dd.guozipay.com/mchsrv/index.php?'; // const Prefix = 'http://192.168.1.218/mchsrv/index.php?'; const Prefix = `${process.env.VUE_APP_HOST}/mchsrv/index.php?`; // const Prefix = 'https://test.xyzshops.cn/mchsrv/index.php?'; // 椰子临时线上地址 // const Prefix = 'http://121.89.196.45/mobile/index.php?'; //椰林接口地址 // const Prefix = 'https://ylweb.xyzshops.cn/mchsrv/index.php?'; //测试请求 export const testRequest = () => { // return requestLoading(`${Prefix}/index.php?index/index/index`, 'get', {}) } //登录 export const login = (params) => { console.log(`${Prefix}act=merchant_login&op=login`) // return requestLoading(`${Prefix}act=merchant_login&op=login&client_type=ajax`, 'post', params) return axios({ method: 'post', url: `${Prefix}act=merchant_login&op=login&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } //登出 export const loginOut = () => { return requestLoading(`${Prefix}act=merchant_login&op=logout&client_type=ajax`, 'post') } // 获取ip列表 export const getIpList = () => { return requestLoading(`${Prefix}act=merchant_info&op=ipwhitelist&client_type=ajax`, 'post') } // 删除ip列表 export const delIpList = (params) => { // return requestLoading(`${Prefix}act=merchant_info&op=ipdel&client_type=ajax`, 'post', params) return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=ipdel&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 添加ip export const addIp = (params) => { // return requestLoading(`${Prefix}act=merchant_info&op=addip&client_type=ajax&ip=${ip}`, 'post') return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=addip&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 获取订单统计列表 export const getOrderList = (params) => { // return requestLoading(`${Prefix}act=merchant_order&op=list&client_type=ajax&curpage=${page}`, 'post') return axios({ method: 'post', url: `${Prefix}act=merchant_order&op=list&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } /** * 查询订单统计列表 * @param {*} page 页码 * @param {*} start_time 开始时间 * @param {*} end_time 结束时间 * @param {*} card_type 充值类型 */ // export const queryList = (page, start_time, end_time, card_type) => { export const queryList = (params) => { // return requestLoading(`${Prefix}act=merchant_order&op=list&client_type=ajax&curpage=${page}&start_time=${start_time}&end_time=${end_time}&card_type=${card_type}`, 'post') return axios({ method: 'post', url: `${Prefix}act=merchant_order&op=list&client_type=ajax&page=200`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 导出 export const exportList = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_order&op=OrderExport&client_type=ajax&page=50`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 修改管理员密码 export const editPwd = (params) => { // return requestLoading(`${Prefix}act=merchant_info&op=modifypw&client_type=ajax`, 'post', params) return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=modifypw&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 个人中心 export const getUserInfo = () => { return requestLoading(`${Prefix}act=merchant_info&op=index&client_type=ajax`, 'post') } // 实时动账 export const getMovingAccount = (page) => { return requestLoading(`${Prefix}act=merchant_info&op=pdlog&client_type=ajax&page=50&curpage=${page}`, 'post') } /** * 查询实时动账 * @param {*} start_time 开始时间 * @param {*} end_time 结束时间 * @param {*} lg_type 变更类型 * @param {*} lg_order_sn 业务单号 */ // export const queryMovingAccount = (page, start_time, end_time, lg_type) => { export const queryMovingAccount = (params) => { // return requestLoading(`${Prefix}act=merchant_info&op=pdlog&client_type=ajax&curpage=${page}&start_time=${start_time}&end_time=${end_time}&lg_type=${lg_type}`, 'post') return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=pdlog&client_type=ajax&page=50`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 导出日志 export const exportMovingAccount = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=pdlogexport&client_type=ajax&page=50`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 设置密钥 // export const updateKey = (secure_key) => { export const updateKey = (params) => { // return requestLoading(`${Prefix}act=merchant_info&op=setkey&client_type=ajax&secure_key=${secure_key}`, 'post') return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=setkey&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 用户设置-提交 充值管理-设置余额预警 export const onSubUser = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=setcontact&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 上传文件 export const updateVoucher = (name) => { // return requestLoading(`${Prefix}act=merchant_recharge&op=voucherupload&client_type=ajax`, 'post', {voucher}) return axios({ method: "post", // url: `http://192.168.1.218/upfile.php`, // url: `http://dd.guozipay.com/upfile.php`, // url: `https://www.xyzshops.cn/upfile.php`, url: `${process.env.VUE_APP_HOST}/upfile.php`, //椰林接口地址 // url : 'https://ylweb.xyzshops.cn/upfile.php', // url: `https://test.xyzshops.cn/upfile.php`, // 椰子临时 // url: `http://121.89.196.45/upfile.php`, // withCredentials: true, data: name, timeout: 120000, }) } // 上传凭证 export const updateVoucherList = (params) => { // return requestLoading(`${Prefix}act=refill_evidence&op=add&client_type=ajax`, 'post', params) return axios({ method: 'post', url: `${Prefix}act=refill_evidence&op=add&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 获取充值列表 export const getVoucherList = () => { return requestLoading(`${Prefix}act=refill_evidence&op=index&client_type=ajax&page=50`, 'post') } // 查询充值列表 // export const queryVoucherList = (page, start_time, end_time) => { export const queryVoucherList = (params) => { // return requestLoading(`${Prefix}act=refill_evidence&op=index&client_type=ajax&curpage=${page}&start_time=${start_time}&end_time=${end_time}`, 'get') return axios({ method: 'post', url: `${Prefix}act=refill_evidence&op=index&client_type=ajax&page=50`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 获取充值金额 export const getRechargeAmount = () => { return requestLoading(`${Prefix}act=merchant_refill&op=goods&client_type=ajax`, 'post') } // 油卡充值 cardno-卡号 amount-充值金额 export const OilCardRecharge = (params) => { // return requestLoading(`${Prefix}act=merchant_refill&op=add&client_type=ajax`, 'post', params) return axios({ method: 'post', url: `${Prefix}act=merchant_refill&op=add&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 首页 export const getHomeData = () => { return requestLoading(`${Prefix}act=merchant_info&op=home&client_type=ajax`, 'post') } // 添加余额预警电话 export const addwphone = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=addwphone&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 删除余额预警电话 export const delwphone = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=wphonedel&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 对账管理 export const getRec = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_order&op=OrderStats&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 对账管理导出订单 export const getExportOrder = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_order&op=create_task&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) } // 对账管理获取导出订单列表 export const getExportOrderList = (curpage) => { return axios({ method: 'post', url: `${Prefix}act=merchant_order&op=task_list&client_type=ajax&curpage=${curpage}`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: {}, timeout: 120000, }) } // 设置话费充值 export const phonrRec = (params) => { return axios({ method: 'post', url: `${Prefix}act=merchant_info&op=SetQualityTimeOut&client_type=ajax`, withCredentials: true, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: params, timeout: 120000, }) }