Authored by 李奇

页面初始化

import httpService from '../../../common/httpService'
import config from '../config'
let conf = query => httpService.get(config.domain + '/activity/wheelSurf/conf', query);
let start = () => httpService.get(config.domain + '/activity/wheelSurf/start');
module.exports = {conf, start};
\ No newline at end of file
... ...
module.exports = {
production: {
routerPath: '/html5/2018/09/wheelSurf',
domain: 'https://action.yoho.cn'
},
development: {
routerPath: '',
// domain: '//yoho-activity-platform.test3.ingress.dev.yohocorp.com'
domain: 'http://localhost:6006'
}
}[process.env.NODE_ENV || 'development']
\ No newline at end of file
... ...
import Loadable from "react-loadable";
import React from 'react';
const home = Loadable({
loader: () => import(/* webpackChunkName: "home" */'./view/home'),
loading(){
return <div></div>
},
});
module.exports = {
home
};
... ...
module.exports = {
home:'大转盘'
};
\ No newline at end of file
... ...
import React, {PureComponent} from 'react';
import './index.scss'
import {conf, start} from '../../api'
import {getQueryObj, linkToMiniApp, invokeMethod, parseUrl} from '../../../../common/utils';
import wxshare from '../../../../common/wxshare'
import wx from 'weixin-js-sdk';
import config from '../../config';
import cookie from 'react-cookies';
import LazyLoad from 'react-lazy-load'
const {actId} = getQueryObj();
export default class wheelSurf extends PureComponent {
constructor(props) {
document.title ='大转盘'
super(props);
this.state = {
env: '',
url: ''
}
// this.collect = this.collect.bind(this);
this.init();
// 微信分享
// let shareData={
// title: '国潮崛起年,中西碰撞博出位!',
// imgUrl: 'https://img01.yohoboys.com/o_1cnilugbs15ajak1gfo1d2h1p348.png?imageView2/1/w/200/h/200',
// desc: '这里有一份中西潮流榜单,请收好!',
// link: 'https://ad.yoho.cn/html5/2018/09/guochao/guochao.html',
// success: function () {
//
// }
// }
// wxshare(shareData);
}
init = async () => {
let uid = cookie.load('app_uid') || getQueryObj().uid || 0;
if(!uid || !parseInt(uid)){
return;
}
let result = await conf({
actId,
uid: uid,
sessionKey: cookie.load('app_session_key') || getQueryObj().session_key || '',
sessionType: cookie.load('app_client_type') || '',
appVersion: cookie.load('app_version') || ''
});
this.setState({
storage: result.data
})
}
collect = async (id) => {
//判断是否是clicked
if (this.state.storage[id]) {
return;
} else {
//判断用户登陆 未登陆跳登陆
if (!parseInt(getQueryObj().uid)) {
if (this.state.env === 'miniprogram') {
return wx.miniProgram.switchTab({url: '/pages/userCenter/userCenter'});
}
else {
return this.goLogin('http://ad.yoho.cn/html5/2018/09/guochao/guochao.html')
}
}
//发送请求
let result = await collectApi({
id: id,
uid: cookie.load('app_uid') || getQueryObj().uid || 0,
sessionKey: cookie.load('app_session_key') || getQueryObj().session_key || '',
sessionType: cookie.load('app_client_type') || '',
appVersion: cookie.load('app_version') || ''
});
if (!result.result)
return;
//替换图标
let storage = this.state.storage;
storage[id] = true;
this.setState({
storage
})
this.forceUpdate();
}
};
goLogin = (refer, data) => {
let url;
if (refer.indexOf('//') === 0) {
refer = location.protocol + refer;
}
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
refer = parseUrl(refer || location.href);
if (this.state.env == 'app') {
if (/Android/i.test(navigator.userAgent || '')) {
if (url.indexOf('?') < 0) {
url += '?appLogin=1';
}
if (location.href.indexOf('&openby') >= 0) {
url = url.substring(0, url.indexOf('&openby'));
}
url += '&';
} else {
if (location.href.indexOf('#openby') >= 0) {
url = url.substring(0, url.indexOf('#openby'));
}
url += '#';
}
url += 'openby:yohobuy=' + (data || JSON.stringify({
action: 'go.weblogin',
params: {
priority: 'N',
jumpurl: {
url: refer.path,
param: refer.query
},
needlogout: 'Y'
}
}));
}
this.setState({url: url}, () => {
document.getElementById('url').click();
});
return false;
};
componentDidMount = () => {
window.addEventListener('scroll', this.handleScroll);
this.wxReady();
};
componentWillUnmount = () => {
window.removeEventListener('scroll', this.handleScroll);
};
handleScroll = () => {
let _this = this;
if (window.pageYOffset > 100) {
_this.setState({display: true});
} else {
_this.setState({display: false});
}
};
wxReady = async () => {
let envFlag = window.__wxjs_environment;
if (!envFlag && navigator.userAgent.match(/yohobuy/i)) {
document.addEventListener('deviceready', function () {
});
this.setState({env: "app"});
} else if (!envFlag && navigator.userAgent.match(/miniProgram/i)) {
this.setState({env: "miniprogram"});
envFlag = true
} else {
this.setState({env: 'h5'})
}
if (envFlag == 'miniprogram') {
if (wx.miniProgram.postMessage) {
wx.miniProgram.postMessage({
data: {
title: '大转盘'
}
});
}
this.setState({env: "miniprogram"});
}
};
scrollTop = () => {
let _this = this;
let timer = setTimeout(function () {
window.scrollBy(0, -100);
if (window.pageYOffset <= 0) {
clearTimeout(timer);
} else {
_this.scrollTop();
}
}, 20);
};
render() {
return (
<div className="wrap">
</div>
)
}
}
\ No newline at end of file
... ...
.wrap{
width: 100%;
height: 100%;
font-size: 12px;
background: red;
}
\ No newline at end of file
... ...
import {stringify} from 'query-string';
module.exports = {
postForm: (targetAPIUri, formData) => {
return fetch(targetAPIUri, {
... ... @@ -29,7 +31,11 @@ module.exports = {
return res2;
})
},
get: (targetAPIUri, formData) => {
get: (targetAPIUri, query) => {
if (query) {
targetAPIUri = `${targetAPIUri}?${stringify(query)}`
}
return fetch(targetAPIUri, {
method: 'get',
credentials: "include",
... ...
... ... @@ -57,6 +57,7 @@
"postcss-import": "^12.0.0",
"postcss-loader": "^3.0.0",
"postcss-pxtorem": "^4.0.1",
"query-string": "^6.2.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.20.3",
"url-loader": "^1.0.1",
... ...
... ... @@ -6,7 +6,7 @@ import HtmlWebpackPlugin from "html-webpack-plugin";
import config from "./config";
let pathsToClean = [
'build'
'dist'
];
let cleanOptions = {
root: __dirname,
... ...
This diff could not be displayed because it is too large.