From dd8637e66b559ab4fc993fe87c11680dac8e49b4 Mon Sep 17 00:00:00 2001 From: dark Date: Wed, 17 Apr 2024 00:33:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9C=E7=A8=8B=E8=B0=83?= =?UTF-8?q?=E7=94=A8api=EF=BC=8C=E5=AE=8C=E5=96=84service=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/request.ts | 6 +++-- src/service/base.ts | 31 +++++++++++++++++++++++++ src/service/system.ts | 25 ++++++++------------- src/store/department.ts | 2 +- src/store/system.ts | 10 ++++----- src/store/types/department.d.ts | 9 -------- src/types/department.d.ts | 15 +++++++++++++ src/types/login.d.ts | 23 +++++++++++++++++++ src/types/menus.d.ts | 50 +++++++++++++++++++++++++++++++++++++++++ src/types/roles.d.ts | 30 +++++++++++++++++++++++++ src/types/user.d.ts | 25 +++++++++++++++++++++ vite.config.ts | 9 ++++++++ 12 files changed, 202 insertions(+), 33 deletions(-) create mode 100644 src/service/base.ts delete mode 100644 src/store/types/department.d.ts create mode 100644 src/types/department.d.ts create mode 100644 src/types/login.d.ts create mode 100644 src/types/menus.d.ts create mode 100644 src/types/roles.d.ts create mode 100644 src/types/user.d.ts diff --git a/src/request.ts b/src/request.ts index 9be7058..d7486c2 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,7 +1,9 @@ -import axios from 'axios' +import axios, { AxiosRequestConfig } from 'axios' + +export type { AxiosRequestConfig } export const request = axios.create({ - baseURL: '/api', + baseURL: '/api/v1', timeout: 1000, headers: { 'Content-Type': 'application/json', diff --git a/src/service/base.ts b/src/service/base.ts new file mode 100644 index 0000000..af3224f --- /dev/null +++ b/src/service/base.ts @@ -0,0 +1,31 @@ +import { request, AxiosRequestConfig } from '@/request.ts' + +type TPage = { + page: number + pageSize: number +} + +export const createCURD = (api: string, options?: AxiosRequestConfig) => { + + return { + list: (params?: TParams & TPage) => { + return request.get(api, { ...options, params }) + }, + add: (data: TParams) => { + return request.post(`${api}/add`, data, options) + }, + update: (id: number, data: TParams) => { + return request.put(`${api}/${id}`, data, options) + }, + delete: (id: number) => { + return request.delete(`${api}/delete`, { ...options, params: { id } }) + }, + batchDelete: (ids: number[]) => { + return request.delete(`${api}/deletes`, { ...options, params: { ids } }) + }, + info: (id: number) => { + return request.get(`${api}/${id}`, options) + } + } + +} \ No newline at end of file diff --git a/src/service/system.ts b/src/service/system.ts index 3370d41..ac45752 100644 --- a/src/service/system.ts +++ b/src/service/system.ts @@ -1,23 +1,16 @@ import request from '../request.ts' +import { LoginRequest, LoginResponse } from '@/types/login' +import { createCURD } from '@/service/base.ts' const systemServ = { - + dept: { + ...createCURD('/sys/dept') + }, menus: { - list: () => { - return request.get('/menus') - }, - add: (data: any) => { - return request.post('/menus', data) - }, - update: (id: number| string, data: any) => { - return request.put(`/menus/${id}`, data) - }, - delete: (id: number| string) => { - return request.delete(`/menus/${id}`) - }, - info: (id: number| string) => { - return request.get(`/menus/${id}`) - } + ...createCURD('/sys/menu') + }, + login: (data: LoginRequest) => { + return request.post('/sys/login', data) } } diff --git a/src/store/department.ts b/src/store/department.ts index 9664def..51f9ccb 100644 --- a/src/store/department.ts +++ b/src/store/department.ts @@ -1,5 +1,5 @@ import { atom } from 'jotai' -import { IDepartment } from './types/department' +import { IDepartment } from '../types/department' import { QueryClient } from '@tanstack/query-core' import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query' import { IApiResult } from '../types' diff --git a/src/store/system.ts b/src/store/system.ts index 737f0ce..41adbb6 100644 --- a/src/store/system.ts +++ b/src/store/system.ts @@ -1,7 +1,7 @@ import { atomWithQuery } from 'jotai-tanstack-query' import systemServ from '../service/system.ts' -import { MenuItem } from '../types' -import { getIcon } from '../components/icon' +import { MenuItem } from '@/types' +import { getIcon } from '@/components/icon' import { atom } from 'jotai/index' // 格式化菜单数据, 把children转换成routes @@ -34,13 +34,13 @@ export const menuDataAtom = atomWithQuery(() => ({ select: data => formatMenuData(data.data ?? []), })) -export const selectedMenuIdAtom = atom(0) -export const selectedMenuAtom = atom({}) +export const selectedMenuIdAtom = atom(0) +export const selectedMenuAtom = atom(undefined) export const byIdMenuAtom = atomWithQuery((get) => ({ queryKey: [ 'selectedMenu', get(selectedMenuIdAtom) ], queryFn: async ({ queryKey: [ , id ] }) => { - return await systemServ.menus.info(id) + return await systemServ.menus.info(id as number) }, select: data => data.data, })) diff --git a/src/store/types/department.d.ts b/src/store/types/department.d.ts deleted file mode 100644 index 91fa0ac..0000000 --- a/src/store/types/department.d.ts +++ /dev/null @@ -1,9 +0,0 @@ - -export interface IDepartment { - id: string - name: string - parentId: number - order: number - createAt: string - updateAt: string -} diff --git a/src/types/department.d.ts b/src/types/department.d.ts new file mode 100644 index 0000000..96fdf33 --- /dev/null +++ b/src/types/department.d.ts @@ -0,0 +1,15 @@ + +export interface IDepartment { + id: number, + parent_id: number, + manager_user_id: number, + phone: string, + name: string, + sort: number, + status: string, + remark: string +} + +export interface DepartmentRequest extends IDepartment { + +} diff --git a/src/types/login.d.ts b/src/types/login.d.ts new file mode 100644 index 0000000..739ab2f --- /dev/null +++ b/src/types/login.d.ts @@ -0,0 +1,23 @@ + +export interface LoginLogRequest { + key: string, + start: string, + end: string, + order: string, + prop: string, + page: number, + pageSize: number +} + +export interface LoginRequest { + 'mfa_status': boolean; + 'username': string; + 'password': string; + 'code': string; +} + +export interface LoginResponse { + 'token': string; + 'mfa_status': boolean; +} + diff --git a/src/types/menus.d.ts b/src/types/menus.d.ts new file mode 100644 index 0000000..8b88f88 --- /dev/null +++ b/src/types/menus.d.ts @@ -0,0 +1,50 @@ + +export interface MenuButton { + code: string, + label: string +} +export interface IMenu { + parent_id: number, + parent_path: string, + sort: number, + code: string, + name: string, + description: string, + sequence: number, + type: string, + path: string, + properties: string, + status: string + buttons: MenuButton[] +} + +export interface MenuRequest extends IMenu { + +} + +export interface MenuResponse { + id: number, +} + + +export interface MenuDropRequest { + source: number, + target: number, + action: string +} + + +export interface MenuListRequest { + order: string, + prop: string, + page: number, + pageSize: number +} + + +export interface MenuListResponse { + page: number, + pageSize: number, + total: number, + rows: IMenu[] +} \ No newline at end of file diff --git a/src/types/roles.d.ts b/src/types/roles.d.ts new file mode 100644 index 0000000..2f9efc0 --- /dev/null +++ b/src/types/roles.d.ts @@ -0,0 +1,30 @@ + +export interface IRole { + sort: number, + code: string, + name: string, + description: string, + sequence: number, + status: string, + menu_ids: number[] +} + +export interface RoleRequest extends IRole { + +} + +export interface RoleListResponse { + key: string, + order: string, + prop: string, + page: number, + pageSize: number + +} + +export interface RoleListResponse { + page: number, + pageSize: number, + total: number, + rows: IRole[] +} \ No newline at end of file diff --git a/src/types/user.d.ts b/src/types/user.d.ts new file mode 100644 index 0000000..5b4b53d --- /dev/null +++ b/src/types/user.d.ts @@ -0,0 +1,25 @@ + + +export interface IUser { + id: number, + created_at: string, + created_by: number, + updated_at: string, + updated_by: number, + username: string, + dept_id: number, + dept_name: string, + name: string, + phone: string, + email: string, + remark: string, + status: string, + mfa_status: boolean, +} + +export interface IUserInfo { + info: IUser, + buttons: string[], + nickname: string, + avatar: string +} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 5321618..c3e8652 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,6 +12,15 @@ export default defineConfig({ '@': '/src', }, }, + server:{ + proxy:{ + '/api': { + target: 'https://proapi.devwork.top', + changeOrigin: true, + // rewrite: (path) => path.replace(/^\/api/, '') + } + } + }, plugins: [ react(), viteMockServe({