tpl-note.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>便签</title>
  5. <meta charset="utf-8"/>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  8. <link rel="stylesheet" href="../../assets/libs/layui/css/layui.css"/>
  9. <link rel="stylesheet" href="../../assets/module/admin.css?v=315"/>
  10. <!--[if lt IE 9]>
  11. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  12. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  13. <![endif]-->
  14. <style>
  15. html, body {
  16. background-color: #F8F8F8;
  17. }
  18. .note-wrapper {
  19. padding-left: 15px;
  20. padding-top: 20px;
  21. margin-bottom: 10px;
  22. }
  23. .note-item {
  24. width: 113px;
  25. height: 100px;
  26. display: inline-block;
  27. margin: 0 6px 15px 0;
  28. padding: 13px;
  29. border: 1px solid #dddddd;
  30. border-radius: 8px;
  31. background-color: #ffffff;
  32. position: relative;
  33. cursor: pointer;
  34. }
  35. .note-item:hover {
  36. background-color: #f1f1f1;
  37. }
  38. .note-item .note-item-content {
  39. font-size: 14px;
  40. color: #666666;
  41. height: 78px;
  42. overflow: hidden;
  43. word-wrap: break-word;
  44. }
  45. .note-item .note-item-time {
  46. font-size: 12px;
  47. color: #999999;
  48. margin-top: 10px;
  49. }
  50. .note-empty {
  51. text-align: center;
  52. color: rgba(0, 0, 0, .45);
  53. padding: 73px 0 88px;
  54. display: none;
  55. }
  56. .note-empty .layui-icon {
  57. margin-bottom: 10px;
  58. display: inline-block;
  59. font-size: 60px;
  60. }
  61. .note-item-del {
  62. position: absolute;
  63. right: 3px;
  64. top: 3px;
  65. display: none;
  66. color: #FF5722;
  67. }
  68. .note-item-del.show {
  69. display: inline-block;
  70. }
  71. .note-item-del .layui-icon {
  72. font-size: 22px;
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <div class="note-wrapper">
  78. </div>
  79. <div class="note-empty">
  80. <i class="layui-icon layui-icon-face-surprised"></i>
  81. <div>没有便签</div>
  82. </div>
  83. <div class="btn-circle" id="btnAdd" title="添加便签"><i class="layui-icon layui-icon-add-1"></i></div>
  84. <script type="text/javascript" src="../../assets/libs/layui/layui.js"></script>
  85. <script type="text/javascript" src="../../assets/js/common.js?v=315"></script>
  86. <script>
  87. var dataList = []; // 标签列表
  88. layui.use(['layer', 'form', 'util', 'admin'], function () {
  89. var $ = layui.jquery;
  90. var layer = layui.layer;
  91. var util = layui.util;
  92. var admin = layui.admin;
  93. renderList(); // 渲染列表
  94. // 添加
  95. $('#btnAdd').click(function () {
  96. showNote();
  97. });
  98. // 显示编辑弹窗
  99. function showNote(object) {
  100. var id, content = '';
  101. if (object) {
  102. id = object.id;
  103. content = object.content;
  104. }
  105. top.layui.admin.open({
  106. id: 'layer-note-item-edt',
  107. title: '便签',
  108. type: 1,
  109. area: '300px',
  110. offset: '50px',
  111. shadeClose: true,
  112. content: '<textarea id="edtNote" placeholder="请输入内容" style="width: 260px;height: 112px;border: none;color: #666666;word-wrap: break-word;padding: 10px 20px;resize: none;">' + content + '</textarea>',
  113. success: function () {
  114. top.layui.jquery('#edtNote').change(function () {
  115. content = top.layui.jquery(this).val();
  116. });
  117. },
  118. end: function () {
  119. if (id != undefined) {
  120. if (!content) {
  121. dataList.splice(id, 1);
  122. for (var i = 0; i < dataList.length; i++) {
  123. dataList[i].id = i;
  124. }
  125. } else if (content != dataList[id].content) {
  126. dataList[id].content = content;
  127. dataList[id].time = util.toDateString(new Date(), 'yyyy/MM/dd HH:mm');
  128. }
  129. } else if (content) {
  130. dataList.push({
  131. id: dataList.length,
  132. content: content,
  133. time: util.toDateString(new Date(), 'yyyy/MM/dd HH:mm')
  134. });
  135. }
  136. putDataList();
  137. renderList();
  138. }
  139. });
  140. }
  141. // 更新缓存
  142. function putDataList() {
  143. layui.data(admin.tableName, {
  144. key: 'notes',
  145. value: dataList
  146. });
  147. }
  148. // 渲染列表
  149. function renderList() {
  150. $('.note-wrapper').empty();
  151. dataList = layui.data(admin.tableName).notes;
  152. if (dataList == undefined) {
  153. dataList = [];
  154. }
  155. for (var i = 0; i < dataList.length; i++) {
  156. var item = dataList[i];
  157. var str = '<div class="note-item" data-id="' + item.id + '">';
  158. str += '<div class="note-item-content">' + item.content + '</div>';
  159. str += '<div class="note-item-time">' + item.time + '</div>';
  160. str += '<span class="note-item-del"><i class="layui-icon layui-icon-close-fill"></i></span>';
  161. str += '</div>';
  162. $('.note-wrapper').prepend(str);
  163. }
  164. if (dataList.length == 0) {
  165. $('.note-empty').css('display', 'block');
  166. } else {
  167. $('.note-empty').css('display', 'none');
  168. }
  169. // 点击修改
  170. $('.note-item').click(function () {
  171. var position = parseInt($(this).attr('data-id'));
  172. showNote(dataList[position]);
  173. });
  174. // 鼠标经过显示删除按钮
  175. $('.note-item').mouseenter(function () {
  176. $(this).find('.note-item-del').addClass('show');
  177. });
  178. $('.note-item').mouseleave(function () {
  179. $(this).find('.note-item-del').removeClass('show');
  180. });
  181. // 点击删除
  182. $('.note-item-del').click(function () {
  183. var position = parseInt($(this).parent().attr('data-id'));
  184. dataList.splice(position, 1);
  185. for (var i = 0; i < dataList.length; i++) {
  186. dataList[i].id = i;
  187. }
  188. putDataList();
  189. renderList();
  190. });
  191. }
  192. });
  193. </script>
  194. </body>
  195. </html>