| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <template>
- <sign-layout class="user-login" :title="islogin ? '登录' : '重置密码'" v-loading="rloading">
- <el-form ref="formRef" :model="formData" :rules="formRules" v-if="islogin">
- <el-form-item prop="userName">
- <el-input placeholder="用户名/账号/手机号" v-model="formData.userName">
- <template #append>
- <el-checkbox v-model="remember"></el-checkbox>
- </template>
- </el-input>
- </el-form-item>
- <el-form-item prop="password">
- <el-input type="password" placeholder="请输入您的登录密码" v-model="formData.password">
- </el-input>
- </el-form-item>
- <el-form-item>
- <span class="text-link" @click="click">立即注册</span>
- <span class="text-link" @click="islogin = false">忘记密码?</span>
- </el-form-item>
- <el-form-item>
- <el-button class="submit" type="primary" :loading="loading" @click="formSubmit">
- <span v-if="loading">正在登录</span>
- <span v-else>登录</span>
- </el-button>
- </el-form-item>
- </el-form>
- <Forget @close="islogin = true" v-else></Forget>
- <el-dialog v-model="isRegister" title="立即注册" width="30%" >
- <span>手机扫描二维码进行注册</span>
- <app-qrcode class="app-register-code__qrcode" :text="qrContent" :logo="require('../../../assets/logo.svg')" />
- <template #footer>
- <span class="dialog-footer">
- <el-button @click="isRegister = false">取消</el-button>
- </span>
- </template>
- </el-dialog>
- </sign-layout>
- </template>
- <script lang="ts" setup>
- import { shallowRef } from 'vue'
- import { useRoute, useRouter } from 'vue-router'
- import { ElMessage, ElDialog } from 'element-plus'
- import type { FormInstance, FormRules } from 'element-plus'
- import { ClientType } from '@/constants/client'
- import { useLogin } from '@/business/login'
- import { useMenuStore } from '@/stores'
- import service from '@/services'
- import SignLayout from '../components/layout/index.vue'
- import Forget from "../forget/index.vue"
- import AppQrcode from '@/components/base/qrcode/index.vue'
- const { formData, remember, userLogin } = useLogin()
- const route = useRoute()
- const router = useRouter()
- const menuStore = useMenuStore()
- const formRef = shallowRef<FormInstance>()
- const loading = shallowRef(false)
- const islogin = shallowRef(true)
- const isRegister = shallowRef(false)
- const qrContent = shallowRef('')
- const rloading = shallowRef(false)
- const formRules: FormRules = {
- userName: [
- { required: true, max: 20, message: '请输入登录账号', trigger: 'blur' }
- ],
- password: [
- { required: true, max: 16, message: '请输入登录密码', trigger: 'blur' }
- ]
- }
- const click = () => {
- rloading.value = true
- service.onReady().then((res) => {
- qrContent.value = res.mobileOpenUrl
- isRegister.value = true
- }).finally(() => {
- rloading.value = false
- })
- }
- const formSubmit = () => {
- formRef.value?.validate(async (valid) => {
- if (valid) {
- try {
- loading.value = true
- formData.clientType = ClientType.Web
- await userLogin()
- await menuStore.getUserMenuList()
- const redirect = route.query.redirect
- if (redirect) {
- router.replace(redirect.toString())
- } else {
- router.replace('/')
- }
- } catch (err) {
- loading.value = false
- ElMessage.error(err as string)
- }
- }
- })
- }
- </script>
- <style lang="less" scoped>
- @import './index.less';
- </style>
|