新型管道消毒机前端代码
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.

183 lines
3.9 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
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 style-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, getAllUserJSON } 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. hideLoginModal: {
  44. type: Function,
  45. default: () => {},
  46. },
  47. modal: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. changeTab: {
  52. type: Function,
  53. default: () => {},
  54. },
  55. })
  56. const activeInput = ref(1)
  57. const handleFocus = flag => {
  58. props.handleShowKey()
  59. props.clearInput()
  60. activeInput.value = flag
  61. }
  62. const router = useRouter()
  63. const userStore = useUserStore()
  64. const webSocketStore = useWebSocketStore()
  65. const showPassword = ref(false)
  66. const username = ref('')
  67. const password = ref('')
  68. const tip = ref('')
  69. const handleEye = () => {
  70. showPassword.value = !showPassword.value
  71. }
  72. watch(() => {
  73. // 需要有个逻辑判断
  74. if (activeInput.value == 1) {
  75. username.value = props.input
  76. } else {
  77. password.value = props.input
  78. }
  79. })
  80. const handleLogin = () => {
  81. props.handleHideKey()
  82. if (username.value == '') {
  83. tip.value = '用户名不能为空'
  84. return
  85. }
  86. if (password.value == '') {
  87. tip.value = '密码不能为空'
  88. return
  89. }
  90. tip.value = ''
  91. webSocketStore?.sendCommandMsg(loginJSON(username.value, password.value))
  92. // 前端自己校验
  93. let flag = false
  94. userStore.allUserList?.map(item => {
  95. if (item.uid == username.value && password.value == item.passwd) {
  96. // 登陆成功
  97. flag = true
  98. userStore.updatePermission(item.permission_level)
  99. userStore.updateLoginUser(item.uid)
  100. if (props.modal) {
  101. props.changeTab(5)
  102. props.hideLoginModal()
  103. // 判断是否在消毒中,如果在消毒中,将TAB切换到设置
  104. } else {
  105. window.location.href = 'http://127.0.0.1/'
  106. }
  107. console.log(props.modal)
  108. }
  109. })
  110. if (!flag) {
  111. // tip.value = '账号或密码错误'
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .login_modal {
  117. width: 476px;
  118. height: 414px;
  119. border-radius: 16px;
  120. overflow: hidden;
  121. background: url(../assets/img/login/login.png) no-repeat;
  122. background-size: 100% 100%;
  123. box-sizing: border-box;
  124. position: relative;
  125. .eye {
  126. width: 16px;
  127. height: 13px;
  128. position: absolute;
  129. right: 78.04px;
  130. top: 211px;
  131. }
  132. .tips {
  133. font-family: Source Han Sans CN;
  134. font-size: 12px;
  135. font-weight: 350;
  136. letter-spacing: 0.06em;
  137. color: #fa1c1c;
  138. position: absolute;
  139. left: 73px;
  140. bottom: 143px;
  141. }
  142. .username {
  143. border: none;
  144. outline: none;
  145. width: 253px;
  146. height: 17px;
  147. position: absolute;
  148. left: 120px;
  149. top: 142px;
  150. font-family: Source Han Sans CN;
  151. font-size: 22px;
  152. font-weight: 350;
  153. letter-spacing: 0.06em;
  154. }
  155. .password {
  156. border: none;
  157. outline: none;
  158. width: 253px;
  159. height: 17px;
  160. position: absolute;
  161. left: 120px;
  162. top: 209px;
  163. font-family: Source Han Sans CN;
  164. font-size: 18px;
  165. font-weight: 350;
  166. letter-spacing: 0.06em;
  167. }
  168. .login_btn {
  169. position: absolute;
  170. width: 340px;
  171. height: 68px;
  172. left: 68px;
  173. bottom: 62px;
  174. }
  175. }
  176. </style>