Authored by 陈峰

Merge branch 'feature/mini' into 'master'

es5 改写



See merge request !8
1 { 1 {
2 - "presets": ["es2015","stage-0"], 2 + "presets": ["es2015", "stage-0"],
3 "plugins": [ 3 "plugins": [
4 "transform-runtime", 4 "transform-runtime",
5 "syntax-dynamic-import" 5 "syntax-dynamic-import"
1 -language : node_js  
2 -node_js:  
3 - - "10"  
4 -  
5 -branches:  
6 - only:  
7 - - master  
8 -  
9 -install:  
10 -- npm install  
11 -  
12 -os:  
13 - - linux  
14 -  
15 -stages:  
16 - - name: deploy  
17 -  
18 -jobs:  
19 - include:  
20 - - stage: deploy  
21 - script:  
22 - - echo "NPM Deploying Started ..."  
23 - - npm version  
24 - - npm run build  
25 - - echo "NPM Building Finished."  
26 -  
27 - deploy:  
28 - provider: npm  
29 - email: chenfengjw@hotmail.com  
30 - api_key: "$NPM_TOKEN"  
31 - skip_cleanup: true  
32 - on:  
33 - all_branches: true  
@@ -18,7 +18,11 @@ @@ -18,7 +18,11 @@
18 2. 微信验签方法提供 18 2. 微信验签方法提供
19 ## 使用说明 19 ## 使用说明
20 20
21 -可以直接import也可以define() 21 +activity-sdk依赖wx-js-sdk,无论登陆还是页面跳转还是分享等等都依赖wx-js-sdk
  22 +
  23 +所以在加载activity-sdk之前先加载wx-js-sdk,之后再调用activity-sdk的方法
  24 +
  25 +可以直接import也可以define();
22 26
23 如果是在html页面引入window.yo_sdk可以获取到所有的api 27 如果是在html页面引入window.yo_sdk可以获取到所有的api
24 28
@@ -51,17 +55,18 @@ @@ -51,17 +55,18 @@
51 55
52 用法:`let env = window.yo_sdk.env` 56 用法:`let env = window.yo_sdk.env`
53 57
54 -#### getUid: 58 +#### getUser:
55 类型:function 59 类型:function
56 60
57 -描述:获取当前用户uid,如果没有用户则该值为0 61 +描述:获取当前用户uid,sessionKey,sessionType,appVersion以Object类型返回,如果没有用户则该uid值为0
58 62
59 用法: 63 用法:
60 ``` 64 ```
61 //执行返回的是一个Promise对象 65 //执行返回的是一个Promise对象
62 -window.yo_sdk.getUid().  
63 - then(function(uid){  
64 - console.log(uid); 66 +window.yo_sdk.getUser().
  67 + then(function(user){
  68 + console.log(user);
  69 + //返回 {uid:1,sessionType:'',sessionKey:'',appVersion:''}
65 }) 70 })
66 71
67 ``` 72 ```
This diff could not be displayed because it is too large.
@@ -12,15 +12,18 @@ @@ -12,15 +12,18 @@
12 <a class="auth" href="http://www.baidu.com">123123</a> 12 <a class="auth" href="http://www.baidu.com">123123</a>
13 <div id="uid"></div> 13 <div id="uid"></div>
14 <div id="url"></div> 14 <div id="url"></div>
  15 +<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
15 <script src="../build/sdk.js"></script> 16 <script src="../build/sdk.js"></script>
16 <script> 17 <script>
17 window.yo_sdk.auth(); 18 window.yo_sdk.auth();
18 document.getElementById('aaa').onclick = function (event) { 19 document.getElementById('aaa').onclick = function (event) {
19 - window.yo_sdk.getUid().then(function(uid){  
20 - console.log(uid);  
21 - document.getElementById('uid').innerText = uid;  
22 - }) 20 + window.yo_sdk.getUser().then(function (user) {
  21 + console.log(user.uid);
  22 + if (user.uid)
  23 + document.getElementById('uid').innerText = user.uid;
  24 + else
23 window.yo_sdk.goLogin(); 25 window.yo_sdk.goLogin();
  26 + })
24 } 27 }
25 document.getElementById('url').innerText = location.href; 28 document.getElementById('url').innerText = location.href;
26 </script> 29 </script>
  1 +<!DOCTYPE html>
  2 +<html lang="en">
  3 +<head>
  4 + <meta charset="UTF-8">
  5 + <title>Title</title>
  6 +</head>
  7 +<body>
  8 +
  9 +</body>
  10 +</html>
@@ -8,9 +8,10 @@ @@ -8,9 +8,10 @@
8 </head> 8 </head>
9 <body> 9 <body>
10 <div id="share"> 分享</div> 10 <div id="share"> 分享</div>
  11 +<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
11 <script src="../build/sdk.js"></script> 12 <script src="../build/sdk.js"></script>
12 <script> 13 <script>
13 - let shareData = { 14 + var shareData = {
14 title: '国潮崛起年,中西碰撞博出位!', 15 title: '国潮崛起年,中西碰撞博出位!',
15 imgUrl: 'https://img01.yohoboys.com/o_1cnilugbs15ajak1gfo1d2h1p348.png?imageView2/1/w/200/h/200', 16 imgUrl: 'https://img01.yohoboys.com/o_1cnilugbs15ajak1gfo1d2h1p348.png?imageView2/1/w/200/h/200',
16 desc: '这里有一份中西潮流榜单,请收好!', 17 desc: '这里有一份中西潮流榜单,请收好!',
1 { 1 {
2 "name": "yoho-activity-sdk", 2 "name": "yoho-activity-sdk",
3 - "version": "1.0.8", 3 + "version": "1.0.9",
4 "description": "YOHO!前端js的功能封装包,主要用于在活动页面中,对主要功能的封装。", 4 "description": "YOHO!前端js的功能封装包,主要用于在活动页面中,对主要功能的封装。",
5 "keywords": [ 5 "keywords": [
6 "YOHO!", 6 "YOHO!",
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 ], 8 ],
9 "main": "build/sdk.js", 9 "main": "build/sdk.js",
10 "scripts": { 10 "scripts": {
11 - "build": "webpack --mode development --config ./webpack.config.babel.js ", 11 + "build": "webpack --mode production --config ./webpack.config.js ",
12 "lint-js": "lint-js" 12 "lint-js": "lint-js"
13 }, 13 },
14 "config": { 14 "config": {
@@ -32,27 +32,26 @@ @@ -32,27 +32,26 @@
32 "babel-core": "^6.26.0", 32 "babel-core": "^6.26.0",
33 "babel-loader": "^7.1.4", 33 "babel-loader": "^7.1.4",
34 "babel-plugin-import": "^1.7.0", 34 "babel-plugin-import": "^1.7.0",
35 - "babel-plugin-transform-runtime": "^6.23.0",  
36 "babel-plugin-syntax-dynamic-import": "^6.18.0", 35 "babel-plugin-syntax-dynamic-import": "^6.18.0",
  36 + "babel-plugin-transform-runtime": "^6.23.0",
37 "babel-preset-env": "^1.6.1", 37 "babel-preset-env": "^1.6.1",
38 "babel-preset-es2015": "^6.24.1", 38 "babel-preset-es2015": "^6.24.1",
39 "babel-preset-stage-0": "^6.24.1", 39 "babel-preset-stage-0": "^6.24.1",
40 "clean-webpack-plugin": "^0.1.19", 40 "clean-webpack-plugin": "^0.1.19",
41 "compression-webpack-plugin": "^1.1.11", 41 "compression-webpack-plugin": "^1.1.11",
42 "copy-webpack-plugin": "^4.5.1", 42 "copy-webpack-plugin": "^4.5.1",
43 - "extract-text-webpack-plugin": "^4.0.0-beta.0",  
44 - "uglifyjs-webpack-plugin": "^2.0.1",  
45 - "file-loader": "^1.1.11",  
46 - "url-loader": "^1.0.1",  
47 - "webpack": "^4.17.2",  
48 - "webpack-cli": "^3.1.2",  
49 - "weixin-js-sdk": "^1.3.3",  
50 - "fetch-jsonp": "^1.1.3",  
51 "eslint": "^3.19.0", 43 "eslint": "^3.19.0",
52 "eslint-config-yoho": "^1.0.1", 44 "eslint-config-yoho": "^1.0.1",
53 "eslint-loader": "^1.7.1", 45 "eslint-loader": "^1.7.1",
54 "eslint-plugin-html": "^2.0.3", 46 "eslint-plugin-html": "^2.0.3",
55 - "promise-polyfill": "^8.1.0" 47 + "extract-text-webpack-plugin": "^4.0.0-beta.0",
  48 + "fetch-jsonp": "^1.1.3",
  49 + "file-loader": "^1.1.11",
  50 + "uglifyjs-webpack-plugin": "^2.0.1",
  51 + "url-loader": "^1.0.1",
  52 + "webpack": "^4.17.2",
  53 + "webpack-bundle-analyzer": "^3.0.3",
  54 + "webpack-cli": "^3.1.2"
56 }, 55 },
57 "dependencies": {}, 56 "dependencies": {},
58 "directories": { 57 "directories": {
1 -import base from './public/base'  
2 -import Login from './public/login'  
3 -import Goto from './public/goto'  
4 -import wxCtrl from './public/share'  
5 -import {getQueryObj,invokeMethod} from './utils/common' 1 +var base = require('./public/base');
  2 +var Login = require('./public/login');
  3 +var Goto = require('./public/goto');
  4 +var wxCtrl = require('./public/share');
  5 +var common = require('./utils/common');
  6 +var env = base.env();
  7 +var loginUrl = base.loginUrl();
  8 +var login = new Login({loginUrl:loginUrl, env:env});
  9 +var goto = new Goto(env);
  10 +var wx = new wxCtrl();
6 11
7 -const env = base.env();  
8 -const loginUrl = base.loginUrl();  
9 -const login = new Login({loginUrl, env});  
10 -const goto = new Goto(env);  
11 -const wx = new wxCtrl();  
12 -  
13 -export default { 12 +module.exports = {
14 auth:login.auth.bind(login), 13 auth:login.auth.bind(login),
15 goLogin: login.goLogin.bind(login), 14 goLogin: login.goLogin.bind(login),
16 getUser:base.getUser, 15 getUser:base.getUser,
@@ -19,6 +18,6 @@ export default { @@ -19,6 +18,6 @@ export default {
19 goBack: goto.goBack.bind(goto), 18 goBack: goto.goBack.bind(goto),
20 wxShare: wx.wxShare.bind(wx), 19 wxShare: wx.wxShare.bind(wx),
21 wxSignature: wx.wxSignature, 20 wxSignature: wx.wxSignature,
22 - getQueryObj,  
23 - invokeMethod 21 + getQueryObj:common.getQueryObj,
  22 + invokeMethod:common.invokeMethod
24 } 23 }
1 -import jsonp from "../utils/jsonp";  
2 -import cookies from '../utils/cookie';  
3 -import {getQueryObj} from '../utils/common'  
4 -import Promise from 'promise-polyfill'  
5 -import {invokeMethod} from '../utils/common'  
6 -  
7 -const parseUrl = (url) => {  
8 - let query = {}, 1 +var jsonp = require('../utils/jsonp');
  2 +var cookies = require('../utils/cookie');
  3 +var common = require('../utils/common');
  4 +var Promise = require('../utils/promise');
  5 +var getQueryObj = common.getQueryObj;
  6 +var parseUrl = function (url) {
  7 + var query = {},
9 hashs, 8 hashs,
10 hash, 9 hash,
11 i; 10 i;
@@ -25,42 +24,44 @@ const parseUrl = (url) => { @@ -25,42 +24,44 @@ const parseUrl = (url) => {
25 query: query 24 query: query
26 } 25 }
27 }; 26 };
28 -let env = '';  
29 27
30 -const _appGetUid = function () { 28 +var env = '';
  29 +
  30 +var _appGetUid = function () {
31 return new Promise(function (resolve) { 31 return new Promise(function (resolve) {
32 - invokeMethod({ 32 + common.invokeMethod({
33 method: 'get.uid', 33 method: 'get.uid',
34 arguments: {}, 34 arguments: {},
35 success: function (uid) { 35 success: function (uid) {
36 resolve(parseInt(uid)); 36 resolve(parseInt(uid));
37 }, 37 },
38 fail: function () { 38 fail: function () {
39 - let uid = Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0; 39 + var uid = Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0;
40 resolve(uid); 40 resolve(uid);
41 } 41 }
42 }); 42 });
43 }) 43 })
44 -}  
45 -const _appGetSessionKey = function () { 44 +};
  45 +var _appGetSessionKey = function () {
46 return new Promise(function (resolve) { 46 return new Promise(function (resolve) {
47 - invokeMethod({ 47 + common.invokeMethod({
48 method: 'get.sessionId', 48 method: 'get.sessionId',
49 arguments: {}, 49 arguments: {},
50 success: function (sessionKey) { 50 success: function (sessionKey) {
51 resolve(sessionKey); 51 resolve(sessionKey);
52 }, 52 },
53 fail: function () { 53 fail: function () {
54 - let sessionKey = cookies.cookie('app_session_key') || getQueryObj().session_key || ''; 54 + var sessionKey = cookies.cookie('app_session_key') || getQueryObj().session_key || '';
55 resolve(sessionKey); 55 resolve(sessionKey);
56 } 56 }
57 }); 57 });
58 }) 58 })
59 -}  
60 -export default { 59 +};
  60 +
  61 +module.exports = {
61 //evn 62 //evn
62 env: function () { 63 env: function () {
63 - let envFlag = window.__wxjs_environment; 64 + var envFlag = window.__wxjs_environment;
64 if (!envFlag && navigator.userAgent.match(/yohobuy/i)) { 65 if (!envFlag && navigator.userAgent.match(/yohobuy/i)) {
65 env = 'app'; 66 env = 'app';
66 document.addEventListener('deviceready', function () { 67 document.addEventListener('deviceready', function () {
@@ -76,7 +77,7 @@ export default { @@ -76,7 +77,7 @@ export default {
76 }, 77 },
77 //url 78 //url
78 loginUrl: function () { 79 loginUrl: function () {
79 - let url, refer = location.href; 80 + var url, refer = location.href;
80 if (env === 'app') { 81 if (env === 'app') {
81 url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer); 82 url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
82 refer = parseUrl(refer); 83 refer = parseUrl(refer);
@@ -122,12 +123,12 @@ export default { @@ -122,12 +123,12 @@ export default {
122 //uid 123 //uid
123 getUser: function () { 124 getUser: function () {
124 return new Promise(function (resolve) { 125 return new Promise(function (resolve) {
125 - let obj = { 126 + var obj = {
126 sessionType: cookies.cookie('app_client_type') || getQueryObj().app_client_type || '', 127 sessionType: cookies.cookie('app_client_type') || getQueryObj().app_client_type || '',
127 appVersion: cookies.cookie('app_version') || getQueryObj().app_version || '' 128 appVersion: cookies.cookie('app_version') || getQueryObj().app_version || ''
128 - } 129 + };
129 if (env === 'h5' || env === 'pc') { 130 if (env === 'h5' || env === 'pc') {
130 - jsonp('//m.yohobuy.com/passport/login/user').then(r => { 131 + jsonp({url: '//m.yohobuy.com/passport/login/user', jsonp: 'callback'}).then(function (r) {
131 obj.uid = 0; 132 obj.uid = 0;
132 if (r.code === 200) { 133 if (r.code === 200) {
133 obj.uid = Number(r.data) 134 obj.uid = Number(r.data)
@@ -136,13 +137,13 @@ export default { @@ -136,13 +137,13 @@ export default {
136 resolve(obj); 137 resolve(obj);
137 }); 138 });
138 } else if (env === 'app') { 139 } else if (env === 'app') {
139 - document.addEventListener('deviceready', () => { 140 + document.addEventListener('deviceready',function() {
140 return Promise.all([_appGetUid(), _appGetSessionKey()]).then(function (r) { 141 return Promise.all([_appGetUid(), _appGetSessionKey()]).then(function (r) {
141 - obj.uid = r[0]  
142 - obj.sessionKey = r[1] 142 + obj.uid = r[0];
  143 + obj.sessionKey = r[1];
143 resolve(obj); 144 resolve(obj);
144 }) 145 })
145 - }); 146 + })
146 } else { 147 } else {
147 obj.uid = Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0; 148 obj.uid = Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0;
148 obj.sessionKey = cookies.cookie('app_session_key') || getQueryObj().session_key || ''; 149 obj.sessionKey = cookies.cookie('app_session_key') || getQueryObj().session_key || '';
@@ -150,4 +151,4 @@ export default { @@ -150,4 +151,4 @@ export default {
150 } 151 }
151 }) 152 })
152 } 153 }
153 -} 154 +};
1 -import wx from 'weixin-js-sdk';  
2 -import {linkToMiniApp, invokeMethod, createLinkButton} from "../utils/common"; 1 +var common = require('../utils/common');
3 2
4 -export default class {  
5 - constructor(_env) { 3 +function goto(_env){
6 this.env = _env; 4 this.env = _env;
7 - }  
8 -  
9 - link(event) {  
10 - let element = event.currentTarget;  
11 - let type = element.getAttribute('data-type') || 'other';  
12 - let id = element.getAttribute('data-id') || '';  
13 - let url = element.getAttribute('data-url') || '';  
14 - let name = element.getAttribute('data-name') || '';  
15 - let linkUrl = ''; 5 +}
  6 +goto.prototype.link = function(event){
  7 + var element = event.currentTarget;
  8 + var type = element.getAttribute('data-type') || 'other';
  9 + var id = element.getAttribute('data-id') || '';
  10 + var url = element.getAttribute('data-url') || '';
  11 + var name = element.getAttribute('data-name') || '';
  12 + var linkUrl = '';
16 if (this.env === 'miniprogram') { 13 if (this.env === 'miniprogram') {
17 if (type === 'product') { 14 if (type === 'product') {
18 linkUrl = '/pages/goodsDetail/goodsDetail?productSkn=' + id + '&page_name=goodsList&page_param=5' 15 linkUrl = '/pages/goodsDetail/goodsDetail?productSkn=' + id + '&page_name=goodsList&page_param=5'
@@ -21,7 +18,7 @@ export default class { @@ -21,7 +18,7 @@ export default class {
21 } else { 18 } else {
22 linkUrl = url 19 linkUrl = url
23 } 20 }
24 - return linkToMiniApp(linkUrl, type); 21 + return common.linkToMiniApp(linkUrl, type);
25 } else if (this.env === 'pc') { 22 } else if (this.env === 'pc') {
26 if (type === 'product') { 23 if (type === 'product') {
27 linkUrl = 'https://www.yohobuy.com/product/' + id + '.html'; 24 linkUrl = 'https://www.yohobuy.com/product/' + id + '.html';
@@ -40,9 +37,9 @@ export default class { @@ -40,9 +37,9 @@ export default class {
40 } 37 }
41 } 38 }
42 if (this.env === 'app') { 39 if (this.env === 'app') {
43 - let dom = document.getElementById('yosdk-goto'); 40 + var dom = document.getElementById('yosdk-goto');
44 if (!dom) { 41 if (!dom) {
45 - dom = createLinkButton(linkUrl, 'yosdk-goto'); 42 + dom = common.createLinkButton(linkUrl, 'yosdk-goto');
46 } else { 43 } else {
47 dom.setAttribute('href', linkUrl); 44 dom.setAttribute('href', linkUrl);
48 } 45 }
@@ -51,16 +48,15 @@ export default class { @@ -51,16 +48,15 @@ export default class {
51 } else { 48 } else {
52 window.location.href = linkUrl 49 window.location.href = linkUrl
53 } 50 }
54 - } 51 +};
55 52
56 - goBack() { 53 +goto.prototype.goBack=function () {
57 if (this.env === 'app') { 54 if (this.env === 'app') {
58 - invokeMethod({method: 'go.back'}) 55 + common.invokeMethod({method: 'go.back'})
59 } else if (this.env === 'miniprogram') { 56 } else if (this.env === 'miniprogram') {
60 wx.miniProgram.navigateBack(); 57 wx.miniProgram.navigateBack();
61 } else { 58 } else {
62 history.go(-1); 59 history.go(-1);
63 } 60 }
64 - }  
65 -  
66 -} 61 +};
  62 +module.exports = goto;
1 -import wx from 'weixin-js-sdk';  
2 -import {createLinkButton} from "../utils/common";  
3 -import base from './base'; 1 +var common = require('../utils/common');
  2 +var base = require('./base');
4 3
5 -export default class {  
6 - constructor(obj) {  
7 - this.env = obj.env;  
8 - this.url = obj.loginUrl; 4 +function login(obj) {
  5 + var _this = this;
  6 + _this.env = obj.env;
  7 + _this.url = obj.loginUrl;
  8 +
  9 + _this.goLogin = function () {
  10 + if (_this.env === 'miniprogram') {
  11 + wx.miniProgram.switchTab({url: _this.url});
  12 + } else if (_this.env === 'app') {
  13 + var loginButton = document.getElementById('yosdk-login');
  14 + if (!loginButton) {
  15 + loginButton = common.createLinkButton(_this.url, 'yosdk-login');
  16 + }
  17 + loginButton.click();
  18 + } else {
  19 + window.location.href = _this.url;
9 } 20 }
  21 + return false;
  22 + };
10 23
11 - auth() {  
12 - base.getUser().then(({uid}) => {  
13 - if (!uid) {  
14 - let list = document.querySelectorAll('.auth'); 24 + _this.auth = function () {
  25 + base.getUser().then(function (user) {
  26 + if (!user.uid) {
  27 + var list = document.querySelectorAll('.auth');
15 if (list.length) { 28 if (list.length) {
16 - list.forEach((value) => {  
17 - value.onclick = (event) => { 29 + list.forEach(function (value) {
  30 + value.onclick = function (event) {
18 event.preventDefault(); 31 event.preventDefault();
19 - this.goLogin(); 32 + _this.goLogin();
20 } 33 }
21 }); 34 });
22 return true; 35 return true;
@@ -24,19 +37,6 @@ export default class { @@ -24,19 +37,6 @@ export default class {
24 } 37 }
25 }); 38 });
26 } 39 }
27 -  
28 - goLogin() {  
29 - if (this.env === 'miniprogram') {  
30 - wx.miniProgram.switchTab({url: this.url});  
31 - } else if(this.env === 'app'){  
32 - let loginButton = document.getElementById('yosdk-login');  
33 - if (!loginButton) {  
34 - loginButton = createLinkButton(this.url, 'yosdk-login');  
35 - }  
36 - loginButton.click();  
37 - } else {  
38 - window.location.href = this.url;  
39 - }  
40 - return false;  
41 - }  
42 } 40 }
  41 +
  42 +module.exports = login;
1 //初始化config信息 1 //初始化config信息
2 -import httpServer from '../utils/jsonp';  
3 -import wx from "weixin-js-sdk"; 2 +var httpServer = require('../utils/jsonp');
4 3
5 -const _weChatInterface = '//action.yoho.cn/api/share/getSignPackage';//签名等相关配置,yoho公众号  
6 -export default class { 4 +var _weChatInterface = '//action.yoho.cn/api/share/getSignPackage';//签名等相关配置,yoho公众号
  5 +function wx() {
  6 +}
7 7
8 - wxSignature = fun => {  
9 - httpServer(_weChatInterface + "?pageurl=" + encodeURIComponent(location.href.split('#')[0])).then((json) => { 8 +wx.prototype.wxSignature = function (fun) {
  9 + httpServer(_weChatInterface + "?pageurl=" + encodeURIComponent(location.href.split('#')[0])).then(function (json) {
10 if (!json.appId) { 10 if (!json.appId) {
11 return false; 11 return false;
12 } else { 12 } else {
13 - let _appId = json.appId.toString();  
14 - let _timestamp = json.timestamp;  
15 - let _nonceStr = json.nonceStr.toString();  
16 - let _signature = json.signature.toString(); 13 + var _appId = json.appId.toString();
  14 + var _timestamp = json.timestamp;
  15 + var _nonceStr = json.nonceStr.toString();
  16 + var _signature = json.signature.toString();
17 wx.config({ 17 wx.config({
18 debug: false, 18 debug: false,
19 appId: _appId, 19 appId: _appId,
@@ -58,15 +58,15 @@ export default class { @@ -58,15 +58,15 @@ export default class {
58 'openCard' 58 'openCard'
59 ] 59 ]
60 }); 60 });
61 - fun && setTimeout(fun,500); 61 + fun && setTimeout(fun, 500);
62 return true; 62 return true;
63 } 63 }
64 }) 64 })
65 - }; 65 +};
66 66
67 - wxShare = shareDate => {  
68 - this.wxSignature(function(){  
69 - let share_data = shareDate || { 67 +wx.prototype.wxShare = function (shareDate) {
  68 + this.wxSignature(function () {
  69 + var share_data = shareDate || {
70 title: '', 70 title: '',
71 imgUrl: '', 71 imgUrl: '',
72 desc: '', 72 desc: '',
@@ -86,6 +86,6 @@ export default class { @@ -86,6 +86,6 @@ export default class {
86 }); 86 });
87 }) 87 })
88 88
89 - }  
90 } 89 }
91 90
  91 +module.exports = wx;
1 -import wx from "weixin-js-sdk";  
2 -  
3 -const invokeMethod = (obj) => { 1 +var invokeMethod = function(obj) {
4 if (window.yohoInterface) { 2 if (window.yohoInterface) {
5 window.yohoInterface.triggerEvent(obj.success || function () { 3 window.yohoInterface.triggerEvent(obj.success || function () {
6 }, obj.fail || function () { 4 }, obj.fail || function () {
@@ -13,20 +11,20 @@ const invokeMethod = (obj) => { @@ -13,20 +11,20 @@ const invokeMethod = (obj) => {
13 } 11 }
14 } 12 }
15 13
16 -const linkToMiniApp = (goUrl, type) => {  
17 - let url = goUrl || ''; 14 +var linkToMiniApp = function(goUrl, type) {
  15 + var url = goUrl || '';
18 if (url && url.indexOf('http') < 0 && type === 'other') { 16 if (url && url.indexOf('http') < 0 && type === 'other') {
19 url = document.location.protocol + '//' + document.location.host + url; 17 url = document.location.protocol + '//' + document.location.host + url;
20 } 18 }
21 if (url) { 19 if (url) {
22 - let scene; 20 + var scene;
23 if (type === 'product' || type === 'brand') { 21 if (type === 'product' || type === 'brand') {
24 scene = url; 22 scene = url;
25 } else { 23 } else {
26 - let base_url = decodeURIComponent(url).split('?')[0];  
27 - let params = getQueryObj(url);  
28 - let paramStr = '';  
29 - Object.keys(params).forEach(key => { 24 + var base_url = decodeURIComponent(url).split('?')[0];
  25 + var params = getQueryObj(url);
  26 + var paramStr = '';
  27 + Object.keys(params).forEach(function(key) {
30 paramStr += paramStr === '' ? '?' + key + '=' + params[key] : '&' + key + '=' + params[key]; 28 paramStr += paramStr === '' ? '?' + key + '=' + params[key] : '&' + key + '=' + params[key];
31 }) 29 })
32 scene = '/pages/webview/webview?url=' + base_url + encodeURIComponent(paramStr); 30 scene = '/pages/webview/webview?url=' + base_url + encodeURIComponent(paramStr);
@@ -39,14 +37,14 @@ const linkToMiniApp = (goUrl, type) => { @@ -39,14 +37,14 @@ const linkToMiniApp = (goUrl, type) => {
39 }; 37 };
40 38
41 39
42 -const getQueryObj = (link) => {  
43 - let loc = decodeURIComponent(document.location.href); 40 +var getQueryObj = function(link) {
  41 + var loc = decodeURIComponent(document.location.href);
44 if (link) { 42 if (link) {
45 loc = decodeURIComponent(link); 43 loc = decodeURIComponent(link);
46 } 44 }
47 - let variables = '';  
48 - let variableArr = [];  
49 - let finalArr = []; 45 + var variables = '';
  46 + var variableArr = [];
  47 + var finalArr = [];
50 48
51 if (loc.indexOf('?') > 0) { 49 if (loc.indexOf('?') > 0) {
52 variables = loc.split('?')[1]; 50 variables = loc.split('?')[1];
@@ -56,30 +54,30 @@ const getQueryObj = (link) => { @@ -56,30 +54,30 @@ const getQueryObj = (link) => {
56 variableArr = variables.split('#')[0].split('&'); 54 variableArr = variables.split('#')[0].split('&');
57 } 55 }
58 56
59 - for (let i = 0; i < variableArr.length; i++) {  
60 - let obj = {}; 57 + for (var i = 0; i < variableArr.length; i++) {
  58 + var obj = {};
61 59
62 obj.name = variableArr[i].split('=')[0]; 60 obj.name = variableArr[i].split('=')[0];
63 obj.value = variableArr[i].split('=')[1]; 61 obj.value = variableArr[i].split('=')[1];
64 if (variableArr[i].split('=').length > 2) { 62 if (variableArr[i].split('=').length > 2) {
65 - for (let j = 2; j < variableArr[i].split('=').length; j++) { 63 + for (var j = 2; j < variableArr[i].split('=').length; j++) {
66 obj.value += '=' + variableArr[i].split('=')[j]; 64 obj.value += '=' + variableArr[i].split('=')[j];
67 } 65 }
68 } 66 }
69 finalArr.push(obj); 67 finalArr.push(obj);
70 } 68 }
71 69
72 - let query_obj = {}; 70 + var query_obj = {};
73 71
74 - for (let i = 0; i < finalArr.length; i++) { 72 + for (var i = 0; i < finalArr.length; i++) {
75 query_obj[finalArr[i].name] = finalArr[i].value; 73 query_obj[finalArr[i].name] = finalArr[i].value;
76 } 74 }
77 75
78 return query_obj; 76 return query_obj;
79 }; 77 };
80 78
81 -const createLinkButton = (url, id) => {  
82 - let a = document.createElement('a'); 79 +var createLinkButton = function(url, id) {
  80 + var a = document.createElement('a');
83 a.style.position = 'fixed'; 81 a.style.position = 'fixed';
84 a.style.top = 0; 82 a.style.top = 0;
85 a.style.left = 0; 83 a.style.left = 0;
@@ -92,10 +90,11 @@ const createLinkButton = (url, id) => { @@ -92,10 +90,11 @@ const createLinkButton = (url, id) => {
92 a.setAttribute('href', url); 90 a.setAttribute('href', url);
93 document.body.appendChild(a); 91 document.body.appendChild(a);
94 return a; 92 return a;
95 -}  
96 -export {  
97 - invokeMethod,  
98 - getQueryObj,  
99 - linkToMiniApp,  
100 - createLinkButton 93 +};
  94 +
  95 +module.exports = {
  96 + invokeMethod: invokeMethod,
  97 + getQueryObj: getQueryObj,
  98 + linkToMiniApp: linkToMiniApp,
  99 + createLinkButton: createLinkButton
101 }; 100 };
@@ -36,7 +36,7 @@ function setCookie(name, value, options) { @@ -36,7 +36,7 @@ function setCookie(name, value, options) {
36 } 36 }
37 } 37 }
38 38
39 -export default {  
40 - cookie,  
41 - setCookie 39 +module.exports = {
  40 + cookie:cookie,
  41 + setCookie:setCookie
42 }; 42 };
1 -import fetchJsonp from 'fetch-jsonp'  
2 -  
3 -module.exports = function (uri, option) {  
4 - return new Promise(resolve => {  
5 - fetchJsonp(uri)  
6 - .then(function (response) {  
7 - return response.json()  
8 - }).then(function (json) {  
9 - return resolve(json)  
10 - }).catch(function (ex) {  
11 - return resolve({code: 202, data: ex})  
12 - }) 1 +var Promise = require('./promise');
  2 +
  3 +// jsonp请求
  4 +function jsonp(params) {
  5 + return new Promise(function (resovle, reject) {
  6 + params = params || {};
  7 + params.data = params.data || {};
  8 + //创建script标签并加入到页面中
  9 + var callbackName = params.jsonp;
  10 +
  11 + // 设置传递给后台的回调参数名
  12 + params.data['callback'] = callbackName;
  13 + var data = formatParams(params.data);
  14 + var script = document.createElement('script');
  15 + document.body.appendChild(script);
  16 +
  17 + // 创建jsonp回调函数
  18 + window[callbackName] = function (json) {
  19 + document.body.removeChild(script);
  20 + clearTimeout(script.timer);
  21 + window[callbackName] = null;
  22 + return resovle(json);
  23 + };
  24 +
  25 + // 发送请求
  26 + script.src = params.url + '?' + data;
  27 +
  28 + //为了得知此次请求是否成功,设置超时处理
  29 + if (params.time) {
  30 + script.timer = setTimeout(function () {
  31 + window[callbackName] = null;
  32 + document.body.removeChild(script);
  33 + reject({message: '超时'});
  34 + }, time);
  35 + }
13 }) 36 })
14 } 37 }
  38 +
  39 +//格式化参数
  40 +function formatParams(data) {
  41 + var arr = [];
  42 + for (var name in data) {
  43 + arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name]));
  44 + }
  45 +
  46 + // 添加一个随机数,防止缓存
  47 + var date = new Date();
  48 + arr.push('v=' + date.getTime());
  49 + return arr.join('&');
  50 +}
  51 +
  52 +module.exports = jsonp;
  53 +
  1 +function Promise(fn) {
  2 + var promise = this;
  3 + promise._value = null;
  4 + promise._reason = function(){};
  5 + promise._resolves = [];
  6 + promise._rejects = [];
  7 + promise._status = 'PENDING';
  8 +
  9 + this.then = function (onFulfilled, onRejected) {
  10 + return new Promise(function(resolve, reject) {
  11 + function handle(value) {
  12 + var ret = typeof onFulfilled === 'function' && onFulfilled(value) || value;
  13 + if(ret && typeof ret['then'] === 'function'){
  14 + ret.then(function(value){
  15 + resolve(value);
  16 + },function(reason){
  17 + reject(reason);
  18 + });
  19 + } else {
  20 + resolve(ret);
  21 + }
  22 + }
  23 + function errback(reason){
  24 + reason = typeof onRejected === 'function' && onRejected(reason) || reason;
  25 + reject(reason);
  26 + }
  27 + if (promise._status === 'PENDING') {
  28 + promise._resolves.push(handle);
  29 + promise._rejects.push(errback);
  30 + } else if(promise._status === 'FULFILLED'){
  31 + handle(promise._value);
  32 + } else if(promise._status === 'REJECTED') {
  33 + errback(promise._reason);
  34 + }
  35 + })
  36 +
  37 + };
  38 +
  39 +
  40 + function resolve(value) {
  41 + setTimeout(function(){
  42 + promise._status = "FULFILLED";
  43 + promise._resolves.forEach(function (callback) {
  44 + promise._value = callback(value);
  45 + })
  46 + },0);
  47 + }
  48 +
  49 + function reject(value) {
  50 + setTimeout(function(){
  51 + promise._status = "REJECTED";
  52 + promise._rejects.forEach(function (callback) {
  53 + promise._reason = callback(value);
  54 + })
  55 + },0);
  56 + }
  57 +
  58 + fn(resolve, reject);
  59 +}
  60 +
  61 +Promise.all = function(promises){
  62 + if (!Array.isArray(promises)) {
  63 + throw new TypeError('You must pass an array to all.');
  64 + }
  65 + return new Promise(function(resolve,reject){
  66 + var i = 0,
  67 + result = [],
  68 + len = promises.length,
  69 + count = len;
  70 +
  71 + function resolver(index) {
  72 + return function(value) {
  73 + resolveAll(index, value);
  74 + };
  75 + }
  76 +
  77 + function rejecter(reason){
  78 + reject(reason);
  79 + }
  80 +
  81 + function resolveAll(index,value){
  82 + result[index] = value;
  83 + if( --count === 0){
  84 + resolve(result)
  85 + }
  86 + }
  87 +
  88 + for (; i < len; i++) {
  89 + promises[i].then(resolver(i),rejecter);
  90 + }
  91 + });
  92 +};
  93 +
  94 +Promise.race = function(promises){
  95 + if (!Array.isArray(promises)) {
  96 + throw new TypeError('You must pass an array to race.');
  97 + }
  98 + return new Promise(function(resolve,reject){
  99 + var i = 0,
  100 + len = promises.length;
  101 +
  102 + function resolver(value) {
  103 + resolve(value);
  104 + }
  105 +
  106 + function rejecter(reason){
  107 + reject(reason);
  108 + }
  109 +
  110 + for (; i < len; i++) {
  111 + promises[i].then(resolver,rejecter);
  112 + }
  113 + });
  114 +};
  115 +
  116 +module.exports = Promise;
1 -import webpack,{DefinePlugin} from 'webpack';  
2 -import path from 'path';  
3 -import CleanWebpackPlugin from 'clean-webpack-plugin';  
4 -const uglify = require('uglifyjs-webpack-plugin'); 1 +var path = require('path');
  2 +var CleanWebpackPlugin = require('clean-webpack-plugin');
5 3
6 -let pathsToClean = [ 4 +var pathsToClean = [
7 'build' 5 'build'
8 ]; 6 ];
9 -let cleanOptions = { 7 +var cleanOptions = {
10 root: __dirname, 8 root: __dirname,
11 verbose: true, 9 verbose: true,
12 dry: false 10 dry: false
13 }; 11 };
14 module.exports = { 12 module.exports = {
15 //项目入口js文件 13 //项目入口js文件
  14 + mode: 'production',
16 entry: ['./src/index.js'], 15 entry: ['./src/index.js'],
17 //项目输出目录 16 //项目输出目录
18 output: { 17 output: {
19 path: path.resolve(__dirname, 'build'), 18 path: path.resolve(__dirname, 'build'),
20 filename: 'sdk.js', 19 filename: 'sdk.js',
21 libraryTarget: 'umd', 20 libraryTarget: 'umd',
22 - library: "yo_sdk",  
23 - libraryExport: "default" 21 + library: "yo_sdk"
24 }, 22 },
25 //插件 23 //插件
26 plugins: [ 24 plugins: [
27 - new CleanWebpackPlugin(pathsToClean, cleanOptions),//清除历史版本  
28 - new uglify({test: /\.js($|\?)/i,parallel: false}) 25 + new CleanWebpackPlugin(pathsToClean, cleanOptions)//清除历史版本
29 ], 26 ],
30 //加载器 27 //加载器
31 module: { 28 module: {
@@ -41,7 +38,6 @@ module.exports = { @@ -41,7 +38,6 @@ module.exports = {
41 } 38 }
42 ] 39 ]
43 }, 40 },
44 - devtool: "inline-source-map",  
45 //模块路径 41 //模块路径
46 resolve:{ 42 resolve:{
47 alias: { 43 alias: {
This diff could not be displayed because it is too large.