mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2025-04-25 16:07:19 +08:00
refactor: 使用父子组件传值来控制登录页
This commit is contained in:
parent
af481d72b9
commit
6130cd3149
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,7 +5,6 @@ dist-ssr
|
|||||||
*.local
|
*.local
|
||||||
.eslintcache
|
.eslintcache
|
||||||
report.html
|
report.html
|
||||||
.idea
|
|
||||||
|
|
||||||
yarn.lock
|
yarn.lock
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
@ -38,5 +38,4 @@ export type setType = {
|
|||||||
export type userType = {
|
export type userType = {
|
||||||
username?: string;
|
username?: string;
|
||||||
roles?: Array<string>;
|
roles?: Array<string>;
|
||||||
currentPage?: number;
|
|
||||||
};
|
};
|
||||||
|
@ -16,9 +16,7 @@ export const useUserStore = defineStore({
|
|||||||
username:
|
username:
|
||||||
storageSession().getItem<DataInfo<number>>(sessionKey)?.username ?? "",
|
storageSession().getItem<DataInfo<number>>(sessionKey)?.username ?? "",
|
||||||
// 页面级别权限
|
// 页面级别权限
|
||||||
roles: storageSession().getItem<DataInfo<number>>(sessionKey)?.roles ?? [],
|
roles: storageSession().getItem<DataInfo<number>>(sessionKey)?.roles ?? []
|
||||||
// 判断登录页面显示哪个组件(0:登录(默认)、1:手机登录、2:二维码登录、3:注册、4:忘记密码)
|
|
||||||
currentPage: 0
|
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
/** 存储用户名 */
|
/** 存储用户名 */
|
||||||
@ -29,10 +27,6 @@ export const useUserStore = defineStore({
|
|||||||
SET_ROLES(roles: Array<string>) {
|
SET_ROLES(roles: Array<string>) {
|
||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
},
|
},
|
||||||
/** 存储登录页面显示哪个组件 */
|
|
||||||
SET_CURRENTPAGE(value: number) {
|
|
||||||
this.currentPage = value;
|
|
||||||
},
|
|
||||||
/** 登入 */
|
/** 登入 */
|
||||||
async loginByUsername(data) {
|
async loginByUsername(data) {
|
||||||
return new Promise<UserResult>((resolve, reject) => {
|
return new Promise<UserResult>((resolve, reject) => {
|
||||||
|
@ -5,10 +5,18 @@ import { message } from "@/utils/message";
|
|||||||
import { phoneRules } from "../utils/rule";
|
import { phoneRules } from "../utils/rule";
|
||||||
import type { FormInstance } from "element-plus";
|
import type { FormInstance } from "element-plus";
|
||||||
import { useVerifyCode } from "../utils/verifyCode";
|
import { useVerifyCode } from "../utils/verifyCode";
|
||||||
import { useUserStoreHook } from "@/store/modules/user";
|
|
||||||
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
||||||
import Iphone from "@iconify-icons/ep/iphone";
|
import Iphone from "@iconify-icons/ep/iphone";
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
currentPage: {
|
||||||
|
type: Number,
|
||||||
|
default: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const $pageEmit = defineEmits(["update:currentPage"]);
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const ruleForm = reactive({
|
const ruleForm = reactive({
|
||||||
phone: "",
|
phone: "",
|
||||||
@ -36,7 +44,7 @@ const onLogin = async (formEl: FormInstance | undefined) => {
|
|||||||
|
|
||||||
function onBack() {
|
function onBack() {
|
||||||
useVerifyCode().end();
|
useVerifyCode().end();
|
||||||
useUserStoreHook().SET_CURRENTPAGE(0);
|
$pageEmit("update:currentPage", 0);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Motion from "../utils/motion";
|
import Motion from "../utils/motion";
|
||||||
import ReQrcode from "@/components/ReQrcode";
|
import ReQrcode from "@/components/ReQrcode";
|
||||||
import { useUserStoreHook } from "@/store/modules/user";
|
|
||||||
|
defineProps({
|
||||||
|
currentPage: {
|
||||||
|
type: Number,
|
||||||
|
default: 2
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const $pageEmit = defineEmits(["update:currentPage"]);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -12,10 +20,7 @@ import { useUserStoreHook } from "@/store/modules/user";
|
|||||||
</el-divider>
|
</el-divider>
|
||||||
</Motion>
|
</Motion>
|
||||||
<Motion :delay="150">
|
<Motion :delay="150">
|
||||||
<el-button
|
<el-button class="w-full mt-4" @click="$pageEmit('update:currentPage', 0)">
|
||||||
class="w-full mt-4"
|
|
||||||
@click="useUserStoreHook().SET_CURRENTPAGE(0)"
|
|
||||||
>
|
|
||||||
{{ "返回" }}
|
{{ "返回" }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</Motion>
|
</Motion>
|
||||||
|
@ -5,12 +5,20 @@ import { message } from "@/utils/message";
|
|||||||
import { updateRules } from "../utils/rule";
|
import { updateRules } from "../utils/rule";
|
||||||
import type { FormInstance } from "element-plus";
|
import type { FormInstance } from "element-plus";
|
||||||
import { useVerifyCode } from "../utils/verifyCode";
|
import { useVerifyCode } from "../utils/verifyCode";
|
||||||
import { useUserStoreHook } from "@/store/modules/user";
|
|
||||||
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
||||||
import Lock from "@iconify-icons/ri/lock-fill";
|
import Lock from "@iconify-icons/ri/lock-fill";
|
||||||
import Iphone from "@iconify-icons/ep/iphone";
|
import Iphone from "@iconify-icons/ep/iphone";
|
||||||
import User from "@iconify-icons/ri/user-3-fill";
|
import User from "@iconify-icons/ri/user-3-fill";
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
currentPage: {
|
||||||
|
type: Number,
|
||||||
|
default: 3
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const $pageEmit = defineEmits(["update:currentPage"]);
|
||||||
|
|
||||||
const checked = ref(false);
|
const checked = ref(false);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const ruleForm = reactive({
|
const ruleForm = reactive({
|
||||||
@ -63,7 +71,7 @@ const onUpdate = async (formEl: FormInstance | undefined) => {
|
|||||||
|
|
||||||
function onBack() {
|
function onBack() {
|
||||||
useVerifyCode().end();
|
useVerifyCode().end();
|
||||||
useUserStoreHook().SET_CURRENTPAGE(0);
|
$pageEmit("update:currentPage", 0);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -5,11 +5,19 @@ import { message } from "@/utils/message";
|
|||||||
import { updateRules } from "../utils/rule";
|
import { updateRules } from "../utils/rule";
|
||||||
import type { FormInstance } from "element-plus";
|
import type { FormInstance } from "element-plus";
|
||||||
import { useVerifyCode } from "../utils/verifyCode";
|
import { useVerifyCode } from "../utils/verifyCode";
|
||||||
import { useUserStoreHook } from "@/store/modules/user";
|
|
||||||
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
||||||
import Lock from "@iconify-icons/ri/lock-fill";
|
import Lock from "@iconify-icons/ri/lock-fill";
|
||||||
import Iphone from "@iconify-icons/ep/iphone";
|
import Iphone from "@iconify-icons/ep/iphone";
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
currentPage: {
|
||||||
|
type: Number,
|
||||||
|
default: 4
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const $pageEmit = defineEmits(["update:currentPage"]);
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const ruleForm = reactive({
|
const ruleForm = reactive({
|
||||||
phone: "",
|
phone: "",
|
||||||
@ -55,7 +63,7 @@ const onUpdate = async (formEl: FormInstance | undefined) => {
|
|||||||
|
|
||||||
function onBack() {
|
function onBack() {
|
||||||
useVerifyCode().end();
|
useVerifyCode().end();
|
||||||
useUserStoreHook().SET_CURRENTPAGE(0);
|
$pageEmit("update:currentPage", 0);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -1,12 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import { ref, toRaw, reactive, onMounted, onBeforeUnmount } from "vue";
|
||||||
ref,
|
|
||||||
toRaw,
|
|
||||||
reactive,
|
|
||||||
computed,
|
|
||||||
onMounted,
|
|
||||||
onBeforeUnmount
|
|
||||||
} from "vue";
|
|
||||||
import Motion from "./utils/motion";
|
import Motion from "./utils/motion";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
import { message } from "@/utils/message";
|
import { message } from "@/utils/message";
|
||||||
@ -14,8 +7,8 @@ import { loginRules } from "./utils/rule";
|
|||||||
import phone from "./components/phone.vue";
|
import phone from "./components/phone.vue";
|
||||||
import TypeIt from "@/components/ReTypeit";
|
import TypeIt from "@/components/ReTypeit";
|
||||||
import qrCode from "./components/qrCode.vue";
|
import qrCode from "./components/qrCode.vue";
|
||||||
import regist from "./components/regist.vue";
|
import register from "./components/register.vue";
|
||||||
import update from "./components/update.vue";
|
import resetPassword from "./components/resetPassword.vue";
|
||||||
import { useNav } from "@/layout/hooks/useNav";
|
import { useNav } from "@/layout/hooks/useNav";
|
||||||
import type { FormInstance } from "element-plus";
|
import type { FormInstance } from "element-plus";
|
||||||
import { operates, thirdParty } from "./utils/enums";
|
import { operates, thirdParty } from "./utils/enums";
|
||||||
@ -41,9 +34,8 @@ const router = useRouter();
|
|||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const checked = ref(false);
|
const checked = ref(false);
|
||||||
const ruleFormRef = ref<FormInstance>();
|
const ruleFormRef = ref<FormInstance>();
|
||||||
const currentPage = computed(() => {
|
// 判断登录页面显示哪个组件(0:登录(默认)、1:手机登录、2:二维码登录、3:注册、4:忘记密码)
|
||||||
return useUserStoreHook().currentPage;
|
const currentPage = ref(0);
|
||||||
});
|
|
||||||
|
|
||||||
const { initStorage } = useLayout();
|
const { initStorage } = useLayout();
|
||||||
initStorage();
|
initStorage();
|
||||||
@ -189,11 +181,7 @@ onBeforeUnmount(() => {
|
|||||||
<el-checkbox v-model="checked">
|
<el-checkbox v-model="checked">
|
||||||
{{ "记住密码" }}
|
{{ "记住密码" }}
|
||||||
</el-checkbox>
|
</el-checkbox>
|
||||||
<el-button
|
<el-button link type="primary" @click="currentPage = 4">
|
||||||
link
|
|
||||||
type="primary"
|
|
||||||
@click="useUserStoreHook().SET_CURRENTPAGE(4)"
|
|
||||||
>
|
|
||||||
{{ "忘记密码" }}
|
{{ "忘记密码" }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
@ -217,7 +205,7 @@ onBeforeUnmount(() => {
|
|||||||
:key="index"
|
:key="index"
|
||||||
class="w-full mt-4"
|
class="w-full mt-4"
|
||||||
size="default"
|
size="default"
|
||||||
@click="useUserStoreHook().SET_CURRENTPAGE(index + 1)"
|
@click="currentPage = item.page"
|
||||||
>
|
>
|
||||||
{{ item.title }}
|
{{ item.title }}
|
||||||
</el-button>
|
</el-button>
|
||||||
@ -247,13 +235,19 @@ onBeforeUnmount(() => {
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</Motion>
|
</Motion>
|
||||||
<!-- 手机号登录 -->
|
<!-- 手机号登录 -->
|
||||||
<phone v-if="currentPage === 1" />
|
<phone v-if="currentPage === 1" v-model:current-page="currentPage" />
|
||||||
<!-- 二维码登录 -->
|
<!-- 二维码登录 -->
|
||||||
<qrCode v-if="currentPage === 2" />
|
<qrCode v-if="currentPage === 2" v-model:current-page="currentPage" />
|
||||||
<!-- 注册 -->
|
<!-- 注册 -->
|
||||||
<regist v-if="currentPage === 3" />
|
<register
|
||||||
|
v-if="currentPage === 3"
|
||||||
|
v-model:current-page="currentPage"
|
||||||
|
/>
|
||||||
<!-- 忘记密码 -->
|
<!-- 忘记密码 -->
|
||||||
<update v-if="currentPage === 4" />
|
<resetPassword
|
||||||
|
v-if="currentPage === 4"
|
||||||
|
v-model:current-page="currentPage"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
const operates = [
|
const operates = [
|
||||||
{
|
{
|
||||||
title: "手机登录"
|
title: "手机登录",
|
||||||
|
page: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "二维码登录"
|
title: "二维码登录",
|
||||||
|
page: 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "注册"
|
title: "注册",
|
||||||
|
page: 3
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user