mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
feat: 权限控制
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { request, requestForMock } from "../service";
|
||||
import { env } from "/@/utils/util.env";
|
||||
|
||||
export interface RegisterReq {
|
||||
username: string;
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
/**
|
||||
* @description: Login interface parameters
|
||||
*/
|
||||
@@ -19,6 +25,14 @@ export interface LoginRes {
|
||||
expire: number;
|
||||
}
|
||||
|
||||
export async function register(user: RegisterReq): Promise<UserInfoRes> {
|
||||
return await request({
|
||||
url: "/register",
|
||||
method: "post",
|
||||
data: user
|
||||
});
|
||||
}
|
||||
|
||||
export async function login(data: LoginReq): Promise<LoginRes> {
|
||||
if (env.PM_ENABLED === "false") {
|
||||
//没有开启权限模块,模拟登录
|
||||
|
||||
@@ -31,7 +31,7 @@ function createService() {
|
||||
const { code } = dataAxios;
|
||||
// 根据 code 进行判断
|
||||
if (code === undefined) {
|
||||
// 如果没有 code 代表这不是项目后端开发的接口 比如可能是 D2Admin 请求最新版本
|
||||
// 如果没有 code 代表这不是项目后端开发的接口
|
||||
errorCreate(`非标准返回:${dataAxios}, ${response.config.url}`);
|
||||
return dataAxios;
|
||||
} else {
|
||||
|
||||
@@ -63,5 +63,7 @@ export function errorLog(error: any) {
|
||||
* @param {String} msg 错误信息
|
||||
*/
|
||||
export function errorCreate(msg: string) {
|
||||
throw new Error(msg);
|
||||
const err = new Error(msg);
|
||||
uiContext.get().notification.error({ message: err.message });
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export const frameworkResource = [
|
||||
component: LayoutFramework,
|
||||
meta: {
|
||||
icon: "ion:accessibility",
|
||||
auth: true
|
||||
authOnly: true
|
||||
},
|
||||
children: [
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ export const certdResources = [
|
||||
redirect: "/certd/pipeline",
|
||||
meta: {
|
||||
icon: "ion:key-outline",
|
||||
auth: true
|
||||
authOnly: true
|
||||
},
|
||||
children: [
|
||||
{
|
||||
@@ -43,7 +43,7 @@ export const certdResources = [
|
||||
redirect: "/certd/settings/email",
|
||||
meta: {
|
||||
icon: "ion:settings-outline",
|
||||
auth: true
|
||||
authOnly: true
|
||||
},
|
||||
children: [
|
||||
{
|
||||
@@ -53,7 +53,7 @@ export const certdResources = [
|
||||
component: "/certd/settings/email-setting.vue",
|
||||
meta: {
|
||||
icon: "ion:mail-outline",
|
||||
auth: true
|
||||
authOnly: true
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -15,6 +15,14 @@ export const outsideResource = [
|
||||
name: "login",
|
||||
path: "/login",
|
||||
component: "/framework/login/index.vue"
|
||||
},
|
||||
{
|
||||
meta: {
|
||||
title: "注册"
|
||||
},
|
||||
name: "register",
|
||||
path: "/register",
|
||||
component: "/framework/register/index.vue"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -35,7 +35,7 @@ export const usePageStore = defineStore({
|
||||
fullPath: "/index",
|
||||
meta: {
|
||||
title: "首页",
|
||||
auth: false
|
||||
authOnly: false
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
@@ -7,10 +7,11 @@ import { LocalStorage } from "/src/utils/util.storage";
|
||||
import * as UserApi from "/src/api/modules/api.user";
|
||||
// @ts-ignore
|
||||
import { LoginReq, UserInfoRes } from "/@/api/modules/api.user";
|
||||
import { Modal } from "ant-design-vue";
|
||||
import { Modal, notification } from "ant-design-vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
import { mitter } from "/src/utils/util.mitt";
|
||||
import { RegisterReq } from "/src/api/modules/api.user";
|
||||
|
||||
interface UserState {
|
||||
userInfo: Nullable<UserInfoRes>;
|
||||
@@ -50,6 +51,14 @@ export const useUserStore = defineStore({
|
||||
LocalStorage.remove(TOKEN_KEY);
|
||||
LocalStorage.remove(USER_INFO_KEY);
|
||||
},
|
||||
|
||||
async register(user: RegisterReq) {
|
||||
await UserApi.register(user);
|
||||
notification.success({
|
||||
message: "注册成功,请登录"
|
||||
});
|
||||
await router.replace("/login");
|
||||
},
|
||||
/**
|
||||
* @description: login
|
||||
*/
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item class="user-login-other">
|
||||
<!-- <router-link class="register" :to="{ name: 'index' }"> 注册 </router-link>-->
|
||||
<router-link class="register" :to="{ name: 'register' }"> 注册 </router-link>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
<template>
|
||||
<div class="main">
|
||||
<a-form
|
||||
ref="formRef"
|
||||
class="user-layout-login"
|
||||
name="custom-validation"
|
||||
:model="formState"
|
||||
:rules="rules"
|
||||
v-bind="layout"
|
||||
@finish="handleFinish"
|
||||
@finishFailed="handleFinishFailed"
|
||||
>
|
||||
<a-form ref="formRef" class="user-layout-register" name="custom-validation" :model="formState" :rules="rules" v-bind="layout" @finish="handleFinish" @finishFailed="handleFinishFailed">
|
||||
<div class="login-title">用户注册</div>
|
||||
|
||||
<a-form-item required has-feedback name="username">
|
||||
<a-input v-model:value="formState.username" size="large" autocomplete="off">
|
||||
<template #prefix>
|
||||
@@ -46,13 +39,14 @@
|
||||
import { defineComponent, reactive, ref, toRaw } from "vue";
|
||||
import { useUserStore } from "/src/store/modules/user";
|
||||
export default defineComponent({
|
||||
name: "Register",
|
||||
name: "RegisterPage",
|
||||
setup() {
|
||||
const userStore = useUserStore();
|
||||
const formRef = ref();
|
||||
const formState = reactive({
|
||||
username: "",
|
||||
password: ""
|
||||
password: "",
|
||||
confirmPassword: ""
|
||||
});
|
||||
|
||||
const rules = {
|
||||
@@ -88,8 +82,7 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
console.log(values, formState);
|
||||
const userInfo = await userStore.login(
|
||||
await userStore.register(
|
||||
toRaw({
|
||||
password: formState.password,
|
||||
username: formState.username
|
||||
@@ -120,16 +113,17 @@ export default defineComponent({
|
||||
|
||||
<style lang="less">
|
||||
@import "../../../style/theme/index.less";
|
||||
.user-layout-login {
|
||||
.user-layout-register {
|
||||
label {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.login-title {
|
||||
color: @primary-color;
|
||||
// color: @primary-color;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
margin: 20px;
|
||||
margin: 30px;
|
||||
margin-top: 50px;
|
||||
}
|
||||
.getCaptcha {
|
||||
display: block;
|
||||
|
||||
Reference in New Issue
Block a user