sdk.js
16.2 KB
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.yo_sdk=n():e.yo_sdk=n()}(window,function(){return function(e){var n={};function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(o,r,function(n){return e[n]}.bind(null,r));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=13)}([function(e,n){var t=e.exports={version:"2.5.7"};"number"==typeof __e&&(__e=t)},function(e,n,t){"use strict";var o=function(e){return e&&e.__esModule?e:{default:e}}(t(18));var r=function(e){var n=decodeURIComponent(document.location.href);e&&(n=decodeURIComponent(e));var t="",o=[],r=[];n.indexOf("?")>0&&(t=n.split("?")[1]),t.length>0&&(o=t.split("#")[0].split("&"));for(var i=0;i<o.length;i++){var u={};if(u.name=o[i].split("=")[0],u.value=o[i].split("=")[1],o[i].split("=").length>2)for(var c=2;c<o[i].split("=").length;c++)u.value+="="+o[i].split("=")[c];r.push(u)}var a={};for(i=0;i<r.length;i++)a[r[i].name]=r[i].value;return a};e.exports={invokeMethod:function(e){window.yohoInterface?window.yohoInterface.triggerEvent(e.success||function(){},e.fail||function(){},{method:e.method,arguments:e.args}):e.fail&&e.fail()},getQueryObj:r,linkToMiniApp:function(e,n){var t=e||"";if(t&&t.indexOf("http")<0&&"other"===n&&(t=document.location.protocol+"//"+document.location.host+t),t){var i;if("product"===n||"brand"===n)i=t;else{var u=decodeURIComponent(t).split("?")[0],c=r(t),a="";(0,o.default)(c).forEach(function(e){a+=""===a?"?"+e+"="+c[e]:"&"+e+"="+c[e]}),i="/pages/webview/webview?url="+u+encodeURIComponent(a)}return wx.miniProgram.navigateTo({url:i}),!1}return!0},createLinkButton:function(e,n){var t=document.createElement("a");return t.style.position="fixed",t.style.top=0,t.style.left=0,t.style.border="none",t.style.outline="none",t.style.resize="none",t.style.background="transparent",t.style.color="transparent",t.setAttribute("id",n),t.setAttribute("href",e),document.body.appendChild(t),t}}},function(e,n){var t=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=t)},function(e,n){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,n,t){e.exports=!t(5)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(e,n){e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,n,t){"use strict";var o=function(e){return e&&e.__esModule?e:{default:e}}(t(15));var r=t(7),i=t(17),u=t(1),c=t(8),a=u.getQueryObj,s="";e.exports={env:function(){var e=window.__wxjs_environment;return!e&&navigator.userAgent.match(/yohobuy/i)?(s="app",document.addEventListener("deviceready",function(){})):s=!e&&navigator.userAgent.match(/miniProgram/i)||"miniprogram"===e?"miniprogram":"https://www.yohobuy.com"===location.origin?"pc":"h5",s},loginUrl:function(){var e,n=location.href;return"app"===s?(e="http://m.yohobuy.com/signin.html?refer="+encodeURIComponent(n),n=function(e){var n,t,o,r={};if((n=((e=(e||"").split("?"))[1]||"").split("&"))&&n.length)for(o=0;o<n.length;o++)r[(t=n[o].split("="))[0]]=t[1];return{path:e[0],query:r}}(n),/Android/i.test(navigator.userAgent||"")?(e.indexOf("?")<0&&(e+="?appLogin=1"),location.href.indexOf("&openby")>=0&&(e=e.substring(0,e.indexOf("&openby"))),e+="&"):(location.href.indexOf("#openby")>=0&&(e=e.substring(0,e.indexOf("#openby"))),e+="#"),e+="openby:yohobuy="+(0,o.default)({action:"go.weblogin",params:{priority:"N",jumpurl:{url:n.path,param:n.query},needlogout:"Y"}})):"pc"===s?e="https://www.yoho/signin.html?refer="+encodeURIComponent(location.href):"miniprogram"===s?e="/pages/userCenter/userCenter":(n.indexOf("?")<0?n+="?skcall=1":n+="&skcall=1",e="http://m.yohobuy.com/signin.html?refer="+encodeURIComponent(n)),e},getUser:function(){return new c(function(e){var n={sessionType:i.cookie("app_client_type")||a().app_client_type||"",appVersion:i.cookie("app_version")||a().app_version||""};"h5"===s||"pc"===s?r({url:"//m.yohobuy.com/passport/login/user",jsonp:"callback"}).then(function(t){n.uid=0,200===t.code&&(n.uid=Number(t.data)),n.sessionKey=i.cookie("app_session_key")||a().session_key||"",e(n)}):"app"===s?document.addEventListener("deviceready",function(){return c.all([new c(function(e){u.invokeMethod({method:"get.uid",arguments:{},success:function(n){e(parseInt(n))},fail:function(){var n=Number(i.cookie("app_uid"))||Number(a().uid)||0;e(n)}})}),new c(function(e){u.invokeMethod({method:"get.sessionId",arguments:{},success:function(n){e(n)},fail:function(){var n=i.cookie("app_session_key")||a().session_key||"";e(n)}})})]).then(function(t){n.uid=t[0],n.sessionKey=t[1],e(n)})}):(n.uid=Number(i.cookie("app_uid"))||Number(a().uid)||0,n.sessionKey=i.cookie("app_session_key")||a().session_key||"",e(n))})}}},function(e,n,t){"use strict";var o=t(8);e.exports=function(e){return new o(function(n,t){(e=e||{}).data=e.data||{};var o=e.jsonp;e.data.callback=o;var r=function(e){var n=[];for(var t in e)n.push(encodeURIComponent(t)+"="+encodeURIComponent(e[t]));var o=new Date;return n.push("v="+o.getTime()),n.join("&")}(e.data),i=document.createElement("script");document.body.appendChild(i),window[o]=function(e){return document.body.removeChild(i),clearTimeout(i.timer),window[o]=null,n(e)},i.src=e.url+"?"+r,e.time&&(i.timer=setTimeout(function(){window[o]=null,document.body.removeChild(i),t({message:"超时"})},time))})}},function(e,n,t){"use strict";function o(e){var n=this;n._value=null,n._reason=function(){},n._resolves=[],n._rejects=[],n._status="PENDING",this.then=function(e,t){return new o(function(o,r){function i(n){var t="function"==typeof e&&e(n)||n;t&&"function"==typeof t.then?t.then(function(e){o(e)},function(e){r(e)}):o(t)}function u(e){e="function"==typeof t&&t(e)||e,r(e)}"PENDING"===n._status?(n._resolves.push(i),n._rejects.push(u)):"FULFILLED"===n._status?i(n._value):"REJECTED"===n._status&&u(n._reason)})},e(function(e){setTimeout(function(){n._status="FULFILLED",n._resolves.forEach(function(t){n._value=t(e)})},0)},function(e){setTimeout(function(){n._status="REJECTED",n._rejects.forEach(function(t){n._reason=t(e)})},0)})}o.all=function(e){if(!Array.isArray(e))throw new TypeError("You must pass an array to all.");return new o(function(n,t){var o=0,r=[],i=e.length,u=i;function c(e){return function(t){!function(e,t){r[e]=t,0==--u&&n(r)}(e,t)}}function a(e){t(e)}for(;o<i;o++)e[o].then(c(o),a)})},o.race=function(e){if(!Array.isArray(e))throw new TypeError("You must pass an array to race.");return new o(function(n,t){var o=0,r=e.length;function i(e){n(e)}function u(e){t(e)}for(;o<r;o++)e[o].then(i,u)})},e.exports=o},function(e,n){e.exports=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e}},function(e,n){var t={}.hasOwnProperty;e.exports=function(e,n){return t.call(e,n)}},function(e,n,t){var o=t(24),r=t(9);e.exports=function(e){return o(r(e))}},function(e,n){var t=Math.ceil,o=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?o:t)(e)}},function(e,n,t){e.exports=t(14)},function(e,n,t){"use strict";var o=t(6),r=t(45),i=t(46),u=t(47),c=t(1),a=o.env(),s=new r({loginUrl:o.loginUrl(),env:a}),p=new i(a),f=new u;e.exports={auth:s.auth.bind(s),goLogin:s.goLogin.bind(s),getUser:o.getUser,env:a,link:p.link.bind(p),goBack:p.goBack.bind(p),wxShare:f.wxShare.bind(f),wxSignature:f.wxSignature,getQueryObj:c.getQueryObj,invokeMethod:c.invokeMethod}},function(e,n,t){e.exports={default:t(16),__esModule:!0}},function(e,n,t){var o=t(0),r=o.JSON||(o.JSON={stringify:JSON.stringify});e.exports=function(e){return r.stringify.apply(r,arguments)}},function(e,n,t){"use strict";e.exports={cookie:function(e){return new RegExp(e+"=([^;$]*)","i").test(decodeURIComponent(document.cookie))?RegExp.$1:""},setCookie:function(e,n,t){var o,r,i,u,c="";void 0!==n&&(t=t||{},null===n&&(n="",t.expires=-1),t.expires&&("number"==typeof t.expires||t.expires.toUTCString)&&("number"==typeof t.expires?(u=new Date).setTime(u.getTime()+24*t.expires*60*60*1e3):u=t.expires,c="; expires="+u.toUTCString()),o=t.path?"; path="+t.path:"",r=t.domain?"; domain="+t.domain:"",i=t.secure?"; secure":"",document.cookie=[e,"=",encodeURIComponent(n),c,o,r,i].join(""))}}},function(e,n,t){e.exports={default:t(19),__esModule:!0}},function(e,n,t){t(20),e.exports=t(0).Object.keys},function(e,n,t){var o=t(21),r=t(22);t(34)("keys",function(){return function(e){return r(o(e))}})},function(e,n,t){var o=t(9);e.exports=function(e){return Object(o(e))}},function(e,n,t){var o=t(23),r=t(33);e.exports=Object.keys||function(e){return o(e,r)}},function(e,n,t){var o=t(10),r=t(11),i=t(26)(!1),u=t(29)("IE_PROTO");e.exports=function(e,n){var t,c=r(e),a=0,s=[];for(t in c)t!=u&&o(c,t)&&s.push(t);for(;n.length>a;)o(c,t=n[a++])&&(~i(s,t)||s.push(t));return s}},function(e,n,t){var o=t(25);e.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==o(e)?e.split(""):Object(e)}},function(e,n){var t={}.toString;e.exports=function(e){return t.call(e).slice(8,-1)}},function(e,n,t){var o=t(11),r=t(27),i=t(28);e.exports=function(e){return function(n,t,u){var c,a=o(n),s=r(a.length),p=i(u,s);if(e&&t!=t){for(;s>p;)if((c=a[p++])!=c)return!0}else for(;s>p;p++)if((e||p in a)&&a[p]===t)return e||p||0;return!e&&-1}}},function(e,n,t){var o=t(12),r=Math.min;e.exports=function(e){return e>0?r(o(e),9007199254740991):0}},function(e,n,t){var o=t(12),r=Math.max,i=Math.min;e.exports=function(e,n){return(e=o(e))<0?r(e+n,0):i(e,n)}},function(e,n,t){var o=t(30)("keys"),r=t(32);e.exports=function(e){return o[e]||(o[e]=r(e))}},function(e,n,t){var o=t(0),r=t(2),i=r["__core-js_shared__"]||(r["__core-js_shared__"]={});(e.exports=function(e,n){return i[e]||(i[e]=void 0!==n?n:{})})("versions",[]).push({version:o.version,mode:t(31)?"pure":"global",copyright:"© 2018 Denis Pushkarev (zloirock.ru)"})},function(e,n){e.exports=!0},function(e,n){var t=0,o=Math.random();e.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++t+o).toString(36))}},function(e,n){e.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(e,n,t){var o=t(35),r=t(0),i=t(5);e.exports=function(e,n){var t=(r.Object||{})[e]||Object[e],u={};u[e]=n(t),o(o.S+o.F*i(function(){t(1)}),"Object",u)}},function(e,n,t){var o=t(2),r=t(0),i=t(36),u=t(38),c=t(10),a=function(e,n,t){var s,p,f,l=e&a.F,d=e&a.G,h=e&a.S,m=e&a.P,y=e&a.B,g=e&a.W,v=d?r:r[n]||(r[n]={}),b=v.prototype,w=d?o:h?o[n]:(o[n]||{}).prototype;for(s in d&&(t=n),t)(p=!l&&w&&void 0!==w[s])&&c(v,s)||(f=p?w[s]:t[s],v[s]=d&&"function"!=typeof w[s]?t[s]:y&&p?i(f,o):g&&w[s]==f?function(e){var n=function(n,t,o){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(n);case 2:return new e(n,t)}return new e(n,t,o)}return e.apply(this,arguments)};return n.prototype=e.prototype,n}(f):m&&"function"==typeof f?i(Function.call,f):f,m&&((v.virtual||(v.virtual={}))[s]=f,e&a.R&&b&&!b[s]&&u(b,s,f)))};a.F=1,a.G=2,a.S=4,a.P=8,a.B=16,a.W=32,a.U=64,a.R=128,e.exports=a},function(e,n,t){var o=t(37);e.exports=function(e,n,t){if(o(e),void 0===n)return e;switch(t){case 1:return function(t){return e.call(n,t)};case 2:return function(t,o){return e.call(n,t,o)};case 3:return function(t,o,r){return e.call(n,t,o,r)}}return function(){return e.apply(n,arguments)}}},function(e,n){e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,n,t){var o=t(39),r=t(44);e.exports=t(4)?function(e,n,t){return o.f(e,n,r(1,t))}:function(e,n,t){return e[n]=t,e}},function(e,n,t){var o=t(40),r=t(41),i=t(43),u=Object.defineProperty;n.f=t(4)?Object.defineProperty:function(e,n,t){if(o(e),n=i(n,!0),o(t),r)try{return u(e,n,t)}catch(e){}if("get"in t||"set"in t)throw TypeError("Accessors not supported!");return"value"in t&&(e[n]=t.value),e}},function(e,n,t){var o=t(3);e.exports=function(e){if(!o(e))throw TypeError(e+" is not an object!");return e}},function(e,n,t){e.exports=!t(4)&&!t(5)(function(){return 7!=Object.defineProperty(t(42)("div"),"a",{get:function(){return 7}}).a})},function(e,n,t){var o=t(3),r=t(2).document,i=o(r)&&o(r.createElement);e.exports=function(e){return i?r.createElement(e):{}}},function(e,n,t){var o=t(3);e.exports=function(e,n){if(!o(e))return e;var t,r;if(n&&"function"==typeof(t=e.toString)&&!o(r=t.call(e)))return r;if("function"==typeof(t=e.valueOf)&&!o(r=t.call(e)))return r;if(!n&&"function"==typeof(t=e.toString)&&!o(r=t.call(e)))return r;throw TypeError("Can't convert object to primitive value")}},function(e,n){e.exports=function(e,n){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:n}}},function(e,n,t){"use strict";var o=t(1),r=t(6);e.exports=function(e){var n=this;n.env=e.env,n.url=e.loginUrl,n.goLogin=function(){if("miniprogram"===n.env)wx.miniProgram.switchTab({url:n.url});else if("app"===n.env){var e=document.getElementById("yosdk-login");e||(e=o.createLinkButton(n.url,"yosdk-login")),e.click()}else window.location.href=n.url;return!1},n.auth=function(){r.getUser().then(function(e){if(!e.uid){var t=document.querySelectorAll(".auth");if(t.length)return t.forEach(function(e){e.onclick=function(e){e.preventDefault(),n.goLogin()}}),!0}})}}},function(e,n,t){"use strict";var o=t(1);function r(e){this.env=e}r.prototype.link=function(e){var n=e.currentTarget,t=n.getAttribute("data-type")||"other",r=n.getAttribute("data-id")||"",i=n.getAttribute("data-url")||"",u=n.getAttribute("data-name")||"",c="";if("miniprogram"===this.env)return c="product"===t?"/pages/goodsDetail/goodsDetail?productSkn="+r+"&page_name=goodsList&page_param=5":"brand"===t?"/pages/goodsList/brandStore?shop_id="+r+"&shop_name="+u:i,o.linkToMiniApp(c,t);if(c="pc"===this.env?"product"===t?"https://www.yohobuy.com/product/"+r+".html":"brand"===t?"https://www.yohobuy.com/shop/"+u+"-"+r+".html":i:"product"===t?"//m.yohobuy.com/product/"+r+'.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":'+r+"}}":"brand"===t?"//m.yohobuy.com/product/index/brand?shop_id="+r+'&openby:yohobuy={"action":"go.shop","params":{"shop_id":"'+r+'","shop_template_type":"1","shop_name":"'+u+'","is_red_shop":"1"}}':i,"app"===this.env){var a=document.getElementById("yosdk-goto");return a?a.setAttribute("href",c):a=o.createLinkButton(c,"yosdk-goto"),a.click()}window.location.href=c},r.prototype.goBack=function(){"app"===this.env?o.invokeMethod({method:"go.back"}):"miniprogram"===this.env?wx.miniProgram.navigateBack():history.go(-1)},e.exports=r},function(e,n,t){"use strict";var o=t(7);function r(){}r.prototype.wxSignature=function(e){o("//action.yoho.cn/api/share/getSignPackage?pageurl="+encodeURIComponent(location.href.split("#")[0])).then(function(n){if(n.appId){var t=n.appId.toString(),o=n.timestamp,i=n.nonceStr.toString(),u=n.signature.toString();return r.config({debug:!1,appId:t,timestamp:o,nonceStr:i,signature:u,jsApiList:["checkJsApi","onMenuShareTimeline","onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo","hideMenuItems","showMenuItems","hideAllNonBaseMenuItem","showAllNonBaseMenuItem","translateVoice","startRecord","stopRecord","onVoiceRecordEnd","playVoice","pauseVoice","stopVoice","uploadVoice","onVoicePlayEnd","downloadVoice","chooseImage","previewImage","uploadImage","downloadImage","getNetworkType","openLocation","getLocation","hideOptionMenu","showOptionMenu","closeWindow","scanQRCode","chooseWXPay","openProductSpecificView","addCard","chooseCard","openCard"]}),e&&setTimeout(e,500),!0}return!1})},r.prototype.wxShare=function(e){this.wxSignature(function(){var n=e||{title:"",imgUrl:"",desc:"",link:document.location.href,success:function(){}};r.ready(function(){r.onMenuShareAppMessage(n),r.onMenuShareTimeline(n),r.onMenuShareQQ(n),r.onMenuShareWeibo(n)})})},e.exports=r}])});