feat:登录接入验证码功能
This commit is contained in:
@@ -63,3 +63,13 @@ export function getCodePhone(data) {
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录验证码
|
||||
*/
|
||||
export function getLoginCode() {
|
||||
return request({
|
||||
url: `/account/captcha-image`,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ const useUserStore = defineStore("user", {
|
||||
icon: null,
|
||||
roles: [],
|
||||
permissions: [],
|
||||
hasPermissions: false,
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
@@ -42,16 +43,22 @@ const useUserStore = defineStore("user", {
|
||||
getUserDetailInfo()
|
||||
.then((response) => {
|
||||
const res = response.data;
|
||||
|
||||
const user = res.user;
|
||||
const avatar =
|
||||
user.icon == "" || user.icon == null
|
||||
? "/favicon.ico"
|
||||
: import.meta.env.VITE_APP_BASEAPI + "/file/" + user.icon;
|
||||
const all_permission = "*:*:*";
|
||||
if (res.roleCodes && res.roleCodes.length > 0) {
|
||||
// 验证返回的roles是否是一个非空数组
|
||||
this.roles = res.roleCodes;
|
||||
this.permissions = res.permissionCodes;
|
||||
this.hasPermissions = res.permissionCodes.some((permission) => {
|
||||
return (
|
||||
all_permission === permission ||
|
||||
permissionFlag.includes(permission)
|
||||
);
|
||||
});
|
||||
// this.roles = ["admin"];
|
||||
// this.permissions=["*:*:*"]
|
||||
} else {
|
||||
|
||||
@@ -20,10 +20,7 @@
|
||||
"
|
||||
>查询</el-button
|
||||
>
|
||||
<el-button
|
||||
@click="enterEditArticle"
|
||||
type="primary"
|
||||
v-hasPer="['bbs:discuss:add']"
|
||||
<el-button @click="enterEditArticle" type="primary"
|
||||
>发布主题</el-button
|
||||
>
|
||||
<el-dropdown>
|
||||
|
||||
@@ -40,6 +40,25 @@
|
||||
show-password
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="验证码" class="title-item"></el-form-item>
|
||||
<div class="flex-between">
|
||||
<el-col :span="18">
|
||||
<el-form-item prop="phone">
|
||||
<el-input
|
||||
size="large"
|
||||
type="text"
|
||||
v-model.trim="loginForm.code"
|
||||
placeholder="请输入验证码"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-image
|
||||
@click="handleGetCode"
|
||||
style="width: 120px; height: 40px; cursor: pointer"
|
||||
:src="codeImageURL"
|
||||
:fit="fit"
|
||||
/>
|
||||
</div>
|
||||
</el-form>
|
||||
<el-form
|
||||
class="registerForm"
|
||||
@@ -136,10 +155,11 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, reactive } from "vue";
|
||||
import { ref, reactive, onMounted } from "vue";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import useAuths from "@/hooks/useAuths";
|
||||
import { getCodePhone } from "@/apis/accountApi";
|
||||
import { getLoginCode } from "@/apis/auth";
|
||||
|
||||
const { loginFun, registerFun } = useAuths();
|
||||
const router = useRouter();
|
||||
@@ -175,6 +195,11 @@ const login = async (formEl) => {
|
||||
}
|
||||
});
|
||||
};
|
||||
// 获取图片验证码
|
||||
const codeImageURL = ref("");
|
||||
const handleGetCode = () => {
|
||||
getImageCode();
|
||||
};
|
||||
|
||||
// 注册逻辑
|
||||
const isRegister = ref(true);
|
||||
@@ -238,6 +263,15 @@ const captcha = async () => {
|
||||
const handleSignInNow = () => {
|
||||
isRegister.value = !isRegister.value;
|
||||
};
|
||||
|
||||
const getImageCode = async () => {
|
||||
const { data } = await getLoginCode();
|
||||
codeImageURL.value = "data:image/jpg;base64," + data.img;
|
||||
loginForm.uuid = data.uuid;
|
||||
};
|
||||
onMounted(async () => {
|
||||
await getImageCode();
|
||||
});
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.login {
|
||||
|
||||
Reference in New Issue
Block a user