Showing
6 changed files
with
43 additions
and
18 deletions
This diff could not be displayed because it is too large.
@@ -25,6 +25,7 @@ var parseUrl = function (url) { | @@ -25,6 +25,7 @@ var parseUrl = function (url) { | ||
25 | } | 25 | } |
26 | }; | 26 | }; |
27 | 27 | ||
28 | +var webCacheUser; | ||
28 | var env = ''; | 29 | var env = ''; |
29 | 30 | ||
30 | var _appGetUid = function () { | 31 | var _appGetUid = function () { |
@@ -121,19 +122,26 @@ module.exports = { | @@ -121,19 +122,26 @@ module.exports = { | ||
121 | return url; | 122 | return url; |
122 | }, | 123 | }, |
123 | //uid | 124 | //uid |
124 | - getUser: function () { | 125 | + getUser: function (force) { |
125 | return new Promise(function (resolve) { | 126 | return new Promise(function (resolve) { |
126 | var obj = { | 127 | var obj = { |
127 | sessionType: cookies.cookie('app_client_type') || getQueryObj().app_client_type || '', | 128 | sessionType: cookies.cookie('app_client_type') || getQueryObj().app_client_type || '', |
128 | appVersion: cookies.cookie('app_version') || getQueryObj().app_version || '' | 129 | appVersion: cookies.cookie('app_version') || getQueryObj().app_version || '' |
129 | }; | 130 | }; |
130 | if (env === 'h5' || env === 'pc') { | 131 | if (env === 'h5' || env === 'pc') { |
132 | + if (!force && webCacheUser) { | ||
133 | + return resolve(webCacheUser); | ||
134 | + }; | ||
135 | + | ||
131 | jsonp({url: '//m.yohobuy.com/passport/login/user', jsonp: 'callback'}).then(function (r) { | 136 | jsonp({url: '//m.yohobuy.com/passport/login/user', jsonp: 'callback'}).then(function (r) { |
132 | obj.uid = 0; | 137 | obj.uid = 0; |
133 | - if (r.code === 200) { | ||
134 | - obj.uid = Number(r.data) | ||
135 | - } | ||
136 | obj.sessionKey = cookies.cookie('app_session_key') || getQueryObj().session_key || ''; | 138 | obj.sessionKey = cookies.cookie('app_session_key') || getQueryObj().session_key || ''; |
139 | + | ||
140 | + if (r.code === 200 || r.code === 403) { | ||
141 | + obj.uid = Number(r.data) || 0; | ||
142 | + webCacheUser = obj; | ||
143 | + } | ||
144 | + | ||
137 | resolve(obj); | 145 | resolve(obj); |
138 | }); | 146 | }); |
139 | } else if (env === 'app') { | 147 | } else if (env === 'app') { |
@@ -23,7 +23,7 @@ function login(obj) { | @@ -23,7 +23,7 @@ function login(obj) { | ||
23 | 23 | ||
24 | _this.auth = function (nodeList, user) { | 24 | _this.auth = function (nodeList, user) { |
25 | if (!user.uid) { | 25 | if (!user.uid) { |
26 | - nodeList.forEach(function (value) { | 26 | + [].forEach.call(nodeList, function(value) { |
27 | value.onclick = function (event) { | 27 | value.onclick = function (event) { |
28 | event.preventDefault(); | 28 | event.preventDefault(); |
29 | _this.goLogin(); | 29 | _this.goLogin(); |
@@ -98,8 +98,8 @@ var _initCoupon = function (nodeList, user) { | @@ -98,8 +98,8 @@ var _initCoupon = function (nodeList, user) { | ||
98 | cookies.setCookie('yoho-conpon-token', ''); | 98 | cookies.setCookie('yoho-conpon-token', ''); |
99 | } | 99 | } |
100 | } | 100 | } |
101 | - console.log(nodeList); | ||
102 | - nodeList.forEach(function (value) { | 101 | + |
102 | + [].forEach.call(nodeList, function (value) { | ||
103 | value.onclick = function (event) { | 103 | value.onclick = function (event) { |
104 | event.preventDefault(); | 104 | event.preventDefault(); |
105 | var el = event.currentTarget; | 105 | var el = event.currentTarget; |
@@ -130,7 +130,7 @@ var _initRedEnvelope = function (nodeList, user) { | @@ -130,7 +130,7 @@ var _initRedEnvelope = function (nodeList, user) { | ||
130 | cookies.setCookie('yoho-redenvelope-token', ''); | 130 | cookies.setCookie('yoho-redenvelope-token', ''); |
131 | } | 131 | } |
132 | } | 132 | } |
133 | - nodeList.forEach(function (value) { | 133 | + [].forEach.call(nodeList, function (value) { |
134 | value.onclick = function (event) { | 134 | value.onclick = function (event) { |
135 | event.preventDefault(); | 135 | event.preventDefault(); |
136 | var el = event.currentTarget; | 136 | var el = event.currentTarget; |
1 | var tipTmpl = '<div class="tip {{tipClassName}}"><div class="title">{{title}}</div><div class="content">{{content}}</div><a class="button {{buttonClass}}">{{button}}</a></div>' | 1 | var tipTmpl = '<div class="tip {{tipClassName}}"><div class="title">{{title}}</div><div class="content">{{content}}</div><a class="button {{buttonClass}}">{{button}}</a></div>' |
2 | var toastTmpl = '<div style="{{style}}" class="feature-toast-content">{{content}}</div>'; | 2 | var toastTmpl = '<div style="{{style}}" class="feature-toast-content">{{content}}</div>'; |
3 | +var frameRate = 75; // 动画帧率 | ||
3 | var showTip = function (data) { | 4 | var showTip = function (data) { |
4 | var tipNode = null; | 5 | var tipNode = null; |
5 | data = data || { | 6 | data = data || { |
@@ -91,6 +92,9 @@ var toast = function (content, options) { | @@ -91,6 +92,9 @@ var toast = function (content, options) { | ||
91 | }, (obj.duration && obj.duration > 0) ? obj.duration : 2000); | 92 | }, (obj.duration && obj.duration > 0) ? obj.duration : 2000); |
92 | }; | 93 | }; |
93 | function fadeIn(el,time){ | 94 | function fadeIn(el,time){ |
95 | + var mt = 1000 / frameRate, | ||
96 | + opacityStep = mt / time; | ||
97 | + | ||
94 | if(el.style.opacity === ""){ | 98 | if(el.style.opacity === ""){ |
95 | el.style.opacity = 0; | 99 | el.style.opacity = 0; |
96 | } | 100 | } |
@@ -98,17 +102,22 @@ function fadeIn(el,time){ | @@ -98,17 +102,22 @@ function fadeIn(el,time){ | ||
98 | el.style.display = 'block'; | 102 | el.style.display = 'block'; |
99 | } | 103 | } |
100 | 104 | ||
101 | - var t = setInterval(function(){ | ||
102 | - if(el.style.opacity < 1){ | ||
103 | - el.style.opacity = parseFloat(el.style.opacity)+0.01; | 105 | + el.timer && clearInterval(el.timer); |
106 | + el.timer = setInterval(function(){ | ||
107 | + if(el.style.opacity < 1 - opacityStep){ | ||
108 | + el.style.opacity = parseFloat(el.style.opacity) + opacityStep; | ||
104 | } | 109 | } |
105 | else{ | 110 | else{ |
106 | - clearInterval(t); | 111 | + clearInterval(el.timer); |
112 | + el.style.opacity = 1; | ||
107 | } | 113 | } |
108 | - },time/100); | 114 | + }, mt); |
109 | } | 115 | } |
110 | 116 | ||
111 | function fadeOut(el,time){ | 117 | function fadeOut(el,time){ |
118 | + var mt = 1000 / frameRate, | ||
119 | + opacityStep = mt / time; | ||
120 | + | ||
112 | if(el.style.opacity === ""){ | 121 | if(el.style.opacity === ""){ |
113 | el.style.opacity = 1; | 122 | el.style.opacity = 1; |
114 | } | 123 | } |
@@ -116,15 +125,17 @@ function fadeOut(el,time){ | @@ -116,15 +125,17 @@ function fadeOut(el,time){ | ||
116 | el.style.display = 'block'; | 125 | el.style.display = 'block'; |
117 | } | 126 | } |
118 | 127 | ||
119 | - var t = setInterval(function(){ | ||
120 | - if(el.style.opacity > 0){ | ||
121 | - el.style.opacity = parseFloat(el.style.opacity)-0.01; | 128 | + el.timer && clearInterval(el.timer); |
129 | + el.timer = setInterval(function(){ | ||
130 | + if(el.style.opacity > opacityStep){ | ||
131 | + el.style.opacity = parseFloat(el.style.opacity) - mt / time; | ||
122 | } | 132 | } |
123 | else{ | 133 | else{ |
124 | - clearInterval(t); | 134 | + clearInterval(el.timer); |
135 | + el.style.opacity = 0; | ||
125 | el.style.display = 'none' | 136 | el.style.display = 'none' |
126 | } | 137 | } |
127 | - },time/100); | 138 | + }, mt); |
128 | } | 139 | } |
129 | 140 | ||
130 | module.exports = { | 141 | module.exports = { |
@@ -6,8 +6,14 @@ function jsonp(params) { | @@ -6,8 +6,14 @@ function jsonp(params) { | ||
6 | params = params || {}; | 6 | params = params || {}; |
7 | params.data = params.data || {}; | 7 | params.data = params.data || {}; |
8 | //创建script标签并加入到页面中 | 8 | //创建script标签并加入到页面中 |
9 | + | ||
9 | var callbackName = params.jsonp; | 10 | var callbackName = params.jsonp; |
10 | 11 | ||
12 | + if (window[callbackName]) { | ||
13 | + callbackName += Math.floor(Math.random() * 1000); | ||
14 | + params.jsonp = callbackName; | ||
15 | + } | ||
16 | + | ||
11 | // 设置传递给后台的回调参数名 | 17 | // 设置传递给后台的回调参数名 |
12 | params.data['callback'] = callbackName; | 18 | params.data['callback'] = callbackName; |
13 | var data = formatParams(params.data); | 19 | var data = formatParams(params.data); |
-
Please register or login to post a comment