Authored by huangyi

活动sdk init

... ... @@ -58,10 +58,11 @@
用法:
```
//这是一个callback方法
window.yo_sdk.getUid(function(uid){
//获取到uid执行内容
})
//执行返回的是一个Promise对象
window.yo_sdk.getUid().
then(function(uid){
console.log(uid);
})
```
... ...
... ... @@ -7,15 +7,17 @@
<title>Title</title>
</head>
<body>
<div id="aaa">232323</div>
<div class="auth">1111111</div>
<a class="auth" href="http://www.baidu.com">123123</a>
<div id="aaa">232323</div>
<script src="../build/sdk.js"></script>
<script>
window.yo_sdk.auth();
document.getElementById('aaa').onclick = function (event) {
yo_sdk.goLogin();
window.yo_sdk.getUid().then(function(uid){
console.log(uid);
})
}
</script>
</body>
</html>
\ No newline at end of file
</html>
... ...
{
"name": "yoho-activity-sdk",
"version": "1.0.0",
"description": "YOHO!前端js的功能封装包,主要用于在活动页面中,对主要功能的封装。",
"keywords": [
"YOHO!",
"JS-SDK"
],
"main": "build/sdk.js",
"scripts": {
"build": "webpack --mode development --config ./webpack.config.babel.js ",
"lint-js": "lint-js"
},
"config": {
"lintJs": [
{
"title": "JS",
"path": [
"."
"name": "yoho-activity-sdk",
"version": "1.0.0",
"description": "YOHO!前端js的功能封装包,主要用于在活动页面中,对主要功能的封装。",
"keywords": [
"YOHO!",
"JS-SDK"
],
"main": "build/sdk.js",
"scripts": {
"build": "webpack --mode development --config ./webpack.config.babel.js ",
"lint-js": "lint-js"
},
"config": {
"lintJs": [
{
"title": "JS",
"path": [
"."
]
}
]
}
]
},
"repository": {
"type": "git",
"url": "http://git.yoho.cn/fe/yoho-activity-sdk.git"
},
"author": "y.huang@yoho.cn",
"licenses": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-import": "^1.7.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"compression-webpack-plugin": "^1.1.11",
"copy-webpack-plugin": "^4.5.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"uglifyjs-webpack-plugin": "^2.0.1",
"file-loader": "^1.1.11",
"url-loader": "^1.0.1",
"webpack": "^4.17.2",
"webpack-cli": "^2.0.14",
"weixin-js-sdk": "^1.3.3",
"fetch-jsonp": "^1.1.3",
"eslint": "^3.19.0",
"eslint-config-yoho": "^1.0.1",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^2.0.3"
},
"dependencies": {},
"directories": {
"example": "example"
},
"license": "ISC"
},
"repository": {
"type": "git",
"url": "http://git.yoho.cn/fe/yoho-activity-sdk.git"
},
"author": "y.huang@yoho.cn",
"licenses": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-import": "^1.7.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"compression-webpack-plugin": "^1.1.11",
"copy-webpack-plugin": "^4.5.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"uglifyjs-webpack-plugin": "^2.0.1",
"file-loader": "^1.1.11",
"url-loader": "^1.0.1",
"webpack": "^4.17.2",
"webpack-cli": "^2.0.14",
"weixin-js-sdk": "^1.3.3",
"fetch-jsonp": "^1.1.3",
"eslint": "^3.19.0",
"eslint-config-yoho": "^1.0.1",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^2.0.3",
"promise-polyfill": "^8.1.0"
},
"dependencies": {},
"directories": {
"example": "example"
},
"license": "ISC"
}
... ...
... ... @@ -7,15 +7,15 @@ const env = base.env();
const loginUrl = base.loginUrl();
const login = new Login({loginUrl, env});
const goto = new Goto(env);
const wx = new wxCtrl();
export default {
auth:login.auth,
goLogin: login.goLogin,
auth:login.auth.bind(login),
goLogin: login.goLogin.bind(login),
getUid:base.getUid,
env: env,
link: goto.link,
goBack: goto.goBack,
wxShare: wxCtrl.wxShare,
wxSignature: wxCtrl.wxSignature
link: goto.link.bind(goto),
goBack: goto.goBack.bind(goto),
wxShare: wx.wxShare.bind(wx),
wxSignature: wx.wxSignature
}
... ...
import jsonp from "../utils/jsonp";
import cookies from '../utils/cookie';
import {getQueryObj} from '../utils/common'
import Promise from 'promise-polyfill'
const parseUrl = (url) => {
let query = {},
... ... @@ -74,24 +75,26 @@ export default {
});
} else if (env === 'pc') {
url = 'https://www.yoho/signin.html?refer=' + encodeURIComponent(location.href) + '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + refer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
} else if (env === 'miniprogram'){
} else if (env === 'miniprogram') {
url = '/pages/userCenter/userCenter'
}
return url;
},
//uid
getUid: function (callback) {
if (env === 'h5' || env === 'pc') {
jsonp('https://m.yohobuy.com/passport/login/user').then(r => {
let uid = 0;
if(r.code === 200 ){
uid = Number(r.data)
}
callback && callback(uid);
});
} else {
let uid = Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0;
callback && callback(uid);
}
getUid: function () {
return new Promise(function (resolve) {
if (env === 'h5' || env === 'pc') {
jsonp('https://m.yohobuy.com/passport/login/user').then(r => {
let uid = 0;
if (r.code === 200) {
uid = Number(r.data)
}
resolve(uid)
});
} else {
let uid = Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0;
resolve(uid)
}
})
}
}
... ...
import wx from 'weixin-js-sdk';
import {linkToMiniApp, invokeMethod, createLinkButton} from "../utils/common";
let env;
export default class {
constructor(_env) {
env = _env;
this.env = _env;
}
link(event) {
... ... @@ -14,7 +13,7 @@ export default class {
let url = element.getAttribute('data-url') || '';
let name = element.getAttribute('data-name') || '';
let linkUrl = '';
if (env === 'miniprogram') {
if (this.env === 'miniprogram') {
if (type === 'product') {
linkUrl = '/pages/goodsDetail/goodsDetail?productSkn=' + id + '&page_name=goodsList&page_param=5'
} else if (type === 'brand') {
... ... @@ -23,7 +22,7 @@ export default class {
linkUrl = url.split('?')[0];
}
return linkToMiniApp(linkUrl, type);
} else if (env === 'pc') {
} else if (this.env === 'pc') {
if (type === 'product') {
linkUrl = 'https://www.yohobuy.com/product/' + id + '.html';
} else if (type === 'brand') {
... ... @@ -40,27 +39,28 @@ export default class {
linkUrl = url
}
}
if (env === 'app') {
if (document.getElementById('yosdk-goto')) {
createLinkButton(linkUrl,'yosdk-goto');
}
if (this.env === 'app') {
let dom = document.getElementById('yosdk-goto');
dom.setAttribute('href', linkUrl);
if (!dom) {
dom = createLinkButton(linkUrl, 'yosdk-goto');
} else {
dom.setAttribute('href', linkUrl);
}
return dom.click();
} else {
window.location.href = linkUrl
}
}
goBack() {
if (env === 'app') {
if (this.env === 'app') {
invokeMethod({method: 'go.back'})
} else if (env === 'miniprogram') {
} else if (this.env === 'miniprogram') {
wx.miniProgram.navigateBack();
} else {
history.go(-1);
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -2,24 +2,22 @@ import wx from 'weixin-js-sdk';
import {createLinkButton} from "../utils/common";
import base from './base';
let env, url;
export default class {
constructor(obj) {
env = obj.env;
url = obj.loginUrl;
this.env = obj.env;
this.url = obj.loginUrl;
}
auth() {
let _gologin = this.goLogin;
base.getUid(function (uid) {
console.log(uid);
base.getUid().then((uid) => {
if (!uid) {
let list = document.querySelectorAll('.auth');
if (list.length) {
list.forEach((value) => {
value.onclick = function (event) {
value.onclick = (event) => {
event.preventDefault();
_gologin();
console.log(this);
this.goLogin();
}
});
return true;
... ... @@ -29,17 +27,17 @@ export default class {
}
goLogin() {
if (env === 'miniprogram') {
wx.miniProgram.switchTab({url: url});
} else if(env === 'app'){
if (!document.getElementById('yosdk-login')) {
createLinkButton(url, 'yosdk-login');
}
if (this.env === 'miniprogram') {
wx.miniProgram.switchTab({url: this.url});
} else if(this.env === 'app'){
let loginButton = document.getElementById('yosdk-login');
if (!loginButton) {
loginButton = createLinkButton(this.url, 'yosdk-login');
}
loginButton.click();
} else {
window.location.href = url;
window.location.href = this.url;
}
return false;
}
}
\ No newline at end of file
}
... ...
... ... @@ -3,15 +3,13 @@ import httpServer from '../utils/jsonp';
import wx from "weixin-js-sdk";
const _weChatInterface = '//action.yoho.cn/api/share/getSignPackage';//签名等相关配置,yoho公众号
export default {
export default class {
wxSignature: fun => {
wxSignature = fun => {
httpServer(_weChatInterface + "?pageurl=" + encodeURIComponent(location.href.split('#')[0])).then((json) => {
if (!json.appId) {
document.getElementById('share').innerText = 'false';
return false;
} else {
document.getElementById('share').innerText = 'true';
let _appId = json.appId.toString();
let _timestamp = json.timestamp;
let _nonceStr = json.nonceStr.toString();
... ... @@ -64,30 +62,30 @@ export default {
return true;
}
})
},
}
wxShare: shareDate => {
document.getElementById('share').innerText = 'wxShare';
wxShare = shareDate => {
this.wxSignature(function(){
let share_data = shareDate || {
title: '',
imgUrl: '',
desc: '',
link: document.location.href,
success: function () {
}
};
wx.ready(function () {
// 2.1 “分享给朋友”
wx.onMenuShareAppMessage(share_data);
// 2.2 “分享到朋友圈”
wx.onMenuShareTimeline(share_data);
// 2.3 “分享到QQ”
wx.onMenuShareQQ(share_data);
// 2.4 “分享到微博”
wx.onMenuShareWeibo(share_data);
});
})
let share_data = shareDate || {
title: '',
imgUrl: '',
desc: '',
link: document.location.href,
success: function () {
}
};
wx.ready(function () {
document.getElementById('share').innerText = JSON.stringify(share_data);
// 2.1 “分享给朋友”
wx.onMenuShareAppMessage(share_data);
// 2.2 “分享到朋友圈”
wx.onMenuShareTimeline(share_data);
// 2.3 “分享到QQ”
wx.onMenuShareQQ(share_data);
// 2.4 “分享到微博”
wx.onMenuShareWeibo(share_data);
});
}
}
... ...
... ... @@ -87,10 +87,11 @@ const createLinkButton = (url, id) => {
a.setAttribute('id', id);
a.setAttribute('href', url);
document.body.appendChild(a);
return a;
}
export {
invokeMethod,
getQueryObj,
linkToMiniApp,
createLinkButton
};
\ No newline at end of file
};
... ...