feat:设置跨域代理

This commit is contained in:
eric
2023-12-03 19:11:19 +08:00
parent 19b4aa7960
commit 7195361a4f
3 changed files with 81 additions and 8 deletions

View File

@@ -67,9 +67,24 @@ const config = {
router: {
mode: 'browser', // 或者是 'browser'
},
// defineConstants: {
// HOST: '"/api"'
// },
// devServer: {
// proxy: {
// '/api/': {
// target: JSON.parse('"http://localhost:8082"'),
// pathRewrite: {
// '^/api/': '/'
// },
// changeOrigin: true
// }
// }
// }
}
}
module.exports = function (merge) {
if (process.env.NODE_ENV === 'development') {
return merge({}, config, require('./dev'))

View File

@@ -38,9 +38,9 @@ const Index = () => {
} else {
// window.alert('不存在')
let nowUrl = window.location.href;
window.alert(nowUrl)
// window.alert(nowUrl)
let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`;
window.location.href = payUrl;
// window.location.href = payUrl;
}
};
@@ -214,7 +214,7 @@ const Index = () => {
className="submitBtn"
onClick={() => {
Taro.navigateTo({
url: "/pages/meetup/Detail/index?id=20231206&openid='",
url: "/pages/meetup/Detail/index?id=20231206",
});
}}
>

View File

@@ -17,9 +17,17 @@ import { AtList, AtListItem } from "taro-ui";
// export default class Index extends Component {
const Detail = () => {
const [current, setcurrent] = useState(2);
const [id, setid] = useState(2);
const [openid, setopenid] = useState(2);
const [id, setid] = useState(null);
const [openid, setopenid] = useState(null);
const [joinMeetup, setjoinMeetup] = useState(false);
useEffect(() => {
let newparams = Taro.getCurrentInstance().router.params;
let newId = newparams.id;
if (newId) {
setid(newId);
}
}, []);
const handleClick = (value) => {
console.log("value", value);
@@ -40,11 +48,57 @@ const Detail = () => {
}
};
const onBridgeReady = () => {
WeixinJSBridge.call("hideOptionMenu");
};
useEffect(() => {
let $instance =Taro. getCurrentInstance()
let $instance = Taro.getCurrentInstance();
// console.log("11");
console.log($instance.router.params)
console.log($instance.router.params);
// if (typeof WeixinJSBridge == "undefined") {
// if (document.addEventListener) {
// document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
// } else if (document.attachEvent) {
// document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
// document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
// }
// }
}, []);
const joinmeet = () => {
console.log("111");
Taro.request({
method:'POST',
url: "/api//payh5", //仅为示例,并非真实的接口地址
data: {},
header: {
"content-type": "application/json", // 默认值
},
success: function (res) {
console.log(res.data);
window.alert(res.data);
WeixinJSBridge.invoke(
"getBrandWCPayRequest",
{
// 以下6个支付参数通过payjs的jsapi接口获取
// appId: "wxc5205a653b0259bf",
// timeStamp: "1701401644",
// nonceStr: "KhOYB0wFV6j9qyQK",
// package: "prepay_id=wx01113404850024729b35f4d69b73500000",
// signType: "MD5",
// paySign: "2A823C8D47CCF871C6C65A56DC228CF8",
...res.data,
},
function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
WeixinJSBridge.call("closeWindow");
}
}
);
},
});
};
return (
<View className="Detail">
{/* <Text>Hello world!</Text> */}
@@ -86,7 +140,11 @@ const Detail = () => {
</AtList> */}
<View>
<AtButton className="bottomBtn" type="primary">
<AtButton
className="bottomBtn"
type="primary"
onClick={() => joinmeet()}
>
立即报名
</AtButton>
</View>