var _paq = _paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//www.tssjsc.cn/matomo/"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.es'; s.parentNode.insertBefore(g,s); })(); //生成URL function getURL(d, p) { return baseUrl.split("?")[0] + "?i=" + baseI + "&c=entry&m=sz_yi&p=" + p + "&do=" + d; } Object.values=Object.values||function(v){ var ret=[]; $.each(v,function(index,item){ ret.push(item); }); return ret; }; //弹出对话框 function xConfirm(msg, fn, ok, cancel, fncancel, style) { var msg = msg || "您确定?", fn = fn || function () {}, ok = ok || "确定", cancel = cancel || "取消", fncancel = fncancel || function () {}, style = style || false, ele = $('\
\
\

' + msg + '

\
\ \ \
\
\
\ '); if (style == true) { ele.addClass("style"); $(".title", ele).removeClass("pixelbottom"); } $("body").append(ele); $("#xccancel", ele).click(function () { ele.fadeOut(200); fncancel(); }); $("#xcok", ele).click(function () { fn(); ele.fadeOut(200); }); } //页面加载效果 var loading = { start: function (msg) { var msg = msg || "加载中..."; if ($("#loading").length != 0) { return; } var html = '\
\
\
\
' + msg + '
\
\
\ '; this.ele = $(html); $("body").append(this.ele); }, end: function () { $(this.ele).css("transition", "all 0s").fadeOut(500, function () { $(this).remove(); }); }, error: function (err) { var err = err || "未知错误"; $("#loadingwrap", this.ele).html("发生错误" + "[" + err + "]"); this.ele.click(function () { $(this).fadeOut(400, function () { $(this).remove(); }); }); } } //延迟加载 function lazyLoad(ele) { var ele = ele || document.body; $("img:not(.loaded)", ele).each(function (index, item) { if (item.dataset.src && item.getBoundingClientRect().top < innerHeight) { item.src = item.dataset.src; $(item).addClass("loaded"); } }); } //设置不过期的cookie function setCookie(nam, val) { document.cookie = nam + "=" + val + ";path=/;expires=Thu, 18 Dec 2500 12:00:00 UTC"; } //删除cookie function delCookie(nam) { document.cookie = nam + '=; Max-Age=-99999999;'; } //获取cookie值 function getCookieValue(nam, restrict) { var restrict = restrict == undefined ? true : restrict; var ret; var arr = document.cookie.split('; '); if (restrict) { for (var i = 0; i < arr.length; i++) { if (nam == arr[i].split("=")[0]) { ret = arr[i].split("=")[1]; } } } else { ret = []; for (var i = 0; i < arr.length; i++) { if (arr[i].split("=")[0].search(nam.replace("[", "\\[")) != -1) { ret = ret.concat(JSON.parse(arr[i].split("=")[1])); } } ret = JSON.stringify(ret); } return ret; } //获取url参数值 function getSearchValue(name, ifarr) { if (!ifarr) { var searchstr = window.location.search.slice(1); var searcharr = searchstr.split("&"); var ret = ''; searcharr.forEach(function (item, index) { if (item.split("=")[0] == name) { ret = item.split("=")[1]; } }); return ret; } else { var ret = []; var arr = decodeURIComponent(location.href).split("&" + name + "[]"); $.each(arr, function (index, item) { if (index == 0) return; ret.push(item.split("&")[0].replace("=", "")); }); return ret; } } //安卓toast模拟 function toast(str, ttl) { if (str == "") return; var ttl = ttl || 2000 $(".toast").remove(); var ele = $("
"); $(ele).html(str); $(ele).addClass("toast"); $("body").append(ele); $(ele).delay(ttl).fadeOut(300); } //判断数组是否包含某值 Array.prototype.contains = function (v) { var ret; $.each(this, function (index, item) { if (item === v) { ret = [true, index]; } }); if (ret) { return ret; } else { return false; } }; //html页面中加载vue组件模板 function loadVueTemplates() { $("script[type='text/x-template']").each(function (index, item) { $.ajax({ url: item.src, type: "get", async: false, success: function (res) { $(item).html(res); } }); }); }; //JS Vue组件中加载模板 function vueTemplate(url) { var ret = ""; $.ajax({ url: url, type: "get", async: false, success: function (res) { ret = res; } }); return ret; }; //加载单文件Vue组件 function vueComponent(name, url) { Vue.component(name, function (resolve) { $.get(url).then(function (res) { $("body").prepend(res); resolve(eval(name + "options")); }); }); } //显示分享指南,需要引入模板common/share function showShareGuide() { $("#share-guide").show(); } //置顶按钮事件监听 function toTop(ele) { var starty = 0, lasty = 0, currenty = 0, offsety = 0; $("#totop").on("touchstart", function (e) { e.stopPropagation(); starty = e.originalEvent.changedTouches[0].pageY; lasty = e.originalEvent.changedTouches[0].pageY; currenty = e.originalEvent.changedTouches[0].pageY; }); $("#totop").on("touchmove", function (e) { e.preventDefault(); currenty = e.originalEvent.changedTouches[0].pageY; offsety = currenty - lasty; $(".side-tool").css({ bottom: "-=" + offsety }); lasty = e.originalEvent.changedTouches[0].pageY; }); $("#totop").click(function () { if (ele == window) { $("body,html").animate({ scrollTop: 0 }, 400); } else { ele.animate({ scrollTop: 0 }, 400); } }); $("#totop").on("animationend", function (e) { if (e.originalEvent.animationName == "toright") { $(this).removeClass("show reverse"); } }); $(ele).on("scroll", function () { if (ele == window) { if (scrollY > innerHeight * 2) { $("#totop").addClass("show"); } else { if ($("#totop").hasClass("show")) { $("#totop").addClass("reverse"); } } } else { if (ele.scrollTop() > ele.innerHeight() * 2) { $("#totop").addClass("show"); } else { if ($("#totop").hasClass("show")) { $("#totop").addClass("reverse"); } } } }); } //微信JSSDK function wxjssdk(config, apilist, fn, fn2) { var fn2 = fn2 || function () {}; if (navigator.userAgent.search("MicroMessenger") != -1 && navigator.platform != "Win32" && navigator.platform.search("Mac") == -1) { if (typeof wx != "undefined") { wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: config.appId, // 必填,公众号的唯一标识 timestamp: config.timestamp, // 必填,生成签名的时间戳 nonceStr: config.nonceStr, // 必填,生成签名的随机串 signature: config.signature, // 必填,签名,见附录1 jsApiList: apilist // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function () { fn(); }); } } } //准备wxjssdk function wxjssdkReady(config) { if (typeof wx != "undefined") { wx.config(config); } } //时间加0 Number.prototype.addZero = function () { if (this.toString().length == 1) { return "0" + this; } else { return this; } } //图片上传 function uploadImg(url, obj, fn1, fn2) { var fn1 = fn1 || function () {}, fn2 = fn2 || function (res) { res.message || toast("上传失败") }; if (obj.size >= 8388608) { toast("图片最大只支持8M"); return; } if (!obj) { toast("已取消上传"); return; }; toast("正在上传图片"); fd = new FormData(); fd.append("file", "imgFile0"); fd.append("imgFile0", obj); $.ajax({ url: url, processData: false, contentType: false, type: "post", data: fd, dataType: "json", success: function (res) { if (res.status == 'success') { toast("上传成功"); fn1(res); } else { fn2(res); } }, error: function (err) { toast("上传失败"); } }); }; //格式化时间 function formatTime(dt) { var hour = Math.floor(dt / 3600); var min = Math.floor((dt - hour * 3600) / 60); var sec = Math.floor(dt - hour * 3600 - min * 60); return Math.abs(hour).addZero() + ":" + min.addZero() + ":" + sec.addZero(); } //格式化日期 function formatDate(dt) { var dt = new Date(dt * 1000); return dt.getFullYear().addZero() + "-" + (dt.getMonth() + 1).addZero() + "-" + dt.getDate().addZero(); } //计算字符数 String.prototype.charLength = function () { var len = 0; for (var i = 0; i < this.length; i++) { if (this.charCodeAt(i) > 127 || this.charCodeAt(i) == 94) { len += 2; } else { len++; } } return len; } //截取20个字符 String.prototype.restrict = function (length) { var ret = ""; var len = 0; var arr = []; for (var i = 0; i < this.length; i++) { if (len < length) { if (this.charCodeAt(i) > 127 || this.charCodeAt(i) == 94) { len += 2; } else { len++; } arr.push(this[i]); } } if (len >= length) { ret = arr.join("") + "..." } else { ret = arr.join("") } return ret } $.fn.extend({ //判断是否为空 isEmpty: function () { if (this.val() == "") { return true; } else { return false; } }, //是否为手机号 isMobile: function (v) { var obj; if (!this || this == window) return false; if (this.constructor.toString().search("Number") != -1 || this.constructor.toString().search("String") != -1) { obj = $.trim(this); } else { obj = $.trim(this.val()); } if (!/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/.test(obj)) { return false; } else { return true; } }, //倒计时功能 countDown: function (sec, txt) { var sec = sec || 60; var txt = txt || "发送验证码"; $(this).prop("disabled", true); $(this).text("剩余" + sec + "秒"); var itv = setInterval(function () { sec--; $(this).text("剩余" + sec + "秒"); if (sec <= 0) { $(this).prop("disabled", false); clearInterval(itv); $(this).text(txt); } }.bind(this), 1000); }, //全屏显示 toggleFullScreen: function () { if (event !== undefined) event.stopPropagation(); if (location.hash == "#fullscreen") { history.back(); return; } if ($(".fullscreen").length == 0) { $(this).wrap("
"); enableScale(); location.hash = "fullscreen"; } } }) //禁用缩放 function disableScale() { $("meta[name='viewport']").prop("content", "width=device-width, initial-scale=1.0,maximum-scale=1,minimum-scale=1,user-scalable=no"); } //启用缩放 function enableScale() { $("meta[name='viewport']").prop("content", "width=device-width, initial-scale=1.0,maximum-scale=3,minimum-scale=1,user-scalable=yes"); } //获取购物车商品数 function getCartNum() { var last = $(".global-cart-num").text(); $.get({ url: getURL("shop", "cart"), dataType: "json", data: { op: "gettotal" }, success: function (res) { if (res.status == 1 && res.result.total != 0) { if ($(".global-cart-num").text() != res.result.total) { $(".global-cart-num").addClass("bump"); } $(".global-cart-num").text(res.result.total); } } }); } //退出全屏 function exitFullScreen() { $('.fullscreen>*').unwrap('.fullscreen'); disableScale(); } //微信支付功能 function wechatPay(obj, fnsuccess, fnfail, fncancel, reurl) { var fnsuccess = fnsuccess || function () {}; var fnfail = fnfail || function () {}; var fncancel = fncancel || function () {}; if (obj.mweb_url && navigator.userAgent.search("MicroMessenger") == -1) { location.href = obj.mweb_url + "&redirect_url=" + encodeURIComponent(reurl); } else { wx.chooseWXPay({ timestamp: obj.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 nonceStr: obj.nonceStr, // 支付签名随机串,不长于 32 位 package: obj.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***) signType: obj.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' paySign: obj.paySign, // 支付签名 success: function (res) { fnsuccess(); }, fail: function (err) { toast(JSON.stringify(err.errMsg)); fnfail(err); }, cancel: function () { toast("支付已取消"); fncancel(); } }); } } $(function () { if (!window.noglobalcart && $(".global-cart-num").length && window.memberid) { getCartNum(); } window.onhashchange = function (e) { if (location.hash == "") { exitFullScreen(); } } if (location.hash == "#fullscreen") { history.replaceState({}, "", location.href.split("#")[0]) } });