mirror of
https://github.com/un-pany/v3-admin-vite.git
synced 2025-04-21 11:29:20 +08:00
refactor: 重命名接口使其更加遵循 RESTful 风格
This commit is contained in:
parent
d8d1ad2ab7
commit
879dd6b318
@ -1,37 +0,0 @@
|
||||
import type * as Table from "./type"
|
||||
import { request } from "@/http/axios"
|
||||
|
||||
/** 增 */
|
||||
export function createTableDataApi(data: Table.CreateOrUpdateTableRequestData) {
|
||||
return request({
|
||||
url: "table",
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 删 */
|
||||
export function deleteTableDataApi(id: number) {
|
||||
return request({
|
||||
url: `table/${id}`,
|
||||
method: "delete"
|
||||
})
|
||||
}
|
||||
|
||||
/** 改 */
|
||||
export function updateTableDataApi(data: Table.CreateOrUpdateTableRequestData) {
|
||||
return request({
|
||||
url: "table",
|
||||
method: "put",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 查 */
|
||||
export function getTableDataApi(params: Table.TableRequestData) {
|
||||
return request<Table.TableResponseData>({
|
||||
url: "table",
|
||||
method: "get",
|
||||
params
|
||||
})
|
||||
}
|
37
src/common/apis/tables/index.ts
Normal file
37
src/common/apis/tables/index.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import type * as Tables from "./type"
|
||||
import { request } from "@/http/axios"
|
||||
|
||||
/** 增 */
|
||||
export function createTableDataApi(data: Tables.CreateOrUpdateTableRequestData) {
|
||||
return request({
|
||||
url: "tables",
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 删 */
|
||||
export function deleteTableDataApi(id: number) {
|
||||
return request({
|
||||
url: `tables/${id}`,
|
||||
method: "delete"
|
||||
})
|
||||
}
|
||||
|
||||
/** 改 */
|
||||
export function updateTableDataApi(data: Tables.CreateOrUpdateTableRequestData) {
|
||||
return request({
|
||||
url: "tables",
|
||||
method: "put",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 查 */
|
||||
export function getTableDataApi(params: Tables.TableRequestData) {
|
||||
return request<Tables.TableResponseData>({
|
||||
url: "tables",
|
||||
method: "get",
|
||||
params
|
||||
})
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
import type * as Login from "./type"
|
||||
import { request } from "@/http/axios"
|
||||
|
||||
/** 获取当前登录用户详情 */
|
||||
export function getUserInfoApi() {
|
||||
return request<Login.UserInfoResponseData>({
|
||||
url: "users/info",
|
||||
method: "get"
|
||||
})
|
||||
}
|
@ -1 +0,0 @@
|
||||
export type UserInfoResponseData = ApiResponseData<{ username: string, roles: string[] }>
|
10
src/common/apis/users/index.ts
Normal file
10
src/common/apis/users/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import type * as Users from "./type"
|
||||
import { request } from "@/http/axios"
|
||||
|
||||
/** 获取当前登录用户详情 */
|
||||
export function getCurrentUserApi() {
|
||||
return request<Users.CurrentUserResponseData>({
|
||||
url: "users/me",
|
||||
method: "get"
|
||||
})
|
||||
}
|
1
src/common/apis/users/type.ts
Normal file
1
src/common/apis/users/type.ts
Normal file
@ -0,0 +1 @@
|
||||
export type CurrentUserResponseData = ApiResponseData<{ username: string, roles: string[] }>
|
@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CreateOrUpdateTableRequestData, TableData } from "@@/apis/table/type"
|
||||
import type { CreateOrUpdateTableRequestData, TableData } from "@@/apis/tables/type"
|
||||
import type { FormInstance, FormRules } from "element-plus"
|
||||
import { createTableDataApi, deleteTableDataApi, getTableDataApi, updateTableDataApi } from "@@/apis/table"
|
||||
import { createTableDataApi, deleteTableDataApi, getTableDataApi, updateTableDataApi } from "@@/apis/tables"
|
||||
import { usePagination } from "@@/composables/usePagination"
|
||||
import { CirclePlus, Delete, Download, Refresh, RefreshRight, Search } from "@element-plus/icons-vue"
|
||||
import { cloneDeep } from "lodash-es"
|
||||
|
@ -1,8 +1,8 @@
|
||||
<script lang="ts" setup>
|
||||
import type { TableResponseData } from "@@/apis/table/type"
|
||||
import type { TableResponseData } from "@@/apis/tables/type"
|
||||
import type { ElMessageBoxOptions } from "element-plus"
|
||||
import type { VxeFormInstance, VxeFormProps, VxeGridInstance, VxeGridProps, VxeModalInstance, VxeModalProps } from "vxe-table"
|
||||
import { deleteTableDataApi, getTableDataApi } from "@@/apis/table"
|
||||
import { deleteTableDataApi, getTableDataApi } from "@@/apis/tables"
|
||||
import { RoleColumnSlots } from "./tsx/RoleColumnSlots"
|
||||
import { StatusColumnSlots } from "./tsx/StatusColumnSlots"
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
import type * as Login from "./type"
|
||||
import type * as Auth from "./type"
|
||||
import { request } from "@/http/axios"
|
||||
|
||||
/** 获取登录验证码 */
|
||||
export function getLoginCodeApi() {
|
||||
return request<Login.LoginCodeResponseData>({
|
||||
url: "login/code",
|
||||
export function getCaptchaApi() {
|
||||
return request<Auth.CaptchaResponseData>({
|
||||
url: "auth/captcha",
|
||||
method: "get"
|
||||
})
|
||||
}
|
||||
|
||||
/** 登录并返回 Token */
|
||||
export function loginApi(data: Login.LoginRequestData) {
|
||||
return request<Login.LoginResponseData>({
|
||||
url: "users/login",
|
||||
export function loginApi(data: Auth.LoginRequestData) {
|
||||
return request<Auth.LoginResponseData>({
|
||||
url: "auth/login",
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
|
@ -7,6 +7,6 @@ export interface LoginRequestData {
|
||||
code: string
|
||||
}
|
||||
|
||||
export type LoginCodeResponseData = ApiResponseData<string>
|
||||
export type CaptchaResponseData = ApiResponseData<string>
|
||||
|
||||
export type LoginResponseData = ApiResponseData<{ token: string }>
|
||||
|
@ -5,7 +5,7 @@ import { useSettingsStore } from "@/pinia/stores/settings"
|
||||
import { useUserStore } from "@/pinia/stores/user"
|
||||
import ThemeSwitch from "@@/components/ThemeSwitch/index.vue"
|
||||
import { Key, Loading, Lock, Picture, User } from "@element-plus/icons-vue"
|
||||
import { getLoginCodeApi, loginApi } from "./apis"
|
||||
import { getCaptchaApi, loginApi } from "./apis"
|
||||
import Owl from "./components/Owl.vue"
|
||||
import { useFocus } from "./composables/useFocus"
|
||||
|
||||
@ -74,7 +74,7 @@ function createCode() {
|
||||
// 清空验证图片
|
||||
codeUrl.value = ""
|
||||
// 获取验证码图片
|
||||
getLoginCodeApi().then((res) => {
|
||||
getCaptchaApi().then((res) => {
|
||||
codeUrl.value = res.data
|
||||
})
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { pinia } from "@/pinia"
|
||||
import { resetRouter } from "@/router"
|
||||
import { routerConfig } from "@/router/config"
|
||||
import { getUserInfoApi } from "@@/apis/user"
|
||||
import { getCurrentUserApi } from "@@/apis/users"
|
||||
import { setToken as _setToken, getToken, removeToken } from "@@/utils/cache/cookies"
|
||||
import { useSettingsStore } from "./settings"
|
||||
import { useTagsViewStore } from "./tags-view"
|
||||
@ -22,7 +22,7 @@ export const useUserStore = defineStore("user", () => {
|
||||
|
||||
// 获取用户详情
|
||||
const getInfo = async () => {
|
||||
const { data } = await getUserInfoApi()
|
||||
const { data } = await getCurrentUserApi()
|
||||
username.value = data.username
|
||||
// 验证返回的 roles 是否为一个非空数组,否则塞入一个没有任何作用的默认角色,防止路由守卫逻辑进入无限循环
|
||||
roles.value = data.roles?.length > 0 ? data.roles : routerConfig.defaultRoles
|
||||
|
Loading…
x
Reference in New Issue
Block a user