Authored by 李奇

add: yas引入

... ... @@ -12,9 +12,12 @@ import { loginAction, checkUidAndSessionKey, getGlobalData } from './libs/login/
import { app_report } from './libs/services/appReport';
import {WeToast} from './vendors/toast/wetoast';
import {getYHStorageSync} from './utils/util'
import Yas from './utils/yas'
const store = createStore();
let yas;
@connect(({ globalData, user }) => ({
globalData
}), (dispatch) => {
... ... @@ -70,7 +73,7 @@ class App extends Component {
"pages/zeroSell/myList",
"pages/zeroSell/snapshootShare",
"pages/zeroSell/h5Page"
],
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
... ... @@ -110,6 +113,7 @@ class App extends Component {
};
componentWillMount () {
yas = new Yas(this);
wx.setStorageSync('show_bind', false);
let {setSystemInfo, wechatLogin, setSessionkey} = this.props;
let options = this.$router.params;
... ... @@ -169,7 +173,7 @@ class App extends Component {
}).catch(error => {
console.log(error);
});
event.on('user-is-login', (loginedCallBack, loginSuccess) => {
let userInfo = Taro.getStorageSync('userInfo');
if (userInfo && userInfo.uid) {
... ...
... ... @@ -9,7 +9,8 @@ export default {
yohoApi: 'http://api-test3.dev.yohocorp.com',
yohoLogin: 'http://java-yoho-wechat.test3.ingress.dev.yohocorp.com',
activityHost: 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com',
reportHost: 'https://app.yoho.cn/collect/v3'
reportHost: 'https://app.yoho.cn/collect/v3',
yasHost: 'https://analysis.yohobuy.com/yas_mobile'
},
apiParams: {
client_type: 'miniapp',
... ... @@ -33,7 +34,8 @@ export default {
yohoApi: 'https://api.yoho.cn',
yohoLogin: 'https://api.yoho.cn',
activityHost: 'https://action.yoho.cn',
reportHost: 'https://app.yoho.cn/collect/v3'
reportHost: 'https://app.yoho.cn/collect/v3',
yasHost: 'https://analysis.yohobuy.com/yas_mobile'
},
apiParams: {
client_type: 'miniapp',
... ...
... ... @@ -10,7 +10,9 @@ import { connect } from '@tarojs/redux';
import { loginAction, decodeUnionId, wechatUserIsBind } from '../../libs/login/login.js'
import getPrivateKey from '../../libs/request/getPrivateKey.js'
import router from '../../router/index.js'
import Yas from '../../utils/yas';
let yas;
@connect(({ filterMenu }) => ({
filterMenu
... ... @@ -48,7 +50,7 @@ export default class Index extends Component {
backgroundTextStyle: "dark",
onReachBottomDistance: 50
};
onPullDownRefresh() {
let filterMenu = this.props.filterMenu;
this.getProductData(filterMenu).then(isFinish => {
... ... @@ -60,7 +62,7 @@ export default class Index extends Component {
}).catch(error => {
Taro.stopPullDownRefresh();
});
}
async getResource() {
... ... @@ -90,6 +92,10 @@ export default class Index extends Component {
}
}
componentWillMount() {
yas = new Yas(this.$scope);
}
componentDidMount() {
let obj = {
page: {},
... ... @@ -112,6 +118,10 @@ export default class Index extends Component {
});
}
componentDidShow() {
yas.pageOpenReport();
}
componentWillReceiveProps(nextProps, oldProps) {
let curType = nextProps.filterMenu.indexType;
let oldCurType = oldProps && oldProps.filterMenu && oldProps.filterMenu.indexType;
... ... @@ -130,7 +140,7 @@ export default class Index extends Component {
obj = obj || filterMenu;
let type = obj.indexType;
console.log(type);
const pk = await getPrivateKey();
Taro.setStorage({ key: 'verifyKey', data: pk });
commonModel.search({
... ... @@ -140,7 +150,7 @@ export default class Index extends Component {
}).then(ret => {
if (ret && ret.code === 200) {
let list = ret.data && ret.data.product_list || [];
if (list.length === 0) {
this.setState({
stopLoading: Object.assign(stopLoading, { [type]: true })
... ... @@ -171,7 +181,7 @@ export default class Index extends Component {
}
}
// gotoNative() {
// Taro.navigateTo({
... ... @@ -192,7 +202,7 @@ export default class Index extends Component {
// }
// <Text onClick={this.gotoNative}>跳转原生页面</Text>
// <Button openType="getUserInfo" onGetUserInfo = { this.login } > 登录 < /Button>
goToSearch() {
router.go('search');
}
... ... @@ -224,14 +234,14 @@ export default class Index extends Component {
lowerThreshold='20'
onScrollToLower={this.onScrollToLower}>
<Resources isRefresh={ isRefresh } floors = { floors } code={ contentCode.index}></Resources>
<FilterMenu filterMenu={filterMenu} tabs={tabs} tabClass="border" fromPage="index"></FilterMenu>
{
list &&
<ProductList list={list}></ProductList>
}
<Image className="goYohoBuy" onClick={this.goYohoBuyMinApp.bind(this)} src={goYohoBuy} mode="aspectFill" />
</View>
</View>
... ...
import udid from './udid';
import Taro from '@tarojs/taro';
import config from '../config';
import rules from '../router/rules';
import { MD5 } from './crypto';
import { parse, stringify } from 'querystringify';
export default class yas {
constructor(app) {
let self = this;
this.app = app;
this.pvid = MD5(`${new Date().getTime()}${udid.get()}`).toString();
this.deviceInfo = {
os: '', // 系统类型
dm: '', // 设备型号
res: '', // 屏幕大小
osv: '', // 系统版本
ak: 'yohoufo_mp',
ch: '',
udid: udid.get()
};
// 获取设备信息
Taro.getSystemInfo({
success(res) {
self.language = res.language;
if (res.platform === 'devtools') {
// self.devEnv = true; //判断开发环境
}
Object.assign(self.deviceInfo, {
os: res.platform,
dm: res.model,
res: `${res.screenWidth}*${res.screenHeight}`,
osv: res.system,
});
}
});
}
uploadData(params) {
let sid = '';
if (this.app && this.app.globalData) {
sid = this.app.globalData.sid || '';
}
// 开发环境不上报
if (this.devEnv) {
return console.log(params);
}
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
return Taro.request({
url: config.domains.yasHost,
data: { _mlogs: JSON.stringify(params) },
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded',
'x-yoho-sid': MD5(sid).toString(),
},
});
}
report(event, info) {
let self = this;
for (let key in info) {
if (info[key]) {
info[key] = decodeURIComponent(info[key]);
}
}
const pageNameMap = {};
for (let i in rules) {
if (rules.hasOwnProperty(i) && rules[i].path) {
pageNameMap[rules[i].path] = i;
}
}
if (event === 'YB_SHARE_RESULT_L') {
info.PAGE_NAME = pageNameMap['/' + info.PATH];
}
let userInfo = info || {};
let statusInfo = { ln: this.language };
let user = Taro.getStorageSync('userInfo') || {};
userInfo.UNION_ID = user.unionid || user.union_id || Taro.getStorageSync('unionid') || '';
userInfo.APP_ID = config.appid || '';
if (!userInfo.PV_ID) {
userInfo.PV_ID = info.PV_ID;
}
return new Promise(resolve => {
Taro.getNetworkType({
success(res) {
switch (res.networkType) {
case 'wifi':
statusInfo.net = '1';
break;
case '2g':
statusInfo.net = '2';
break;
case '3g':
statusInfo.net = '3';
break;
case '4g':
statusInfo.net = '1';
break;
default:
statusInfo.net = '0';
break;
}
},
complete() {
self.app.globalData = self.app.globalData || {};
let ch = self.app.globalData.ch || '';
let uid = self.app.globalData.userInfo && self.app.globalData.userInfo.uid || '';
// ch = self.app.getUnion_type() || ch;
self.deviceInfo.ch = ch;
return resolve(self.uploadData({
status: statusInfo,
device: self.deviceInfo,
events: [{
param: userInfo,
ts: new Date().getTime(),
op: event,
uid: uid,
sid: self.app.globalData.sid || ''
}]
}));
}
});
});
}
pageOpenReport(pvid, extra) {
let pages = getCurrentPages();
let currentPage = pages[pages.length - 1];
let path = `/${currentPage.route}`,
options = currentPage.options || {},
copyOptions = Object.assign({}, options), // 拷贝options对象,用于获取当前页面参数
fromPage = options.fromPage || '',
fromParam = parse(decodeURIComponent(options.fromParam || ''));
let info = { PV_ID: pvid || this.pvid };
for (let i in rules) {
if (rules.hasOwnProperty(i) && rules[i].path === path) {
Object.assign(info, {
PAGE_PATH: path,
PAGE_NAME: rules[i].report && rules[i].report.pageName || i,
FROM_PAGE_NAME: fromPage && rules[fromPage].report && rules[fromPage].report.pageName || fromPage
});
delete copyOptions.fromPage; // 删除拷贝对象的两个from属性
delete copyOptions.fromParam;
info.PAGE_PARAM = stringify(copyOptions); // 获取当前页param
info.FROM_PAGE_PARAM = ''; // decodeURIComponent(options.fromParam || ''); // 获取来源页param
if (rules[i].report && rules[i].report.paramKey) {
info.PAGE_PARAM = decodeURIComponent(options[rules[i].report.paramKey] || '');
}
if (fromPage && rules[fromPage].report && rules[fromPage].report.paramKey) {
info.FROM_PAGE_PARAM = decodeURIComponent(fromParam[rules[fromPage].report.paramKey] || '');
}
}
}
this.report('YB_PAGE_OPEN_L', Object.assign(info, extra || {}));
}
}
... ...