index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="vab-lock">
  3. <vab-icon icon="lock-2-line" @click="handleLock" />
  4. <el-drawer
  5. v-model="lock"
  6. append-to-body
  7. class="vab-lock-drawer"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. direction="ttb"
  11. :show-close="false"
  12. size="100%"
  13. :with-header="false"
  14. >
  15. <div class="vab-screen-lock">
  16. <div id="vab-screen-lock-background" class="vab-screen-lock-background" :style="style"></div>
  17. <div class="vab-screen-lock-content">
  18. <div class="vab-screen-lock-content-title">
  19. <el-avatar :size="180" :src="avatar" />
  20. <vab-icon icon="lock-2-line" />
  21. {{ title }} {{ translate('屏幕已锁定') }}
  22. </div>
  23. <div class="vab-screen-lock-content-form">
  24. <el-form ref="formRef" :model="form" :rules="rules" @submit.prevent>
  25. <el-form-item prop="password">
  26. <el-input v-model="form.password" v-focus autocomplete="off" :placeholder="translate('请输入密码123456')" type="password" />
  27. <el-button native-type="submit" type="primary" @click="handleUnLock">
  28. <vab-icon icon="rotate-lock-2-line" />
  29. <span>{{ translate('解锁') }}</span>
  30. </el-button>
  31. </el-form-item>
  32. </el-form>
  33. </div>
  34. <span @click="randomBackground">{{ translate('切换壁纸') }}</span>
  35. </div>
  36. </div>
  37. </el-drawer>
  38. </div>
  39. </template>
  40. <script lang="ts" setup>
  41. import { sample, shuffle } from 'lodash-es'
  42. import { translate } from '/@/i18n'
  43. import { useBingStore } from '/@/store/modules/bing'
  44. import { useSettingsStore } from '/@/store/modules/settings'
  45. import { useUserStore } from '/@/store/modules/user'
  46. defineOptions({
  47. name: 'VabLock',
  48. })
  49. const userStore = useUserStore()
  50. const { avatar } = storeToRefs(userStore)
  51. const settingsStore = useSettingsStore()
  52. const { lock, title } = storeToRefs(settingsStore)
  53. const { handleLock: _handleLock, handleUnLock: _handleUnLock } = settingsStore
  54. const bingStore = useBingStore()
  55. const { backgroundList } = storeToRefs(bingStore)
  56. const url = 'https://cdn.jsdelivr.net/gh/chuzhixin/image/vab-image-lock/'
  57. const background = ref<string | undefined>(`${url}${Math.round(Math.random() * 31)}.jpg`)
  58. const style = reactive<any>({
  59. background: 'var(--el-color-primary-light-5)',
  60. backgroundSize: '100%',
  61. filter: 'blur(5px)',
  62. transform: 'scale(1.05)',
  63. transition: 'all 3s ease-in-out',
  64. })
  65. const randomBackground = () => {
  66. style.transform = 'scale(1.05)'
  67. style.transition = 'none'
  68. background.value = sample(shuffle(backgroundList.value))
  69. style.background = `fixed url(${background.value}) center`
  70. setTimeout(() => {
  71. style.transform = 'scale(1.2)'
  72. style.transition = 'all 3s ease-in-out'
  73. }, 0)
  74. }
  75. const validatePass = (rule: any, value: string, callback: any) => {
  76. if (value === '' || value !== '123456') {
  77. callback(new Error('请输入正确的密码'))
  78. } else {
  79. callback()
  80. }
  81. }
  82. const formRef = ref()
  83. const form = reactive({
  84. password: '123456',
  85. })
  86. const rules = {
  87. password: [{ validator: validatePass, trigger: 'blur' }],
  88. }
  89. const handleUnLock = () => {
  90. formRef.value?.validate(async (valid: boolean) => {
  91. if (valid) await _handleUnLock()
  92. })
  93. }
  94. const handleLock = () => {
  95. _handleLock()
  96. }
  97. watch(
  98. lock,
  99. () => {
  100. setTimeout(() => {
  101. lock.value ? (style.transform = 'scale(1.2)') : (style.transform = 'scale(1.05)')
  102. }, 500)
  103. },
  104. {
  105. immediate: true,
  106. }
  107. )
  108. onMounted(() => {
  109. setTimeout(() => {
  110. randomBackground()
  111. }, 50)
  112. })
  113. </script>
  114. <style lang="scss">
  115. .el-overlay:has(.vab-lock-drawer) {
  116. backdrop-filter: none;
  117. .vab-lock-drawer {
  118. .el-drawer__body {
  119. padding: 0 !important;
  120. overflow: hidden !important;
  121. }
  122. }
  123. }
  124. </style>
  125. <style lang="scss" scoped>
  126. .vab-lock-drawer {
  127. .vab-screen-lock {
  128. position: relative;
  129. z-index: var(--el-z-index);
  130. display: flex;
  131. flex-wrap: wrap;
  132. align-items: center;
  133. justify-content: center;
  134. width: 100vw;
  135. height: calc(var(--vh, 1vh) * 100);
  136. font-weight: bold;
  137. background: var(--el-mask-color);
  138. opacity: var(--opacity-value);
  139. &-background {
  140. position: absolute;
  141. top: 0;
  142. right: 0;
  143. bottom: 0;
  144. left: 0;
  145. z-index: calc(var(--el-z-index) - 1);
  146. }
  147. &-content {
  148. z-index: var(--el-z-index);
  149. width: 400px;
  150. padding: 40px 55px 40px 55px;
  151. color: var(--el-color-grey);
  152. text-align: center;
  153. background: var(--el-mask-color);
  154. backdrop-filter: blur(10px);
  155. border: 1px solid var(--el-border-color);
  156. border-radius: 15px;
  157. > span {
  158. font-size: var(--el-font-size-extra-small);
  159. cursor: pointer;
  160. }
  161. &-title {
  162. line-height: 50px;
  163. color: var(--el-color-grey);
  164. text-align: center;
  165. :deep() {
  166. .el-avatar {
  167. width: 150px;
  168. height: 150px;
  169. img {
  170. padding: 30px;
  171. cursor: pointer;
  172. }
  173. }
  174. [class*='ri-'] {
  175. display: block;
  176. margin: auto !important;
  177. font-size: 30px;
  178. color: var(--el-color-grey) !important;
  179. }
  180. }
  181. }
  182. &-form {
  183. :deep() {
  184. .el-input {
  185. position: relative;
  186. width: 100%;
  187. height: 40px;
  188. line-height: 40px;
  189. &__wrapper {
  190. padding-right: 0;
  191. border: 1px solid var(--el-color-primary);
  192. box-shadow: none;
  193. }
  194. &__inner {
  195. width: 180px;
  196. }
  197. &__suffix {
  198. .el-input__validateIcon {
  199. display: none;
  200. }
  201. }
  202. }
  203. .el-button {
  204. position: absolute;
  205. right: -1px;
  206. z-index: 999;
  207. height: 40px;
  208. margin-left: 0 !important;
  209. line-height: 40px;
  210. border-top-left-radius: 0;
  211. border-bottom-left-radius: 0;
  212. [class*='ri-'] {
  213. margin-left: 0 !important;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. @media (max-width: 768px) {
  220. .vab-screen-lock-content {
  221. width: 100% !important;
  222. padding: 40px 35px 40px 35px;
  223. margin: 5vw;
  224. }
  225. }
  226. }
  227. }
  228. </style>