nalinv-mobile/README.md

68 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## MOM 移动端
## 下载 HBuilderX
https://www.dcloud.io/hbuilderx.html
## 下载微信开发者工具
https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html
## 配置开发者工具
![](README_files/5.jpg)
![](README_files/2.jpg)
## HBuilderX
![](README_files/3.jpg)
## 后台配置跨域
### 网关跨域配置
## nacos 配置如下配置即可
- nacos mom-gateway-dev.yml
````
spring:
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOriginPatterns: '*' #注意这个设置只对 spring boot 2.4+ 有效, mom v4.0+ ,低版本 使用 allowedOrigins: "*"
allowed-methods: '*'
allowed-headers: '*'
allow-credentials: true
exposedHeaders: 'Content-Disposition,Content-Type,Cache-Control'
````
以上配置可作为开发环境使用,生成环境建议你根据实际情况修改(请先理解 CORS,并参考 org.springframework.cloud.gateway.config.GlobalCorsProperties) 跨域时会产生预检请求(Pre-Flight Request),这样就会对你的服务器产生额外的网络请求。如果可以通过部署手段解决跨域,则可以关闭跨域支持,方法是把以上配置信息清理掉。
## 测试
为了演示跨域支持效果,可以修改一下前端项目(momx-ui)的登录代码
* login.js
````
export const loginByUsername = (username, password, code, randomStr) => {
const grant_type = 'password';
return request({
// 原来的API接口地址
//url: '/auth/oauth/token',
// 为了触发跨域,直接修改为网关的url,这里的IP需要改成你自己的,要用真实IP
url: 'http://127.0.0.1:9999/auth/oauth/token',
headers: {
isToken: false,
Authorization: 'Basic cGlnOnBpZw==',
},
method: 'post',
params: { username, password, randomStr, code, grant_type, scope },
});
};
````
* 登录会发出两个请求, 一个是 options 预检查、一个是实际的请求
![](README_files/1.png)