|
@@ -1,53 +1,53 @@
|
1
|
1
|
import store from '@/store/index'
|
2
|
2
|
|
3
|
3
|
// 统一请求方法
|
4
|
|
-export default function fetch(url, params = {}, method = 'POST', showFail = true) {
|
5
|
|
- let showLoading = true
|
6
|
|
- if (params && params.notShowLoading) {
|
7
|
|
- showLoading = false
|
8
|
|
- }
|
9
|
|
- if (showLoading) {
|
10
|
|
- uni.showLoading({
|
11
|
|
- mask: true,
|
12
|
|
- title: '加载中...'
|
13
|
|
- })
|
14
|
|
- }
|
15
|
|
- url = process.env.VUE_APP_BASE_URL + url
|
16
|
|
- params.token = store.getters.token
|
17
|
|
- params.student_id = params.student_id || store.getters.kid
|
18
|
|
- return new Promise((resolve, reject) => {
|
19
|
|
- uni.request({
|
20
|
|
- url,
|
21
|
|
- data: params,
|
22
|
|
- method,
|
23
|
|
- header: {},
|
24
|
|
- success: (res) => {
|
25
|
|
- uni.hideLoading()
|
26
|
|
- // 0:错误; 1:正确; 10000:没有token -2: 需要绑定手机
|
27
|
|
- const rs = res.data
|
28
|
|
- if (rs && rs.code === 1) {
|
29
|
|
- resolve(rs)
|
30
|
|
- } else if (rs.code === 10000) {
|
31
|
|
- // // 跳转至登录页
|
32
|
|
- uni.showModal({
|
33
|
|
- title: '请先登录',
|
34
|
|
- content: '您还没有登录,请先去登录',
|
35
|
|
- success: res => {
|
36
|
|
- if (res.confirm) {
|
37
|
|
- uni.navigateTo({ url: '/pages/login/index' })
|
38
|
|
- }
|
39
|
|
- }
|
40
|
|
- })
|
41
|
|
- } else {
|
42
|
|
- if (showFail) uni.showToast({ title: rs.msg, icon: 'none', duration: 2000 })// 直接提示错误
|
43
|
|
- resolve(rs)
|
44
|
|
- }
|
45
|
|
- },
|
46
|
|
- fail: (err) => {
|
47
|
|
- uni.hideLoading()
|
48
|
|
- uni.showToast({ title: err, icon: 'none', duration: 2000 })
|
49
|
|
- reject(err)
|
50
|
|
- }
|
51
|
|
- })
|
52
|
|
- })
|
|
4
|
+export default function fetch (url, params = {}, method = 'POST', showFail = true) {
|
|
5
|
+ let showLoading = true
|
|
6
|
+ if (params && params.notShowLoading) {
|
|
7
|
+ showLoading = false
|
|
8
|
+ }
|
|
9
|
+ if (showLoading) {
|
|
10
|
+ uni.showLoading({
|
|
11
|
+ mask: true,
|
|
12
|
+ title: '加载中...'
|
|
13
|
+ })
|
|
14
|
+ }
|
|
15
|
+ url = process.env.VUE_APP_BASE_URL + url
|
|
16
|
+ params.token = store.getters.token
|
|
17
|
+ params.student_id = params.student_id || store.getters.kid
|
|
18
|
+ return new Promise((resolve, reject) => {
|
|
19
|
+ uni.request({
|
|
20
|
+ url,
|
|
21
|
+ data: params,
|
|
22
|
+ method,
|
|
23
|
+ header: {},
|
|
24
|
+ success: (res) => {
|
|
25
|
+ uni.hideLoading()
|
|
26
|
+ // 0:错误; 1:正确; 10000:没有token -2: 需要绑定手机
|
|
27
|
+ const rs = res.data
|
|
28
|
+ if (rs && rs.code === 1) {
|
|
29
|
+ resolve(rs)
|
|
30
|
+ } else if (rs.code === 10000) {
|
|
31
|
+ // // 跳转至登录页
|
|
32
|
+ uni.showModal({
|
|
33
|
+ title: '请先登录',
|
|
34
|
+ content: '您还没有登录,请先去登录',
|
|
35
|
+ success: res => {
|
|
36
|
+ if (res.confirm) {
|
|
37
|
+ uni.navigateTo({ url: '/pages/login/index' })
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+ })
|
|
41
|
+ } else {
|
|
42
|
+ if (showFail) uni.showToast({ title: rs.msg, icon: 'none', duration: 2000 })// 直接提示错误
|
|
43
|
+ resolve(rs)
|
|
44
|
+ }
|
|
45
|
+ },
|
|
46
|
+ fail: (err) => {
|
|
47
|
+ uni.hideLoading()
|
|
48
|
+ uni.showToast({ title: err, icon: 'none', duration: 2000 })
|
|
49
|
+ reject(err)
|
|
50
|
+ }
|
|
51
|
+ })
|
|
52
|
+ })
|
53
|
53
|
}
|