1、修改请求方式 (请求头加入env和moduleCode)
2、新增配置
Showing
7 changed files
with
112 additions
and
45 deletions
1 | NODE_ENV = 'development' | 1 | NODE_ENV = 'development' |
2 | VUE_APP_TITLE = 'development' | 2 | VUE_APP_TITLE = 'development' |
3 | VUE_APP_PUBLIC_PATH = './' | 3 | VUE_APP_PUBLIC_PATH = './' |
4 | VUE_APP_OUTPUT_DIR = 'dist' | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
4 | VUE_APP_OUTPUT_DIR = 'dist' | ||
5 | |||
6 | VUE_APP_ENV = 'demo' | ||
7 | VUE_APP_MODULE_CODE = '6f9f27c42878499a965c94bc8f203b23' | ||
8 | VUE_APP_BASE_API = 'https://bizapi.kdao.xin' | ||
9 | VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+87WEJxYnlMOzoDHBgMTmkQyVSMdYRi4tqcnqTibTqEB6xbL5S2w8kjq5ItMKjNcrFvdlh/oj+Qb2LtrHE/O6EOGQf58qH3kZmIhZ32tejJ57c67cXhqbaswUU8WhN4LkhdINrNcpKvnWBd6v2nmEUrmgvi/aL6DIG+OgUyFys0l5BQOeGqzEEYXQgR9ppwDl/QadKpIBgm87qPnhzR++EPKzScgqgqT8D8uw2A96Mj02HXS1n74eCViW+M04UiQ0p0Rq9RMs5EtVJMo2CuArHaPsvsjkUTVdsSROoRTvBzq+T1WmCZJzDvITPZ0hbpD5pTeaXHm7qItQIDAQAB' | ||
10 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' | ||
11 | VUE_APP_TOKEN_KEY = 'kd_template_token' | ||
12 | VUE_APP_IS_POST_ENC = true | ... | ... |
1 | NODE_ENV = 'production' | 1 | NODE_ENV = 'production' |
2 | VUE_APP_TITLE = 'production' | 2 | VUE_APP_TITLE = 'production' |
3 | VUE_APP_PUBLIC_PATH = './' | 3 | VUE_APP_PUBLIC_PATH = './' |
4 | VUE_APP_OUTPUT_DIR = 'dist' | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
4 | VUE_APP_OUTPUT_DIR = 'dist' | ||
5 | |||
6 | |||
7 | VUE_APP_ENV = 'demo' | ||
8 | VUE_APP_MODULE_CODE = '6f9f27c42878499a965c94bc8f203b23' | ||
9 | VUE_APP_BASE_API = 'https://bizapi.kdao.xin' | ||
10 | VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+87WEJxYnlMOzoDHBgMTmkQyVSMdYRi4tqcnqTibTqEB6xbL5S2w8kjq5ItMKjNcrFvdlh/oj+Qb2LtrHE/O6EOGQf58qH3kZmIhZ32tejJ57c67cXhqbaswUU8WhN4LkhdINrNcpKvnWBd6v2nmEUrmgvi/aL6DIG+OgUyFys0l5BQOeGqzEEYXQgR9ppwDl/QadKpIBgm87qPnhzR++EPKzScgqgqT8D8uw2A96Mj02HXS1n74eCViW+M04UiQ0p0Rq9RMs5EtVJMo2CuArHaPsvsjkUTVdsSROoRTvBzq+T1WmCZJzDvITPZ0hbpD5pTeaXHm7qItQIDAQAB' | ||
11 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' | ||
12 | VUE_APP_TOKEN_KEY = 'kd_template_token' | ||
13 | VUE_APP_IS_POST_ENC = true | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,3 +2,12 @@ NODE_ENV = 'production' | ... | @@ -2,3 +2,12 @@ NODE_ENV = 'production' |
2 | VUE_APP_TITLE = 'sandbox' | 2 | VUE_APP_TITLE = 'sandbox' |
3 | VUE_APP_PUBLIC_PATH = './' | 3 | VUE_APP_PUBLIC_PATH = './' |
4 | VUE_APP_OUTPUT_DIR = 'sandbox' | 4 | VUE_APP_OUTPUT_DIR = 'sandbox' |
5 | |||
6 | |||
7 | VUE_APP_ENV = 'demo' | ||
8 | VUE_APP_MODULE_CODE = '6f9f27c42878499a965c94bc8f203b23' | ||
9 | VUE_APP_BASE_API = 'https://bizapi.kdao.xin' | ||
10 | VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+87WEJxYnlMOzoDHBgMTmkQyVSMdYRi4tqcnqTibTqEB6xbL5S2w8kjq5ItMKjNcrFvdlh/oj+Qb2LtrHE/O6EOGQf58qH3kZmIhZ32tejJ57c67cXhqbaswUU8WhN4LkhdINrNcpKvnWBd6v2nmEUrmgvi/aL6DIG+OgUyFys0l5BQOeGqzEEYXQgR9ppwDl/QadKpIBgm87qPnhzR++EPKzScgqgqT8D8uw2A96Mj02HXS1n74eCViW+M04UiQ0p0Rq9RMs5EtVJMo2CuArHaPsvsjkUTVdsSROoRTvBzq+T1WmCZJzDvITPZ0hbpD5pTeaXHm7qItQIDAQAB' | ||
11 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' | ||
12 | VUE_APP_TOKEN_KEY = 'kd_template_token' | ||
13 | VUE_APP_IS_POST_ENC = true | ... | ... |
... | @@ -7,7 +7,7 @@ npm install | ... | @@ -7,7 +7,7 @@ npm install |
7 | 7 | ||
8 | ### Compiles and hot-reloads for development | 8 | ### Compiles and hot-reloads for development |
9 | ``` | 9 | ``` |
10 | npm run serve | 10 | npm run dev |
11 | ``` | 11 | ``` |
12 | 12 | ||
13 | ### Compiles and minifies for production | 13 | ### Compiles and minifies for production |
... | @@ -25,5 +25,22 @@ npm run test | ... | @@ -25,5 +25,22 @@ npm run test |
25 | npm run lint | 25 | npm run lint |
26 | ``` | 26 | ``` |
27 | 27 | ||
28 | ### Customize configuration | 28 | |
29 | See [Configuration Reference](https://cli.vuejs.org/config/). | 29 | # 配置 |
30 | ## 环境配置 | ||
31 | 配置说明: | ||
32 | 本地环境: .env.development | ||
33 | 沙箱环境: .env.sandbox | ||
34 | 正式环境: .env.development | ||
35 | |||
36 | ## 配置项说明 | ||
37 | ```bash | ||
38 | # 接口环境 | ||
39 | VUE_APP_ENV = 'demo' # 请求头环境参数:demo/prod,即开发/生产。不填写默认连接prod。 | ||
40 | VUE_APP_MODULE_CODE = '' # 请求头module code,由后端提供。 | ||
41 | VUE_APP_BASE_API = '' # api请求域名 | ||
42 | VUE_APP_RSA_PUBLIC_KEY = '' # 加密公钥 | ||
43 | VUE_APP_AES_IV = '' # 加密偏移量 | ||
44 | VUE_APP_TOKEN_KEY = 'kd_template_token' # 埋cookies时,token以该值为key | ||
45 | VUE_APP_IS_POST_ENC = true # 该值为true所有post接口请求加密;为false不加密,但可配置opt.enc=true自定义接口加密 | ||
46 | ``` | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -17,15 +17,16 @@ import { | ... | @@ -17,15 +17,16 @@ import { |
17 | 17 | ||
18 | import api from '@/api/api'; | 18 | import api from '@/api/api'; |
19 | 19 | ||
20 | |||
20 | // axios的默认url | 21 | // axios的默认url |
21 | // axios.defaults.baseURL = "" | 22 | // axios.defaults.baseURL = "" |
23 | let base = process.env.VUE_APP_BASE_API; | ||
24 | const ENV = process.env.VUE_APP_ENV; | ||
25 | const MODULE_CODE = process.env.VUE_APP_MODULE_CODE; | ||
26 | const IS_POST_ENC = process.env.VUE_APP_IS_POST_ENC; | ||
27 | // 默认超时 | ||
28 | axios.defaults.timeout = 5000; | ||
22 | 29 | ||
23 | // 服务器地址 | ||
24 | // let base = process.env.VUE_APP_API_HOST + "/jxMallApi"; | ||
25 | let base = "https://ow.go.qudone.com"; | ||
26 | if (location.href.indexOf("//k.wxpai.cn") > 0) { | ||
27 | base = "https://api.k.wxpai.cn/bizproxy" | ||
28 | } | ||
29 | 30 | ||
30 | // 请求拦截器 | 31 | // 请求拦截器 |
31 | // axios.interceptors.request.use( | 32 | // axios.interceptors.request.use( |
... | @@ -98,28 +99,31 @@ axios.interceptors.response.use( | ... | @@ -98,28 +99,31 @@ axios.interceptors.response.use( |
98 | ); | 99 | ); |
99 | 100 | ||
100 | 101 | ||
101 | //formDataHeaders设置 | ||
102 | let formDataHeaders = { | ||
103 | headers: { | ||
104 | "Content-Type": "multipart/form-data" | ||
105 | } | ||
106 | } | ||
107 | |||
108 | /** | 102 | /** |
109 | * 封装get方法 | 103 | * 分解参数&拦截请求 |
110 | * @param {*} params | ||
111 | * | ||
112 | */ | 104 | */ |
113 | export const httpGet = params => { | 105 | function analysisParams(params) { |
114 | let { | 106 | let { |
115 | url, | 107 | url, |
116 | data, | 108 | data, |
117 | mode, | 109 | mode, |
118 | opt = Object.assign({}, params.opt), | 110 | opt = Object.assign({}, params.opt), |
119 | sid = true | 111 | sid = true, |
112 | config, | ||
113 | method | ||
120 | } = params; | 114 | } = params; |
121 | if (opt.enc) { | 115 | if (IS_POST_ENC == 'true') { |
122 | data = makeEncrypt(data); | 116 | if (method == 'post') { |
117 | data = makeEncrypt(data); | ||
118 | } | ||
119 | } else { | ||
120 | if (opt.enc) { | ||
121 | data = makeEncrypt(data); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | if (opt.dec) { | ||
126 | data = makerypt(data); | ||
123 | } | 127 | } |
124 | let reqUrl = `${base}${url}`; | 128 | let reqUrl = `${base}${url}`; |
125 | if (mode == "custom") { | 129 | if (mode == "custom") { |
... | @@ -128,7 +132,32 @@ export const httpGet = params => { | ... | @@ -128,7 +132,32 @@ export const httpGet = params => { |
128 | let headers = {} | 132 | let headers = {} |
129 | if (sid) { | 133 | if (sid) { |
130 | headers.sessionId = getToken(); | 134 | headers.sessionId = getToken(); |
135 | headers['-kd-platform-module'] = MODULE_CODE | ||
136 | headers['-kd-platform-env'] = ENV | ||
131 | } | 137 | } |
138 | return { | ||
139 | reqUrl, | ||
140 | data, | ||
141 | headers, | ||
142 | opt, | ||
143 | method, | ||
144 | config | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * 封装get方法 | ||
150 | * @param {*} params | ||
151 | */ | ||
152 | export const httpGet = params => { | ||
153 | params.method = 'get'; | ||
154 | let { | ||
155 | reqUrl, | ||
156 | data, | ||
157 | headers, | ||
158 | opt, | ||
159 | method | ||
160 | } = analysisParams(params); | ||
132 | return axios.get(reqUrl, { | 161 | return axios.get(reqUrl, { |
133 | params: data, | 162 | params: data, |
134 | headers, | 163 | headers, |
... | @@ -138,27 +167,18 @@ export const httpGet = params => { | ... | @@ -138,27 +167,18 @@ export const httpGet = params => { |
138 | 167 | ||
139 | /** | 168 | /** |
140 | * 封装post方法 | 169 | * 封装post方法 |
170 | * mode为custom时,忽略baseUrl | ||
141 | * @param {*} params | 171 | * @param {*} params |
142 | */ | 172 | */ |
143 | export const httpPost = params => { | 173 | export const httpPost = params => { |
174 | params.method = 'post'; | ||
144 | let { | 175 | let { |
145 | url, | 176 | reqUrl, |
146 | data, | 177 | data, |
147 | mode, | 178 | headers, |
148 | opt = Object.assign({}, params.opt), | 179 | opt, |
149 | sid = true | 180 | method |
150 | } = params; | 181 | } = analysisParams(params); |
151 | if (opt.enc) { | ||
152 | data = makeEncrypt(data); | ||
153 | } | ||
154 | let reqUrl = `${base}${url}`; | ||
155 | if (mode == "custom") { | ||
156 | reqUrl = `${url}` | ||
157 | } | ||
158 | let headers = {} | ||
159 | if (sid) { | ||
160 | headers.sessionId = getToken(); | ||
161 | } | ||
162 | return axios.post(reqUrl, data, { | 182 | return axios.post(reqUrl, data, { |
163 | headers, | 183 | headers, |
164 | opt | 184 | opt |
... | @@ -186,7 +206,11 @@ export const formdata = params => { | ... | @@ -186,7 +206,11 @@ export const formdata = params => { |
186 | for (let key in data) { | 206 | for (let key in data) { |
187 | formData.append(key, data[key]); | 207 | formData.append(key, data[key]); |
188 | } | 208 | } |
189 | return axios.post(`${base}${url}`, formData, formDataHeaders).then(res => res.data.content); | 209 | return axios.post(`${base}${url}`, formData, { |
210 | headers: { | ||
211 | "Content-Type": "multipart/form-data" | ||
212 | } | ||
213 | }).then(res => res.data.content); | ||
190 | } | 214 | } |
191 | 215 | ||
192 | 216 | ... | ... |
1 | import Cookies from 'js-cookie' | 1 | import Cookies from 'js-cookie' |
2 | 2 | ||
3 | const TokenKey = 'temp-app-token' | 3 | const TokenKey = process.env.VUE_APP_TOKEN_KEY; // TokenKey 自行配置 |
4 | 4 | ||
5 | export function getToken() { | 5 | export function getToken() { |
6 | return Cookies.get(TokenKey) | 6 | return Cookies.get(TokenKey) | ... | ... |
... | @@ -11,8 +11,8 @@ let rsa = new JsEncrypt(); | ... | @@ -11,8 +11,8 @@ let rsa = new JsEncrypt(); |
11 | * iv 偏移量 | 11 | * iv 偏移量 |
12 | */ | 12 | */ |
13 | export function makeEncrypt(param) { | 13 | export function makeEncrypt(param) { |
14 | let key = ""; | 14 | let key = process.env.VUE_APP_RSA_PUBLIC_KEY; // process.env.AES_KEY |
15 | let iv = "" | 15 | let iv = process.env.VUE_APP_AES_IV; // process.env.AES_IV |
16 | rsa.setPublicKey(key); | 16 | rsa.setPublicKey(key); |
17 | let chars = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(","); | 17 | let chars = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(","); |
18 | 18 | ... | ... |
-
Please register or sign in to post a comment