12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import * as types from '@/utils/types'
- import tools from "@/utils/tools.js"
- const API_URL={
- 'DEV':'http://127.0.0.1:8082/charging-parking',
- 'TEST':'http://192.168.31.248:8082/charging-parking',
- 'PRO':'https://51team.xiaoxinda.com/charging-parking'
- }
- //当前环境
- const BASEURL=API_URL['DEV']
- const service = function(obj) {
- obj.method = obj.method || 'get';
- if (obj.url === undefined) {
- return;
- }
-
- //uni.showNavigationBarLoading() //在当前页面显示导航条加载动画
- return new Promise((resolve, reject) => {
- const header = obj.header ? obj.header : {};
- header['content-type'] = 'application/x-www-form-urlencoded';
- //store.state.access_token && (header['token'] = store.state.access_token);
- uni.request({
- url: BASEURL + obj.url,
- data: obj.data,
- method: obj.method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header, // 设置请求的 header
- success: function(res) {
- // success
-
- resolve(res.data);
- },
- fail: function(error) {
- //console.log(error);
- uni.showToast({
- title: '出现网络问题',
- icon: "none"
- })
- reject(error); //请求失败
- },
- })
- })
- }
- //const request = service;
- export default service; //暴露出来供其他文件引用
|