✨ 完成实验部分功能
This commit is contained in:
+82
-12
@@ -1,20 +1,21 @@
|
||||
interface RegisterData {
|
||||
email: string;
|
||||
username: string;
|
||||
identifyingCode: string;
|
||||
password: string;
|
||||
passwordRepeat: string;
|
||||
birth: string;
|
||||
avatarURL: string;
|
||||
avatarFile: string;
|
||||
}
|
||||
|
||||
interface LoginData {
|
||||
username: string;
|
||||
usernameOrEmail: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface resetData {
|
||||
username: string;
|
||||
oldPassword: string;
|
||||
usernameOrEmail: string;
|
||||
identifyingCode: string;
|
||||
password: string;
|
||||
passwordRepeat: string;
|
||||
}
|
||||
@@ -34,18 +35,19 @@ export interface LoginStore {
|
||||
|
||||
export const useLoginStore = defineStore('Login', {
|
||||
state: (): LoginStore => ({
|
||||
loginForm: { username: '', password: '' },
|
||||
loginForm: { usernameOrEmail: '', password: '' },
|
||||
registerForm: {
|
||||
email: '',
|
||||
identifyingCode: '',
|
||||
username: '',
|
||||
password: '',
|
||||
passwordRepeat: '',
|
||||
birth: '',
|
||||
avatarURL: '',
|
||||
avatarFile: '',
|
||||
},
|
||||
resetForm: {
|
||||
username: '',
|
||||
oldPassword: '',
|
||||
usernameOrEmail: '',
|
||||
identifyingCode: '',
|
||||
password: '',
|
||||
passwordRepeat: '',
|
||||
},
|
||||
@@ -53,15 +55,83 @@ export const useLoginStore = defineStore('Login', {
|
||||
}),
|
||||
actions: {
|
||||
async login() {
|
||||
console.log(this.loginForm);
|
||||
const router = useRouter();
|
||||
await router.push('/base/home');
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
await $http.POST('/login/', this.loginForm);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
async sendRegisterIdentifyingCode(): Promise<boolean> {
|
||||
const email = this.registerForm.email;
|
||||
if (email === '') {
|
||||
await MessagePlugin.error('请输入邮箱');
|
||||
return false;
|
||||
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
await MessagePlugin.error('请输入正确的邮箱');
|
||||
return false;
|
||||
}
|
||||
const { $http } = useNuxtApp();
|
||||
let result: APIResponse<unknown>;
|
||||
try {
|
||||
result = await $http.GET('/login/register/identifyingCode', {
|
||||
email: email,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return false;
|
||||
}
|
||||
if (result.code === 200) {
|
||||
return true;
|
||||
} else {
|
||||
await MessagePlugin.error(result.message);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
async sendResetIdentifyingCode(): Promise<boolean> {
|
||||
const { $http } = useNuxtApp();
|
||||
const usernameOrEmail = this.resetForm.usernameOrEmail;
|
||||
if (usernameOrEmail === '') {
|
||||
await MessagePlugin.error('请输入用户名或邮箱');
|
||||
return false;
|
||||
}
|
||||
const result = await $http.GET('/login/passwordReset/identifyingCode', {
|
||||
usernameOrEmail: usernameOrEmail,
|
||||
});
|
||||
if (result.code === 200) {
|
||||
return true;
|
||||
} else {
|
||||
await MessagePlugin.error(result.message);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
async register() {
|
||||
console.log(this.registerForm);
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
await $http.POST('/login/register', this.registerForm);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
},
|
||||
async reset() {
|
||||
console.log(this.resetForm);
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
await $http.POST('/login/passwordReset', this.resetForm);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
},
|
||||
async logout() {
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
await $http.GET('/login/logout');
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const router = useRouter();
|
||||
await router.push('/login');
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
export interface PeopleInfo {
|
||||
id: number;
|
||||
date: string;
|
||||
name: string;
|
||||
province: string;
|
||||
city: string;
|
||||
address: string;
|
||||
zip: string;
|
||||
}
|
||||
export interface BasicPagination {
|
||||
current: number;
|
||||
pageSize: number;
|
||||
defaultPageSize: number;
|
||||
total: number;
|
||||
defaultCurrent: number;
|
||||
}
|
||||
export interface PeopleState {
|
||||
peopleList: PeopleInfo[];
|
||||
showAddPeople: boolean;
|
||||
showEditPeople: boolean;
|
||||
situation: string;
|
||||
pagination: BasicPagination;
|
||||
currentForm: PeopleInfo;
|
||||
}
|
||||
export const usePeopleStore = defineStore('People', {
|
||||
state: (): PeopleState => ({
|
||||
peopleList: [],
|
||||
showAddPeople: false,
|
||||
showEditPeople: false,
|
||||
situation: '',
|
||||
pagination: {
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
defaultPageSize: 10,
|
||||
total: 0,
|
||||
defaultCurrent: 1,
|
||||
},
|
||||
currentForm: {
|
||||
id: 0,
|
||||
date: '',
|
||||
name: '',
|
||||
province: '',
|
||||
city: '',
|
||||
address: '',
|
||||
zip: '',
|
||||
},
|
||||
}),
|
||||
actions: {
|
||||
async getPeopleList() {
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
const res = await $http.GET<{ records: PeopleInfo[] }>(
|
||||
'/userManager/page',
|
||||
{
|
||||
page: '' + this.pagination!.current,
|
||||
size: '' + this.pagination!.pageSize,
|
||||
situation: this.situation,
|
||||
},
|
||||
);
|
||||
this.peopleList = res.data.records;
|
||||
console.log(this.peopleList);
|
||||
} catch (error) {
|
||||
console.error('Error fetching people list:', error);
|
||||
}
|
||||
},
|
||||
async getTotal() {
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
const res = await $http.GET<number>('/userManager/total', {
|
||||
situation: this.situation,
|
||||
});
|
||||
this.pagination!.total = res.data;
|
||||
if (
|
||||
(this.pagination!.current - 1) * this.pagination!.pageSize >
|
||||
this.pagination!.total
|
||||
) {
|
||||
this.pagination!.current = Math.ceil(
|
||||
this.pagination!.total / this.pagination!.pageSize,
|
||||
);
|
||||
this.getPeopleList();
|
||||
}
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
},
|
||||
async addPeople() {
|
||||
console.log('add');
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
await $http.POST('/userManager/addUser', this.currentForm);
|
||||
this.getTotal();
|
||||
this.getPeopleList();
|
||||
} catch (error) {
|
||||
await MessagePlugin.error('Error adding people:' + error);
|
||||
}
|
||||
this.showEditPeople = false;
|
||||
this.showAddPeople = false;
|
||||
},
|
||||
|
||||
async updatePeople() {
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
await $http.POST('/userManager/updateUser', this.currentForm);
|
||||
this.getTotal();
|
||||
this.getPeopleList();
|
||||
} catch (error) {
|
||||
await MessagePlugin.error('Error updating people:' + error);
|
||||
}
|
||||
this.showEditPeople = false;
|
||||
this.showAddPeople = false;
|
||||
},
|
||||
|
||||
async deletePeople(peopleId: number) {
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
await $http.GET('/userManager/deleteUser', { id: '' + peopleId });
|
||||
this.getTotal();
|
||||
this.getPeopleList();
|
||||
} catch (error) {
|
||||
await MessagePlugin.error('Error deleting people:' + error);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
+41
-2
@@ -1,14 +1,53 @@
|
||||
export interface UserState {
|
||||
export interface UserInfo {
|
||||
userId: string;
|
||||
userName: string;
|
||||
userEmail: string;
|
||||
userAvatar: string;
|
||||
userAmount: string;
|
||||
lastGetTime: Date;
|
||||
}
|
||||
export interface UserState extends UserInfo {
|
||||
usernameOrEmail: string;
|
||||
}
|
||||
export const useUserStore = defineStore('User', {
|
||||
state: (): UserState => ({
|
||||
usernameOrEmail: '',
|
||||
userId: '',
|
||||
userName: '李晨鑫',
|
||||
userName: '',
|
||||
userEmail: '',
|
||||
userAvatar: '',
|
||||
userAmount: '',
|
||||
lastGetTime: new Date(),
|
||||
}),
|
||||
actions: {
|
||||
async getUserInfo() {
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
const res = await $http.GET<UserInfo>('/user/info');
|
||||
console.log(res.data);
|
||||
this.userId = res.data.userId;
|
||||
this.userName = res.data.userName;
|
||||
this.userEmail = res.data.userEmail;
|
||||
this.userAvatar = res.data.userAvatar;
|
||||
this.userAmount = '500';
|
||||
this.lastGetTime = new Date();
|
||||
} catch (error) {
|
||||
console.error('Error fetching user info:', error);
|
||||
}
|
||||
},
|
||||
async getAvatarURL() {
|
||||
const now = new Date();
|
||||
if (now.getTime() - this.lastGetTime.getTime() < 1000 * 60 * 9) {
|
||||
return this.userAvatar;
|
||||
}
|
||||
this.lastGetTime = now;
|
||||
const { $http } = useNuxtApp();
|
||||
try {
|
||||
const res = await $http.GET<string>('/user/avatar');
|
||||
this.userAvatar = res.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching user avatar:', error);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user