index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <div v-show="state.isShowLockScreen">
  3. <div class="layout-lock-screen-mask"></div>
  4. <div class="layout-lock-screen-img" :class="{ 'layout-lock-screen-filter': state.isShowLoockLogin }"></div>
  5. <div class="layout-lock-screen">
  6. <div
  7. class="layout-lock-screen-date"
  8. ref="layoutLockScreenDateRef"
  9. @mousedown="onDownPc"
  10. @mousemove="onMovePc"
  11. @mouseup="onEnd"
  12. @touchstart.stop="onDownApp"
  13. @touchmove.stop="onMoveApp"
  14. @touchend.stop="onEnd"
  15. >
  16. <div class="layout-lock-screen-date-box">
  17. <div class="layout-lock-screen-date-box-time">
  18. {{ state.time.hm }}<span class="layout-lock-screen-date-box-minutes">{{ state.time.s }}</span>
  19. </div>
  20. <div class="layout-lock-screen-date-box-info">{{ state.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="state.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="userInfos.avatar || 'https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500'" />
  32. </div>
  33. <div class="layout-lock-screen-login-box-name">{{ userInfos.account }}</div>
  34. <div v-if="state.showMessage" class="layout-lock-screen-login-box-message">
  35. <span>{{ state.message }}</span>
  36. <el-button style="max-width: 80px; margin-top: 20px" size="default" @click="hideMessage"> 确认 </el-button>
  37. </div>
  38. <div v-else class="layout-lock-screen-login-box-value">
  39. <el-input placeholder="请输入密码" type="password" ref="layoutLockScreenInputRef" size="default" v-model="state.lockScreenPassword" @keyup.enter.native.stop="onLockScreenSubmit()">
  40. <template #append>
  41. <el-button @click="onLockScreenSubmit">
  42. <el-icon class="el-input__icon">
  43. <ele-Right />
  44. </el-icon>
  45. </el-button>
  46. </template>
  47. </el-input>
  48. </div>
  49. </div>
  50. <div class="layout-lock-screen-login-icon">
  51. <SvgIcon name="ele-Microphone" :size="20" />
  52. <SvgIcon name="ele-AlarmClock" :size="20" />
  53. <SvgIcon name="ele-SwitchButton" :size="20" />
  54. </div>
  55. </div>
  56. </transition>
  57. </div>
  58. </div>
  59. </template>
  60. <script setup lang="ts" name="layoutLockScreen">
  61. import { nextTick, onMounted, reactive, ref, onUnmounted } from 'vue';
  62. import { formatDate } from '/@/utils/formatTime';
  63. import { Local } from '/@/utils/storage';
  64. import { storeToRefs } from 'pinia';
  65. import { useThemeConfig } from '/@/stores/themeConfig';
  66. import { useUserInfo } from '/@/stores/userInfo';
  67. import { sm2 } from 'sm-crypto-v2';
  68. import { feature, getAPI } from '/@/utils/axios-utils';
  69. import { SysAuthApi } from '/@/api-services';
  70. // 定义变量内容
  71. const layoutLockScreenDateRef = ref<HtmlType>();
  72. const layoutLockScreenInputRef = ref();
  73. const storesThemeConfig = useThemeConfig();
  74. const { themeConfig } = storeToRefs(storesThemeConfig);
  75. const storesUserInfo = useUserInfo();
  76. const { userInfos } = storeToRefs(storesUserInfo);
  77. const state = reactive({
  78. transparency: 1,
  79. downClientY: 0,
  80. moveDifference: 0,
  81. isShowLoockLogin: false,
  82. isFlags: false,
  83. querySelectorEl: '' as HtmlType,
  84. time: {
  85. hm: '',
  86. s: '',
  87. mdq: '',
  88. },
  89. setIntervalTime: 0,
  90. isShowLockScreen: false,
  91. isShowLockScreenIntervalTime: 0,
  92. lockScreenPassword: '',
  93. message: '',
  94. showMessage: false,
  95. });
  96. // 鼠标按下 pc
  97. const onDownPc = (down: MouseEvent) => {
  98. state.isFlags = true;
  99. state.downClientY = down.clientY;
  100. };
  101. // 鼠标按下 app
  102. const onDownApp = (down: TouchEvent) => {
  103. state.isFlags = true;
  104. state.downClientY = down.touches[0].clientY;
  105. };
  106. // 鼠标移动 pc
  107. const onMovePc = (move: MouseEvent) => {
  108. state.moveDifference = move.clientY - state.downClientY;
  109. onMove();
  110. };
  111. // 鼠标移动 app
  112. const onMoveApp = (move: TouchEvent) => {
  113. state.moveDifference = move.touches[0].clientY - state.downClientY;
  114. onMove();
  115. };
  116. // 鼠标移动事件
  117. const onMove = () => {
  118. if (state.isFlags) {
  119. const el = <HTMLElement>state.querySelectorEl;
  120. const opacitys = (state.transparency -= 1 / 200);
  121. if (state.moveDifference >= 0) return false;
  122. el.setAttribute('style', `top:${state.moveDifference}px;cursor:pointer;opacity:${opacitys};`);
  123. if (state.moveDifference < -400) {
  124. el.setAttribute('style', `top:${-el.clientHeight}px;cursor:pointer;transition:all 0.3s ease;`);
  125. state.moveDifference = -el.clientHeight;
  126. setTimeout(() => {
  127. el && el.parentNode?.removeChild(el);
  128. }, 300);
  129. }
  130. if (state.moveDifference === -el.clientHeight) {
  131. state.isShowLoockLogin = true;
  132. layoutLockScreenInputRef.value.focus();
  133. }
  134. }
  135. };
  136. // 鼠标松开
  137. const onEnd = () => {
  138. state.isFlags = false;
  139. state.transparency = 1;
  140. if (state.moveDifference >= -400) {
  141. (<HTMLElement>state.querySelectorEl).setAttribute('style', `top:0px;opacity:1;transition:all 0.3s ease;`);
  142. }
  143. };
  144. // 获取要拖拽的初始元素
  145. const initGetElement = () => {
  146. nextTick(() => {
  147. state.querySelectorEl = layoutLockScreenDateRef.value;
  148. });
  149. };
  150. // 时间初始化
  151. const initTime = () => {
  152. state.time.hm = formatDate(new Date(), 'HH:MM');
  153. state.time.s = formatDate(new Date(), 'SS');
  154. state.time.mdq = formatDate(new Date(), 'mm月dd日,WWW');
  155. };
  156. // 时间初始化定时器
  157. const initSetTime = () => {
  158. initTime();
  159. state.setIntervalTime = window.setInterval(() => {
  160. initTime();
  161. }, 1000);
  162. };
  163. // 锁屏时间定时器
  164. const initLockScreen = () => {
  165. if (themeConfig.value.isLockScreen) {
  166. state.isShowLockScreenIntervalTime = window.setInterval(() => {
  167. // 锁屏时间为null重置为300秒,防止白屏
  168. if (themeConfig.value.lockScreenTime == null) {
  169. themeConfig.value.lockScreenTime = 300;
  170. setLocalThemeConfig();
  171. return false;
  172. }
  173. if (themeConfig.value.lockScreenTime <= 1) {
  174. state.isShowLockScreen = true;
  175. setLocalThemeConfig();
  176. return false;
  177. }
  178. themeConfig.value.lockScreenTime--;
  179. }, 1000);
  180. } else {
  181. clearInterval(state.isShowLockScreenIntervalTime);
  182. }
  183. };
  184. // 存储布局配置
  185. const setLocalThemeConfig = () => {
  186. themeConfig.value.isDrawer = false;
  187. Local.set('themeConfig', themeConfig.value);
  188. };
  189. // 密码输入点击事件
  190. const onLockScreenSubmit = async () => {
  191. if (state.lockScreenPassword) {
  192. try {
  193. // SM2加密密码
  194. // const keys = SM2.generateKeyPair();
  195. const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
  196. const password = sm2.doEncrypt(state.lockScreenPassword, publicKey, 1);
  197. const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthUnLockScreenPost(password));
  198. if (err) {
  199. console.log(err);
  200. state.message = err.message;
  201. state.showMessage = true;
  202. state.lockScreenPassword = '';
  203. return;
  204. }
  205. if (res.data.result) {
  206. themeConfig.value.isLockScreen = false;
  207. themeConfig.value.lockScreenTime = 30;
  208. setLocalThemeConfig();
  209. }
  210. } catch (ex: any) {
  211. state.message = `出错了:${ex}`;
  212. state.showMessage = true;
  213. }
  214. }
  215. };
  216. // 隐藏消息
  217. const hideMessage = () => {
  218. state.showMessage = false;
  219. nextTick(() => {
  220. layoutLockScreenInputRef.value.focus();
  221. });
  222. };
  223. // 页面加载时
  224. onMounted(() => {
  225. initGetElement();
  226. initSetTime();
  227. initLockScreen();
  228. //侦听ENTER按钮事件
  229. document.onkeydown = (e) => {
  230. if (e.key === 'Enter') {
  231. //当显示锁屏页时,按ENTER切到密码输入
  232. if (state.isShowLoockLogin == false) {
  233. const moveInterval = setInterval(() => {
  234. state.isFlags = true;
  235. state.moveDifference = state.moveDifference - 10;
  236. onMove();
  237. //超过600像素则结束
  238. if (state.moveDifference < -600) clearInterval(moveInterval);
  239. }, 5);
  240. }
  241. //当显示消息时,按ENTER切到密码输入
  242. if (state.showMessage == true) hideMessage();
  243. }
  244. };
  245. });
  246. // 页面卸载时
  247. onUnmounted(() => {
  248. window.clearInterval(state.setIntervalTime);
  249. window.clearInterval(state.isShowLockScreenIntervalTime);
  250. });
  251. </script>
  252. <style scoped lang="scss">
  253. .layout-lock-screen-fixed {
  254. position: fixed;
  255. top: 0;
  256. left: 0;
  257. width: 100%;
  258. height: 100%;
  259. }
  260. .layout-lock-screen-filter {
  261. filter: blur(1px);
  262. }
  263. .layout-lock-screen-mask {
  264. background: var(--el-color-white);
  265. @extend .layout-lock-screen-fixed;
  266. z-index: 9999990;
  267. }
  268. .layout-lock-screen-img {
  269. @extend .layout-lock-screen-fixed;
  270. background-image: url('https://i.hd-r.cn/e4a19d84364f185266666765ac21a5db.jpg');
  271. background-size: 100% 100%;
  272. z-index: 9999991;
  273. }
  274. .layout-lock-screen {
  275. @extend .layout-lock-screen-fixed;
  276. z-index: 9999992;
  277. &-date {
  278. position: absolute;
  279. left: 0;
  280. top: 0;
  281. width: 100%;
  282. height: 100%;
  283. color: var(--el-color-white);
  284. z-index: 9999993;
  285. user-select: none;
  286. &-box {
  287. position: absolute;
  288. left: 30px;
  289. bottom: 50px;
  290. &-time {
  291. font-size: 100px;
  292. color: var(--el-color-white);
  293. }
  294. &-info {
  295. font-size: 40px;
  296. color: var(--el-color-white);
  297. }
  298. &-minutes {
  299. font-size: 16px;
  300. }
  301. }
  302. &-top {
  303. width: 40px;
  304. height: 40px;
  305. line-height: 40px;
  306. border-radius: 100%;
  307. border: 1px solid var(--el-border-color-light, #ebeef5);
  308. background: rgba(255, 255, 255, 0.1);
  309. color: var(--el-color-white);
  310. opacity: 0.8;
  311. position: absolute;
  312. right: 30px;
  313. bottom: 50px;
  314. text-align: center;
  315. overflow: hidden;
  316. transition: all 0.3s ease;
  317. i {
  318. transition: all 0.3s ease;
  319. }
  320. &-text {
  321. opacity: 0;
  322. position: absolute;
  323. top: 150%;
  324. font-size: 12px;
  325. color: var(--el-color-white);
  326. left: 50%;
  327. line-height: 1.2;
  328. transform: translate(-50%, -50%);
  329. transition: all 0.3s ease;
  330. width: 35px;
  331. }
  332. &:hover {
  333. border: 1px solid rgba(255, 255, 255, 0.5);
  334. background: rgba(255, 255, 255, 0.2);
  335. box-shadow: 0 0 12px 0 rgba(255, 255, 255, 0.5);
  336. color: var(--el-color-white);
  337. opacity: 1;
  338. transition: all 0.3s ease;
  339. i {
  340. transform: translateY(-40px);
  341. transition: all 0.3s ease;
  342. }
  343. .layout-lock-screen-date-top-text {
  344. opacity: 1;
  345. top: 50%;
  346. transition: all 0.3s ease;
  347. }
  348. }
  349. }
  350. }
  351. &-login {
  352. position: relative;
  353. z-index: 9999994;
  354. width: 100%;
  355. height: 100%;
  356. left: 0;
  357. top: 0;
  358. display: flex;
  359. flex-direction: column;
  360. justify-content: center;
  361. color: var(--el-color-white);
  362. &-box {
  363. text-align: center;
  364. margin: auto;
  365. &-img {
  366. width: 180px;
  367. height: 180px;
  368. margin: auto;
  369. img {
  370. width: 100%;
  371. height: 100%;
  372. border-radius: 100%;
  373. }
  374. }
  375. &-name {
  376. font-size: 26px;
  377. margin: 15px 0 30px;
  378. }
  379. &-message {
  380. font-size: 16px;
  381. display: flex;
  382. flex-direction: column;
  383. align-items: center;
  384. }
  385. &-value {
  386. min-height: 73px;
  387. }
  388. }
  389. &-icon {
  390. position: absolute;
  391. right: 30px;
  392. bottom: 30px;
  393. i {
  394. font-size: 20px;
  395. margin-left: 15px;
  396. cursor: pointer;
  397. opacity: 0.8;
  398. &:hover {
  399. opacity: 1;
  400. }
  401. }
  402. }
  403. }
  404. }
  405. :deep(.el-input-group__append) {
  406. background: var(--el-color-white);
  407. padding: 0px 15px;
  408. }
  409. :deep(.el-input__wrapper.is-focus) {
  410. box-shadow: unset !important;
  411. }
  412. :deep(.el-input__inner) {
  413. border-right-color: var(--el-border-color-extra-light);
  414. &:hover {
  415. border-color: var(--el-border-color-extra-light);
  416. }
  417. }
  418. </style>