默认提交
Showing
6 changed files
with
112 additions
and
100 deletions
1 | NODE_ENV = 'development' | 1 | NODE_ENV = 'development' |
2 | VUE_APP_TITLE = 'development' | 2 | VUE_APP_TITLE = 'development' |
3 | VUE_APP_BASE_URL= 'https://ow.go.qudone.com' | ||
4 | VUE_APP_RSA_PUBLIC_KEY = 'B5FE03847F02046C47292AF0FF2DE88977241483DD40C123046EB39CBE4C48167B120096CFF12CD16559322884A3C56FA92B07B89AB51FC8C91A75127622151DDD730DFF1F993D5A290CEAC0BBA7FC88285D8994ACBAFF50101EDE9A0925AD5DFFAFE96D53C370E9C5B37DF2F871F81C4D7CA6B7EC37FF459C07975AD9A74A95' | ||
5 | VUE_APP_RSA_KEY_INDEX = '10001' | ... | ... |
1 | 1 | ||
2 | NODE_ENV = 'production' | 2 | NODE_ENV = 'production' |
3 | VUE_APP_TITLE = 'dist' | 3 | VUE_APP_TITLE = 'dist' |
4 | VUE_APP_BASE_URL= 'https://ow.go.qudone.com' | ||
5 | VUE_APP_RSA_PUBLIC_KEY = 'B5FE03847F02046C47292AF0FF2DE88977241483DD40C123046EB39CBE4C48167B120096CFF12CD16559322884A3C56FA92B07B89AB51FC8C91A75127622151DDD730DFF1F993D5A290CEAC0BBA7FC88285D8994ACBAFF50101EDE9A0925AD5DFFAFE96D53C370E9C5B37DF2F871F81C4D7CA6B7EC37FF459C07975AD9A74A95' | ||
6 | VUE_APP_RSA_KEY_INDEX = '10001' | ... | ... |
1 | NODE_ENV = 'sandbox' | 1 | NODE_ENV = 'sandbox' |
2 | VUE_APP_TITLE = 'sandbox' | 2 | VUE_APP_TITLE = 'sandbox' |
3 | REQUEST_DOMAIN= 'https://ow.go.qudone.com' | ||
4 | RSA_PUBLIC_KEY = 'B5FE03847F02046C47292AF0FF2DE88977241483DD40C123046EB39CBE4C48167B120096CFF12CD16559322884A3C56FA92B07B89AB51FC8C91A75127622151DDD730DFF1F993D5A290CEAC0BBA7FC88285D8994ACBAFF50101EDE9A0925AD5DFFAFE96D53C370E9C5B37DF2F871F81C4D7CA6B7EC37FF459C07975AD9A74A95' | ||
5 | RSA_KEY_INDEX = '10001' | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
3 | VUE_APP_BASE_URL= 'https://ow.go.qudone.com' | ||
4 | VUE_APP_RSA_PUBLIC_KEY = 'B5FE03847F02046C47292AF0FF2DE88977241483DD40C123046EB39CBE4C48167B120096CFF12CD16559322884A3C56FA92B07B89AB51FC8C91A75127622151DDD730DFF1F993D5A290CEAC0BBA7FC88285D8994ACBAFF50101EDE9A0925AD5DFFAFE96D53C370E9C5B37DF2F871F81C4D7CA6B7EC37FF459C07975AD9A74A95' | ||
5 | VUE_APP_RSA_KEY_INDEX = '10001' | ... | ... |
1 | import axios from 'axios'; | 1 | import axiosIns from 'axios'; |
2 | // import { | 2 | // import { |
3 | // Toast | 3 | // Toast |
4 | // } from 'vant'; | 4 | // } from 'vant'; |
5 | 5 | ||
6 | function Toast(msg) { | 6 | function Toast(msg) { |
7 | console.log("msg:", msg); | 7 | console.log("msg:", msg); |
8 | } | 8 | } |
9 | 9 | ||
10 | // axios的默认url | 10 | // axios的默认url |
11 | // axios.defaults.baseURL = "" | 11 | // axios.defaults.baseURL = "" |
12 | 12 | ||
13 | // 服务器地址 | 13 | // 服务器地址 |
14 | let base = process.env.REQUEST_DOMAIN || "http://localhost:9101"; | 14 | // let base = process.env.REQUEST_DOMAIN || "http://localhost:9101"; |
15 | // let base = COM.baseUrl; | 15 | // let base = COM.baseUrl; |
16 | let base = "" | ||
17 | console.log("process.env:", process.env); | ||
18 | const axios = axiosIns.create({ | ||
19 | baseURL: process.env.VUE_APP_BASE_URL || "http://localhost:9101", | ||
20 | timeout: 5000 | ||
21 | }) | ||
16 | 22 | ||
17 | // 请求拦截器 | 23 | // 请求拦截器 |
18 | // axios.interceptors.request.use( | 24 | // axios.interceptors.request.use( |
... | @@ -29,82 +35,82 @@ let base = process.env.REQUEST_DOMAIN || "http://localhost:9101"; | ... | @@ -29,82 +35,82 @@ let base = process.env.REQUEST_DOMAIN || "http://localhost:9101"; |
29 | 35 | ||
30 | // 响应拦截器 | 36 | // 响应拦截器 |
31 | axios.interceptors.response.use( | 37 | axios.interceptors.response.use( |
32 | response => { | 38 | response => { |
33 | if (response.status === 200) { | 39 | if (response.status === 200) { |
34 | if (response.data.code === 200) { | 40 | if (response.data.code === 200) { |
35 | return Promise.resolve(response); | 41 | return Promise.resolve(response); |
36 | } else { | 42 | } else { |
37 | Toast(response.data.bizMsg); | 43 | Toast(response.data.bizMsg); |
38 | return Promise.reject(response); | 44 | return Promise.reject(response); |
39 | } | 45 | } |
40 | } else { | 46 | } else { |
41 | return Promise.reject(response); | 47 | return Promise.reject(response); |
42 | } | 48 | } |
43 | }, | 49 | }, |
44 | // 服务器状态码不是200的情况 | 50 | // 服务器状态码不是200的情况 |
45 | error => { | 51 | error => { |
46 | if (error.response.status) { | 52 | if (error.response.status) { |
47 | switch (error.response.status) { | 53 | switch (error.response.status) { |
48 | // 401: 未登录 | 54 | // 401: 未登录 |
49 | // 未登录则跳转登录页面,并携带当前页面的路径 | 55 | // 未登录则跳转登录页面,并携带当前页面的路径 |
50 | // 在登录成功后返回当前页面,这一步需要在登录页操作。 | 56 | // 在登录成功后返回当前页面,这一步需要在登录页操作。 |
51 | case 401: | 57 | case 401: |
52 | router.replace({ | 58 | router.replace({ |
53 | path: '/login', | 59 | path: '/login', |
54 | query: { | 60 | query: { |
55 | redirect: router.currentRoute.fullPath | 61 | redirect: router.currentRoute.fullPath |
56 | } | 62 | } |
57 | }); | 63 | }); |
58 | break; | 64 | break; |
59 | // 403 token过期 | 65 | // 403 token过期 |
60 | // 登录过期对用户进行提示 | 66 | // 登录过期对用户进行提示 |
61 | // 清除本地token和清空vuex中token对象 | 67 | // 清除本地token和清空vuex中token对象 |
62 | // 跳转登录页面 | 68 | // 跳转登录页面 |
63 | case 403: | 69 | case 403: |
64 | Toast({ | 70 | Toast({ |
65 | message: '登录过期,请重新登录', | 71 | message: '登录过期,请重新登录', |
66 | duration: 1000, | 72 | duration: 1000, |
67 | forbidClick: true | 73 | forbidClick: true |
68 | }); | 74 | }); |
69 | // 清除token | 75 | // 清除token |
70 | localStorage.removeItem('token'); | 76 | localStorage.removeItem('token'); |
71 | store.commit('loginSuccess', null); | 77 | store.commit('loginSuccess', null); |
72 | // 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面 | 78 | // 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面 |
73 | setTimeout(() => { | 79 | setTimeout(() => { |
74 | router.replace({ | 80 | router.replace({ |
75 | path: '/login', | 81 | path: '/login', |
76 | query: { | 82 | query: { |
77 | redirect: router.currentRoute.fullPath | 83 | redirect: router.currentRoute.fullPath |
78 | } | 84 | } |
79 | }); | 85 | }); |
80 | }, 1000); | 86 | }, 1000); |
81 | break; | 87 | break; |
82 | // 404请求不存在 | 88 | // 404请求不存在 |
83 | case 404: | 89 | case 404: |
84 | Toast({ | 90 | Toast({ |
85 | message: '网络请求不存在', | 91 | message: '网络请求不存在', |
86 | duration: 1500, | 92 | duration: 1500, |
87 | forbidClick: true | 93 | forbidClick: true |
88 | }); | 94 | }); |
89 | break; | 95 | break; |
90 | // 其他错误,直接抛出错误提示 | 96 | // 其他错误,直接抛出错误提示 |
91 | default: | 97 | default: |
92 | Toast({ | 98 | Toast({ |
93 | message: error.response.data.message, | 99 | message: error.response.data.message, |
94 | duration: 1500, | 100 | duration: 1500, |
95 | forbidClick: true | 101 | forbidClick: true |
96 | }); | 102 | }); |
97 | } | 103 | } |
98 | return Promise.reject(error.response); | 104 | return Promise.reject(error.response); |
99 | } | 105 | } |
100 | } | 106 | } |
101 | ); | 107 | ); |
102 | 108 | ||
103 | //formDataHeaders设置 | 109 | //formDataHeaders设置 |
104 | let formDataHeaders = { | 110 | let formDataHeaders = { |
105 | headers: { | 111 | headers: { |
106 | "Content-Type": "multipart/form-data" | 112 | "Content-Type": "multipart/form-data" |
107 | } | 113 | } |
108 | } | 114 | } |
109 | 115 | ||
110 | /** | 116 | /** |
... | @@ -112,13 +118,13 @@ let formDataHeaders = { | ... | @@ -112,13 +118,13 @@ let formDataHeaders = { |
112 | * @param {*} params | 118 | * @param {*} params |
113 | */ | 119 | */ |
114 | export const httpGet = params => { | 120 | export const httpGet = params => { |
115 | let { | 121 | let { |
116 | url, | 122 | url, |
117 | data | 123 | data |
118 | } = params; | 124 | } = params; |
119 | return axios.get(`${base}${url}`, { | 125 | return axios.get(`${base}${url}`, { |
120 | params: data | 126 | params: data |
121 | }).then(res => res.data.content); | 127 | }).then(res => res.data.content); |
122 | } | 128 | } |
123 | 129 | ||
124 | /** | 130 | /** |
... | @@ -126,11 +132,11 @@ export const httpGet = params => { | ... | @@ -126,11 +132,11 @@ export const httpGet = params => { |
126 | * @param {*} params | 132 | * @param {*} params |
127 | */ | 133 | */ |
128 | export const httpPost = params => { | 134 | export const httpPost = params => { |
129 | let { | 135 | let { |
130 | url, | 136 | url, |
131 | data | 137 | data |
132 | } = params; | 138 | } = params; |
133 | return axios.post(`${base}${url}`, data).then(res => res.data.content); | 139 | return axios.post(`${base}${url}`, data).then(res => res.data.content); |
134 | } | 140 | } |
135 | 141 | ||
136 | 142 | ||
... | @@ -145,9 +151,9 @@ export const httpPost = params => { | ... | @@ -145,9 +151,9 @@ export const httpPost = params => { |
145 | data.append('file', file.file) | 151 | data.append('file', file.file) |
146 | */ | 152 | */ |
147 | export const formdata = params => { | 153 | export const formdata = params => { |
148 | let { | ||
149 | url, | ||
150 | data | ||
151 | } = params; | ||
152 | return axios.post(`${base}${url}`, data, formDataHeaders).then(res => res.data); | ||
153 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
154 | let { | ||
155 | url, | ||
156 | data | ||
157 | } = params; | ||
158 | return axios.post(`${base}${url}`, data, formDataHeaders).then(res => res.data); | ||
159 | } | ... | ... |
... | @@ -45,8 +45,8 @@ export default { | ... | @@ -45,8 +45,8 @@ export default { |
45 | showImageCode: false, | 45 | showImageCode: false, |
46 | agreeProtocol: false | 46 | agreeProtocol: false |
47 | }, | 47 | }, |
48 | PK: process.env.RSA_PUBLIC_KEY || PK, | 48 | PK: process.env.VUE_APP_RSA_PUBLIC_KEY || PK, |
49 | E: process.env.RSA_KEY_INDEX || E, | 49 | E: process.env.VUE_APP_RSA_KEY_INDEX || E, |
50 | } | 50 | } |
51 | }, | 51 | }, |
52 | components: {}, | 52 | components: {}, | ... | ... |
... | @@ -39,8 +39,8 @@ export default { | ... | @@ -39,8 +39,8 @@ export default { |
39 | remain: 0, // 剩余时间 | 39 | remain: 0, // 剩余时间 |
40 | tip: "" // 显示的文字 | 40 | tip: "" // 显示的文字 |
41 | }, | 41 | }, |
42 | PK: process.env.RSA_PUBLIC_KEY || PK, | 42 | PK: process.env.VUE_APP_RSA_PUBLIC_KEY || PK, |
43 | E: process.env.RSA_KEY_INDEX || E, | 43 | E: process.env.VUE_APP_RSA_KEY_INDEX || E, |
44 | } | 44 | } |
45 | }, | 45 | }, |
46 | components: {}, | 46 | components: {}, | ... | ... |
-
Please register or sign in to post a comment