From 867710828938a77b09c28becc95c06a0a131b59a Mon Sep 17 00:00:00 2001 From: jia <1451658316@qq.com> Date: Sat, 23 Sep 2023 20:59:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/requestb.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 utils/requestb.js diff --git a/utils/requestb.js b/utils/requestb.js new file mode 100644 index 0000000..fd41a3e --- /dev/null +++ b/utils/requestb.js @@ -0,0 +1,81 @@ +// +---------------------------------------------------------------------- +// | CRMEB [ CRMEB赋能开发者,助力企业发展 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved. +// +---------------------------------------------------------------------- +// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 +// +---------------------------------------------------------------------- +// | Author: CRMEB Team +// +---------------------------------------------------------------------- +import { + HTTP_REQUEST_URL, + HEADER, + TOKENNAME +} from '@/config/app'; +import { + checkLogin +} from '../libs/login'; +import store from '../store'; + + + +/** + * 发送请求 + */ +function baseRequest(url, method, data, { + noAuth = false, + noVerify = false +}) { + + let Url = 'https://ceshi-worker-task.lihaink.cn', + header = HEADER; + + + + if (store.state.app.token) header[TOKENNAME] = 'Bearer ' + store.state.app.token; + + return new Promise((reslove, reject) => { + uni.request({ + url: Url + '/api/' + url, + method: method || 'GET', + header: header, + data: data || {}, + success: (res) => { + // #ifdef APP-PLUS + // console.log('app', Url + '/api/' + url, res.data); + // #endif + console.log(res.data.code) + if (noVerify) + reslove(res.data, res); + else if (res.data.status == 200) + reslove(res.data, res); + else if ([410000, 410001, 410002, 40000].indexOf(res.data.status) !== -1) { + + reject(res.data); + } else if (res.data.status == 501) { + uni.reLaunch({ + url: '/pages/error/index' + }) + reject(res.data); + } else if (res.statusCode==200) { +console.log(res) + reslove(res.data,res.data); + } else + reject(res.data.message || '系统错误'); + }, + fail: (message) => { + reject('请求失败'); + } + }) + }); +} + +const request = {}; + +['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => { + request[method] = (api, data, opt) => baseRequest(api, method, data, opt || {}) +}); + + + +export default request; \ No newline at end of file