lock-screen.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <div class="lock-screen-wrapper">
  2. <div class="lock-screen-time"></div>
  3. <div class="lock-screen-date"></div>
  4. <div class="lock-screen-form">
  5. <input placeholder="输入123456解锁" class="lock-screen-psw" maxlength="20" type="password"/>
  6. <i class="layui-icon layui-icon-right lock-screen-enter"></i>
  7. <br/>
  8. <div class="lock-screen-tip"></div>
  9. </div>
  10. <div class="lock-screen-tool">
  11. <div class="lock-screen-tool-item">
  12. <i class="layui-icon layui-icon-logout" ew-event="logout" data-confirm="false"
  13. data-url="components/template/login.html"></i>
  14. <div class="lock-screen-tool-tip">退出登录</div>
  15. </div>
  16. </div>
  17. </div>
  18. <script>
  19. layui.use(['util', 'admin'], function () {
  20. var $ = layui.jquery;
  21. var util = layui.util;
  22. var admin = layui.admin;
  23. var rightPsw = '123456'; // 正确的密码
  24. // 获取各个组件
  25. var $form = $('.lock-screen-wrapper .lock-screen-form');
  26. var $psw = $form.find('.lock-screen-psw');
  27. var $tip = $form.find('.lock-screen-tip');
  28. var $time = $('.lock-screen-wrapper .lock-screen-time');
  29. var $date = $('.lock-screen-wrapper .lock-screen-date');
  30. // 监听enter键
  31. $(window).keydown(function (event) {
  32. if (admin.isLockScreen) {
  33. if (event.keyCode === 13) {
  34. doVer();
  35. } else if (event.keyCode === 8 && !$psw.val()) {
  36. restForm();
  37. }
  38. }
  39. });
  40. // 监听输入
  41. $psw.on('input', function () {
  42. var psw = $psw.val();
  43. if (rightPsw === psw) {
  44. restForm();
  45. admin.unlockScreen();
  46. } else if (psw) {
  47. $form.removeClass('show-back');
  48. $tip.text('');
  49. } else {
  50. $form.addClass('show-back');
  51. }
  52. });
  53. // 监听按钮点击
  54. $form.find('.lock-screen-enter').click(function (e) {
  55. doVer(true);
  56. });
  57. // 处理事件
  58. function doVer(emptyRest) {
  59. if ($form.hasClass('show-psw')) {
  60. $psw.focus();
  61. var psw = $psw.val();
  62. if (!psw) {
  63. emptyRest ? restForm() : $tip.text('请输入解锁密码');
  64. } else if (rightPsw === psw) {
  65. restForm();
  66. admin.unlockScreen();
  67. } else {
  68. $psw.val('');
  69. $tip.text('密码不正确');
  70. $form.addClass('show-back');
  71. }
  72. } else {
  73. $form.addClass('show-psw show-back');
  74. $psw.focus();
  75. }
  76. }
  77. // 重置
  78. function restForm() {
  79. $psw.blur();
  80. $psw.val('');
  81. $tip.text('');
  82. $form.removeClass('show-psw show-back');
  83. }
  84. // 时间、日期
  85. function setDate() {
  86. var date = new Date();
  87. $time.text(util.toDateString(date, 'HH:mm'));
  88. var weeks = ['日', '一', '二', '三', '四', '五', '六'];
  89. $date.text(util.toDateString(date, 'MM月dd日,星期') + weeks[date.getDay()]);
  90. }
  91. setDate();
  92. setInterval(function () {
  93. if (admin.isLockScreen) {
  94. setDate();
  95. }
  96. }, 1000);
  97. });
  98. </script>
  99. <style>
  100. .lock-screen-wrapper {
  101. color: #ffffff;
  102. width: 100%;
  103. height: 100%;
  104. box-sizing: border-box;
  105. padding: 50px 60px 0 60px;
  106. background-color: #000000;
  107. background-image: url("assets/images/bg-screen.jpg");
  108. background-repeat: no-repeat;
  109. background-size: cover;
  110. position: relative;
  111. }
  112. .lock-screen-time {
  113. font-size: 88px;
  114. }
  115. .lock-screen-date {
  116. font-size: 24px;
  117. padding: 0 0 0 15px;
  118. }
  119. .lock-screen-form {
  120. position: absolute;
  121. left: 0;
  122. right: 0;
  123. top: 65%;
  124. width: 100%;
  125. text-align: center;
  126. }
  127. .lock-screen-psw {
  128. color: #ffffff;
  129. font-size: 22px;
  130. width: 0;
  131. height: 0;
  132. line-height: 40px;
  133. border-radius: 40px;
  134. border: 2px solid transparent;
  135. background-color: transparent;
  136. box-sizing: border-box;
  137. vertical-align: middle;
  138. -webkit-transition: all .3s;
  139. transition: all .3s;
  140. text-align: center;
  141. }
  142. .lock-screen-psw::-webkit-input-placeholder {
  143. color: #F6F6F6;
  144. font-size: 16px;
  145. }
  146. .lock-screen-psw::-moz-placeholder {
  147. color: #F6F6F6;
  148. font-size: 16px;
  149. }
  150. .lock-screen-psw::-ms-input-placeholder {
  151. color: #F6F6F6;
  152. font-size: 16px;
  153. }
  154. .lock-screen-enter {
  155. width: 65px;
  156. height: 65px;
  157. line-height: 1;
  158. font-size: 28px;
  159. padding-top: 18px;
  160. border: 2px solid #ffffff;
  161. border-radius: 50%;
  162. text-align: center;
  163. display: inline-block;
  164. box-sizing: border-box;
  165. vertical-align: middle;
  166. transition: all .3s;
  167. cursor: pointer;
  168. }
  169. .lock-screen-enter:hover {
  170. background-color: rgba(255, 255, 255, .3);
  171. }
  172. .lock-screen-form.show-psw .lock-screen-psw {
  173. height: 40px;
  174. width: 180px;
  175. padding: 0 5px;
  176. margin-right: 10px;
  177. border-color: #ffffff;
  178. background-color: rgba(255, 255, 255, .3);
  179. }
  180. .lock-screen-form.show-psw .lock-screen-enter {
  181. width: 40px;
  182. height: 40px;
  183. font-size: 20px;
  184. padding-top: 8px;
  185. }
  186. .lock-screen-form.show-back .lock-screen-enter:before {
  187. content: "\e603";
  188. }
  189. .lock-screen-tip {
  190. color: red;
  191. width: 230px;
  192. padding: 0 3px;
  193. font-size: 14px;
  194. text-align: left;
  195. box-sizing: border-box;
  196. display: none;
  197. }
  198. .lock-screen-form.show-psw .lock-screen-tip {
  199. display: inline-block;
  200. }
  201. .lock-screen-tool {
  202. width: 20px;
  203. position: absolute;
  204. right: 20px;
  205. bottom: 20px;
  206. }
  207. .lock-screen-tool .lock-screen-tool-item {
  208. position: relative;
  209. width: 20px;
  210. height: 20px;
  211. line-height: 20px;
  212. margin-top: 15px;
  213. cursor: pointer;
  214. }
  215. .lock-screen-tool .lock-screen-tool-item:hover .layui-icon {
  216. color: #ffffff;
  217. }
  218. .lock-screen-tool .layui-icon {
  219. font-size: 20px;
  220. }
  221. .lock-screen-tool .lock-screen-tool-item .lock-screen-tool-tip {
  222. position: absolute;
  223. top: 50%;
  224. right: 100%;
  225. height: 24px;
  226. line-height: 24px;
  227. width: max-content;
  228. margin-right: 10px;
  229. margin-top: -12px;
  230. font-size: 12px;
  231. padding: 0 8px;
  232. color: rgba(255, 255, 255, .5);
  233. background-color: rgba(255, 255, 255, .3);
  234. word-break: break-all;
  235. border-radius: 3px;
  236. display: none;
  237. }
  238. .lock-screen-tool .lock-screen-tool-item:hover .lock-screen-tool-tip {
  239. display: inline-block;
  240. }
  241. .lock-screen-tool .lock-screen-tool-item .lock-screen-tool-tip:before {
  242. content: "";
  243. border: 4px solid transparent;
  244. border-left-color: rgba(255, 255, 255, .3);
  245. position: absolute;
  246. right: -8px;
  247. top: 50%;
  248. margin-top: -4px;
  249. }
  250. </style>