diff --git a/src/api/index.ts b/src/api/index.ts index 407903d..598e5ca 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -3,6 +3,8 @@ // API 更新时间: // API 唯一标识: import * as mainController from './mainController' +import * as userController from './userController' export default { mainController, + userController, } diff --git a/src/api/typings.d.ts b/src/api/typings.d.ts index 839b127..8ae9a37 100644 --- a/src/api/typings.d.ts +++ b/src/api/typings.d.ts @@ -1,7 +1,143 @@ declare namespace API { + type DeleteRequest = { + id?: number + } + + type getUserByIdUsingGETParams = { + /** id */ + id?: number + } + + type getUserVoByIdUsingGETParams = { + /** id */ + id?: number + } + + type LoginUserVO = { + createTime?: string + editTime?: string + id?: number + updateTime?: string + userAccount?: string + userAvatar?: string + userName?: string + userProfile?: string + userRole?: string + } + + type PageUserVO_ = { + current?: number + pages?: number + records?: UserVO[] + size?: number + total?: number + } + + type RBoolean_ = { + code?: number + data?: boolean + msg?: string + } + + type RLoginUserVO_ = { + code?: number + data?: LoginUserVO + msg?: string + } + + type RLong_ = { + code?: number + data?: number + msg?: string + } + type RObject_ = { code?: number data?: Record msg?: string } + + type RPageUserVO_ = { + code?: number + data?: PageUserVO_ + msg?: string + } + + type RUser_ = { + code?: number + data?: User + msg?: string + } + + type RUserVO_ = { + code?: number + data?: UserVO + msg?: string + } + + type User = { + createTime?: string + editTime?: string + id?: number + isDelete?: number + updateTime?: string + userAccount?: string + userAvatar?: string + userName?: string + userPassword?: string + userProfile?: string + userRole?: string + } + + type UserAddRequest = { + userAccount?: string + userAvatar?: string + userName?: string + userProfile?: string + userRole?: string + } + + type UserLoginRequest = { + userAccount?: string + userPassword?: string + } + + type UserQueryRequest = { + current?: number + id?: number + pageSize?: number + sortField?: string + sortOrder?: string + userAccount?: string + userName?: string + userProfile?: string + userRole?: string + } + + type UserRegisterRequest = { + checkPassword?: string + userAccount?: string + userPassword?: string + } + + type UserUpdateRequest = { + id?: number + userAvatar?: string + userName?: string + userProfile?: string + userRole?: string + } + + type UserVO = { + createTime?: string + id?: number + userAccount?: string + userAvatar?: string + userName?: string + userProfile?: string + userRole?: string + vipCode?: string + vipExpireTime?: string + vipNumber?: number + } } diff --git a/src/api/userController.ts b/src/api/userController.ts new file mode 100644 index 0000000..e7f29e7 --- /dev/null +++ b/src/api/userController.ts @@ -0,0 +1,136 @@ +// @ts-ignore +/* eslint-disable */ +import request from '@/request' + +/** addUser POST /api/user/add */ +export async function addUserUsingPost(body: API.UserAddRequest, options?: { [key: string]: any }) { + return request('/api/user/add', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }) +} + +/** deleteUser POST /api/user/delete */ +export async function deleteUserUsingPost( + body: API.DeleteRequest, + options?: { [key: string]: any } +) { + return request('/api/user/delete', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }) +} + +/** getUserById GET /api/user/get */ +export async function getUserByIdUsingGet( + // 叠加生成的Param类型 (非body参数swagger默认没有生成对象) + params: API.getUserByIdUsingGETParams, + options?: { [key: string]: any } +) { + return request('/api/user/get', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }) +} + +/** getLoginUser GET /api/user/get/login */ +export async function getLoginUserUsingGet(options?: { [key: string]: any }) { + return request('/api/user/get/login', { + method: 'GET', + ...(options || {}), + }) +} + +/** getUserVoById GET /api/user/get/vo */ +export async function getUserVoByIdUsingGet( + // 叠加生成的Param类型 (非body参数swagger默认没有生成对象) + params: API.getUserVoByIdUsingGETParams, + options?: { [key: string]: any } +) { + return request('/api/user/get/vo', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }) +} + +/** listUserVOByPage POST /api/user/list/page/vo */ +export async function listUserVoByPageUsingPost( + body: API.UserQueryRequest, + options?: { [key: string]: any } +) { + return request('/api/user/list/page/vo', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }) +} + +/** userLogin POST /api/user/login */ +export async function userLoginUsingPost( + body: API.UserLoginRequest, + options?: { [key: string]: any } +) { + return request('/api/user/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }) +} + +/** userLogout POST /api/user/logout */ +export async function userLogoutUsingPost(options?: { [key: string]: any }) { + return request('/api/user/logout', { + method: 'POST', + ...(options || {}), + }) +} + +/** userRegister POST /api/user/register */ +export async function userRegisterUsingPost( + body: API.UserRegisterRequest, + options?: { [key: string]: any } +) { + return request('/api/user/register', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }) +} + +/** updateUser POST /api/user/update */ +export async function updateUserUsingPost( + body: API.UserUpdateRequest, + options?: { [key: string]: any } +) { + return request('/api/user/update', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }) +} diff --git a/src/pages/admin/UserManagePage.vue b/src/pages/admin/UserManagePage.vue new file mode 100644 index 0000000..c23b631 --- /dev/null +++ b/src/pages/admin/UserManagePage.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/src/pages/user/UserLoginPage.vue b/src/pages/user/UserLoginPage.vue new file mode 100644 index 0000000..a2495c2 --- /dev/null +++ b/src/pages/user/UserLoginPage.vue @@ -0,0 +1,87 @@ + + + + + diff --git a/src/pages/user/UserRegisterPage.vue b/src/pages/user/UserRegisterPage.vue new file mode 100644 index 0000000..c23b631 --- /dev/null +++ b/src/pages/user/UserRegisterPage.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/src/router/index.ts b/src/router/index.ts index 04d0ed2..d6b38bd 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,14 +1,32 @@ import { createRouter, createWebHistory } from 'vue-router' import HomePage from '@/pages/HomePage.vue' +import UserLoginPage from '@/pages/user/UserLoginPage.vue' +import UserRegisterPage from '@/pages/user/UserRegisterPage.vue' +import UserManagePage from '@/pages/admin/UserManagePage.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/', - name: 'home', + name: '主页', component: HomePage, }, + { + path: '/user/login', + name: '用户登录', + component: UserLoginPage, + }, + { + path: '/user/register', + name: '用户注册', + component: UserRegisterPage, + }, + { + path: '/admin/userManage', + name: '用户管理', + component: UserManagePage, + }, ], }) diff --git a/src/stores/useLoginUserStore.ts b/src/stores/useLoginUserStore.ts index a046c1e..ee9b3ae 100644 --- a/src/stores/useLoginUserStore.ts +++ b/src/stores/useLoginUserStore.ts @@ -1,21 +1,21 @@ import { defineStore } from 'pinia' import { ref } from 'vue' +import { getLoginUserUsingGet } from '@/api/userController.ts' export const useLoginUserStore = defineStore('loginUser', () => { - const loginUser = ref({ + const loginUser = ref({ userName: '未登录', }) async function fetchLoginUser() { - // todo 由于后端还没提供接口,暂时注释 - // const res = await getCurrentUser(); - // if (res.data.code === 0 && res.data.data) { - // loginUser.value = res.data.data; - // } - // 测试用户登录,3 秒后自动登录 - setTimeout(() => { - loginUser.value = { userName: '测试用户', id: 1 } - }, 3000) + const res = await getLoginUserUsingGet() + if (res.data.code === 0 && res.data.data) { + loginUser.value = res.data.data + } + // // 测试用户登录,3 秒后自动登录 + // setTimeout(() => { + // loginUser.value = { userName: '测试用户', id: 1 } + // }, 3000) } function setLoginUser(newLoginUser: any) {