refactor: login

pull/2/head
xingyu 2022-11-22 21:41:59 +08:00
parent 9532570491
commit d604c6c5fb
4 changed files with 49 additions and 56 deletions

View File

@ -59,21 +59,18 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { LoginForm, MobileForm, RegisterForm, QrCodeForm } from './components' import { underlineToHump } from '@/utils'
import { useI18n } from '@/hooks/web/useI18n'
import { useDesign } from '@/hooks/web/useDesign'
import { useAppStore } from '@/store/modules/app'
import { ThemeSwitch } from '@/components/ThemeSwitch' import { ThemeSwitch } from '@/components/ThemeSwitch'
import { LocaleDropdown } from '@/components/LocaleDropdown' import { LocaleDropdown } from '@/components/LocaleDropdown'
import { useI18n } from '@/hooks/web/useI18n' import { LoginForm, MobileForm, RegisterForm, QrCodeForm } from './components'
import { underlineToHump } from '@/utils'
import { useAppStore } from '@/store/modules/app'
import { useDesign } from '@/hooks/web/useDesign'
const { t } = useI18n() const { t } = useI18n()
const { getPrefixCls } = useDesign()
const prefixCls = getPrefixCls('login')
const appStore = useAppStore() const appStore = useAppStore()
const { getPrefixCls } = useDesign()
const prefixCls = getPrefixCls('login')
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -137,7 +137,7 @@
</el-form> </el-form>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useIcon } from '@/hooks/web/useIcon' import { reactive, ref, unref, onMounted, computed, watch } from 'vue'
import LoginFormTitle from './LoginFormTitle.vue' import LoginFormTitle from './LoginFormTitle.vue'
import { import {
ElForm, ElForm,
@ -150,20 +150,24 @@ import {
ElDivider, ElDivider,
ElLoading ElLoading
} from 'element-plus' } from 'element-plus'
import { reactive, ref, unref, onMounted, computed, watch } from 'vue'
import * as LoginApi from '@/api/login'
import { setToken, setTenantId } from '@/utils/auth'
import { usePermissionStore } from '@/store/modules/permission'
import { useRouter } from 'vue-router'
import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { Icon } from '@/components/Icon'
import { LoginStateEnum, useLoginState, useFormValid } from './useLogin'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { Verify } from '@/components/Verifition'
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import { useRouter } from 'vue-router'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { useI18n } from '@/hooks/web/useI18n'
import { useIcon } from '@/hooks/web/useIcon'
import { required } from '@/utils/formRules'
import { setToken, setTenantId } from '@/utils/auth'
import { decrypt, encrypt } from '@/utils/jsencrypt' import { decrypt, encrypt } from '@/utils/jsencrypt'
import { Icon } from '@/components/Icon'
import { Verify } from '@/components/Verifition'
import { usePermissionStore } from '@/store/modules/permission'
import * as LoginApi from '@/api/login'
import { LoginStateEnum, useLoginState, useFormValid } from './useLogin'
const { t } = useI18n()
const iconHouse = useIcon({ icon: 'ep:house' })
const iconAvatar = useIcon({ icon: 'ep:avatar' })
const iconLock = useIcon({ icon: 'ep:lock' })
const { currentRoute, push } = useRouter() const { currentRoute, push } = useRouter()
const permissionStore = usePermissionStore() const permissionStore = usePermissionStore()
const formLogin = ref() const formLogin = ref()
@ -173,16 +177,12 @@ const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
const iconSize = 30 const iconSize = 30
const iconColor = '#999' const iconColor = '#999'
const redirect = ref<string>('') const redirect = ref<string>('')
const { t } = useI18n() const loginLoading = ref(false)
const iconHouse = useIcon({ icon: 'ep:house' })
const iconAvatar = useIcon({ icon: 'ep:avatar' })
const iconLock = useIcon({ icon: 'ep:lock' })
const LoginRules = { const LoginRules = {
tenantName: [required], tenantName: [required],
username: [required], username: [required],
password: [required] password: [required]
} }
const loginLoading = ref(false)
const loginData = reactive({ const loginData = reactive({
isShowPassword: false, isShowPassword: false,
captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE, captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE,
@ -202,7 +202,6 @@ const loginData = reactive({
// blockPuzzle clickWord // blockPuzzle clickWord
const verify = ref() const verify = ref()
const captchaType = ref('blockPuzzle') const captchaType = ref('blockPuzzle')
// //
const getCode = async () => { const getCode = async () => {
// //
@ -210,7 +209,6 @@ const getCode = async () => {
await handleLogin({}) await handleLogin({})
return return
} }
// //
// //
verify.value.show() verify.value.show()

View File

@ -85,31 +85,34 @@
</el-form> </el-form>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useIcon } from '@/hooks/web/useIcon'
import { reactive, ref, unref, watch, computed } from 'vue' import { reactive, ref, unref, watch, computed } from 'vue'
import LoginFormTitle from './LoginFormTitle.vue' import { ElForm, ElFormItem, ElInput, ElRow, ElCol } from 'element-plus'
import { ElForm, ElFormItem, ElInput, ElRow, ElCol, ElMessage } from 'element-plus'
import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { getTenantIdByNameApi, sendSmsCodeApi, smsLoginApi } from '@/api/login'
import { useCache } from '@/hooks/web/useCache'
import { usePermissionStore } from '@/store/modules/permission'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { setToken } from '@/utils/auth'
import type { RouteLocationNormalizedLoaded } from 'vue-router' import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { useI18n } from '@/hooks/web/useI18n'
import { useIcon } from '@/hooks/web/useIcon'
import { useCache } from '@/hooks/web/useCache'
import { useMessage } from '@/hooks/web/useMessage'
import { setToken } from '@/utils/auth'
import { required } from '@/utils/formRules'
import { usePermissionStore } from '@/store/modules/permission'
import { getTenantIdByNameApi, sendSmsCodeApi, smsLoginApi } from '@/api/login'
import LoginFormTitle from './LoginFormTitle.vue'
import { useLoginState, LoginStateEnum, useFormValid } from './useLogin' import { useLoginState, LoginStateEnum, useFormValid } from './useLogin'
const { t } = useI18n()
const { wsCache } = useCache()
const message = useMessage()
const permissionStore = usePermissionStore()
const { currentRoute, push } = useRouter()
const formSmsLogin = ref() const formSmsLogin = ref()
const { validForm } = useFormValid(formSmsLogin) const loginLoading = ref(false)
const { handleBackLogin, getLoginState } = useLoginState()
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.MOBILE)
const iconHouse = useIcon({ icon: 'ep:house' }) const iconHouse = useIcon({ icon: 'ep:house' })
const iconCellphone = useIcon({ icon: 'ep:cellphone' }) const iconCellphone = useIcon({ icon: 'ep:cellphone' })
const iconCircleCheck = useIcon({ icon: 'ep:circle-check' }) const iconCircleCheck = useIcon({ icon: 'ep:circle-check' })
const { wsCache } = useCache() const { validForm } = useFormValid(formSmsLogin)
const permissionStore = usePermissionStore() const { handleBackLogin, getLoginState } = useLoginState()
const { currentRoute, push } = useRouter() const getShow = computed(() => unref(getLoginState) === LoginStateEnum.MOBILE)
const loginLoading = ref(false)
const { t } = useI18n()
const rules = { const rules = {
tenantName: [required], tenantName: [required],
@ -146,11 +149,7 @@ const getSmsCode = async () => {
await getTenantId() await getTenantId()
smsVO.smsCode.mobile = loginData.loginForm.mobileNumber smsVO.smsCode.mobile = loginData.loginForm.mobileNumber
await sendSmsCodeApi(smsVO.smsCode).then(async () => { await sendSmsCodeApi(smsVO.smsCode).then(async () => {
// message.success(t('login.SmsSendMsg'))
ElMessage({
type: 'success',
message: t('login.SmsSendMsg')
})
// //
mobileCodeTimer.value = 60 mobileCodeTimer.value = 60
let msgTimer = setInterval(() => { let msgTimer = setInterval(() => {

View File

@ -35,22 +35,21 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { Form } from '@/components/Form'
import { computed, reactive, ref, unref } from 'vue' import { computed, reactive, ref, unref } from 'vue'
import { ElInput, FormRules } from 'element-plus'
import { Form } from '@/components/Form'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { useForm } from '@/hooks/web/useForm' import { useForm } from '@/hooks/web/useForm'
import { ElInput, FormRules } from 'element-plus'
import { useValidator } from '@/hooks/web/useValidator' import { useValidator } from '@/hooks/web/useValidator'
import { useLoginState, LoginStateEnum } from './useLogin' import { useLoginState, LoginStateEnum } from './useLogin'
import LoginFormTitle from './LoginFormTitle.vue' import LoginFormTitle from './LoginFormTitle.vue'
import { FormSchema } from '@/types/form' import { FormSchema } from '@/types/form'
const { t } = useI18n()
const { required } = useValidator()
const { register, elFormRef } = useForm() const { register, elFormRef } = useForm()
const { handleBackLogin, getLoginState } = useLoginState() const { handleBackLogin, getLoginState } = useLoginState()
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER) const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER)
const { t } = useI18n()
const { required } = useValidator()
const schema = reactive<FormSchema[]>([ const schema = reactive<FormSchema[]>([
{ {