index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <div v-show="isShowLockScreen">
  3. <div class="layout-lock-screen-mask"></div>
  4. <div class="layout-lock-screen-img" :class="{ 'layout-lock-screen-filter': isShowLoockLogin }"></div>
  5. <div class="layout-lock-screen">
  6. <div
  7. class="layout-lock-screen-date"
  8. ref="layoutLockScreenDateRef"
  9. @mousedown="onDown"
  10. @mousemove="onMove"
  11. @mouseup="onEnd"
  12. @touchstart.stop="onDown"
  13. @touchmove.stop="onMove"
  14. @touchend.stop="onEnd"
  15. >
  16. <div class="layout-lock-screen-date-box">
  17. <div class="layout-lock-screen-date-box-time">
  18. {{ time.hm }}<span class="layout-lock-screen-date-box-minutes">{{ time.s }}</span>
  19. </div>
  20. <div class="layout-lock-screen-date-box-info">{{ time.mdq }}</div>
  21. </div>
  22. <div class="layout-lock-screen-date-top">
  23. <SvgIcon name="ele-Top" />
  24. <div class="layout-lock-screen-date-top-text">上滑解锁</div>
  25. </div>
  26. </div>
  27. <transition name="el-zoom-in-center">
  28. <div v-show="isShowLoockLogin" class="layout-lock-screen-login">
  29. <div class="layout-lock-screen-login-box">
  30. <div class="layout-lock-screen-login-box-img">
  31. <img src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1813762643,1914315241&fm=26&gp=0.jpg" />
  32. </div>
  33. <div class="layout-lock-screen-login-box-name">Administrator</div>
  34. <div class="layout-lock-screen-login-box-value">
  35. <el-input
  36. placeholder="请输入密码"
  37. ref="layoutLockScreenInputRef"
  38. v-model="lockScreenPassword"
  39. @keyup.enter.native.stop="onLockScreenSubmit()"
  40. >
  41. <template #append>
  42. <el-button @click="onLockScreenSubmit">
  43. <el-icon class="el-input__icon">
  44. <ele-Right />
  45. </el-icon>
  46. </el-button>
  47. </template>
  48. </el-input>
  49. </div>
  50. </div>
  51. <div class="layout-lock-screen-login-icon">
  52. <SvgIcon name="ele-Microphone" />
  53. <SvgIcon name="ele-AlarmClock" />
  54. <SvgIcon name="ele-SwitchButton" />
  55. </div>
  56. </div>
  57. </transition>
  58. </div>
  59. </div>
  60. </template>
  61. <script lang="ts">
  62. import { nextTick, onMounted, reactive, toRefs, ref, onUnmounted, getCurrentInstance, defineComponent } from 'vue';
  63. import { useStore } from '/@/store/index';
  64. import { formatDate } from '/@/utils/formatTime';
  65. import { Local } from '/@/utils/storage';
  66. // 定义接口来定义对象的类型
  67. interface LockScreenState {
  68. transparency: number;
  69. downClientY: number;
  70. moveDifference: number;
  71. isShowLoockLogin: boolean;
  72. isFlags: boolean;
  73. querySelectorEl: HTMLElement | string;
  74. time: {
  75. hm: string;
  76. s: string;
  77. mdq: string;
  78. };
  79. setIntervalTime: number;
  80. isShowLockScreen: boolean;
  81. isShowLockScreenIntervalTime: number;
  82. lockScreenPassword: string;
  83. }
  84. export default defineComponent({
  85. name: 'layoutLockScreen',
  86. setup() {
  87. const { proxy } = <any>getCurrentInstance();
  88. const layoutLockScreenInputRef = ref();
  89. const store = useStore();
  90. const state = reactive<LockScreenState>({
  91. transparency: 1,
  92. downClientY: 0,
  93. moveDifference: 0,
  94. isShowLoockLogin: false,
  95. isFlags: false,
  96. querySelectorEl: '',
  97. time: {
  98. hm: '',
  99. s: '',
  100. mdq: '',
  101. },
  102. setIntervalTime: 0,
  103. isShowLockScreen: false,
  104. isShowLockScreenIntervalTime: 0,
  105. lockScreenPassword: '',
  106. });
  107. // 鼠标按下
  108. const onDown = (down: any) => {
  109. state.isFlags = true;
  110. state.downClientY = down.touches ? down.touches[0].clientY : down.clientY;
  111. };
  112. // 鼠标移动
  113. const onMove = (move: any) => {
  114. if (state.isFlags) {
  115. const el = <HTMLElement>state.querySelectorEl;
  116. const opacitys = (state.transparency -= 1 / 200);
  117. if (move.touches) {
  118. state.moveDifference = move.touches[0].clientY - state.downClientY;
  119. } else {
  120. state.moveDifference = move.clientY - state.downClientY;
  121. }
  122. if (state.moveDifference >= 0) return false;
  123. el.setAttribute('style', `top:${state.moveDifference}px;cursor:pointer;opacity:${opacitys};`);
  124. if (state.moveDifference < -400) {
  125. el.setAttribute('style', `top:${-el.clientHeight}px;cursor:pointer;transition:all 0.3s ease;`);
  126. state.moveDifference = -el.clientHeight;
  127. setTimeout(() => {
  128. el && el.parentNode?.removeChild(el);
  129. }, 300);
  130. }
  131. if (state.moveDifference === -el.clientHeight) {
  132. state.isShowLoockLogin = true;
  133. layoutLockScreenInputRef.value.focus();
  134. }
  135. }
  136. };
  137. // 鼠标松开
  138. const onEnd = () => {
  139. state.isFlags = false;
  140. state.transparency = 1;
  141. if (state.moveDifference >= -400) {
  142. (<HTMLElement>state.querySelectorEl).setAttribute('style', `top:0px;opacity:1;transition:all 0.3s ease;`);
  143. }
  144. };
  145. // 获取要拖拽的初始元素
  146. const initGetElement = () => {
  147. nextTick(() => {
  148. state.querySelectorEl = proxy.$refs.layoutLockScreenDateRef;
  149. });
  150. };
  151. // 时间初始化
  152. const initTime = () => {
  153. state.time.hm = formatDate(new Date(), 'HH:MM');
  154. state.time.s = formatDate(new Date(), 'SS');
  155. state.time.mdq = formatDate(new Date(), 'mm月dd日,WWW');
  156. };
  157. // 时间初始化定时器
  158. const initSetTime = () => {
  159. initTime();
  160. state.setIntervalTime = window.setInterval(() => {
  161. initTime();
  162. }, 1000);
  163. };
  164. // 锁屏时间定时器
  165. const initLockScreen = () => {
  166. if (store.state.themeConfig.themeConfig.isLockScreen) {
  167. state.isShowLockScreenIntervalTime = window.setInterval(() => {
  168. if (store.state.themeConfig.themeConfig.lockScreenTime <= 1) {
  169. state.isShowLockScreen = true;
  170. setLocalThemeConfig();
  171. return false;
  172. }
  173. store.state.themeConfig.themeConfig.lockScreenTime--;
  174. }, 1000);
  175. } else {
  176. clearInterval(state.isShowLockScreenIntervalTime);
  177. }
  178. };
  179. // 存储布局配置
  180. const setLocalThemeConfig = () => {
  181. store.state.themeConfig.themeConfig.isDrawer = false;
  182. Local.set('themeConfig', store.state.themeConfig.themeConfig);
  183. };
  184. // 密码输入点击事件
  185. const onLockScreenSubmit = () => {
  186. store.state.themeConfig.themeConfig.isLockScreen = false;
  187. store.state.themeConfig.themeConfig.lockScreenTime = 30;
  188. setLocalThemeConfig();
  189. };
  190. // 页面加载时
  191. onMounted(() => {
  192. initGetElement();
  193. initSetTime();
  194. initLockScreen();
  195. });
  196. // 页面卸载时
  197. onUnmounted(() => {
  198. window.clearInterval(state.setIntervalTime);
  199. window.clearInterval(state.isShowLockScreenIntervalTime);
  200. });
  201. return {
  202. layoutLockScreenInputRef,
  203. onDown,
  204. onMove,
  205. onEnd,
  206. onLockScreenSubmit,
  207. ...toRefs(state),
  208. };
  209. },
  210. });
  211. </script>
  212. <style scoped lang="scss">
  213. .layout-lock-screen-fixed {
  214. position: fixed;
  215. top: 0;
  216. left: 0;
  217. width: 100%;
  218. height: 100%;
  219. }
  220. .layout-lock-screen-filter {
  221. filter: blur(1px);
  222. }
  223. .layout-lock-screen-mask {
  224. background: var(--el-color-white);
  225. @extend .layout-lock-screen-fixed;
  226. z-index: 9999990;
  227. }
  228. .layout-lock-screen-img {
  229. @extend .layout-lock-screen-fixed;
  230. background-image: url('https://gitee.com/lyt-top/vue-next-admin-images/raw/master/images/03.jpg');
  231. background-size: 100% 100%;
  232. z-index: 9999991;
  233. }
  234. .layout-lock-screen {
  235. @extend .layout-lock-screen-fixed;
  236. z-index: 9999992;
  237. &-date {
  238. position: absolute;
  239. left: 0;
  240. top: 0;
  241. width: 100%;
  242. height: 100%;
  243. color: var(--el-color-white);
  244. z-index: 9999993;
  245. user-select: none;
  246. &-box {
  247. position: absolute;
  248. left: 30px;
  249. bottom: 50px;
  250. &-time {
  251. font-size: 100px;
  252. color: var(--color-whites);
  253. }
  254. &-info {
  255. font-size: 40px;
  256. color: var(--color-whites);
  257. }
  258. &-minutes {
  259. font-size: 16px;
  260. }
  261. }
  262. &-top {
  263. width: 40px;
  264. height: 40px;
  265. line-height: 40px;
  266. border-radius: 100%;
  267. border: 1px solid var(--el-border-color-light, #ebeef5);
  268. background: rgba(255, 255, 255, 0.1);
  269. color: var(--color-whites);
  270. opacity: 0.8;
  271. position: absolute;
  272. right: 30px;
  273. bottom: 50px;
  274. text-align: center;
  275. overflow: hidden;
  276. transition: all 0.3s ease;
  277. i {
  278. transition: all 0.3s ease;
  279. }
  280. &-text {
  281. opacity: 0;
  282. position: absolute;
  283. top: 150%;
  284. font-size: 12px;
  285. color: var(--color-whites);
  286. left: 50%;
  287. line-height: 1.2;
  288. transform: translate(-50%, -50%);
  289. transition: all 0.3s ease;
  290. width: 35px;
  291. }
  292. &:hover {
  293. border: 1px solid rgba(255, 255, 255, 0.5);
  294. background: rgba(255, 255, 255, 0.2);
  295. box-shadow: 0 0 12px 0 rgba(255, 255, 255, 0.5);
  296. color: var(--color-whites);
  297. opacity: 1;
  298. transition: all 0.3s ease;
  299. i {
  300. transform: translateY(-40px);
  301. transition: all 0.3s ease;
  302. }
  303. .layout-lock-screen-date-top-text {
  304. opacity: 1;
  305. top: 50%;
  306. transition: all 0.3s ease;
  307. }
  308. }
  309. }
  310. }
  311. &-login {
  312. position: relative;
  313. z-index: 9999994;
  314. width: 100%;
  315. height: 100%;
  316. left: 0;
  317. top: 0;
  318. display: flex;
  319. flex-direction: column;
  320. justify-content: center;
  321. color: var(--color-whites);
  322. &-box {
  323. text-align: center;
  324. margin: auto;
  325. &-img {
  326. width: 180px;
  327. height: 180px;
  328. margin: auto;
  329. img {
  330. width: 100%;
  331. height: 100%;
  332. border-radius: 100%;
  333. }
  334. }
  335. &-name {
  336. font-size: 26px;
  337. margin: 15px 0 30px;
  338. }
  339. }
  340. &-icon {
  341. position: absolute;
  342. right: 30px;
  343. bottom: 30px;
  344. i {
  345. font-size: 20px;
  346. margin-left: 15px;
  347. cursor: pointer;
  348. opacity: 0.8;
  349. &:hover {
  350. opacity: 1;
  351. }
  352. }
  353. }
  354. }
  355. }
  356. :deep(.el-input-group__append) {
  357. background: var(--el-color-white);
  358. padding: 0px 15px;
  359. }
  360. :deep(.el-input__inner) {
  361. border-right-color: var(--el-border-color-extra-light);
  362. &:hover {
  363. border-color: var(--el-border-color-extra-light);
  364. }
  365. }
  366. </style>