hookehuyr

✨ feat: 配置API接口请求,处理cookie参数问题

1 /* 1 /*
2 * @Date: 2022-09-19 14:11:05 2 * @Date: 2022-09-19 14:11:05
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-09-28 14:18:13 4 + * @LastEditTime: 2022-10-09 18:09:06
5 * @FilePath: /swx/src/app.js 5 * @FilePath: /swx/src/app.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -10,10 +10,31 @@ import { createPinia } from 'pinia' ...@@ -10,10 +10,31 @@ import { createPinia } from 'pinia'
10 10
11 import './app.less' 11 import './app.less'
12 import '@/components/vant-weapp/common/index.wxss' 12 import '@/components/vant-weapp/common/index.wxss'
13 +import request from './utils/request';
13 14
14 const App = createApp({ 15 const App = createApp({
15 // 可以使用所有的 Vue 生命周期方法 16 // 可以使用所有的 Vue 生命周期方法
16 - mounted() { }, 17 + mounted() {
18 + // TODO: 现在先传openid,小程序的密钥还有搞到
19 + // 保存主办方信息
20 + request.post('/srv/?a=openid', {
21 + openid: 'wxa2e50e76487d1d7b'
22 + })
23 + .then(res => {
24 + if (res.data.code) {
25 + // console.warn(res.data.data);
26 + var cookie = res.cookies[0];
27 + if (cookie != null) {
28 + wx.setStorageSync("sessionid", res.cookies[0]);//服务器返回的 Set-Cookie,保存到本地
29 + }
30 + } else {
31 + console.warn(res.data.msg);
32 + }
33 + })
34 + .catch(err => {
35 + console.error(err);
36 + });
37 + },
17 38
18 // 对应 onLaunch 39 // 对应 onLaunch
19 onLaunch() { }, 40 onLaunch() { },
......
1 /* 1 /*
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-09-19 14:19:05 4 + * @LastEditTime: 2022-10-09 15:41:43
5 * @FilePath: /swx/src/utils/config.js 5 * @FilePath: /swx/src/utils/config.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
8 -const BASE_URL = "http://voice.onwall.cn"; 8 +const BASE_URL = "http://wenxuan.onwall.cn";
9 9
10 export default BASE_URL 10 export default BASE_URL
......
1 /* 1 /*
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-09-19 14:19:18 4 + * @LastEditTime: 2022-10-09 18:21:32
5 * @FilePath: /swx/src/utils/request.js 5 * @FilePath: /swx/src/utils/request.js
6 * @Description: 简单axios封装,后续按实际处理 6 * @Description: 简单axios封装,后续按实际处理
7 */ 7 */
...@@ -16,17 +16,21 @@ import BASE_URL from './config'; ...@@ -16,17 +16,21 @@ import BASE_URL from './config';
16 const service = axios.create({ 16 const service = axios.create({
17 baseURL: BASE_URL, // url = base url + request url 17 baseURL: BASE_URL, // url = base url + request url
18 // withCredentials: true, // send cookies when cross-domain requests 18 // withCredentials: true, // send cookies when cross-domain requests
19 - timeout: 5000 // request timeout 19 + timeout: 5000, // request timeout
20 + headers: {
21 + //TAG 小程序绑定cookie
22 + 'cookie': wx.getStorageSync("sessionid") //读取本地保存好的上⼀次cookie
23 + }
20 }) 24 })
21 25
22 service.defaults.params = { 26 service.defaults.params = {
23 - f: 'voice', 27 + f: 'swx',
24 }; 28 };
25 29
26 // request interceptor 30 // request interceptor
27 service.interceptors.request.use( 31 service.interceptors.request.use(
28 config => { 32 config => {
29 - console.warn(config) 33 + // console.warn(config)
30 // console.warn(store) 34 // console.warn(store)
31 35
32 return config 36 return config
......