index.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <article class="cl pd-10" style="min-width: 900px;">
  2. <div class="cl pd-5 bg-1 bk-gray mt-20">
  3. <span class="l">
  4. <a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
  5. <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
  6. <a class="btn btn-primary radius" href="javascript:save(0);">
  7. <i class="Hui-iconfont">&#xe600;</i> 添加文章</a>
  8. </span>
  9. <span class="select-box inline ml-50">
  10. <select name="cid" id="sel_option" class="select">
  11. <option value="0" {eq name='cid' value="0" }selected{/eq}>所有栏目</option>
  12. {foreach $category_tree as $value}
  13. <option value="{$value.id}" {eq name='cid' value="$value.id" }selected{/eq}>{$value.category_name}</option>
  14. {notempty name="value.child"}
  15. {foreach $value.child as $val}
  16. <option value="{$val.id}" {eq name='cid' value="$val.id" }selected{/eq}>--{$val.category_name}</option>
  17. {notempty name="val.child"}
  18. {foreach $val.child as $vo}
  19. <option value="{$vo.id}" {eq name='cid' value="$vo.id" }selected{/eq}>&nbsp;&nbsp;└ --{$vo.category_name}
  20. </option>
  21. {/foreach}
  22. {/notempty}
  23. {/foreach}
  24. {/notempty}
  25. {/foreach}
  26. </select>
  27. </span>
  28. <span class="r">共有数据:<strong id="total">{notempty name="data"}{$data->total()}{else/}0{/notempty}</strong>
  29. 条</span>
  30. </div>
  31. <div id="edatalist">
  32. <table class="table table-border table-bordered table-bg">
  33. <thead>
  34. <tr class="text-c">
  35. <th width="25px;">
  36. <input type="checkbox" name="" value="">
  37. </th>
  38. <th width="80px;">ID</th>
  39. <th style="min-width: 260px;">标题</th>
  40. <th width="240px;">栏目</th>
  41. <th width="160px;">发布者</th>
  42. <th width="180px;">发布时间</th>
  43. <th width="140px;">点击量</th>
  44. <th width="80px;">排序</th>
  45. <th width="200px;">操作</th>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. {foreach $data as $val}
  50. <tr class="text-c va-m">
  51. <td>
  52. <input type="checkbox" value="{$val.id}" name="checkbox[]">
  53. </td>
  54. <td>{$val.id}</td>
  55. <td class="text-l">
  56. <a href="/index/article/detail/id/{$val.id}" style="text-decoration:none" title="浏览"
  57. target="_blank">{$val.title}</a>
  58. </td>
  59. <td>{:isset($categories_name[$val['cid']]) ? $categories_name[$val['cid']] : ""}</td>
  60. <td>{$val.username}</td>
  61. <td>{$val.create_time}</td>
  62. <td>{$val.hits}</td>
  63. <td><input type="text" class="input-text input-sort" value="{$val.sort}" data-id="{$val.id}" style="text-align: center;"></td>
  64. <td class="td-manage">
  65. <a href="{:url('save?cid='.$val['cid'].'&id='.$val['id'])}" title="编辑"
  66. style="text-decoration:none" class="ml-10">
  67. <i class="Hui-iconfont">&#xe6df;</i>
  68. </a>
  69. <a href="javascript:;" title="删除" style="text-decoration:none" class="ml-10"
  70. onClick="del(this,'{$val.id}')">
  71. <i class="Hui-iconfont">&#xe6e2;</i>
  72. </a>
  73. </td>
  74. </tr>
  75. {/foreach}
  76. </tbody>
  77. </table>
  78. </div>
  79. <div class="cl pd-5 bg-1 bk-gray mt-20 ">
  80. <span class="r">{notempty name="data"}{$data->render()}{/notempty}</span>
  81. </div>
  82. </article>
  83. <script>
  84. $("#sel_option").change(function () {
  85. var cid = $("#sel_option").val();
  86. console.log(cid);
  87. if (cid) {
  88. window.location.href = '/admin/article/index?cid=' + cid;
  89. } else {
  90. window.location.href = '/admin/article/index';
  91. }
  92. return false;
  93. })
  94. function save(id) {
  95. var cid = $("#sel_option").val();
  96. // console.log(cid);
  97. // return false;
  98. if (!cid || cid == 0) {
  99. layer.msg("请选择栏目", {
  100. icon: 5,
  101. time: 2000
  102. });
  103. return false;
  104. }
  105. window.location.href = '/admin/article/save?id='+id+'&cid='+cid;
  106. return false;
  107. }
  108. // 排序
  109. $(".input-sort").change(function () {
  110. var sort = $(this).val();
  111. var id = $(this).data('id');
  112. // console.log(sort);
  113. // console.log(id);
  114. $.post('sort', {
  115. 'id': id,
  116. 'sort': sort
  117. }, function (res) {
  118. console.log(res);
  119. if (res) {
  120. layer.msg('排序成功', {
  121. icon: 1,
  122. time: 2000
  123. });
  124. } else {
  125. layer.msg('排序失败', {
  126. icon: 5,
  127. time: 2000
  128. });
  129. }
  130. }, 'json');
  131. })
  132. //列表删除条目
  133. function del(obj, id) {
  134. layer.confirm('确认要删除吗?', function (index) {
  135. $.post('delete', {
  136. 'id': id
  137. }, function (data) {
  138. if (data.code == 2) {
  139. $(obj).parents("tr").remove();
  140. layer.msg(data.msg, {
  141. icon: 1,
  142. time: 1000
  143. });
  144. } else {
  145. layer.msg(data.msg, {
  146. icon: 5,
  147. time: 2000
  148. });
  149. return false;
  150. }
  151. }, 'json');
  152. });
  153. }
  154. //列表多选删除条目
  155. function del_all() {
  156. if (isNull(controller)) {
  157. url = 'del';
  158. } else {
  159. url = '/admin/' + controller + '/del';
  160. }
  161. var checkbox = $('.text-c input[name="checkbox[]"]');
  162. var ids = new Array();
  163. checkbox.each(function (x) {
  164. if (this.checked)
  165. ids.push(this.value);
  166. })
  167. var length = ids.length;
  168. if (length == 0) {
  169. layer.msg('请选择要删除的选项', {
  170. icon: 5,
  171. time: 1000
  172. });
  173. return false;
  174. }
  175. layer.confirm('确认要删除选中项吗?', function (index) {
  176. $.post('delete', {
  177. 'id': ids
  178. }, function (data) {
  179. if (data.code == 2) {
  180. checkbox.each(function (x) {
  181. if (this.checked)
  182. $(this).parents("tr").remove();
  183. })
  184. layer.msg(data.msg, {
  185. icon: 1,
  186. time: 1000
  187. });
  188. } else {
  189. layer.msg(data.msg, {
  190. icon: 5,
  191. time: 2000
  192. });
  193. return false;
  194. }
  195. }, 'json');
  196. });
  197. }
  198. /* 置顶 or 首页 */
  199. function top_home(action, obj, column, id) {
  200. var col = '首页';
  201. var style = 'style="margin-left: 10%"';
  202. if (column == 'top') {
  203. col = '置顶';
  204. style = '';
  205. }
  206. var value = 2;
  207. var cancel = '';
  208. var color = 'default';
  209. if (action == 'up') {
  210. value = 1;
  211. action = 'down';
  212. cancel = '取消';
  213. color = 'success';
  214. } else {
  215. action = 'up';
  216. }
  217. var text = "<a href=\"javascript:void(0);\" title='" + cancel + col + "' onClick=\"top_home('" + action + "',this,'" + column + "'," + id + ")\" style=\"text-decoration:none\">";
  218. text += '<span class="label label-' + color + ' radius" ' + style + '>' + col + '</span></a>';
  219. $.post('top', {
  220. 'id': id,
  221. 'column': column,
  222. 'value': value
  223. }, function (data) {
  224. if (data.code == 2) {
  225. $(obj).after(text);
  226. $(obj).remove();
  227. layer.msg(data.msg, {
  228. icon: 6,
  229. time: 1000
  230. });
  231. } else {
  232. layer.msg(data.msg, {
  233. icon: 5,
  234. time: 1000
  235. });
  236. }
  237. }, 'json');
  238. }
  239. // 产品上加/下架 or 文章上线.下线
  240. function duty(action, obj, id) {
  241. var duty = 2,
  242. title = '上线',
  243. button = 'default',
  244. status = '下线';
  245. if (action == 'up') {
  246. duty = 1;
  247. title = '下线';
  248. status = '正常';
  249. button = 'success';
  250. action = 'down';
  251. } else {
  252. action = 'up';
  253. }
  254. var text = "<a href=\"javascript:void(0);\" title=" + title + " onClick=\"duty('" + action + "', this," + id + ")\" >";
  255. text += '<span class="label label-' + button + ' radius">' + status + '</span></a>';
  256. $.post("duty", {
  257. 'id': id,
  258. 'status': duty
  259. }, function (data) {
  260. if (data.code == 2) {
  261. $(obj).after(text);
  262. $(obj).remove();
  263. layer.msg(data.msg, {
  264. icon: 6,
  265. time: 1000
  266. });
  267. } else {
  268. layer.msg(data.msg, {
  269. icon: 5,
  270. time: 1000
  271. });
  272. }
  273. }, 'json');
  274. }
  275. </script>