新型管道消毒机前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
3.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="login_modal">
  3. <img :src="showPassword ? Open : Eye" class="eye" @click="handleEye" />
  4. <p class="tips">{{ tip }}</p>
  5. <input
  6. type="text"
  7. v-model="username"
  8. class="username"
  9. @focus="handleFocus(1)"
  10. placeholder="请输入用户名"
  11. />
  12. <input
  13. :type="showPassword ? 'text' : 'password'"
  14. class="password"
  15. v-model="password"
  16. @focus="handleFocus(2)"
  17. id="txtPassword"
  18. placeholder="请输入设备密码"
  19. />
  20. <div class="login_btn" @click="handleLogin"></div>
  21. </div>
  22. </template>
  23. <script setup>
  24. import Eye from '@/assets/img/login/eye.png'
  25. import Open from '@/assets/img/login/open.png'
  26. import { useWebSocketStore, useUserStore } from '@/store'
  27. import { ref, watch } from 'vue'
  28. import { useRouter } from 'vue-router'
  29. import { loginJSON } from '@/mock/command'
  30. const props = defineProps({
  31. handleShowKey: {
  32. type: Function,
  33. },
  34. handleHideKey: {
  35. type: Function,
  36. },
  37. clearInput: {
  38. type: Function,
  39. },
  40. input: {
  41. type: String,
  42. },
  43. })
  44. const activeInput = ref(1)
  45. const handleFocus = flag => {
  46. props.handleShowKey()
  47. props.clearInput()
  48. activeInput.value = flag
  49. }
  50. const router = useRouter()
  51. const userStore = useUserStore()
  52. const webSocketStore = useWebSocketStore()
  53. const showPassword = ref(false)
  54. const username = ref('')
  55. const password = ref('')
  56. const tip = ref('')
  57. const handleEye = () => {
  58. showPassword.value = !showPassword.value
  59. }
  60. watch(() => {
  61. // 需要有个逻辑判断
  62. if (activeInput.value == 1) {
  63. username.value = props.input
  64. } else {
  65. password.value = props.input
  66. }
  67. })
  68. const handleLogin = () => {
  69. props.handleHideKey()
  70. if (username.value == '') {
  71. tip.value = '用户名不能为空'
  72. return
  73. }
  74. if (password.value == '') {
  75. tip.value = '密码不能为空'
  76. return
  77. }
  78. tip.value = ''
  79. webSocketStore?.sendCommandMsg(loginJSON(username.value, password.value))
  80. // 前端自己校验
  81. let flag = false
  82. userStore.allUserList?.map(item => {
  83. if (item.uid == username.value && password.value == item.passwd) {
  84. // 登陆成功
  85. flag = true
  86. userStore.updatePermission(item.permission_level)
  87. userStore.updateLoginUser(item.uid)
  88. }
  89. })
  90. if (flag) {
  91. router.push('/')
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .login_modal {
  97. width: 476px;
  98. height: 414px;
  99. border-radius: 16px;
  100. overflow: hidden;
  101. background: url(../assets/img/login/login.png) no-repeat;
  102. background-size: 100% 100%;
  103. box-sizing: border-box;
  104. position: relative;
  105. .eye {
  106. width: 16px;
  107. height: 13px;
  108. position: absolute;
  109. right: 78.04px;
  110. top: 211px;
  111. }
  112. .tips {
  113. font-family: Source Han Sans CN;
  114. font-size: 12px;
  115. font-weight: 350;
  116. letter-spacing: 0.06em;
  117. color: #fa1c1c;
  118. position: absolute;
  119. left: 73px;
  120. bottom: 143px;
  121. }
  122. .username {
  123. border: none;
  124. outline: none;
  125. width: 253px;
  126. height: 17px;
  127. position: absolute;
  128. left: 120px;
  129. top: 142px;
  130. font-family: Source Han Sans CN;
  131. font-size: 12px;
  132. font-weight: 350;
  133. letter-spacing: 0.06em;
  134. }
  135. .password {
  136. border: none;
  137. outline: none;
  138. width: 253px;
  139. height: 17px;
  140. position: absolute;
  141. left: 120px;
  142. top: 209px;
  143. font-family: Source Han Sans CN;
  144. font-size: 12px;
  145. font-weight: 350;
  146. letter-spacing: 0.06em;
  147. }
  148. .login_btn {
  149. position: absolute;
  150. width: 340px;
  151. height: 68px;
  152. left: 68px;
  153. bottom: 62px;
  154. }
  155. }
  156. </style>