添加请求拦截和请求文件
This commit is contained in:
parent
36608c7555
commit
366bf072a9
2
App.vue
2
App.vue
@ -4,7 +4,7 @@ onLaunch(() => {
|
||||
const updateManager = wx.getUpdateManager()
|
||||
updateManager.onCheckForUpdate(function (res) {
|
||||
// 请求完新版本信息的回调
|
||||
console.log(res.hasUpdate)
|
||||
// console.log(res.hasUpdate)
|
||||
})
|
||||
|
||||
updateManager.onUpdateReady(function () {
|
||||
|
||||
@ -19,8 +19,9 @@
|
||||
"navigationBarTitleText": "个人中心"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "pages/patient/addTask.vue",
|
||||
"path": "pages/patient/addTask",
|
||||
"style": {
|
||||
"navigationBarTitleText": "新增任务"
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
<script setup>
|
||||
|
||||
</script>
|
||||
<template></template>
|
||||
<template>
|
||||
新增任务
|
||||
</template>
|
||||
<style lang="scss" scoped></style>
|
||||
0
services/doctoc.js
Normal file
0
services/doctoc.js
Normal file
8
services/patient.js
Normal file
8
services/patient.js
Normal file
@ -0,0 +1,8 @@
|
||||
import {http} from "@/utils/http.js"
|
||||
|
||||
// 获取患者列表
|
||||
export const getPatientList = () => {
|
||||
http({
|
||||
url: "/patient"
|
||||
})
|
||||
}
|
||||
65
utils/http.js
Normal file
65
utils/http.js
Normal file
@ -0,0 +1,65 @@
|
||||
import {} from "@/store"
|
||||
|
||||
const baseURL = "http://192.168.0.180:3000"
|
||||
import { useUserStore } from '@/store';
|
||||
|
||||
// 请求拦截器配置
|
||||
const httpInterceptor = {
|
||||
invoke(options) {
|
||||
// 拼接请求地址
|
||||
options.url = baseURL + options.url
|
||||
console.log(111, options);
|
||||
// 请求超时
|
||||
options.timeout = 5000
|
||||
|
||||
// 添加 token 请求头标识
|
||||
// const useUser = useUserStore()
|
||||
// const token = useUser
|
||||
// if (token) {
|
||||
// options.header.Authorization = token
|
||||
// }
|
||||
},
|
||||
}
|
||||
|
||||
// 拦截 request 请求
|
||||
uni.addInterceptor("request", httpInterceptor)
|
||||
|
||||
/*
|
||||
请求函数
|
||||
*/
|
||||
export const http = (options) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
...options,
|
||||
// 响应成功
|
||||
success(res) {
|
||||
// 请求成功
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
//提取数据
|
||||
resolve(res.data)
|
||||
} else if (res.statusCode === 401) {
|
||||
// 401错误,清理用户信息,跳转到登录页
|
||||
const memberStore = useMemberStore()
|
||||
memberStore.clearProfile()
|
||||
uni.navigateTo({ url: '/pages/login/login' })
|
||||
reject(res)
|
||||
} else {
|
||||
// 其他错误,根据后端错误信息轻提示
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: (res.data).msg || '请求错误',
|
||||
})
|
||||
reject(res)
|
||||
}
|
||||
},
|
||||
// 响应失败
|
||||
fail(err) {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '网络错误',
|
||||
})
|
||||
reject(err)
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user