index.blade.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. <link href="{{asset('css/bootstrap.min14ed.css?v=3.3.6')}}" rel="stylesheet">
  10. <style>
  11. .my-ul {
  12. list-style-type: none;
  13. padding: 0;
  14. margin: 10px 0 5px 10px;
  15. }
  16. .my-ul li {
  17. float: left;
  18. }
  19. .my-ul::after {
  20. content: '';
  21. display: block;
  22. clear: both;
  23. }
  24. .nav-li {
  25. padding: 5px 10px;
  26. border-radius: 5px;
  27. cursor: pointer;
  28. }
  29. .active {
  30. background-color: #404650;
  31. color: white;
  32. }
  33. .tool {
  34. background-color: #F0F0F0;
  35. padding: 10px;
  36. }
  37. .search-input {
  38. width: 200px;
  39. padding: 5px;
  40. border: 1px solid #999c9e;
  41. }
  42. .btn {
  43. padding: 5px 10px;
  44. border-radius: 5px;
  45. background-color: #0d8ddb;
  46. border: none;
  47. color: white;
  48. cursor: pointer;
  49. }
  50. .section-ul {
  51. list-style-type: none;
  52. margin: 0;
  53. padding: 0;
  54. }
  55. .section-li {
  56. display: none;
  57. }
  58. .sectionActive {
  59. display: block;
  60. }
  61. .image-ul {
  62. list-style-type: none;
  63. margin: 0;
  64. padding: 0 0 15px 0;
  65. }
  66. .image-ul::after {
  67. content: '';
  68. display: block;
  69. clear: both;
  70. }
  71. .image-li {
  72. cursor: pointer;
  73. float: left;
  74. width: 16.6%;
  75. padding: 5px 5px;
  76. }
  77. .imageDiv{
  78. border: 4px solid #F0F0F0;
  79. border-radius: 5px;
  80. }
  81. .image-li img {
  82. width: 100%;
  83. max-height: 100%;
  84. }
  85. .page{
  86. margin-left: 10px;
  87. }
  88. .imageActive{
  89. border-color: green !important;
  90. }
  91. button {
  92. cursor: pointer;
  93. }
  94. </style>
  95. </head>
  96. <body>
  97. <main>
  98. <nav>
  99. <ul class="my-ul">
  100. <li class="nav-li active">当前版块</li>
  101. <li class="nav-li">全部图片</li>
  102. </ul>
  103. </nav>
  104. <div class="tool">
  105. <div style="float: left">
  106. <input type="text" class="search-input" placeholder="请输入图片名称" id="title">
  107. <button type="button" class="btn" onclick="utils.search()">搜索</button>
  108. </div>
  109. <div style="float: left;margin-left: 50px;">
  110. <button type="button" class="btn" name=file_upload>本地上传</button>
  111. <input type="file" value="" style="display: none" name="uploadFile">
  112. </div>
  113. <div style="clear: both"></div>
  114. </div>
  115. <section>
  116. <ul class="section-ul">
  117. <li class="section-li sectionActive">
  118. <div class="img-list" id="now">
  119. </div>
  120. <div class="page">
  121. <button type="button" class="btn btn-success" onclick="utils.prev(this,'now')">prev</button>
  122. <button type="button" class="btn btn-info" onclick="utils.next(this,'now')">next</button>
  123. 当前页: <span class="pageNo">1</span>
  124. </div>
  125. </li>
  126. <li class="section-li">
  127. <div class="img-list" id="all">
  128. </div>
  129. <div class="page">
  130. <button type="button" class="btn btn-success" onclick="utils.prev(this,'all')">prev</button>
  131. <button type="button" class="btn btn-info" onclick="utils.next(this,'all')">next</button>
  132. 当前页: <span class="pageNo">1</span>
  133. </div>
  134. </li>
  135. </ul>
  136. </section>
  137. </main>
  138. <script src="{{asset('js/jquery.min.js?v=2.1.4')}}"></script>
  139. <script src="{{asset('js/bootstrap.min.js?v=3.3.6')}}"></script>
  140. <script src="{{asset('js/plugins/layer-v3.1.1/layer/layer.js')}}"></script>
  141. <script src="{{asset('js/tools/tips.js')}}"></script>
  142. <script>
  143. $(document).on('click', '.my-ul li', function () {
  144. $(this).addClass('active').siblings().removeClass('active');
  145. $(".section-li").eq($(this).index()).addClass('sectionActive').siblings().removeClass('sectionActive');
  146. });
  147. $(document).on('click', '[name=file_upload]', function () {
  148. $(this).next().trigger('click');
  149. });
  150. $(document).on('change', '[name=uploadFile]', function () {
  151. // var _this = this;
  152. if (!$(this)[0].files[0]) {
  153. return;
  154. }
  155. var siteId=0;
  156. $(".nav-li").each(function () {
  157. if ($(this).hasClass('active')) {
  158. if ($(this).index() === 0) {
  159. siteId="{{$siteId}}";
  160. }
  161. }
  162. });
  163. var formData = new FormData();
  164. formData.append('file', $(this)[0].files[0]);
  165. var ln;
  166. $.ajax({
  167. url: '/admin/image/upload?siteId='+siteId,
  168. type: 'POST',
  169. cache: false,
  170. data: formData,
  171. processData: false,
  172. contentType: false,
  173. beforeSend: function () {
  174. ln = layer.load();
  175. },
  176. complete: function () {
  177. layer.close(ln);
  178. },
  179. success: function (result) {
  180. utils.getData(1, 'now');
  181. utils.getData(1, 'all');
  182. },
  183. error: function (XMLHttpRequest) {
  184. if (XMLHttpRequest.status === 500) {
  185. layer.alert("异步请求失败", {icon: 5});
  186. return;
  187. }
  188. layer.alert(JSON.parse(XMLHttpRequest.responseText).message, {icon: 0});
  189. }
  190. });
  191. });
  192. var utils = {
  193. search: function () {
  194. $(".nav-li").each(function () {
  195. if ($(this).hasClass('active')) {
  196. var type;
  197. if ($(this).index() === 0) {
  198. $(".pageNo").eq(0).text(1);
  199. type = 'now';
  200. } else {
  201. type = 'all';
  202. $(".pageNo").eq(1).text(1);
  203. }
  204. utils.getData(1, type,$("#title").val())
  205. }
  206. });
  207. },
  208. prev: function (_this, type) {
  209. var obj = $(_this).parent().find(".pageNo");
  210. var page = parseInt(obj.text());
  211. if (page > 1) {
  212. obj.text(page - 1);
  213. utils.getData(page - 1, type);
  214. }
  215. },
  216. next: function (_this, type) {
  217. var obj = $(_this).parent().find(".pageNo");
  218. var page = parseInt(obj.text());
  219. obj.text(page + 1);
  220. utils.getData(page + 1, type)
  221. },
  222. getData: function (page, type,title) {
  223. if(!title){
  224. title='';
  225. }
  226. var url = '/admin/image/index?page=' + page+'&title='+title;
  227. if (type === 'now') {
  228. url += '&siteId={{$siteId}}'
  229. }
  230. var config = {
  231. url: url,
  232. success: function (result) {
  233. var len = result.rows.length;
  234. var content;
  235. if (len > 0) {
  236. content = '';
  237. for (var i = 0; i < len; i++) {
  238. if (i % 6 === 0) {
  239. content += '<ul class="image-ul">';
  240. }
  241. content += '<li class="image-li"><div class="imageDiv">' +
  242. ' <div style="height:100px"><img src="' + result.rows[i]['url'] + '" alt=""></div>' +
  243. '<div>'+tips.subStr(result.rows[i]['title'])+'</div></div>'+
  244. '</li>';
  245. if (i % 6 === 5 || i === (len - 1)) {
  246. content += '</ul>';
  247. }
  248. }
  249. } else {
  250. content = '<div style="padding:10px;">无数据</div>';
  251. }
  252. $("#" + type).html(content);
  253. }
  254. };
  255. tips.ajax(config)
  256. }
  257. };
  258. $(document).on('click','.imageDiv',function () {
  259. if ($(this).hasClass('imageActive')){
  260. $(this).removeClass('imageActive')
  261. } else {
  262. $(".imageDiv").removeClass('imageActive');
  263. $(this).addClass('imageActive');
  264. }
  265. });
  266. $(function () {
  267. utils.getData(1, 'now');
  268. utils.getData(1, 'all');
  269. })
  270. </script>
  271. </body>
  272. </html>