note.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <style>
  2. .note-wrapper {
  3. padding-left: 15px;
  4. padding-top: 20px;
  5. margin-bottom: 10px;
  6. }
  7. .note-item {
  8. width: 113px;
  9. height: 100px;
  10. display: inline-block;
  11. margin: 0 6px 15px 0;
  12. padding: 13px;
  13. border: 1px solid #dddddd;
  14. border-radius: 8px;
  15. background-color: #ffffff;
  16. position: relative;
  17. cursor: pointer;
  18. }
  19. .note-item:hover {
  20. background-color: #f1f1f1;
  21. }
  22. .note-item .note-item-content {
  23. font-size: 14px;
  24. color: #666666;
  25. height: 78px;
  26. overflow: hidden;
  27. word-wrap: break-word;
  28. }
  29. .note-item .note-item-time {
  30. font-size: 12px;
  31. color: #999999;
  32. margin-top: 10px;
  33. }
  34. .note-empty {
  35. text-align: center;
  36. color: rgba(0, 0, 0, .45);
  37. padding: 73px 0 88px;
  38. display: none;
  39. }
  40. .note-empty .layui-icon {
  41. margin-bottom: 10px;
  42. display: inline-block;
  43. font-size: 60px;
  44. }
  45. .note-item-del {
  46. position: absolute;
  47. right: 3px;
  48. top: 3px;
  49. display: none;
  50. color: #FF5722;
  51. }
  52. .note-item-del.show {
  53. display: inline-block;
  54. }
  55. .note-item-del .layui-icon {
  56. font-size: 22px;
  57. }
  58. </style>
  59. <div class="layui-card-header">本地便签</div>
  60. <div class="note-wrapper">
  61. </div>
  62. <div class="note-empty">
  63. <i class="layui-icon layui-icon-face-surprised"></i>
  64. <div>没有便签</div>
  65. </div>
  66. <div class="btn-circle" id="btnAdd" title="添加便签"><i class="layui-icon layui-icon-add-1"></i></div>
  67. <script>
  68. var dataList = []; // 标签列表
  69. layui.use(['layer', 'form', 'util', 'setter', 'admin'], function () {
  70. var $ = layui.jquery;
  71. var layer = layui.layer;
  72. var util = layui.util;
  73. var config = layui.setter;
  74. var admin = layui.admin;
  75. renderList(); // 渲染列表
  76. // 添加
  77. $('#btnAdd').click(function () {
  78. showNote();
  79. });
  80. // 显示编辑弹窗
  81. function showNote(object) {
  82. var id, content = '';
  83. if (object) {
  84. id = object.id;
  85. content = object.content;
  86. }
  87. admin.open({
  88. id: 'layer-note-item-edt',
  89. title: '便签',
  90. type: 1,
  91. area: '300px',
  92. offset: '50px',
  93. shadeClose: true,
  94. 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>',
  95. success: function () {
  96. top.layui.jquery('#edtNote').change(function () {
  97. content = top.layui.jquery(this).val();
  98. });
  99. },
  100. end: function () {
  101. if (id != undefined) {
  102. if (!content) {
  103. dataList.splice(id, 1);
  104. for (var i = 0; i < dataList.length; i++) {
  105. dataList[i].id = i;
  106. }
  107. } else if (content != dataList[id].content) {
  108. dataList[id].content = content;
  109. dataList[id].time = util.toDateString(new Date(), 'yyyy/MM/dd HH:mm');
  110. }
  111. } else if (content) {
  112. dataList.push({
  113. id: dataList.length,
  114. content: content,
  115. time: util.toDateString(new Date(), 'yyyy/MM/dd HH:mm')
  116. });
  117. }
  118. putDataList();
  119. renderList();
  120. }
  121. });
  122. }
  123. // 更新缓存
  124. function putDataList() {
  125. layui.data(config.tableName, {
  126. key: 'notes',
  127. value: dataList
  128. });
  129. }
  130. // 渲染列表
  131. function renderList() {
  132. $('.note-wrapper').empty();
  133. dataList = layui.data(config.tableName).notes;
  134. if (dataList == undefined) {
  135. dataList = [];
  136. }
  137. for (var i = 0; i < dataList.length; i++) {
  138. var item = dataList[i];
  139. var str = '<div class="note-item" data-id="' + item.id + '">';
  140. str += '<div class="note-item-content">' + item.content + '</div>';
  141. str += '<div class="note-item-time">' + item.time + '</div>';
  142. str += '<span class="note-item-del"><i class="layui-icon layui-icon-close-fill"></i></span>';
  143. str += '</div>';
  144. $('.note-wrapper').prepend(str);
  145. }
  146. if (dataList.length == 0) {
  147. $('.note-empty').css('display', 'block');
  148. } else {
  149. $('.note-empty').css('display', 'none');
  150. }
  151. // 点击修改
  152. $('.note-item').click(function () {
  153. var position = parseInt($(this).attr('data-id'));
  154. showNote(dataList[position]);
  155. });
  156. // 鼠标经过显示删除按钮
  157. $('.note-item').mouseenter(function () {
  158. $(this).find('.note-item-del').addClass('show');
  159. });
  160. $('.note-item').mouseleave(function () {
  161. $(this).find('.note-item-del').removeClass('show');
  162. });
  163. // 点击删除
  164. $('.note-item-del').click(function () {
  165. var position = parseInt($(this).parent().attr('data-id'));
  166. dataList.splice(position, 1);
  167. for (var i = 0; i < dataList.length; i++) {
  168. dataList[i].id = i;
  169. }
  170. putDataList();
  171. renderList();
  172. });
  173. }
  174. });
  175. </script>