magic-login.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <magic-dialog :title="$i('message.login')" :showClose="false" v-model:value="value" >
  3. <div class="magic-login">
  4. <label>{{ $i('message.username') }}:</label>
  5. <magic-input :onEnter="doLogin" v-model:value="username"/>
  6. <div style="height: 2px"/>
  7. <label>{{ $i('message.password') }}:</label>
  8. <magic-input :onEnter="doLogin" v-model:value="password" type="password"/>
  9. <div style="height: 2px"/>
  10. </div>
  11. <magic-button-group align="center">
  12. <magic-button :value="$i('message.login')" @onClick="doLogin"/>
  13. </magic-button-group>
  14. </magic-dialog>
  15. </template>
  16. <script setup>
  17. import { ref } from 'vue'
  18. import bus from '../../../scripts/bus.js'
  19. import $i from '../../../scripts/i18n.js'
  20. import constants from '../../../scripts/constants.js'
  21. import Message from '../../../scripts/constants/message.js'
  22. import request from '../../../scripts/request.js'
  23. import store from '../../../scripts/store.js'
  24. defineProps({
  25. value: Boolean
  26. })
  27. const username = ref('')
  28. const password = ref('')
  29. const emit = defineEmits(['update:value'])
  30. const doLogin = () => {
  31. if(username.value && password.value){
  32. request.sendPost('/login', { username: username.value, password: password.value }).success((successed, response) => {
  33. if(successed){
  34. emit('update:value', false)
  35. constants.HEADER_MAGIC_TOKEN_VALUE = response.headers[constants.HEADER_MAGIC_TOKEN]
  36. store.set(constants.STORE.token, constants.HEADER_MAGIC_TOKEN_VALUE)
  37. bus.$emit(Message.LOGINED)
  38. }
  39. })
  40. }
  41. }
  42. </script>
  43. <style scoped>
  44. label {
  45. width: 60px;
  46. text-align: right;
  47. display: inline-block;
  48. }
  49. .magic-login :deep(.magic-input){
  50. width: auto !important;
  51. }
  52. </style>