Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完善导航CURD #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions wwwroot/Application/Admin/Controller/ChannelController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ class ChannelController extends AdminController {
*/
public function index(){
$pid = I('get.pid', 0);
if($pid){
$data = M('Channel')->where("id={$pid}")->field(true)->find();
$this->assign('data',$data);
}
/* 获取频道列表 */
$map = array('status' => array('gt', -1), 'pid'=>$pid);
$title = trim(I('get.title'));
if($title)
$map['title'] = array('like',"%{$title}%");
$list = M('Channel')->where($map)->order('sort asc,id asc')->select();

$this->assign('list', $list);
$this->assign('pid', $pid);
// 记录当前列表页的cookie
Cookie('__forward__',$_SERVER['REQUEST_URI']);

$this->meta_title = '导航管理';
$this->display();
}
Expand All @@ -43,7 +53,7 @@ public function add(){
if($data){
$id = $Channel->add();
if($id){
$this->success('新增成功', U('index'));
$this->success('新增成功', Cookie('__forward__'));
//记录行为
action_log('update_channel', 'channel', $id, UID);
} else {
Expand Down Expand Up @@ -79,7 +89,7 @@ public function edit($id = 0){
if($Channel->save()){
//记录行为
action_log('update_channel', 'channel', $data['id'], UID);
$this->success('编辑成功', U('index'));
$this->success('编辑成功',Cookie('__forward__'));
} else {
$this->error('编辑失败');
}
Expand Down Expand Up @@ -130,7 +140,43 @@ public function del(){
$this->error('删除失败!');
}
}


public function import(){
if(IS_POST){
$tree = I('post.tree');
$lists = explode(PHP_EOL, $tree);
$channelModel = M('Channel');
if($lists == array()){
$this->error('请按格式填写批量导入的菜单,至少一个菜单');
}else{
$pid = I('post.pid');
foreach ($lists as $key => $value) {
$record = explode('|', $value);
if(count($record) == 2){
$channelModel->add(array(
'title'=>$record[0],
'url'=>$record[1],
'pid'=>$pid,
'sort'=>0,
'create_time'=>time(),
'update_time'=>time(),
'status'=>0,
'target'=>0,
));
}
}
$this->success('导入成功',U('index?pid='.$pid));
}
}else{
$this->meta_title = '批量导入前台导航';
$pid = (int)I('get.pid');
$this->assign('pid', $pid);
$data = M('Channel')->where("id={$pid}")->field(true)->find();
$this->assign('data', $data);
$this->display();
}
}

/**
* 导航排序
* @author huajie <[email protected]>
Expand Down Expand Up @@ -169,4 +215,4 @@ public function sort(){
$this->error('非法请求!');
}
}
}
}
50 changes: 50 additions & 0 deletions wwwroot/Application/Admin/View/Channel/import.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<extend name="Public/base" />

<block name="body">
<div class="main-title cf">
<h2>
批量导入 [{$data.title|default='顶级导航'}]
</h2>
</div>
<!-- 标签页导航 -->
<div class="tab-wrap">
<div class="tab-content">
<!-- 表单 -->
<form id="form" action="{:U('import')}" method="post" class="form-horizontal">
<!-- 基础文档模型 -->
<div id="tab1" class="tab-pane in tab1">
<div class="form-item cf">
<label class="item-label">导入的内容<span class="check-tips">(请按照导入格式输入)</span></label>
<div class="controls">
<label class="textarea input-large">
<textarea name="tree"></textarea>
</label>
</div>
<span class="check-tips">导入格式:标题|url(回车键)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标题|url</span>
</div>
</div>
<div class="form-item cf">
<button class="btn submit-btn ajax-post hidden" id="submit" type="submit" target-form="form-horizontal">确 定</button>
<a class="btn btn-return" href="{:U('index?pid='.$pid)}">返 回</a>
<input type="hidden" name="pid" value="{$pid}"/>
<input type="hidden" name="cate_id" value="{$cate_id|default=0}">
</div>
</form>
</div>
</div>
</block>

<block name="script">
<script type="text/javascript">

$('#submit').click(function(){
$('#form').submit();
});


$(function(){
//导航高亮
highlight_subnav('{:U('index')}');
});
</script>
</block>
39 changes: 34 additions & 5 deletions wwwroot/Application/Admin/View/Channel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

<block name="body">
<div class="main-title">
<h2>导航管理</h2>
</div>
<h2><present name="data">[ {$data.title} ] 子</present>导航管理 </h2>
</div>

<div class="cf">
<a class="btn" href="{:U('add','pid='.$pid)}">新 增</a>
<a class="btn" href="javascript:;">删 除</a>
<button class="btn ajax-post confirm" url="{:U('del')}" target-form="ids">删 除</button>
<a class="btn" href="{:U('import',array('pid'=>I('get.pid',0)))}">导 入</a>
<button class="btn list_sort" url="{:U('sort',array('pid'=>I('get.pid',0)),'')}">排序</button>
<!-- 高级搜索 -->
<div class="search-form fr cf">
<div class="sleft">
<input type="text" name="title" class="search-input" value="{:I('title')}" placeholder="请输入导航名称">
<a class="sch-btn" href="javascript:;" id="search" url="__SELF__"><i class="btn-search"></i></a>
</div>
</div>
</div>

<div class="data-table table-striped">
Expand All @@ -29,7 +37,7 @@ <h2>导航管理</h2>
<notempty name="list">
<volist name="list" id="channel">
<tr>
<td><input class="ids row-selected" type="checkbox" name="" id="" value="{$channel['id']}"> </td>
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$channel['id']}"> </td>
<td>{$channel.id}</td>
<td><a href="{:U('index?pid='.$channel['id'])}">{$channel.title}</a></td>
<td>{$channel.url}</td>
Expand Down Expand Up @@ -69,6 +77,27 @@ <h2>导航管理</h2>
window.location.href = url + '/ids/' + param;
}
});

//搜索功能
$("#search").click(function() {
var url = $(this).attr('url');
var query = $('.search-form').find('input').serialize();
query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
query = query.replace(/^&/g, '');
if (url.indexOf('?') > 0) {
url += '&' + query;
} else {
url += '?' + query;
}
window.location.href = url;
});
//回车搜索
$(".search-input").keyup(function(e) {
if (e.keyCode === 13) {
$("#search").click();
return false;
}
});
});
</script>
</block>
</block>