12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import {
- HTTP_REQUEST_URL,
- HEADER,
- TOKENNAME,
- HEADERPARAMS
- } from '@/config/app';
- import {
- toLogin,
- checkLogin
- } from '@/libs/login';
- import store from '@/store';
- function baseRequest(url, method, data, {
- noAuth = false,
- noVerify = false
- }, params) {
- let Url = HTTP_REQUEST_URL,
- header = HEADER
-
-
-
- if (!noAuth) {
-
- if (!store.state.app.token && !checkLogin()) {
- toLogin();
- return Promise.reject({
- msg: '未登录'
- });
- }
- }
- if (store.state.app.token) header[TOKENNAME] = store.state.app.token;
- return new Promise((reslove, reject) => {
- uni.request({
- url: Url + '/api/front/' + url,
- method: method || 'GET',
- header: header,
- data: data || {},
- success: (res) => {
- reslove(res.data, res);
- },
- fail: (msg) => {
- reject('请求失败');
- }
- })
- });
- }
- const request = {};
- ['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
- request[method] = (api, data, opt, params) => baseRequest(api, method, data, opt || {}, params)
- });
- export default request;
|