| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- const axios = require('axios')
- /* axios.defaults.withCredentials = true*/
- // create an axios instance
- const service = axios.create()
- const baseUrl = 'http://127.0.0.1:7074/'
- const basePrefixUrl = 'api'
- const timeout = 600000
- const uploadTimeout = 600000
- function request(config) {
- return service(config)
- }
- /* get 默认取数据 */
- function get(config) {
- return _get({ ...config, baseUrl })
- }
- function getPay(config) {
- return _get({ ...config, basePayUrl })
- }
- function _get(config = {
- baseUrl,
- url: '',
- data: {}
- }) {
- const thisBasePrefixUrl = config.basePrefixUrl !== undefined ? config.basePrefixUrl : basePrefixUrl
- return service.get(config.baseUrl + thisBasePrefixUrl + config.url, {
- params: {
- ...config.data
- },
- headers: config.headers || {},
- timeout: config.timeout || timeout
- })
- }
- function post(config) {
- return _post({ ...config, baseUrl })
- }
- function postPay(config) {
- return _post({ ...config, baseUrl: basePayUrl })
- }
- /* post 默认提交数据 */
- function _post(config = {
- baseUrl,
- url: '',
- data: {}
- }) {
- const thisBasePrefixUrl = config.basePrefixUrl !== undefined ? config.basePrefixUrl : basePrefixUrl
- return service.post(config.baseUrl + thisBasePrefixUrl + config.url, {
- ...config.data
- }, {
- headers: config.headers || {},
- timeout: config.timeout || timeout,
- roles:config.roles,
- })
- }
- module.exports = {
- get,
- post
- }
|