From df118b179546963cbb29fcd7deec78c765c23d9e Mon Sep 17 00:00:00 2001 From: spirit2020 <1194501891@qq.com> Date: Wed, 19 Jan 2022 09:53:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E7=BD=91=E7=BB=9C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/http.js | 41 +++++++++++++++++++++++++++++++++++++++++ api/index.js | 5 +++++ api/modules/Login.js | 15 +++++++++++++++ app.config.js | 5 +++++ 4 files changed, 66 insertions(+) create mode 100644 app.config.js diff --git a/api/http.js b/api/http.js index e69de29..0d622b4 100644 --- a/api/http.js +++ b/api/http.js @@ -0,0 +1,41 @@ +import Request from '@/common/libs/luch-request/index.js' +import App from '@/app.config.js' + +const http = new Request() +http.setConfig(config => { + config.baseURL = App.BASE_URL + return config +}) + +function Token () { + return uni.getStorageSync('token') || '' +} + +http.interceptors.request.use(config => { + config.header = { + ...config.header, + token: Token + } + return config +}, config => { + return Promise.reject(config) +}) + +http.interceptors.response.use((response) => { + + const data = response.data + + if(/([1345]\d*)/.test(data.code)) { + uni.showToast({ + icon: 'none', + title: data.msg + }) + return Promise.reject(response) + } + + return response +}, (response) => { + return Promise.reject(response) +}) + +export default http diff --git a/api/index.js b/api/index.js index e69de29..574bbab 100644 --- a/api/index.js +++ b/api/index.js @@ -0,0 +1,5 @@ +import LoginApi from '@/api/modules/Login.js' + +export { + LoginApi +} diff --git a/api/modules/Login.js b/api/modules/Login.js index e69de29..59ce5c9 100644 --- a/api/modules/Login.js +++ b/api/modules/Login.js @@ -0,0 +1,15 @@ +import http from '../http.js' + +const BASE_PREFIX = '/test/login' + +class Login { + constructor() { + this.api = { + login: BASE_PREFIX + '/loign' + } + } + + login(data) { + return http.post(this.api.login, data).then(r => r.data) + } +} diff --git a/app.config.js b/app.config.js new file mode 100644 index 0000000..579a1d7 --- /dev/null +++ b/app.config.js @@ -0,0 +1,5 @@ +const BASE_URL = 'http://baidu.com' + +export default { + BASE_URL +}