Bläddra i källkod

配置代理、测试对接本地Java服务接口

test
Dingei 11 månader sedan
förälder
incheckning
b532e6340c
7 ändrade filer med 149 tillägg och 12 borttagningar
  1. +14
    -0
      src/api/optimize.js
  2. +1
    -0
      src/config/env.development.js
  3. +1
    -0
      src/config/env.production.js
  4. +1
    -0
      src/config/env.testing.js
  5. +98
    -0
      src/config/request_java.js
  6. +14
    -1
      src/views/optimize/index.vue
  7. +20
    -11
      vue.config.js

+ 14
- 0
src/api/optimize.js Visa fil

@@ -0,0 +1,14 @@
import request from '@/config/request_java';

export const APIOptimize = {
getExpertList // 获取专家列表
};
export default APIOptimize;

// 获取专家列表
function getExpertList() {
return request({
url: `/java_api/optimize/getExpertList`,
method: 'get'
});
}

+ 1
- 0
src/config/env.development.js Visa fil

@@ -3,6 +3,7 @@ module.exports = {
title: '健康同学',
baseUrl: 'https://id.ssjlai.com/webapi', // 项目地址
baseApi: 'https://id.ssjlai.com/webapi', // 本地api请求地址,注意:如果你使用了代理,请设置成'/'
javaAPI: '/', // Java服务api
APPID: 'xxx',
APPSECRET: 'xxx'
};

+ 1
- 0
src/config/env.production.js Visa fil

@@ -3,6 +3,7 @@ module.exports = {
title: '健康同学',
baseUrl: 'https://id.ssjlai.com/webapi', // 正式项目地址
baseApi: 'https://id.ssjlai.com/webapi', // 正式api请求地址
javaAPI: 'https://id.ssjlai.com/healthstudent', // 正式环境-Java服务api
APPID: 'xxx',
APPSECRET: 'xxx'
};

+ 1
- 0
src/config/env.testing.js Visa fil

@@ -2,6 +2,7 @@ module.exports = {
title: '健康同学',
baseUrl: 'https://id.ssjlai.com/webapi', // 测试项目地址
baseApi: 'https://id.ssjlai.com/webapi', // 测试api请求地址
javaAPI: 'https://id.ssjlai.com/healthstudent', // 测试环境-Java服务api
APPID: 'xxx',
APPSECRET: 'xxx'
};

+ 98
- 0
src/config/request_java.js Visa fil

@@ -0,0 +1,98 @@
/*
* @Author: linwl
* @Date: 2020-04-13 14:47:59
* @LastEditTime: 2023-06-15 10:32:04
* @LastEditors: JinxChen
* @Description: axios请求配置
* @FilePath: \ParentWeb\src\config\request.js
*/
import axios from 'axios';
import router from '@/router';
import { javaAPI } from '@/config';
import prefix from '@/store/prefix';
const httpProxyPrefix = javaAPI;

// create an axios instance axios.create创建一个实例
const service = axios.create({
// baseURL: process.env.VUE_APP_BASE_API,
baseURL: httpProxyPrefix
// timeout: 5000 // request timeout
});

const errorHandler = error => {
// const status = get(error, 'response.status');
const status = error.response.status;
console.log(status);
switch (status) {
case 400:
error.message = '请求错误';
break;
case 401:
error.message = '未授权,请登录';
break;
case 403:
error.message = '拒绝访问';
break;
case 404:
error.message = '请求地址出错';
break;
case 408:
error.message = '请求超时';
break;
case 500:
error.message = '服务器内部错误';
break;
case 501:
error.message = '服务未实现';
break;
case 502:
error.message = '网关错误';
break;
case 503:
error.message = '服务器不可用';
break;
case 504:
error.message = '网关超时';
break;
case 505:
error.message = 'HTTP版本不受支持';
break;
default:
break;
}
this.$notify({ message: `您的网络异常(${error.message})`, type: 'warning' });
return Promise.reject(error);
};

// 请求拦截器,增加 token interceptors拦截
service.interceptors.request.use(request => {
if (localStorage.getItem(prefix + 'authToken')) {
request.headers.AuthToken = localStorage.getItem(prefix + 'authToken');
} else if (
window.location.href.indexOf('login') < 0 &&
window.location.href.indexOf('forgetPassword') < 0 &&
window.location.href.indexOf('verifyInfos') < 0 &&
window.location.href.indexOf('register') < 0 &&
window.location.href.indexOf('verificationLogin') < 0 &&
window.location.href.indexOf('changePassword') < 0
) {
router.push({ name: 'login' });
return request;
}
// 全局请求统一增加一个 sourcetype: 1的参数跟区分新旧接口
if (request.method == 'get') {
request.params = {
...request.params,
sourcetype: 1
};
} else if (request.method == 'post') {
request.data = {
...request.data,
sourcetype: 1
};
}

return request;
}, errorHandler);

export default service;

+ 14
- 1
src/views/optimize/index.vue Visa fil

@@ -133,6 +133,7 @@

<script>
import Vue from 'vue';
import APIOptimize from '@/api/optimize';
import TabBar from '@/components/TabBar';
import expertImage from '@/assets/optimize/images/3_08.png';
import { Swipe, SwipeItem, Lazyload } from 'vant';
@@ -161,9 +162,21 @@ export default {
]
};
},
created() {},
created() {
this.init();
},
mounted() {},
methods: {
init() {
// 专家列表
APIOptimize.getExpertList()
.then(res => {
console.log(res);
})
.catch(e => {
console.log(e);
})
},
goExperts(id) {
this.$router.push({
name: 'experts',


+ 20
- 11
vue.config.js Visa fil

@@ -21,18 +21,27 @@ module.exports = defineConfig({
hot: true, //热更新
client: {
overlay: false //报错是否显示遮罩层,不显示
},
proxy: {
// //配置跨域
// '/api': {
// target: "https://test.xxx.com",
// // ws:true,
// changOrigin:true,
// pathRewrite:{
// '^/api':'/'
// }
// }
//配置跨域
'/java_api': {
target: "http://127.0.0.1:8010/",
// ws:true,
changOrigin:true,
pathRewrite:{
'^/java_api':'/'
}
}
}
// proxy: {
// //配置跨域
// '/api': {
// target: "https://test.xxx.com",
// // ws:true,
// changOrigin:true,
// pathRewrite:{
// '^/api':'/'
// }
// }
// }
},
css: {
extract: true, // 是否将组件中的 CSS 提取至一个独立的 CSS 文件中 (而不是动态注入到 JavaScript 中的 inline 代码)。


Laddar…
Avbryt
Spara