index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <sign-layout class="user-login" :title="islogin ? '登录' : '重置密码'" v-loading="rloading">
  3. <el-form ref="formRef" :model="formData" :rules="formRules" v-if="islogin">
  4. <el-form-item prop="userName">
  5. <el-input placeholder="用户名/账号/手机号" v-model="formData.userName">
  6. <template #append>
  7. <el-checkbox v-model="remember"></el-checkbox>
  8. </template>
  9. </el-input>
  10. </el-form-item>
  11. <el-form-item prop="password">
  12. <el-input type="password" placeholder="请输入您的登录密码" v-model="formData.password">
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item>
  16. <span class="text-link" @click="click">立即注册</span>
  17. <span class="text-link" @click="islogin = false">忘记密码?</span>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button class="submit" type="primary" :loading="loading" @click="formSubmit">
  21. <span v-if="loading">正在登录</span>
  22. <span v-else>登录</span>
  23. </el-button>
  24. </el-form-item>
  25. </el-form>
  26. <Forget @close="islogin = true" v-else></Forget>
  27. <el-dialog v-model="isRegister" title="立即注册" width="30%" >
  28. <span>手机扫描二维码进行注册</span>
  29. <app-qrcode class="app-register-code__qrcode" :text="qrContent" :logo="require('../../../assets/logo.svg')" />
  30. <template #footer>
  31. <span class="dialog-footer">
  32. <el-button @click="isRegister = false">取消</el-button>
  33. </span>
  34. </template>
  35. </el-dialog>
  36. </sign-layout>
  37. </template>
  38. <script lang="ts" setup>
  39. import { shallowRef } from 'vue'
  40. import { useRoute, useRouter } from 'vue-router'
  41. import { ElMessage, ElDialog } from 'element-plus'
  42. import type { FormInstance, FormRules } from 'element-plus'
  43. import { ClientType } from '@/constants/client'
  44. import { useLogin } from '@/business/login'
  45. import { useMenuStore } from '@/stores'
  46. import service from '@/services'
  47. import SignLayout from '../components/layout/index.vue'
  48. import Forget from "../forget/index.vue"
  49. import AppQrcode from '@/components/base/qrcode/index.vue'
  50. const { formData, remember, userLogin } = useLogin()
  51. const route = useRoute()
  52. const router = useRouter()
  53. const menuStore = useMenuStore()
  54. const formRef = shallowRef<FormInstance>()
  55. const loading = shallowRef(false)
  56. const islogin = shallowRef(true)
  57. const isRegister = shallowRef(false)
  58. const qrContent = shallowRef('')
  59. const rloading = shallowRef(false)
  60. const formRules: FormRules = {
  61. userName: [
  62. { required: true, max: 20, message: '请输入登录账号', trigger: 'blur' }
  63. ],
  64. password: [
  65. { required: true, max: 16, message: '请输入登录密码', trigger: 'blur' }
  66. ]
  67. }
  68. const click = () => {
  69. rloading.value = true
  70. service.onReady().then((res) => {
  71. qrContent.value = res.mobileOpenUrl
  72. isRegister.value = true
  73. }).finally(() => {
  74. rloading.value = false
  75. })
  76. }
  77. const formSubmit = () => {
  78. formRef.value?.validate(async (valid) => {
  79. if (valid) {
  80. try {
  81. loading.value = true
  82. formData.clientType = ClientType.Web
  83. await userLogin()
  84. await menuStore.getUserMenuList()
  85. const redirect = route.query.redirect
  86. if (redirect) {
  87. router.replace(redirect.toString())
  88. } else {
  89. router.replace('/')
  90. }
  91. } catch (err) {
  92. loading.value = false
  93. ElMessage.error(err as string)
  94. }
  95. }
  96. })
  97. }
  98. </script>
  99. <style lang="less" scoped>
  100. @import './index.less';
  101. </style>