前端页面的问题
来源:9-7 店铺列表页前端的开发下
墨肃
2019-12-17
如图所示,在店铺列表这里,我复制了老师的前端代码,跟着视频把里面不一样的改掉以后,访问的这个全部类别与全部区域跟视频里的看起来不同,很别扭,
视频界面如下:
我对于前端的认识很浅,希望老师可以帮我指正我的错误,谢谢老师
6回答
-
同学好,感觉你可以直接使用我的最终源码,没问题后,再对比下区别在哪里
shoplist.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>商店列表</title> <meta name="viewport" content="initial-scale=1, maximum-scale=1"> <link rel="shortcut icon" href="/favicon.ico"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css"> <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css"> <link rel="stylesheet" href="../resources/css/frontend/shoplist.css"> </head> <body> <div class="page-group"> <div class="page"> <header class="bar bar-nav"> <a class="button button-link button-nav pull-left" external href="index" data-transition='slide-out'> <span class="icon icon-left"></span> 返回 </a> <h1 class="title">商店列表</h1> </header> <div class="bar bar-header-secondary"> <div class="searchbar"> <a class="searchbar-cancel">取消</a> <!-- 搜索栏 --> <div class="search-input"> <label class="icon icon-search" for="search"></label> <input type="search" id='search' placeholder='输入关键字...' /> </div> </div> </div> <nav class="bar bar-tab"> <a class="tab-item" href="/o2o/frontend/index" external> <span class="icon icon-home"></span> <span class="tab-label">首页</span> </a> <a class="tab-item" href="#" id="me"> <span class="icon icon-me"></span> <span class="tab-label">我</span> </a> </nav> <div class="content infinite-scroll infinite-scroll-bottom" data-distance="100"> <!-- 类别列表展示区 --> <div class="shoplist-button-div" id="shoplist-search-div"> <!-- <a href="#" class="button">所有货物</a> <a href="#" class="button">吃的</a> <a href="#" class="button">喝的</a> <a href="#" class="button">Usual Button 1</a> <a href="#" class="button">Usual Button 1</a> <a href="#" class="button">Usual Button 1</a> --> </div> <div class="select-wrap"> <!-- 区域列表展示区 --> <select class="select" id="area-search"></select> </div> <!-- 店铺列表在此添加 --> <div class="list-div shop-list"> <!-- <div class="card"> <div class="card-header">传统火锅店</div> <div class="card-content"> <div class="list-block media-list"> <ul> <li class="item-content"> <div class="item-media"> <img src="http://gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i3/TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg" width="44"> </div> <div class="item-inner"> <div class="item-subtitle"></div> </div> </li> </ul> </div> </div> <div class="card-footer"> <span>2015/01/15</span> <span>5 评论</span> </div> </div> --> </div> <div class="infinite-scroll-preloader"> <div class="preloader"></div> </div> </div> </div> </div> <!--侧边栏 --> <div class="panel-overlay"></div> <div class="panel panel-right panel-reveal" id="panel-right-demo"> <div class="content-block"> <p> <a href="/o2o/local/accountbind?usertype=1" class="close-panel">绑定帐号</a> </p> <p> <a href="/o2o/local/changepsw?usertype=1" class="close-panel">修改密码</a> </p> <p> <a href="/o2o/frontend/myrecord" class="close-panel">消费记录</a> </p> <p> <a href="/o2o/frontend/mypoint" class="close-panel">我的积分</a> </p> <p> <a href="/o2o/frontend/pointrecord" class="close-panel">兑换记录</a> </p> <p> <a href="#" usertype="1" class="close-panel" id="log-out">登出系统</a> </p> <!-- Click on link with "close-panel" class will close panel --> </div> </div> <script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script> <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script> <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script> <script type='text/javascript' src='../resources/js/common/common.js' charset='utf-8'></script> <script type='text/javascript' src='../resources/js/frontend/shoplist.js' charset='utf-8'></script> <script type='text/javascript' src='../resources/js/local/login.js' charset='utf-8'></script> </body> </html>
012019-12-19 -
翔仔
2019-12-18
shoplist.css
.infinite-scroll-preloader { margin-top: -5px; } .shoplist-button-div { margin: 0 .3rem; } .shoplist-button-div > .button { width: 30%; height: 1.5rem; line-height: 1.5rem; display: inline-block; margin: 1%; overflow: hidden; } .select-wrap { margin: 0 .5rem; } .select { border: 1px solid #0894ec; color: #0894ec; background-color: #efeff4; width: 100%; height: 1.5rem; font-size: .7rem; }
012020-03-09 -
翔仔
2019-12-18
shoplist.js
$(function() { var loading = false; // 分页允许返回的最大条数,超过此数则禁止访问后台 var maxItems = 999; // 一页返回的最大条数 var pageSize = 3; // 获取店铺列表的URL var listUrl = '/o2o/frontend/listshops'; // 获取店铺类别列表以及区域列表的URL var searchDivUrl = '/o2o/frontend/listshopspageinfo'; // 页码 var pageNum = 1; // 从地址栏URL里尝试获取parent shop category id. var parentId = getQueryString('parentId'); // 是否选择了子类 var selectedParent = false; if (parentId){ selectedParent = true; } var areaId = ''; var shopCategoryId = ''; var shopName = ''; // 渲染出店铺类别列表以及区域列表以供搜索 getSearchDivData(); // 预先加载10条店铺信息 addItems(pageSize, pageNum); /** * 获取店铺类别列表以及区域列表信息 * * @returns */ function getSearchDivData() { // 如果传入了parentId,则取出此一级类别下面的所有二级类别 var url = searchDivUrl + '?' + 'parentId=' + parentId; $ .getJSON( url, function(data) { if (data.success) { // 获取后台返回过来的店铺类别列表 var shopCategoryList = data.shopCategoryList; var html = ''; html += '<a href="#" class="button" data-category-id=""> 全部类别 </a>'; // 遍历店铺类别列表,拼接出a标签集 shopCategoryList .map(function(item, index) { html += '<a href="#" class="button" data-category-id=' + item.shopCategoryId + '>' + item.shopCategoryName + '</a>'; }); // 将拼接好的类别标签嵌入前台的html组件里 $('#shoplist-search-div').html(html); var selectOptions = '<option value="">全部街道</option>'; // 获取后台返回过来的区域信息列表 var areaList = data.areaList; // 遍历区域信息列表,拼接出option标签集 areaList.map(function(item, index) { selectOptions += '<option value="' + item.areaId + '">' + item.areaName + '</option>'; }); // 将标签集添加进area列表里 $('#area-search').html(selectOptions); } }); } /** * 获取分页展示的店铺列表信息 * * @param pageSize * @param pageIndex * @returns */ function addItems(pageSize, pageIndex) { // 拼接出查询的URL,赋空值默认就去掉这个条件的限制,有值就代表按这个条件去查询 var url = listUrl + '?' + 'pageIndex=' + pageIndex + '&pageSize=' + pageSize + '&parentId=' + parentId + '&areaId=' + areaId + '&shopCategoryId=' + shopCategoryId + '&shopName=' + shopName; // 设定加载符,若还在后台取数据则不能再次访问后台,避免多次重复加载 loading = true; // 访问后台获取相应查询条件下的店铺列表 $.getJSON(url, function(data) { if (data.success) { // 获取当前查询条件下店铺的总数 maxItems = data.count; var html = ''; // 遍历店铺列表,拼接出卡片集合 data.shopList.map(function(item, index) { html += '' + '<div class="card" data-shop-id="' + item.shopId + '">' + '<div class="card-header">' + item.shopName + '</div>' + '<div class="card-content">' + '<div class="list-block media-list">' + '<ul>' + '<li class="item-content">' + '<div class="item-media">' + '<img src="' + item.shopImg + '" width="44">' + '</div>' + '<div class="item-inner">' + '<div class="item-subtitle">' + item.shopDesc + '</div>' + '</div>' + '</li>' + '</ul>' + '</div>' + '</div>' + '<div class="card-footer">' + '<p class="color-gray">' + new Date(item.lastEditTime).Format("yyyy-MM-dd") + '更新</p>' + '<span>点击查看</span>' + '</div>' + '</div>'; }); // 将卡片集合添加到目标HTML组件里 $('.list-div').append(html); // 获取目前为止已显示的卡片总数,包含之前已经加载的 var total = $('.list-div .card').length; // 若总数达到跟按照此查询条件列出来的总数一致,则停止后台的加载 if (total >= maxItems) { // 隐藏提示符 $('.infinite-scroll-preloader').hide(); } else { $('.infinite-scroll-preloader').show(); } // 否则页码加1,继续load出新的店铺 pageNum += 1; // 加载结束,可以再次加载了 loading = false; // 刷新页面,显示新加载的店铺 $.refreshScroller(); } }); } // 下滑屏幕自动进行分页搜索 $(document).on('infinite', '.infinite-scroll-bottom', function() { if (loading) return; addItems(pageSize, pageNum); }); // 点击店铺的卡片进入该店铺的详情页 $('.shop-list').on('click', '.card', function(e) { var shopId = e.currentTarget.dataset.shopId; window.location.href = '/o2o/frontend/shopdetail?shopId=' + shopId; }); // 选择新的店铺类别之后,重置页码,清空原先的店铺列表,按照新的类别去查询 $('#shoplist-search-div').on( 'click', '.button', function(e) { if (parentId && selectedParent) {// 如果传递过来的是一个父类下的子类 shopCategoryId = e.target.dataset.categoryId; // 若之前已选定了别的category,则移除其选定效果,改成选定新的 if ($(e.target).hasClass('button-fill')) { $(e.target).removeClass('button-fill'); shopCategoryId = ''; } else { $(e.target).addClass('button-fill').siblings() .removeClass('button-fill'); } // 由于查询条件改变,清空店铺列表再进行查询 $('.list-div').empty(); // 重置页码 pageNum = 1; addItems(pageSize, pageNum); } else {// 如果传递过来的父类为空,则按照父类查询 parentId = e.target.dataset.categoryId; if ($(e.target).hasClass('button-fill')) { $(e.target).removeClass('button-fill'); parentId = ''; } else { $(e.target).addClass('button-fill').siblings() .removeClass('button-fill'); } // 由于查询条件改变,清空店铺列表再进行查询 $('.list-div').empty(); // 重置页码 pageNum = 1; addItems(pageSize, pageNum); } }); // 需要查询的店铺名字发生变化后,重置页码,清空原先的店铺列表,按照新的名字去查询 $('#search').on('change', function(e) { shopName = e.target.value; $('.list-div').empty(); pageNum = 1; addItems(pageSize, pageNum); }); // 区域信息发生变化后,重置页码,清空原先的店铺列表,按照新的区域去查询 $('#area-search').on('change', function() { areaId = $('#area-search').val(); $('.list-div').empty(); pageNum = 1; addItems(pageSize, pageNum); }); // 点击后打开右侧栏 $('#me').click(function() { $.openPanel('#panel-right-demo'); }); // 初始化页面 $.init(); });
00 -
墨肃
提问者
2019-12-17
上面是我的html代码和JS代码,求指正,谢谢
00 -
墨肃
提问者
2019-12-17
$(function() {
var loading = false;
// 分页允许返回的最大条数,超过此数则禁止访问后台
var maxItems = 999;
// 一页返回的最大条数
var pageSize = 2;
// 获取店铺列表的URL
var listUrl = '/o3o/frontend/listshops';
// 获取店铺类别列表以及区域列表的URL
var searchDivUrl = '/o3o/frontend/listshopspageinfo';
// 页码
var pageNum = 1;
// 从地址栏URL里尝试获取parent shop category id.
var parentId = getQueryString('parentId');
// 是否选择了子类
/* var selectedParent = false;
if (parentId){
selectedParent = true;
}*/
var areaId = '';
var shopCategoryId = '';
var shopName = '';
// 渲染出店铺类别列表以及区域列表以供搜索
getSearchDivData();
// 预先加载10条店铺信息
addItems(pageSize, pageNum);
/**
* 获取店铺类别列表以及区域列表信息
*
* @returns
*/
function getSearchDivData() {
// 如果传入了parentId,则取出此一级类别下面的所有二级类别
var url = searchDivUrl + '?' + 'parentId=' + parentId;
$
.getJSON(
url,
function(data) {
if (data.success) {
// 获取后台返回过来的店铺类别列表
var shopCategoryList = data.shopCategoryList;
var html = '';
html += '<a href="#" class="button" data-category-id=""> 全部类别 </a>';
// 遍历店铺类别列表,拼接出a标签集
shopCategoryList
.map(function(item, index) {
html += '<a href="#" class="button" data-category-id='
+ item.shopCategoryId
+ '>'
+ item.shopCategoryName
+ '</a>';
});
// 将拼接好的类别标签嵌入前台的html组件里
$('#shoplist-search-div').html(html);
var selectOptions = '<option value="">全部区域</option>';
// 获取后台返回过来的区域信息列表
var areaList = data.areaList;
// 遍历区域信息列表,拼接出option标签集
areaList.map(function(item, index) {
selectOptions += '<option value="'
+ item.areaId + '">'
+ item.areaName + '</option>';
});
// 将标签集添加进area列表里
$('#area-search').html(selectOptions);
}
});
}
/**
* 获取分页展示的店铺列表信息
*
* @param pageSize
* @param pageIndex
* @returns
*/
function addItems(pageSize, pageIndex) {
// 拼接出查询的URL,赋空值默认就去掉这个条件的限制,有值就代表按这个条件去查询
var url = listUrl + '?' + 'pageIndex=' + pageIndex + '&pageSize='
+ pageSize + '&parentId=' + parentId + '&areaId=' + areaId
+ '&shopCategoryId=' + shopCategoryId + '&shopName=' + shopName;
// 设定加载符,若还在后台取数据则不能再次访问后台,避免多次重复加载
loading = true;
// 访问后台获取相应查询条件下的店铺列表
$.getJSON(url, function(data) {
if (data.success) {
// 获取当前查询条件下店铺的总数
maxItems = data.count;
var html = '';
// 遍历店铺列表,拼接出卡片集合
data.shopList.map(function(item, index) {
html += '' + '<div class="card" data-shop-id="'
+ item.shopId + '">' + '<div class="card-header">'
+ item.shopName + '</div>'
+ '<div class="card-content">'
+ '<div class="list-block media-list">' + '<ul>'
+ '<li class="item-content">'
+ '<div class="item-media">' + '<img src="'
+ item.shopImg + '" width="44">' + '</div>'
+ '<div class="item-inner">'
+ '<div class="item-subtitle">' + item.shopDesc
+ '</div>' + '</div>' + '</li>' + '</ul>'
+ '</div>' + '</div>' + '<div class="card-footer">'
+ '<p class="color-gray">'
+ new Date(item.lastEditTime).Format("yyyy-MM-dd")
+ '更新</p>' + '<span>点击查看</span>' + '</div>'
+ '</div>';
});
// 将卡片集合添加到目标HTML组件里
$('.list-div').append(html);
// 获取目前为止已显示的卡片总数,包含之前已经加载的
var total = $('.list-div .card').length;
// 若总数达到跟按照此查询条件列出来的总数一致,则停止后台的加载
/* if (total >= maxItems) {
// 隐藏提示符
$('.infinite-scroll-preloader').hide();
} else {
$('.infinite-scroll-preloader').show();
}*/
if(total >= maxItems){
//加载完毕,则注销无限加载的事件,以防不必要的加载(会导致资源浪费)
$.detachInfiniteScroll($(".infinite-scroll"));
//删除加载提示符
$(".infinite-scroll-preloader").remove();
}
// 否则页码加1,继续load出新的店铺
pageNum += 1;
// 加载结束,可以再次加载了
loading = false;
// 刷新页面,显示新加载的店铺
$.refreshScroller();
}
});
}
// 下滑屏幕自动进行分页搜索
$(document).on('infinite', '.infinite-scroll-bottom', function() {
if (loading)
return;
addItems(pageSize, pageNum);
});
// 点击店铺的卡片进入该店铺的详情页
$('.shop-list').on('click', '.card', function(e) {
var shopId = e.currentTarget.dataset.shopId;
window.location.href = '/o3o/frontend/shopdetail?shopId=' + shopId;
});
// 选择新的店铺类别之后,重置页码,清空原先的店铺列表,按照新的类别去查询
$('#shoplist-search-div').on(
'click',
'.button',
function(e) {
// if (parentId && selectedParent) {// 如果传递过来的是一个父类下的子类
if (parentId) {// 如果传递过来的是一个父类下的子类
shopCategoryId = e.target.dataset.categoryId;
// 若之前已选定了别的category,则移除其选定效果,改成选定新的
if ($(e.target).hasClass('button-fill')) {
$(e.target).removeClass('button-fill');
shopCategoryId = '';
} else {
$(e.target).addClass('button-fill').siblings()
.removeClass('button-fill');
}
// 由于查询条件改变,清空店铺列表再进行查询
$('.list-div').empty();
// 重置页码
pageNum = 1;
addItems(pageSize, pageNum);
} else {// 如果传递过来的父类为空,则按照父类查询
parentId = e.target.dataset.categoryId;
if ($(e.target).hasClass('button-fill')) {
$(e.target).removeClass('button-fill');
parentId = '';
} else {
$(e.target).addClass('button-fill').siblings()
.removeClass('button-fill');
}
// 由于查询条件改变,清空店铺列表再进行查询
$('.list-div').empty();
// 重置页码
pageNum = 1;
addItems(pageSize, pageNum);
parentId='';
}
});
// 需要查询的店铺名字发生变化后,重置页码,清空原先的店铺列表,按照新的名字去查询
// $('#search').on('change', function(e) {
$('#search').on('input', function(e) {
shopName = e.target.value;
$('.list-div').empty();
pageNum = 1;
addItems(pageSize, pageNum);
});
// 区域信息发生变化后,重置页码,清空原先的店铺列表,按照新的区域去查询
$('#area-search').on('change', function() {
areaId = $('#area-search').val();
$('.list-div').empty();
pageNum = 1;
addItems(pageSize, pageNum);
});
// 点击后打开右侧栏
$('#me').click(function() {
$.openPanel('#panel-right-demo');
});
// 初始化页面
$.init();
});
00 -
墨肃
提问者
2019-12-17
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>商店列表</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet"
href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<link rel="stylesheet"
href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
<link rel="stylesheet" href="../resources/css/frontend/shoplist.css">
</head>
<body>
<div class="page-group">
<div class="page">
<header class="bar bar-nav">
<a class="button button-link button-nav pull-left" external
href="index" data-transition='slide-out'> <span
class="icon icon-left"></span> 返回
</a>
<h1 class="title">商店列表</h1>
</header>
<div class="bar bar-header-secondary">
<div class="searchbar">
<a class="searchbar-cancel">取消</a>
<!-- 搜索栏 -->
<div class="search-input">
<label class="icon icon-search" for="search"></label> <input
type="search" id='search' placeholder='输入关键字...' />
</div>
</div>
</div>
<nav class="bar bar-tab">
<a class="tab-item" href="/o2o/frontend/index" external> <span
class="icon icon-home"></span> <span class="tab-label">首页</span>
</a> <a class="tab-item" href="#" id="me"> <span
class="icon icon-me"></span> <span class="tab-label">我</span>
</a>
</nav>
<div class="content infinite-scroll infinite-scroll-bottom"
data-distance="100">
<!-- 类别列表展示区 -->
<div class="shoplist-button-div" id="shoplist-search-div">
<!-- <a href="#" class="button">所有货物</a>
<a href="#" class="button">吃的</a>
<a href="#" class="button">喝的</a>
<a href="#" class="button">Usual Button 1</a>
<a href="#" class="button">Usual Button 1</a>
<a href="#" class="button">Usual Button 1</a> -->
</div>
<div class="select-wrap">
<!-- 区域列表展示区 -->
<select class="select" id="area-search"></select>
</div>
<!-- 店铺列表在此添加 -->
<div class="list-div shop-list">
<!-- <div class="card">
<div class="card-header">传统火锅店</div>
<div class="card-content">
<div class="list-block media-list">
<ul>
<li class="item-content">
<div class="item-media">
<img src="http://gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i3/TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg" width="44">
</div>
<div class="item-inner">
<div class="item-subtitle"></div>
</div>
</li>
</ul>
</div>
</div>
<div class="card-footer">
<span>2019/12/12</span>
<span>5 评论</span>
</div>
</div> -->
</div>
<!-- 无极分页加载这个控件 -->
<div class="infinite-scroll-preloader">
<div class="preloader"></div>
</div>
</div>
</div>
</div>
<!--侧边栏 -->
<div class="panel-overlay"></div>
<div class="panel panel-right panel-reveal" id="panel-right-demo">
<div class="content-block">
<!-- <p>
<a href="/o3o/local/accountbind?usertype=1" class="close-panel">绑定帐号</a>
</p>
<p>
<a href="/o3o/local/changepsw?usertype=1" class="close-panel">修改密码</a>
</p> -->
<p>
<a href="/o3o/frontend/myrecord" class="close-panel">消费记录</a>
</p>
<p>
<a href="/o3o/frontend/mypoint" class="close-panel">我的积分</a>
</p>
<p>
<a href="/o3o/frontend/pointrecord" class="close-panel">兑换记录</a>
</p>
<!-- <p>
<a href="#" usertype="1" class="close-panel" id="log-out">登出系统</a>
</p> -->
<!-- Click on link with "close-panel" class will close panel -->
</div>
</div>
<script type='text/javascript'
src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript'
src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript'
src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
<script type='text/javascript' src='../resources/js/common/common.js'
charset='utf-8'></script>
<script type='text/javascript'
src='../resources/js/frontend/shoplist.js' charset='utf-8'></script>
<script type='text/javascript' src='../resources/js/local/login.js'
charset='utf-8'></script>
</body>
</html>
00
相似问题