store.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. @Name: 应用市场
  3. @Author: xuxinyu
  4. */
  5. layui.define(['fly', 'carousel', 'rate', 'laypage'], function(exports){
  6. var $ = layui.jquery
  7. ,element = layui.element
  8. ,carousel = layui.carousel
  9. ,rate = layui.rate
  10. ,laypage = layui.laypage
  11. ,form = layui.form
  12. ,util = layui.util;
  13. //轮播渲染
  14. var elemBanner = $('#LAY-store-banner'), ins1 = carousel.render({
  15. elem: elemBanner
  16. ,width: '100%'
  17. ,height: elemBanner.height() + 'px'
  18. ,arrow: 'none'
  19. ,interval: 6000
  20. ,anim: 'fade'
  21. });
  22. $(window).on('resize', function(){
  23. var width = $(this).prop('innerWidth');
  24. ins1.reload({
  25. height: (width > 768 ? 460 : 115) + 'px'
  26. });
  27. });
  28. //监听轮播切换事件
  29. carousel.on('change(LAY-store-banner)', function(obj){
  30. $('.shop-banner').css('background', obj.item.data('color'));
  31. });
  32. //搜索区域固定在上
  33. var topbar = $('#LAY-topbar')
  34. ,topbarScroll = topbar.find('.input-search')
  35. ,fixTop = function(){
  36. var top = $(window).scrollTop();
  37. if(top > 200){
  38. topbar.height(topbar.height())
  39. topbarScroll.addClass('scroll');
  40. } else {
  41. topbar.height('auto')
  42. topbarScroll.removeClass('scroll');
  43. }
  44. };
  45. fixTop(), $(window).on('scroll', fixTop);
  46. //监听排序
  47. form.on('select(storeOrder)', function(obj){
  48. var pathname = location.pathname
  49. ,byExp = /(\/*)(\bby\b)(\/[^\/]+)(\/*)/
  50. ,pageExp = /(\/*)(\bpage\b)(\/[^\/]+)(\/*)/;
  51. //如果末尾没有 / ,则追加
  52. if(!/\/$/.test(pathname)){
  53. pathname += '/';
  54. }
  55. //如果存在排序路由
  56. if(byExp.test(pathname)){
  57. pathname = pathname.replace(byExp, '$1$2/'+ obj.value +'$4');
  58. console.log(1)
  59. } else if(pageExp.test(pathname)){ //如果存在分页路由
  60. pathname = pathname.replace(pageExp, '/by/'+ obj.value + '$1$2$3$4');
  61. } else {
  62. pathname = pathname + 'by/'+ obj.value +'/';
  63. }
  64. //跳转
  65. location.href = pathname + location.search + location.hash;
  66. });
  67. //固定 bar
  68. util.fixbar({
  69. //bar1: '',
  70. click: function(type){
  71. if(type === 'bar1'){
  72. //location.href = '/jie/add/';
  73. }
  74. }
  75. });
  76. exports('store', {});
  77. });