作者 anyv
1 个管道 的构建 失败 耗费 0 秒

分类添加

@@ -19,49 +19,15 @@ class LabelController extends AdminBaseController{ @@ -19,49 +19,15 @@ class LabelController extends AdminBaseController{
19 } 19 }
20 20
21 /** 21 /**
22 - * 分类添加 22 + *分类添加
23 */ 23 */
24 public function classify_add(){ 24 public function classify_add(){
25 25
26 - $data['name'] = $_POST['name'];  
27 - $data['create_time'] = time();  
28 - $res = Db::name('classification') -> insertGetId($data);  
29 - if($res){  
30 - $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);  
31 - $data['id'] = $res;  
32 - return json_encode($data);  
33 - }else{  
34 - return true;  
35 - }  
36 -  
37 - }  
38 -  
39 - /**  
40 - * 分类编辑  
41 - */  
42 - public function classify_edit(){  
43 -  
44 - $id = $_POST['id'];  
45 - $data = Db::name('classification') -> where('id',$id) -> find();  
46 - return json_encode($data); 26 + return $this -> fetch();
47 27
48 } 28 }
49 29
50 - /**  
51 - * 分类编辑修改数据  
52 - */  
53 - public function classify_edit_post(){  
54 -  
55 - $data['id'] = $_POST['id'];  
56 - $data['name'] = $_POST['name'];  
57 - $res = Db::name('classification') -> update($data);  
58 - if($res){  
59 - return true;  
60 - }else{  
61 - return false;  
62 - }  
63 30
64 - }  
65 31
66 /** 32 /**
67 * 删除分类 33 * 删除分类
  1 +<include file="public@header"/>
  2 +</head>
  3 +<body>
  4 +<div class="wrap js-check-wrap">
  5 + <ul class="nav nav-tabs">
  6 + <li><a href="{:url('Label/classify_list')}">分类管理</a></li>
  7 + <li class="active">添加分类</li>
  8 + </ul>
  9 + <form action="{:url('Label/classify_add')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
  10 + <div class="row">
  11 + <div class="col-md-9">
  12 + <table class="table table-bordered">
  13 + <tr>
  14 + <th>标题<span class="form-required">*</span></th>
  15 + <td>
  16 + <input class="form-control" type="text" name="post[post_title]"
  17 + id="title" required value="" placeholder="请输入标题"/>
  18 + </td>
  19 + </tr>
  20 + </table>
  21 + <div class="form-group">
  22 + <div class="col-sm-offset-2 col-sm-10">
  23 + <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
  24 + </div>
  25 + </div>
  26 + </div>
  27 + <div class="col-md-3">
  28 + <table class="table table-bordered">
  29 + <tr>
  30 + <th><b>缩略图</b></th>
  31 + </tr>
  32 + <tr>
  33 + <td>
  34 + <div style="text-align: center;">
  35 + <input type="hidden" name="post[more][thumbnail]" id="thumbnail" value="">
  36 + <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
  37 + <img src="__TMPL__/public/assets/images/default-thumbnail.png"
  38 + id="thumbnail-preview"
  39 + width="135" style="cursor: pointer"/>
  40 + </a>
  41 + <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
  42 + </div>
  43 + </td>
  44 + </tr>
  45 + </table>
  46 + </div>
  47 + </div>
  48 + </form>
  49 +</div>
  50 +</body>
  51 +</html>
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <li class="active"><a href="#">分类管理</a></li> 6 <li class="active"><a href="#">分类管理</a></li>
7 <li ><a href="{:url('Label/lab_list')}">标签管理</a></li> 7 <li ><a href="{:url('Label/lab_list')}">标签管理</a></li>
8 </ul> 8 </ul>
9 - <button type="button" class="btn btn-default" style="margin-top: 10px;" data-toggle="modal" data-target="#myModal">添加分类</button> 9 + <a href="{:url('Label/classify_add')}"><button type="button" class="btn btn-default" style="margin-top: 10px;">添加分类</button></a>
10 <table class="table table-bordered"> 10 <table class="table table-bordered">
11 <caption>分类管理列表</caption> 11 <caption>分类管理列表</caption>
12 <thead> 12 <thead>
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 <td>{$vo.name}</td> 22 <td>{$vo.name}</td>
23 <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td> 23 <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
24 <td> 24 <td>
25 - <button type="button" class="btn btn-default" data-toggle="modal" data-target="#myeditModal" onclick="myedit({$vo.id})">编辑</button> 25 + <button type="button" class="btn btn-default">编辑</button>
26 <button type="button" class="btn btn-default" onclick="del({$vo.id})">删除</button> 26 <button type="button" class="btn btn-default" onclick="del({$vo.id})">删除</button>
27 </td> 27 </td>
28 </tr> 28 </tr>
@@ -30,99 +30,9 @@ @@ -30,99 +30,9 @@
30 </tbody> 30 </tbody>
31 </table> 31 </table>
32 </div> 32 </div>
33 -<!-- 添加模态框(Modal) -->  
34 -<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">  
35 - <div class="modal-dialog">  
36 - <div class="modal-content">  
37 - <div class="modal-header">  
38 - <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>  
39 - <h4 class="modal-title" id="myModalLabel">添加分类</h4>  
40 - </div>  
41 - <div class="modal-body">  
42 - <div style="padding: 10px 100px 10px;">  
43 - <form class="bs-example bs-example-form" role="form">  
44 - <div class="input-group">  
45 - <span class="input-group-addon">分类名称:</span>  
46 - <input type="text" class="form-control" name="name">  
47 - </div>  
48 - <br>  
49 - </form>  
50 - </div>  
51 - </div>  
52 - <div class="modal-footer">  
53 - <button type="button" class="btn btn-default guanbi" data-dismiss="modal">关闭</button>  
54 - <button type="button" class="btn btn-primary" onclick="mysave()">保存</button>  
55 - </div>  
56 - </div><!-- /.modal-content -->  
57 - </div><!-- /.modal -->  
58 -</div>  
59 -  
60 -<!-- 编辑模态框(Modal) -->  
61 -<div class="modal fade" id="myeditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">  
62 - <div class="modal-dialog">  
63 - <div class="modal-content">  
64 - <div class="modal-header">  
65 - <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>  
66 - <h4 class="modal-title" id="myModalLabel">编辑</h4>  
67 - </div>  
68 - <div class="modal-body">  
69 - <div style="padding: 10px 100px 10px;">  
70 - <form class="bs-example bs-example-form" role="form">  
71 - <div class="input-group">  
72 - <span class="input-group-addon">分类名称:</span>  
73 - <input type="text" class="form-control" name="edit_name">  
74 - <input type="hidden" name="id" value="">  
75 - </div>  
76 - <br>  
77 - </form>  
78 - </div>  
79 - </div>  
80 - <div class="modal-footer">  
81 - <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>  
82 - <button type="button" class="btn btn-primary" onclick="edit_post()">保存</button>  
83 - </div>  
84 - </div><!-- /.modal-content -->  
85 - </div><!-- /.modal -->  
86 -</div>  
87 33
88 <script type="text/javascript" src="__STATIC__/js/admin.js"></script> 34 <script type="text/javascript" src="__STATIC__/js/admin.js"></script>
89 <script> 35 <script>
90 - //添加分类保存  
91 - function mysave(){  
92 - name = $("input[name='name']").val();  
93 - if(name == ''){  
94 - alert('分类名称不能为空');  
95 - }else{  
96 - $.post("{:url('Label/classify_add')}",{name:name},function(data){  
97 - if(data){  
98 - shuju = JSON.parse(data);  
99 - $('.tb').append("<tr class='tr"+shuju.id+"'><td>"+name+"</td><td>"+shuju.create_time+"</td><td><button type='button' class='btn btn-default' data-toggle='modal' data-target='#myeditModal' onclick='myedit("+shuju.id+")'>编辑</button><button type='button' class='btn btn-default' onclick='del("+shuju.id+")'>删除</button></td></tr>");  
100 - $('.guanbi').trigger('click');  
101 - }else{  
102 - alert('添加失败');  
103 - }  
104 - });  
105 - }  
106 - }  
107 -  
108 - //编辑分类  
109 - function myedit(id){  
110 - $.post("{:url('Label/classify_edit')}",{id:id},function(data){  
111 - shuju = JSON.parse(data);  
112 - $("input[name='edit_name']").val(shuju.name);  
113 - $("input[name='id']").val(shuju.id);  
114 - })  
115 - }  
116 -  
117 - //编辑修改分类  
118 - function edit_post(){  
119 - name = $("input[name='edit_name']").val();  
120 - id = $("input[name='id']").val();  
121 - $.post("{:url('Label/classify_edit_post')}",{name:name,id:id},function(data){  
122 - window.location.reload();  
123 - });  
124 - }  
125 -  
126 //删除 36 //删除
127 function del(id){ 37 function del(id){
128 ccc = window.confirm('是否删除这条分类?'); 38 ccc = window.confirm('是否删除这条分类?');