index.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. {extend name="../../admin/view/main"}
  2. {block name="button"}
  3. {if auth('add')}
  4. <button data-open="{:url('add')}" class='layui-btn layui-btn-sm layui-btn-primary'>添加图文</button>
  5. {/if}
  6. {/block}
  7. {block name='content'}
  8. <div class="think-box-shadow">
  9. <div id="news-box" class="layui-clear layui-hide">
  10. {foreach $list as $vo}
  11. <div class="news-item">
  12. <div class='news-tools layui-hide'>
  13. <a data-phone-view="{:url('wechat/api.view/news')}?id={$vo.id}" href='javascript:void(0)'>预览</a>
  14. <a data-open='{:url("edit")}?id={$vo.id}' href='javascript:void(0)'>编辑</a>
  15. <a data-news-del="{$vo.id}" href='javascript:void(0)'>删除</a>
  16. </div>
  17. {foreach $vo.articles as $k => $v}
  18. {if $k < 1}
  19. <div data-tips-image='{$v.local_url}' data-lazy-src="{$v.local_url}" class='news-articel-item'>
  20. {if $v.title}<p>{$v.title}</p>{/if}
  21. </div>
  22. <div class="hr-line-dashed"></div>
  23. {else}
  24. <div class='news-articel-item other'>
  25. <span>{$v.title}</span>
  26. <div data-tips-image='{$v.local_url}' data-lazy-src="{$v.local_url}"></div>
  27. </div>
  28. <div class="hr-line-dashed"></div>
  29. {/if}{/foreach}
  30. </div>
  31. {/foreach}
  32. </div>
  33. {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
  34. </div>
  35. {/block}
  36. {block name='script'}
  37. <script>
  38. $('body').off('mouseenter', '.news-item').on('mouseenter', '.news-item', function () {
  39. $(this).find('.news-tools').removeClass('layui-hide');
  40. }).off('mouseleave', '.news-item').on('mouseleave', '.news-item', function () {
  41. $(this).find('.news-tools').addClass('layui-hide');
  42. });
  43. $.msg.loading();
  44. require(['jquery.masonry'], function (Masonry) {
  45. layui.layer.closeAll();
  46. $('#news-box').removeClass('layui-hide');
  47. var newsbox = document.querySelector('#news-box');
  48. var msnry = new Masonry(newsbox, {itemSelector: '.news-item', columnWidth: 0});
  49. msnry.layout(), $('body').on('click', '[data-news-del]', function (event) {
  50. $.msg.confirm('确定要删除图文吗?', function (index) {
  51. $.msg.close(index), $.form.load('{:url("remove")}', {value: 0, field: 'delete', id: $(event.target).data('news-del')}, 'post', function (ret) {
  52. if (ret.code) {
  53. $(event.target).parents('.news-item').remove();
  54. msnry = new Masonry(newsbox, {itemSelector: '.news-item', columnWidth: 0});
  55. return msnry.layout(), (msnry.items.length < 1 && $.form.open('{:url("index")}')), $.msg.success(ret.info), false;
  56. } else {
  57. return $.msg.error(ret.info), false;
  58. }
  59. });
  60. });
  61. });
  62. });
  63. </script>
  64. {/block}
  65. {block name="style"}
  66. <style>
  67. #news-box {
  68. position: relative
  69. }
  70. #news-box .news-item {
  71. top: 0;
  72. left: 0;
  73. padding: 5px;
  74. margin: 10px;
  75. width: 300px;
  76. overflow: hidden;
  77. position: relative;
  78. border-radius: 5px;
  79. border: 1px solid #ccc;
  80. box-sizing: content-box;
  81. box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.2);
  82. }
  83. #news-box .news-item .news-articel-item {
  84. height: 150px;
  85. }
  86. #news-box .news-item .news-articel-item p {
  87. bottom: 0;
  88. width: 100%;
  89. color: #fff;
  90. padding: 5px;
  91. max-height: 5em;
  92. font-size: 12px;
  93. overflow: hidden;
  94. position: absolute;
  95. text-overflow: ellipsis;
  96. background: rgba(0, 0, 0, .7)
  97. }
  98. #news-box .news-item .news-articel-item.other {
  99. height: 50px;
  100. padding: 5px 0
  101. }
  102. #news-box .news-item .news-articel-item span {
  103. width: 225px;
  104. overflow: hidden;
  105. line-height: 50px;
  106. white-space: nowrap;
  107. display: inline-block;
  108. text-overflow: ellipsis
  109. }
  110. #news-box .news-item .news-articel-item div {
  111. width: 70px;
  112. height: 50px;
  113. float: right;
  114. overflow: hidden;
  115. position: relative;
  116. background-position: center center;
  117. background-size: cover;
  118. }
  119. #news-box .hr-line-dashed {
  120. margin: 6px 0 1px 0
  121. }
  122. #news-box .news-item .hr-line-dashed:last-child {
  123. display: none
  124. }
  125. #news-box .news-tools {
  126. top: 0;
  127. z-index: 80;
  128. color: #fff;
  129. width: 302px;
  130. padding: 0 5px;
  131. margin-left: -6px;
  132. line-height: 38px;
  133. text-align: right;
  134. position: absolute;
  135. background: rgba(0, 0, 0, .7)
  136. }
  137. #news-box .news-tools a {
  138. color: #fff;
  139. margin-left: 10px
  140. }
  141. </style>
  142. {/block}