unlock.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <transition name="show-unlock">
  3. <div v-if="showUnlock" class="unlock-body-con" @keydown.enter="handleUnlock">
  4. <div :style="{marginLeft: avatarLeft}" class="unlock-avatar-con" @click="handleClickAvatar">
  5. <el-avatar
  6. :src="avatar"
  7. :text="userName"
  8. shape="square"
  9. class="unlock-avatar-img"
  10. @error="errorImageHandler"
  11. >
  12. <img :src="errorImage">
  13. </el-avatar>
  14. <div class="unlock-avatar-cover">
  15. <span><i class="ibps-icon-unlock" /></span>
  16. <p>{{ $t('components.lockScreen.unlock') }}</p>
  17. </div>
  18. </div>
  19. <div :style="{marginLeft: avatarLeft}" class="unlock-avatar-under-back" />
  20. <div class="unlock-input-con">
  21. <div class="unlock-input-overflow-con">
  22. <div :style="{right: inputLeft}" class="unlock-overflow-body">
  23. <input ref="inputEle" v-model="password" :placeholder="$t('components.lockScreen.placeholder')" class="unlock-input" autocomplete="false" type="password">
  24. <button ref="unlockBtn" class="unlock-btn" @mousedown="unlockMousedown" @mouseup="unlockMouseup" @click="handleUnlock">
  25. <i class="ibps-icon-key" />
  26. </button>
  27. </div>
  28. </div>
  29. </div>
  30. <div class="unlock-locking-tip-con logo-title">{{ $t('components.lockScreen.locked') }}</div>
  31. </div>
  32. </transition>
  33. </template>
  34. <script>
  35. import { mapState } from 'vuex'
  36. import hotkeys from 'hotkeys-js'
  37. import { getFile } from '@/utils/avatar'
  38. import setting from '@/setting.js'
  39. export default {
  40. name: 'unlock',
  41. props: {
  42. showUnlock: {
  43. type: Boolean,
  44. default: false
  45. }
  46. },
  47. data() {
  48. return {
  49. open: false,
  50. avatarLeft: '0px',
  51. inputLeft: '400px',
  52. password: '',
  53. check: null
  54. }
  55. },
  56. computed: {
  57. ...mapState('ibps/user', [
  58. 'info'
  59. ]),
  60. avatar() {
  61. const photo = this.info && this.info.employee ? this.info.employee.photo : null
  62. if (this.$utils.isEmpty(photo)) {
  63. return this.errorImage
  64. }
  65. return getFile(photo)
  66. },
  67. errorImage() {
  68. return this.$baseUrl + setting.userInfo.user.photo
  69. },
  70. userName() {
  71. return this.info && this.info.user ? this.info.user.fullname : ''
  72. }
  73. },
  74. mounted() {
  75. // 绑定回车功能快捷键
  76. hotkeys('Enter', event => {
  77. event.preventDefault()
  78. this.handleEnter()
  79. })
  80. },
  81. beforeDestroy() {
  82. hotkeys.unbind('Enter')
  83. },
  84. methods: {
  85. errorImageHandler() {
  86. return false
  87. },
  88. validator() {
  89. if (this.password === '') { return false }
  90. return true // TODO: 你可以在这里写密码验证方式,如发起ajax请求将用户输入的密码this.password与数据库用户密码对比
  91. },
  92. handleEnter() {
  93. if (this.open) {
  94. this.handleUnlock()
  95. } else {
  96. this.handleClickAvatar()
  97. }
  98. },
  99. handleClickAvatar() {
  100. this.open = true
  101. this.avatarLeft = '-180px'
  102. this.inputLeft = '0px'
  103. if (this.$refs && this.$refs.inputEle) {
  104. this.$refs.inputEle.focus()
  105. }
  106. },
  107. handleUnlock() {
  108. if (this.validator()) {
  109. this.open = false
  110. this.avatarLeft = '0px'
  111. this.inputLeft = '400px'
  112. this.password = ''
  113. this.$utils.cookies.set('locking', 'unlock')
  114. this.$emit('on-unlock')
  115. } else {
  116. this.$message({
  117. message: this.$t('components.lockScreen.tip'),
  118. type: 'error'
  119. })
  120. }
  121. },
  122. unlockMousedown() {
  123. this.$refs.unlockBtn.className = 'unlock-btn click-unlock-btn'
  124. },
  125. unlockMouseup() {
  126. this.$refs.unlockBtn.className = 'unlock-btn'
  127. }
  128. }
  129. }
  130. </script>
  131. <style rel="stylesheet/scss" lang="scss" scoped>
  132. @import '~@/assets/styles/pages/unlock.scss'
  133. </style>