image.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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('js/plugins/mricode-pagination-master/mricode.pagination.css?v=1')}}" rel="stylesheet"/>
  10. <link href="{{asset('css/bootstrap.min14ed.css?v=3.3.6')}}" rel="stylesheet">
  11. <style>
  12. .my-ul {
  13. list-style-type: none;
  14. padding: 0;
  15. margin: 10px 0 5px 10px;
  16. }
  17. .my-ul li {
  18. float: left;
  19. }
  20. .my-ul::after {
  21. content: '';
  22. display: block;
  23. clear: both;
  24. }
  25. .nav-li {
  26. padding: 5px 10px;
  27. border-radius: 5px;
  28. cursor: pointer;
  29. }
  30. .active {
  31. background-color: #404650;
  32. color: white;
  33. }
  34. .tool {
  35. background-color: #F0F0F0;
  36. padding: 10px;
  37. }
  38. .search-input {
  39. width: 200px;
  40. padding: 5px;
  41. border: 1px solid #999c9e;
  42. }
  43. .btn {
  44. padding: 5px 10px;
  45. border-radius: 5px;
  46. background-color: #0d8ddb;
  47. border: none;
  48. color: white;
  49. cursor: pointer;
  50. }
  51. .section-ul {
  52. list-style-type: none;
  53. margin: 0;
  54. padding: 0;
  55. }
  56. .section-li {
  57. display: none;
  58. }
  59. .sectionActive {
  60. display: block;
  61. }
  62. .image-ul {
  63. list-style-type: none;
  64. margin: 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: 2px 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. .image-div {
  95. justify-content: center;
  96. align-items: center;
  97. flex-direction: column;
  98. overflow: hidden;
  99. margin: auto;
  100. }
  101. .image-font {
  102. white-space: nowrap;
  103. overflow: hidden;
  104. text-overflow: ellipsis;
  105. padding: 10px;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <main>
  111. <nav>
  112. <ul class="my-ul">
  113. <li class="nav-li active" data-type="now">当前版块</li>
  114. <li class="nav-li" data-type="all">全部图片</li>
  115. </ul>
  116. </nav>
  117. <input type="hidden" id="pageId" value="1">
  118. <div class="tool">
  119. <div style="float: left">
  120. <input type="text" class="search-input" placeholder="请输入图片名称" id="title">
  121. <button type="button" class="btn" onclick="utils.search()" style="background: #009688;">搜索</button>
  122. </div>
  123. <div style="float: left;margin-top: 2px;margin-left: 5px">
  124. <button type="button" class="btn" name="file_upload" style="background: #009688;">本地上传</button>
  125. (alt多选)
  126. <input type="file" value="" style="display: none" name="uploadFile" multiple>
  127. </div>
  128. <button type="button" class="btn" onclick="utils.save('{{$type}}')"
  129. style="background: #009688;">确定
  130. </button>
  131. <div style="clear: both"></div>
  132. </div>
  133. <input type="hidden" id="type-index" value="{{$type}}">
  134. <section>
  135. <ul class="section-ul">
  136. <li class="section-li sectionActive">
  137. <div class="img-list" id="now">
  138. </div>
  139. <div class="page">
  140. <div id="page" class="m-pagination"></div>
  141. </div>
  142. </li>
  143. <li class="section-li">
  144. <div class="img-list" id="all">
  145. </div>
  146. <div class="page">
  147. <div id="page1" class="m-pagination"></div>
  148. </div>
  149. </li>
  150. </ul>
  151. <input type="hidden" id="type" value="{{$type}}">
  152. </section>
  153. </main>
  154. <script src="{{asset('js/jquery.min.js?v=2.1.4')}}"></script>
  155. <script src="{{asset('js/bootstrap.min.js?v=3.3.6')}}"></script>
  156. <script src="{{asset('js/plugins/layer-v3.1.1/layer/layer.js')}}"></script>
  157. <script src="{{asset('js/tools/tips.js')}}"></script>
  158. <script src="{{asset('js/plugins/mricode-pagination-master/mricode.pagination.js')}}"></script>
  159. <script>
  160. function getPage(object) {
  161. var list = 'all';
  162. if (object === 'page') {
  163. list = 'now';
  164. }
  165. $("#" + object).pagination({
  166. showInfo: true,
  167. showJump: true,
  168. pageSize: 12,
  169. pageElementSort: ['$page', '$size', '$jump', '$info'],
  170. remote: {
  171. url: '/admin/stencil/images/{{$siteId}}/{{$type}}',
  172. pageParams: function (data) {
  173. return {
  174. page: data.pageIndex + 1,
  175. pageSize: data.pageSize,
  176. title: $("#title").val()
  177. };
  178. },
  179. success: function (result) {
  180. var len = result.rows.length;
  181. if (len > 0) {
  182. var content = '<ul class="image-ul">';
  183. $(result.rows).each(function (key, value) {
  184. content +=
  185. '<li class="image-li">' +
  186. '<div class="imageDiv">' +
  187. '<div style="height: 150px;display: flex;justify-content: center;align-items: center;flex-direction: column;overflow: hidden;">' +
  188. '<img src="' + value.src + '" alt="' + value.name + '" data-id="' + value.id + '">' +
  189. '</div>' +
  190. '<div style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;padding: 10px;">' + value.name + '</div>' +
  191. '</div>' +
  192. '</li>';
  193. });
  194. content += '</ul>';
  195. } else {
  196. content = '<div style="padding:10px;">无数据</div>';
  197. }
  198. $("#" + list).html(content);
  199. }
  200. }
  201. });
  202. }
  203. $(document).on('click', '.my-ul li', function () {
  204. $(this).addClass('active').siblings().removeClass('active');
  205. $(".section-li").eq($(this).index()).addClass('sectionActive').siblings().removeClass('sectionActive');
  206. });
  207. $(document).on('click', '[name=file_upload]', function () {
  208. $(this).next().trigger('click');
  209. });
  210. $(document).on('change', '[name=uploadFile]', function () {
  211. if (!$(this)[0].files[0]) {
  212. return;
  213. }
  214. var siteId = 0;
  215. $(".nav-li").each(function () {
  216. if ($(this).hasClass('active')) {
  217. if ($(this).index() === 0) {
  218. siteId = "{{$siteId}}";
  219. }
  220. }
  221. });
  222. var formData = new FormData();
  223. if ($(this)[0].files.length > 10) {
  224. layer.alert("最多只能选择10张图片哦", {icon: 5});
  225. return;
  226. }
  227. var maxSize = 3072;//文件上传大小限制
  228. for (var i = 0; i < $(this)[0].files.length; i++) {
  229. var size = $(this)[0].files[i].size;
  230. var fileSize = (size / 1024).toFixed(2);
  231. if (fileSize > maxSize) {
  232. layer.alert("上传文件不许超过3MB", {icon: 5});
  233. return;
  234. }
  235. formData.append('files[]', $(this)[0].files[i]);
  236. }
  237. formData.append('siteId', '{{$siteId}}');
  238. var ln;
  239. $.ajax({
  240. url: '/admin/stencil/uploadImages/{{$siteId}}',
  241. type: 'POST',
  242. cache: false,
  243. data: formData,
  244. processData: false,
  245. contentType: false,
  246. beforeSend: function () {
  247. ln = layer.load();
  248. },
  249. complete: function () {
  250. layer.close(ln);
  251. },
  252. success: function () {
  253. $("#page").pagination('remote');
  254. $("#page1").pagination('remote');
  255. },
  256. error: function (XMLHttpRequest) {
  257. if (XMLHttpRequest.status === 500) {
  258. layer.alert("异步请求失败", {icon: 5});
  259. return;
  260. }
  261. layer.alert(JSON.parse(XMLHttpRequest.responseText).message, {icon: 0});
  262. }
  263. });
  264. });
  265. var utils = {
  266. search: function () {
  267. $(".nav-li").each(function () {
  268. if ($(this).hasClass('active')) {
  269. var type = $(this).attr('data-type');
  270. if (type === 'now') {
  271. $("#page").pagination('remote');
  272. } else {
  273. $("#page1").pagination('remote');
  274. }
  275. }
  276. });
  277. },
  278. save: function (type) {
  279. var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
  280. if (type === 'advertise') {
  281. parent.$('#images').empty();
  282. $(".imageActive").each(function () {
  283. var img = $(this).find('img').attr('src');
  284. var name = $(this).find('div').text();
  285. var str =
  286. '<div class="col-sm-2 control-label">' +
  287. '</div>' +
  288. '<li class="image-li">' +
  289. '<div class="imageDiv">' +
  290. '<div class="image-div">' +
  291. '<img src="' + img + '" alt="' + img + '">' +
  292. '</div>' +
  293. '<div class="image-font" >' + name + '</div>' +
  294. '<a href="javascript:;" class="js-del-item">' +
  295. '<i class="fa fa-remove"></i>移除' +
  296. '</a>' +
  297. '</div>' +
  298. '</li>';
  299. parent.$('#images').append(str);
  300. });
  301. }else if (type === 'alone') {
  302. parent.$('#images').empty();
  303. $(".imageActive").each(function () {
  304. var img = $(this).find('img').attr('src');
  305. var name = $(this).find('div').text();
  306. var str =
  307. '<li class="image-li">' +
  308. '<div class="imageDiv">' +
  309. '<div class="image-div">' +
  310. '<img src="' + img + '" alt="' + img + '">' +
  311. '</div>' +
  312. '<div class="image-font" >' + name + '</div>' +
  313. '<a href="javascript:;" class="js-del-item-alone">' +
  314. '<i class="fa fa-remove"></i>移除' +
  315. '</a>' +
  316. '</div>' +
  317. '</li>';
  318. parent.$('#images').append(str);
  319. });
  320. }else {
  321. $(".imageActive").each(function () {
  322. var img = $(this).find('img').attr('src');
  323. var alt = $(this).find('img').attr('alt');
  324. var id = $(this).find('img').attr('data-id');
  325. var str =
  326. '<div class="js-item img-item images-list {{$type}}" style="cursor:pointer">' +
  327. '<div class="box">' +
  328. '<a class="thumb">' +
  329. '<img class="image-result" src="' + img + '" alt="' + alt + '">' +
  330. '</a>' +
  331. '<div class="title cutstr">' + img + '</div>' +
  332. '<div class="summary" data-id="' + id + '">alt<input type="text" class="form-control image-alt" value="' + alt + '"></div>' +
  333. '<div class="operate">' +
  334. '<a href="javascript:;" class="js-del-item">' +
  335. '<i class="fa fa-remove"></i>移除' +
  336. '</a>' +
  337. '</div>' +
  338. '</div>' +
  339. '</div>';
  340. parent.$('#{{$type}}').append(str);
  341. });
  342. }
  343. parent.layer.close(index);
  344. }
  345. };
  346. var typeIndex = $('#type-index').val();
  347. if (typeIndex === 'advertise' || typeIndex === 'alone') {
  348. $(document).on('click', '.imageDiv', function () {
  349. if ($(this).hasClass('imageActive')){
  350. $(this).removeClass('imageActive')
  351. } else {
  352. $(".imageDiv").removeClass('imageActive');
  353. $(this).addClass('imageActive');
  354. }
  355. });
  356. } else {
  357. $(document).on('click', '.imageDiv', function () {
  358. $(this).addClass('imageActive');
  359. });
  360. $(document).on('click', '.imageActive', function () {
  361. $(this).removeClass('imageActive');
  362. });
  363. }
  364. $(function () {
  365. getPage('page');
  366. getPage('page1');
  367. })
  368. </script>
  369. </body>
  370. </html>