parent
d3d97928aa
commit
18d70cfa51
@ -1,38 +0,0 @@
|
||||
import { request } from "@/utils/service"
|
||||
|
||||
export interface ILoginRequestData {
|
||||
/** admin 或 editor */
|
||||
username: "admin" | "editor"
|
||||
/** 密码 */
|
||||
password: string
|
||||
/** 验证码 */
|
||||
code: string
|
||||
}
|
||||
|
||||
type LoginCodeResponseData = IApiResponseData<string>
|
||||
type LoginResponseData = IApiResponseData<{ token: string }>
|
||||
type UserInfoResponseData = IApiResponseData<{ username: string; roles: string[] }>
|
||||
|
||||
/** 获取登录验证码 */
|
||||
export function getLoginCodeApi() {
|
||||
return request<LoginCodeResponseData>({
|
||||
url: "login/code",
|
||||
method: "get"
|
||||
})
|
||||
}
|
||||
|
||||
/** 登录并返回 Token */
|
||||
export function loginApi(data: ILoginRequestData) {
|
||||
return request<LoginResponseData>({
|
||||
url: "users/login",
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
}
|
||||
/** 获取用户详情 */
|
||||
export function getUserInfoApi() {
|
||||
return request<UserInfoResponseData>({
|
||||
url: "users/info",
|
||||
method: "get"
|
||||
})
|
||||
}
|
26
src/api/login/index.ts
Normal file
26
src/api/login/index.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { request } from "@/utils/service"
|
||||
import type * as Login from "./types/login"
|
||||
|
||||
/** 获取登录验证码 */
|
||||
export function getLoginCodeApi() {
|
||||
return request<Login.LoginCodeResponseData>({
|
||||
url: "login/code",
|
||||
method: "get"
|
||||
})
|
||||
}
|
||||
|
||||
/** 登录并返回 Token */
|
||||
export function loginApi(data: Login.ILoginRequestData) {
|
||||
return request<Login.LoginResponseData>({
|
||||
url: "users/login",
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
}
|
||||
/** 获取用户详情 */
|
||||
export function getUserInfoApi() {
|
||||
return request<Login.UserInfoResponseData>({
|
||||
url: "users/info",
|
||||
method: "get"
|
||||
})
|
||||
}
|
14
src/api/login/types/login.ts
Normal file
14
src/api/login/types/login.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export interface ILoginRequestData {
|
||||
/** admin 或 editor */
|
||||
username: "admin" | "editor"
|
||||
/** 密码 */
|
||||
password: string
|
||||
/** 验证码 */
|
||||
code: string
|
||||
}
|
||||
|
||||
export type LoginCodeResponseData = IApiResponseData<string>
|
||||
|
||||
export type LoginResponseData = IApiResponseData<{ token: string }>
|
||||
|
||||
export type UserInfoResponseData = IApiResponseData<{ username: string; roles: string[] }>
|
@ -1,70 +0,0 @@
|
||||
import { request } from "@/utils/service"
|
||||
|
||||
interface ICreateTableRequestData {
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
interface IUpdateTableRequestData {
|
||||
id: string
|
||||
username: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
interface IGetTableRequestData {
|
||||
/** 当前页码 */
|
||||
currentPage: number
|
||||
/** 查询条数 */
|
||||
size: number
|
||||
/** 查询参数 */
|
||||
username?: string
|
||||
phone?: string
|
||||
}
|
||||
|
||||
type GetTableResponseData = IApiResponseData<{
|
||||
list: {
|
||||
createTime: string
|
||||
email: string
|
||||
id: string
|
||||
phone: string
|
||||
roles: string
|
||||
status: boolean
|
||||
username: string
|
||||
}[]
|
||||
total: number
|
||||
}>
|
||||
|
||||
/** 增 */
|
||||
export function createTableDataApi(data: ICreateTableRequestData) {
|
||||
return request({
|
||||
url: "table",
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 删 */
|
||||
export function deleteTableDataApi(id: string) {
|
||||
return request({
|
||||
url: `table/${id}`,
|
||||
method: "delete"
|
||||
})
|
||||
}
|
||||
|
||||
/** 改 */
|
||||
export function updateTableDataApi(data: IUpdateTableRequestData) {
|
||||
return request({
|
||||
url: "table",
|
||||
method: "put",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 查 */
|
||||
export function getTableDataApi(params: IGetTableRequestData) {
|
||||
return request<GetTableResponseData>({
|
||||
url: "table",
|
||||
method: "get",
|
||||
params
|
||||
})
|
||||
}
|
37
src/api/table/index.ts
Normal file
37
src/api/table/index.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { request } from "@/utils/service"
|
||||
import type * as Table from "./types/table"
|
||||
|
||||
/** 增 */
|
||||
export function createTableDataApi(data: Table.ICreateTableRequestData) {
|
||||
return request({
|
||||
url: "table",
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 删 */
|
||||
export function deleteTableDataApi(id: string) {
|
||||
return request({
|
||||
url: `table/${id}`,
|
||||
method: "delete"
|
||||
})
|
||||
}
|
||||
|
||||
/** 改 */
|
||||
export function updateTableDataApi(data: Table.IUpdateTableRequestData) {
|
||||
return request({
|
||||
url: "table",
|
||||
method: "put",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 查 */
|
||||
export function getTableDataApi(params: Table.IGetTableRequestData) {
|
||||
return request<Table.GetTableResponseData>({
|
||||
url: "table",
|
||||
method: "get",
|
||||
params
|
||||
})
|
||||
}
|
33
src/api/table/types/table.ts
Normal file
33
src/api/table/types/table.ts
Normal file
@ -0,0 +1,33 @@
|
||||
export interface ICreateTableRequestData {
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface IUpdateTableRequestData {
|
||||
id: string
|
||||
username: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
export interface IGetTableRequestData {
|
||||
/** 当前页码 */
|
||||
currentPage: number
|
||||
/** 查询条数 */
|
||||
size: number
|
||||
/** 查询参数 */
|
||||
username?: string
|
||||
phone?: string
|
||||
}
|
||||
|
||||
export type GetTableResponseData = IApiResponseData<{
|
||||
list: {
|
||||
createTime: string
|
||||
email: string
|
||||
id: string
|
||||
phone: string
|
||||
roles: string
|
||||
status: boolean
|
||||
username: string
|
||||
}[]
|
||||
total: number
|
||||
}>
|
@ -4,7 +4,8 @@ import { defineStore } from "pinia"
|
||||
import { usePermissionStore } from "./permission"
|
||||
import { getToken, removeToken, setToken } from "@/utils/cache/cookies"
|
||||
import router, { resetRouter } from "@/router"
|
||||
import { type ILoginRequestData, loginApi, getUserInfoApi } from "@/api/login"
|
||||
import { loginApi, getUserInfoApi } from "@/api/login"
|
||||
import { type ILoginRequestData } from "@/api/login/types/login"
|
||||
import { type RouteRecordRaw } from "vue-router"
|
||||
|
||||
export const useUserStore = defineStore("user", () => {
|
||||
|
@ -5,7 +5,8 @@ import { useUserStore } from "@/store/modules/user"
|
||||
import { User, Lock, Key, Picture, Loading } from "@element-plus/icons-vue"
|
||||
import ThemeSwitch from "@/components/ThemeSwitch/index.vue"
|
||||
import { type FormInstance, FormRules } from "element-plus"
|
||||
import { type ILoginRequestData, getLoginCodeApi } from "@/api/login"
|
||||
import { getLoginCodeApi } from "@/api/login"
|
||||
import { type ILoginRequestData } from "@/api/login/types/login"
|
||||
|
||||
const router = useRouter()
|
||||
const loginFormRef = ref<FormInstance | null>(null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user