Skip to content

Commit

Permalink
文章列表页添加文章搜索及标记筛选功能
Browse files Browse the repository at this point in the history
  • Loading branch information
livisky committed Jul 1, 2016
1 parent 8f0e160 commit a553ac8
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 132 deletions.
37 changes: 31 additions & 6 deletions src/admin/controller/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,42 @@ export default class extends Base
*/
async indexAction()
{
let articlelist ={},result={}
let articlelist ={},result={},list={};
let selval=this.get('type');
let searchtxt=this.get('search');
// 设置分页
if(this.post('marksel')){

if(selval){
//文章筛选
let map={};
map[this.post('marksel')]=1;
articlelist = await this.model("article").field("*,li_article.id as aid").join("li_tags ON li_article.tag=li_tags.id").where(map).page(this.get("page"), this.get("pagesize")).order("createtime DESC").select();
map[this.get('type')]=1;
articlelist = await this.model("article").join({
tags: {on: "tag, id"},
item: {on: ["item", "id"]},
}).where(map).page(this.get("page"), this.get("pagesize")).order("createtime DESC").select();
result = await this.model("article").where(map).page(this.get('page'), this.get('pagesize')).order("createtime DESC").countSelect();
this.assign("type", selval);
}else if(searchtxt){
//文章搜索
let map={title: ["like", "%"+searchtxt+"%"]};
articlelist = await this.model("article").join({
tags: {on: "tag, id"},
item: {on: ["item", "id"]},
}).where(map).page(this.get("page"), this.get("pagesize")).order("createtime DESC").select();
result = await this.model("article").where(map).page(this.get('page'), this.get('pagesize')).order("createtime DESC").countSelect();
if(articlelist.length==0){
let map={id:searchtxt*1};
articlelist = await this.model("article").where(map).page(this.get("page"), this.get("pagesize")).order("createtime DESC").select();
result = await this.model("article").where(map).page(this.get('page'), this.get('pagesize')).order("createtime DESC").countSelect();
}
this.assign("type", '');
}else{
articlelist = await this.model("article").field("*,li_article.id as aid").join("li_tags ON li_article.tag=li_tags.id").page(this.get("page"), this.get("pagesize")).order("createtime DESC").select();
let map={};
articlelist = await this.model("article").join({
tags: {on: "tag, id"},
item: {on: ["item", "id"]},
}).where(map).page(this.get("page"), this.get("pagesize")).order("createtime DESC").select();
result = await this.model("article").page(this.get('page'), this.get('pagesize')).order("createtime DESC").countSelect();
this.assign("type", '');
}
let Page = think.adapter("template", "page");
let page = new Page(this.http);
Expand Down
10 changes: 1 addition & 9 deletions view/admin/content_article.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
<link rel="stylesheet" href="<%=_web.url%>static/vendors/webuploader/ezviz/upload.css"/>
<script src="<%=_web.url%>static/vendors/webuploader/ezviz/jquery.form.js"></script>
<script src="<%=_web.url%>static/vendors/webuploader/ezviz/uploader.js"></script>
<link rel="stylesheet" href="<%=_web.url%>static/src/css/business/admin/article/article.css">
<body>
<style>
#filepick a{padding: 55px 15px;}
#filepick{text-align: center;vertical-align: middle; width: 140px; height: 130px}
.webuploader-pick{padding: 50px 50px; background: #fff; }
#uploader-demo{margin-top:20px;width: 142px; border: 1px dashed #ccc}
.flag span{margin-right: 10px;}
input[type=checkbox], input[type=radio]{margin:0px;}
.row {margin-top: 15px;}
</style>
<!-- Table -->
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> <a href="/admin/index/welcome">首页</a><span class="c-gray en">&gt;</span> 文章添加 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
Expand Down
122 changes: 10 additions & 112 deletions view/admin/content_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
<link rel="stylesheet" href="<%=_web.url%>static/vendors/webuploader/ezviz/upload.css"/>
<script src="<%=_web.url%>static/vendors/webuploader/ezviz/jquery.form.js"></script>
<script src="<%=_web.url%>static/vendors/webuploader/ezviz/uploader.js"></script>
<style>
.modal-backdrop{background-color: #fff;}
</style>
<link rel="stylesheet" href="<%=_web.url%>static/src/css/business/admin/article/article.css">
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> <a href="/admin/index/welcome">首页</a><span class="c-gray en">&gt;</span> 文章列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container" style="margin-bottom: 140px;">
<% if(!isdraft){ %>
<div class="text-c">
<input type="text" name="" id="" placeholder=" 文章名称" style="width:250px" class="input-text">
<button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont"></i> 搜资讯</button>
<input type="text" name="searchText" id="searchText" placeholder=" 文章名称" style="width:250px" class="input-text">
<button name="" id="search_article" class="btn btn-success" type="submit"><i class="Hui-iconfont"></i> 搜资讯</button>
</div>
<%}%>
<div class="cl pd-5 bg-1 bk-gray mt-20" style="margin-bottom: 15px;">
Expand All @@ -28,15 +26,16 @@
<i class="Hui-iconfont"></i> 批量删除
</a>
</span>

<span class="r">
标记筛选&nbsp;
<span class="select-box inline">
<select name="" class="select" id="markselect">
<option value="totop">文章置顶</option>
<option value="torecom">站长推荐</option>
<option value="topicrecom">图文推荐</option>
<option value="" <%=(type==="all")?'selected':''%> >全部文章</option>
<option value="totop" <%=(type==="totop")?'selected':''%> >文章置顶</option>
<option value="torecom" <%=(type==="torecom")?'selected':''%> >站长推荐</option>
<option value="topicrecom" <%=(type==="topicrecom")?'selected':''%> >图文推荐</option>
</select>
<input type="hidden" id="markval" value="<%=type%>">
</span>&nbsp;
</span>
</div>
Expand Down Expand Up @@ -69,7 +68,7 @@
<a style="cursor:pointer" class="text-primary" onclick="window.open('/preview/<%=item.aid%>','_blank')" title="查看"><%=item.title%></a>
<% }%>
</td>
<td><%=item.item%></td>
<td><%=item.itemname%></td>
<td><%=item.tagname%></td>
<td><%=liFormatDate(think.datetime(item.cteatetime))%></td>
<td><%=item.view%></td>
Expand Down Expand Up @@ -107,107 +106,6 @@
</div>
</div>
</div>
<script>
$('.add-img-btn input[type="file"]').on('change', function () {
var $this = $(this);
var addimgBtn=$this.parent();

if($this.val()){
$this.upload({
url: '/admin/content/uploadfile',
data:{__CSRF__:G_csrf},
success: function (result) {
if (result) {
} else {
console.log('上传失败');
}
},
error: function (code, xhr, status, error) {
console.log(error ? ('上传失败: ' + error) : "上传失败");
}
});
}
});

$(function () {
$('.delete').bind('click', function () {
var delId = $(this).attr("del-id");
var delids=[];
delids.push(delId);
var r = confirm("确定删除?");
if (r) {
$.ajax({
url: '/admin/content/delsome',
data: {delarr:delids,__CSRF__: G_csrf},
type: 'POST',
success: function (json) {
if (json.errno === 0) {
alert("删除成功!");
window.location.href = "/admin/content";
}
}
})
} else {
}
})

$("#markselect").on('change',function(){
var selval=$(this).val();
$.ajax({
url: '/admin/content/index',
data: {marksel:selval,__CSRF__: G_csrf},
type: 'POST'
})
})

//发布文章
$('#published').bind('click', function () {
var pubId = $(this).attr("pub-id");
var r = confirm("确定发布?");
if (r) {
$.ajax({
url: '/admin/content/updatestatus',
data: {id:pubId,__CSRF__: G_csrf},
type: 'POST',
success: function (json) {
debugger
if (json.errno === 0) {
alert("发布成功!");
window.location.href = "/admin/content/draftlist";
}
}
})
} else {
}
})
})


var delsome=function(){
var delids=[];
$.each($('input[type="checkbox"]','tbody'),function(i,item){
if($(item).is(':checked')){
delids.push($(this).val());
}
})
var r = confirm("确定删除?");
if (r) {
$.ajax({
url: '/admin/content/delsome',
data: {delarr:delids,__CSRF__: G_csrf},
type: 'POST',
success: function (json) {
if (json.errno === 0) {
alert("删除成功!");
window.location.href = "/admin/content";
}
}
})
} else {
return false
}
}
</script>

<script type="text/javascript" src="<%=_web.url%>static/src/js/business/admin/contentList.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions www/static/src/css/business/admin/article/article.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#filepick a{padding: 55px 15px;}
#filepick{text-align: center;vertical-align: middle; width: 140px; height: 130px}
.webuploader-pick{padding: 50px 50px; background: #fff; }
#uploader-demo{margin-top:20px;width: 142px; border: 1px dashed #ccc}
.flag span{margin-right: 10px;}
input[type=checkbox], input[type=radio]{margin:0px;}
.row {margin-top: 15px;}
.modal-backdrop{background-color: #fff;}
5 changes: 0 additions & 5 deletions www/static/src/js/business/admin/content.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Created by livi on 16/4/19.
*/

//生成编辑器
// var editor = new wangEditor('editor');
// editor.create();
//上传markdown文件,返回html解析并赋值
$('.add-img-btn2 input[type="file"]').on('change', function () {
var $this = $(this);
var addimgBtn=$this.parent();
Expand Down
56 changes: 56 additions & 0 deletions www/static/src/js/business/admin/contentList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Created by livi on 16/4/19.
*/
//文章搜索
$("#search_article").on('click',function(){
var searchTxt=$("#searchText").val();
window.location.href="/admin/content/index?page=1&pagesize=10&search="+searchTxt;
})
$("#markselect").on('change',function(){
var filter=$(this).val();
window.location.href="/admin/content/index?page=1&pagesize=10&type="+filter;
})
$('.delete').bind('click', function () {
var delId = $(this).attr("del-id");
var delids = [];
delids.push(delId);
var r = confirm("确定删除?");
if (r) {
$.ajax({
url: '/admin/content/delsome',
data: {delarr: delids, __CSRF__: G_csrf},
type: 'POST',
success: function (json) {
if (json.errno === 0) {
alert("删除成功!");
window.location.href = "/admin/content";
}
}
})
} else {
}
})
var delsome = function () {
var delids = [];
$.each($('input[type="checkbox"]', 'tbody'), function (i, item) {
if ($(item).is(':checked')) {
delids.push($(this).val());
}
})
var r = confirm("确定删除?");
if (r) {
$.ajax({
url: '/admin/content/delsome',
data: {delarr: delids, __CSRF__: G_csrf},
type: 'POST',
success: function (json) {
if (json.errno === 0) {
alert("删除成功!");
window.location.href = "/admin/content";
}
}
})
} else {
return false
}
}

0 comments on commit a553ac8

Please sign in to comment.