123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <template>
- <div class="view-account">
- <div class="view-account-container">
- <div class="stylesWrap">
- <img :src="loginStyles" alt="" />
- </div>
- <div class="view-account-form">
- <div class="view-account-form-wrap">
- <div class="formTitle">
- <div class="dot"></div>
- 内容管理平台登录
- </div>
- <n-form
- ref="formRef"
- label-placement="left"
- size="large"
- :model="formInline"
- :rules="rules"
- >
- <n-form-item path="username">
- <n-input v-model:value="formInline.username" placeholder="请输入用户名">
- <template #prefix>
- <img :src="useIcon" class="prefixIcon" alt="" />
- </template>
- </n-input>
- </n-form-item>
- <n-form-item path="password">
- <n-input
- v-model:value="formInline.password"
- type="text"
- showPasswordOn="click"
- placeholder="请输入密码"
- autocomplete="off"
- :class="[showPwd ? '' : 'no-pwd']"
- :loading="loading"
- @keydown.enter="
- (event:any) => {
- event.target.blur();
- handleSubmit(event);
- }
- "
- >
- <template #prefix>
- <img :src="lockIcon" class="prefixIcon" alt="" />
- </template>
- <template #suffix>
- <img
- :src="showPwd ? closeEye : openEye"
- class="pwdIcon"
- alt=""
- @click="
- () => {
- showPwd = !showPwd
- }
- "
- />
- </template>
- </n-input>
- </n-form-item>
- <n-form-item class="default-color">
- <div class="flex justify-between">
- <div class="flex-initial">
- <n-checkbox v-model:checked="autoLogin">记住密码</n-checkbox>
- </div>
- <!-- <div class="flex-initial order-last">
- <a href="javascript:">忘记密码</a>
- </div> -->
- </div>
- </n-form-item>
- <n-form-item>
- <n-button
- class="submitBtm"
- type="primary"
- @click="handleSubmit"
- size="large"
- :loading="loading"
- block
- >
- 登录
- </n-button>
- </n-form-item>
- </n-form>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import { reactive, ref } from 'vue'
- import { useRoute, useRouter } from 'vue-router'
- import { useUserStore } from '@/store/modules/user'
- import { useMessage } from 'naive-ui'
- import { ResultEnum } from '@/enums/httpEnum'
- import { storage } from '@/utils/storage'
- import { PersonOutline, LockClosedOutline, LogoGithub, LogoFacebook } from '@vicons/ionicons5'
- import { PageEnum } from '@/enums/pageEnum'
- import { websiteConfig } from '@/config/website.config'
- import loginStyles from './images/login_styles.png'
- import loginLogo from './images/login_logo.png'
- import lockIcon from './images/lock-icon.png'
- import useIcon from './images/user-icon.png'
- import openEye from './images/openEye.png'
- import closeEye from './images/closeEye.png'
- import { useTabsViewStore } from '@/store/modules/tabsView'
- import { TABS_ROUTES } from '@/store/mutation-types'
- interface FormState {
- username: string
- password: string
- grant_type: string
- loginType: string
- client_id: string
- client_secret: string
- }
- const formRef = ref()
- const message = useMessage()
- const loading = ref(false)
- const autoLogin = ref(true)
- const LOGIN_NAME = PageEnum.BASE_LOGIN_NAME
- const tabsViewStore = useTabsViewStore()
- const showPwd = ref(false)
- let formInline = reactive({
- username: '',
- password: '',
- isCaptcha: true
- })
- const formInlineHistory = storage.get('userInfo')
- if (formInlineHistory) {
- formInline = reactive({ ...JSON.parse(formInlineHistory) })
- }
- const rules = {
- username: { required: true, message: '请输入用户名', trigger: 'blur' },
- password: { required: true, message: '请输入密码', trigger: 'blur' }
- }
- const userStore = useUserStore()
- const router = useRouter()
- const route = useRoute()
- const handleSubmit = (e: any) => {
- e.preventDefault()
- localStorage.removeItem(TABS_ROUTES)
- formRef.value.validate(async (errors: any) => {
- if (!errors) {
- const { username, password } = formInline
- message.loading('登录中...')
- loading.value = true
- const params: FormState = {
- username,
- password,
- loginType: 'password',
- grant_type: 'password',
- client_id: 'dayaedu-backend',
- client_secret: 'dayaedu-backend'
- }
- try {
- const some = (await userStore.login(params)) as any
- // return;
- message.destroyAll()
- if (some.code == ResultEnum.SUCCESS) {
- // 判断是否勾选自动登录
- if (autoLogin) {
- storage.set('userInfo', JSON.stringify(formInline))
- } else {
- storage.remove('userInfo')
- }
- // route.query?.redirect ||
- tabsViewStore.closeAllTabs()
- const toPath = decodeURIComponent('/' as string)
- message.success('登录成功,即将进入系统')
- console.log(route.name, LOGIN_NAME, toPath)
- if (route.name === LOGIN_NAME) {
- router.replace('/')
- } else router.replace(toPath)
- } else {
- // message.info(some.msg || "登录失败");
- }
- } finally {
- loading.value = false
- }
- } else {
- message.error('请填写完整信息,并且进行验证码校验')
- }
- })
- }
- </script>
- <style lang="less" scoped>
- .no-pwd {
- font-family: 'dotfont';
- ::v-deep .n-input__input-el {
- -webkit-text-security: disc !important;
- -moz-text-security: disc !important;
- }
- }
- .view-account {
- background: url('./images/login_bg.png') no-repeat 100% 100%;
- background-size: 100%;
- display: flex;
- flex-direction: column;
- min-height: 100vh;
- width: 100vw;
- background-color: #e9f7ff;
- overflow: auto;
- &-container {
- margin-top: 10%;
- display: flex;
- flex-direction: row;
- justify-content: center;
- align-items: center;
- .stylesWrap {
- width: 40%;
- margin-right: 190px;
- img {
- width: 100%;
- // height: 100%;
- }
- }
- }
- &-form {
- width: 30%;
- .view-account-form-wrap {
- position: relative;
- padding: 12% 15% 12%;
- background: #ffffff;
- border-radius: 16px;
- .prefixIcon {
- width: 18px;
- height: 18px;
- margin-right: 5px;
- }
- .pwdIcon {
- width: 24px;
- height: 24px;
- cursor: pointer;
- }
- .formTitle {
- display: flex;
- flex-direction: row;
- align-items: center;
- font-size: 32px;
- font-weight: 600;
- color: #333333;
- line-height: 45px;
- margin-bottom: 50px;
- .dot {
- width: 6px;
- height: 21px;
- background: #3594fa;
- border-radius: 3px;
- margin-right: 8px;
- }
- }
- }
- }
- .submitBtm {
- margin-top: 20px;
- background: #3594fa;
- border-radius: 35px;
- font-size: 22px;
- font-family: PingFangSC-Semibold, PingFang SC;
- font-weight: 600;
- color: #ffffff;
- height: 50px;
- line-height: 50px;
- }
- &-top {
- padding: 32px 0;
- text-align: center;
- &-desc {
- font-size: 14px;
- color: #808695;
- }
- }
- &-other {
- width: 100%;
- }
- .default-color {
- color: #515a6e;
- .ant-checkbox-wrapper {
- color: #515a6e;
- }
- }
- }
- // @media (min-width: 768px) {
- // .view-account {
- // // background-image: url("../../assets/images/login.svg");
- // // background-repeat: no-repeat;
- // // background-position: 50%;
- // // background-size: 100%;
- // }
- // .page-account-container {
- // padding: 32px 0 24px 0;
- // }
- // }
- </style>
|