Commit ec78b36f by zhanghaozhe

weixin config

parent 2f4d90b4
...@@ -5,7 +5,7 @@ import { connect } from "react-redux"; ...@@ -5,7 +5,7 @@ import { connect } from "react-redux";
import { setCurrentUser, startFetchUser } from "@/store/userAction"; import { setCurrentUser, startFetchUser } from "@/store/userAction";
import { withRouter } from 'react-router-dom' import { withRouter } from 'react-router-dom'
import { compose } from 'redux' import { compose } from 'redux'
import { getParam, http } from "@/utils"; import { getParam, http, browser } from "@/utils";
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { addDays } from 'date-fns' import { addDays } from 'date-fns'
...@@ -41,6 +41,10 @@ class App extends Component { ...@@ -41,6 +41,10 @@ class App extends Component {
//平台信息 //平台信息
cookie.set('plat', '5', {domain: '.julyedu.com'}) cookie.set('plat', '5', {domain: '.julyedu.com'})
if(browser.isWeixin && browser.isIOS){
sessionStorage.setItem('enter_url', window.location.href)
}
this.props.startFetchUser() this.props.startFetchUser()
http.get(`${API.home}/m/user_info`).then(res => { http.get(`${API.home}/m/user_info`).then(res => {
this.props.setCurrentUser(this.transformUser(res)) this.props.setCurrentUser(this.transformUser(res))
...@@ -51,7 +55,7 @@ class App extends Component { ...@@ -51,7 +55,7 @@ class App extends Component {
history.listen(location => { history.listen(location => {
const {pathname} = location const {pathname} = location
if (pathname.startsWith('/passport')) { if (pathname.startsWith('/passport')) {
if(routeMatchRule.test(pathname)){ if (routeMatchRule.test(pathname)) {
return return
} }
location.state = {from: this.previousLocation}; location.state = {from: this.previousLocation};
...@@ -159,7 +163,12 @@ class App extends Component { ...@@ -159,7 +163,12 @@ class App extends Component {
} }
render() { render() {
return <Routes/> return (
<>
<div style={{position: 'fixed', bottom: '0', right: '0', fontSize: '20px', color: 'red', zIndex: '1000'}} onClick={e => {alert(location.href)}}>url</div>
<Routes/>
</>
)
} }
} }
......
...@@ -46,12 +46,14 @@ class Detail extends Component { ...@@ -46,12 +46,14 @@ class Detail extends Component {
} }
componentDidMount() { componentDidMount() {
wxShare({ if(browser.isWeixin){
title: `课程详情页`, wxShare({
desc: `课程详情页`, title: `课程详情页`,
link: encodeURI(location.origin + '/detail?id=' + getParam('id')), desc: `课程详情页`,
imgUrl: '' link: location.href,
}); imgUrl: `${location.origin}/favicon.ico`
})
}
this.fetchCourseInfo(); this.fetchCourseInfo();
const { location: { state = {} } } = this.props; const { location: { state = {} } } = this.props;
......
import { http } from "@/utils/index" import { http, browser } from "@/utils"
const url = `https://res.wx.qq.com/open/js/jweixin-1.4.0.js` const url = `https://res.wx.qq.com/open/js/jweixin-1.4.0.js`
...@@ -7,7 +7,7 @@ const jsApiList = ['updateAppMessageShareData','updateTimelineShareData','onMenu ...@@ -7,7 +7,7 @@ const jsApiList = ['updateAppMessageShareData','updateTimelineShareData','onMenu
export const getSignature = async (config = {}) => { export const getSignature = async (config = {}) => {
let res = await http.post(`${API['base-api']}/m/sale/signature`, { let res = await http.post(`${API['base-api']}/m/sale/signature`, {
url: window.location.href.split('#')[0] url: browser.isWeixin && browser.isIOS ? sessionStorage.getItem('enter_url') : window.location.href.split('#')[0],
}) })
return wx.config({ return wx.config({
debug: false, // 开启调试模式, debug: false, // 开启调试模式,
......
import { getWXObject, getSignature } from './base' import { getWXObject, getSignature } from './base'
const shareApiList = ['updateAppMessageShareData','updateTimelineShareData','onMenuShareAppMessage', 'onMenuShareTimeline'] const shareApiList = ['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline']
export default async function (data = {title: '',desc: '', link: '', imgUrl: ''}) { export default async function (data = {title: '', desc: '', link: '', imgUrl: ''}, config = {}) {
await getWXObject() await getWXObject()
await getSignature() await getSignature(config)
wx.ready(function () { wx.ready(function () {
console.log('ready'); console.log('ready');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment