diff --git a/app/pages/login/components/ResetPart.vue b/app/pages/login/components/ResetPart.vue
index b53741f..448435c 100644
--- a/app/pages/login/components/ResetPart.vue
+++ b/app/pages/login/components/ResetPart.vue
@@ -52,7 +52,7 @@
:data="resetForm"
:rules="rules"
class="flex flex-col items-center gap-4"
- @submit="store.reset()"
+ @submit="store.reset(backToLogin)"
>
{
- console.log('$http', $http);
nuxtApp.provide('http', $http);
});
diff --git a/app/stores/articleUser.ts b/app/stores/articleUser.ts
new file mode 100644
index 0000000..881117a
--- /dev/null
+++ b/app/stores/articleUser.ts
@@ -0,0 +1,197 @@
+export type Article = {
+ id: number;
+ title: string;
+ mainIdea: string;
+ content: string;
+};
+export type ArticleUser = {
+ id: number;
+ name: string;
+ amount: number;
+};
+type ArticleStore = {
+ articleList: ArticleUser[];
+ pagination: BasicPagination;
+ currentManageUser: UserInfo;
+ currentUserAvatar: string;
+ currentUserLastGetTime: Date;
+ currentUserArticleList: Article[];
+ currentUserPagination: BasicPagination;
+ currentArticle: Article;
+};
+export const useArticleStore = defineStore('Article', {
+ state: (): ArticleStore => ({
+ articleList: [],
+ pagination: {
+ current: 1,
+ pageSize: 5,
+ defaultPageSize: 5,
+ total: 0,
+ defaultCurrent: 1,
+ },
+ currentManageUser: {
+ userId: '',
+ userName: '',
+ userEmail: '',
+ userAvatarPath: '',
+ userAmount: '',
+ userBirthday: '',
+ },
+ currentUserAvatar: '',
+ currentUserLastGetTime: new Date(),
+ currentUserArticleList: [],
+ currentUserPagination: {
+ current: 1,
+ pageSize: 5,
+ defaultPageSize: 5,
+ total: 0,
+ defaultCurrent: 1,
+ },
+ currentArticle: {
+ id: 0,
+ title: '',
+ mainIdea: '',
+ content: '',
+ },
+ }),
+ actions: {
+ async modifyArticle() {
+ const { $http } = useNuxtApp();
+ try {
+ await $http.POST('/article/updateArticle', {
+ ...this.currentArticle,
+ author: this.currentManageUser.userName,
+ });
+ this.getCurrentManageUserArticleList();
+ } catch (error) {
+ await MessagePlugin.error('Error adding article:' + error);
+ }
+ },
+ async deleteArticle(id: number) {
+ const { $http } = useNuxtApp();
+ try {
+ await $http.GET('/article/deleteArticle', {
+ id: '' + id,
+ });
+ this.getCurrentManageUserArticleList();
+ } catch (error) {
+ await MessagePlugin.error('Error deleting article:' + error);
+ }
+ },
+ async addNewArticle() {
+ const { $http } = useNuxtApp();
+ try {
+ await $http.POST('/article/addArticle', {
+ ...this.currentArticle,
+ author: this.currentManageUser.userName,
+ });
+ this.getCurrentManageUserArticleList();
+ } catch (error) {
+ await MessagePlugin.error('Error adding article:' + error);
+ }
+ },
+ async getCurrentManageUserArticleList() {
+ const { $http } = useNuxtApp();
+ try {
+ const res = await $http.GET<{ records: Article[] }>(
+ `/article/page/${this.currentManageUser.userName}`,
+ {
+ page: '' + this.pagination!.current,
+ size: '' + this.pagination!.pageSize,
+ },
+ );
+ this.currentUserArticleList = res.data.records;
+ } catch (error) {
+ await MessagePlugin.error('Error fetching people list:' + error);
+ }
+ },
+ async getCurrentManageUserArticleTotal() {
+ const { $http } = useNuxtApp();
+ try {
+ const res = await $http.GET(
+ `/article/total/${this.currentManageUser.userName}`,
+ );
+ console.log(res.data);
+ this.currentUserPagination.total = res.data;
+ if (
+ (this.currentUserPagination!.current - 1) *
+ this.currentUserPagination!.pageSize >
+ this.currentUserPagination!.total
+ ) {
+ this.currentUserPagination!.current = Math.ceil(
+ this.currentUserPagination!.total /
+ this.currentUserPagination!.pageSize,
+ );
+ }
+ } catch (error) {
+ await MessagePlugin.error('Error fetching article total:' + error);
+ }
+ },
+ async getCurrentManageUserAvatar(forceUpdate: boolean = false) {
+ const now = new Date();
+ if (
+ !forceUpdate &&
+ this.currentUserAvatar !== '' &&
+ now.getTime() - this.currentUserLastGetTime.getTime() < 1000 * 60 * 9
+ ) {
+ return this.currentUserAvatar;
+ }
+ const { $http } = useNuxtApp();
+ try {
+ const res = await $http.GET('/article/userAvatar', {
+ userId: this.currentManageUser.userId,
+ });
+ this.currentUserAvatar = res.data;
+ return this.currentUserAvatar;
+ } catch (error) {
+ await MessagePlugin.error(
+ 'Error fetching article user avatar:' + error,
+ );
+ }
+ },
+ async getCurrentManageUserInfo(userId: string) {
+ const { $http } = useNuxtApp();
+ try {
+ const res = await $http.GET('/article/userInfo', {
+ userId: userId,
+ });
+ this.currentManageUser = res.data;
+ } catch (error) {
+ await MessagePlugin.error('Error fetching article user info:' + error);
+ }
+ },
+ async getArticleList() {
+ const { $http } = useNuxtApp();
+ try {
+ const res = await $http.GET<{ records: ArticleUser[] }>(
+ '/article/page',
+ {
+ page: '' + this.pagination!.current,
+ size: '' + this.pagination!.pageSize,
+ },
+ );
+ this.articleList = res.data.records;
+ } catch (error) {
+ await MessagePlugin.error('Error fetching article list:' + error);
+ }
+ },
+ async getTotal() {
+ const { $http } = useNuxtApp();
+ try {
+ const res = await $http.GET('/article/total');
+ 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.getArticleList();
+ }
+ } catch (error) {
+ await MessagePlugin.error('Error fetching article total:' + error);
+ }
+ },
+ },
+});
diff --git a/app/stores/login.ts b/app/stores/login.ts
index 16f2f1d..8f8e6e5 100644
--- a/app/stores/login.ts
+++ b/app/stores/login.ts
@@ -79,7 +79,7 @@ export const useLoginStore = defineStore('Login', {
email: email,
});
} catch (e) {
- console.log(e);
+ await MessagePlugin.error(e as string);
return false;
}
if (result.code === 200) {
@@ -106,19 +106,20 @@ export const useLoginStore = defineStore('Login', {
}
return false;
},
- async register() {
+ async register(recallWhenSuccess: () => void) {
const { $http } = useNuxtApp();
try {
await $http.POST('/login/register', this.registerForm);
+ recallWhenSuccess();
} catch {
return;
}
},
- async reset() {
- console.log(this.resetForm);
+ async reset(recallWhenSuccess: () => void) {
const { $http } = useNuxtApp();
try {
await $http.POST('/login/passwordReset', this.resetForm);
+ recallWhenSuccess();
} catch {
return;
}
@@ -144,7 +145,6 @@ export const useLoginStore = defineStore('Login', {
case PageType.reset:
return '重置密码';
default:
- console.log('未知');
return '未知';
}
},
diff --git a/app/stores/people.ts b/app/stores/people.ts
index 9be7349..565790f 100644
--- a/app/stores/people.ts
+++ b/app/stores/people.ts
@@ -58,9 +58,8 @@ export const usePeopleStore = defineStore('People', {
},
);
this.peopleList = res.data.records;
- console.log(this.peopleList);
} catch (error) {
- console.error('Error fetching people list:', error);
+ await MessagePlugin.error('Error fetching people list:' + error);
}
},
async getTotal() {
@@ -79,12 +78,11 @@ export const usePeopleStore = defineStore('People', {
);
this.getPeopleList();
}
- } catch {
- return;
+ } catch (error) {
+ await MessagePlugin.error('Error fetching people total:' + error);
}
},
async addPeople() {
- console.log('add');
const { $http } = useNuxtApp();
try {
await $http.POST('/userManager/addUser', this.currentForm);
diff --git a/app/stores/user.ts b/app/stores/user.ts
index c01539c..49814b4 100644
--- a/app/stores/user.ts
+++ b/app/stores/user.ts
@@ -2,36 +2,45 @@ export interface UserInfo {
userId: string;
userName: string;
userEmail: string;
- userAvatar: string;
+ userAvatarPath: string;
userAmount: string;
userBirthday: string;
- lastGetTime: Date;
+}
+export class ExampleUserInfo implements UserInfo {
+ userId = '';
+ userName = '';
+ userEmail = '';
+ userAvatarPath = '';
+ userAmount = '0';
+ userBirthday = '';
}
export interface UserState extends UserInfo {
+ lastGetTime: Date;
usernameOrEmail: string;
+ userAvatarUrl: string;
}
export const useUserStore = defineStore('User', {
state: (): UserState => ({
- usernameOrEmail: '',
userId: '',
userName: '',
userEmail: '',
- userAvatar: '',
+ userAvatarPath: '',
userAmount: '',
userBirthday: '',
lastGetTime: new Date(),
+ usernameOrEmail: '',
+ userAvatarUrl: '',
}),
actions: {
async getUserInfo() {
const { $http } = useNuxtApp();
try {
const res = await $http.GET('/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.userAvatarPath = res.data.userAvatarPath;
+ this.userAmount = res.data.userAmount;
this.userBirthday = res.data.userBirthday;
this.lastGetTime = new Date();
} catch (error) {
@@ -40,14 +49,23 @@ export const useUserStore = defineStore('User', {
},
async getAvatarURL() {
const now = new Date();
- if (now.getTime() - this.lastGetTime.getTime() < 1000 * 60 * 9) {
- return this.userAvatar;
+ console.log('Current time:', now);
+ if (
+ this.userAvatarUrl !== '' &&
+ now.getTime() - this.lastGetTime.getTime() < 1000 * 60 * 9
+ ) {
+ console.log('Using cached avatar URL');
+ console.log('Cached avatar URL:', this.userAvatarUrl);
+ return this.userAvatarUrl;
}
+ console.log('Fetching new avatar URL');
this.lastGetTime = now;
const { $http } = useNuxtApp();
try {
const res = await $http.GET('/user/avatar');
- this.userAvatar = res.data;
+ this.userAvatarUrl = res.data;
+ console.log('User avatar URL:', this.userAvatarUrl);
+ return this.userAvatarUrl;
} catch (error) {
console.error('Error fetching user avatar:', error);
}
diff --git a/app/types/auto-imports.d.ts b/app/types/auto-imports.d.ts
index 1e3957b..770786c 100644
--- a/app/types/auto-imports.d.ts
+++ b/app/types/auto-imports.d.ts
@@ -8,6 +8,7 @@ export {}
declare global {
const APIResponse: typeof import('../utils/APIResponse')['APIResponse']
const APIResponseErrorException: typeof import('../utils/APIResponse')['APIResponseErrorException']
+ const ExampleUserInfo: typeof import('../stores/user')['ExampleUserInfo']
const PageType: typeof import('../stores/login')['PageType']
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
const createPinia: typeof import('pinia')['createPinia']
@@ -21,6 +22,7 @@ declare global {
const setActivePinia: typeof import('pinia')['setActivePinia']
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix']
const storeToRefs: typeof import('pinia')['storeToRefs']
+ const useArticleStore: typeof import('../stores/articleUser')['useArticleStore']
const useLoginStore: typeof import('../stores/login')['useLoginStore']
const usePeopleStore: typeof import('../stores/people')['usePeopleStore']
const useSystemStore: typeof import('../stores/system')['useSystemStore']
@@ -29,6 +31,9 @@ declare global {
}
// for type re-export
declare global {
+ // @ts-ignore
+ export type { Article, ArticleUser } from '../stores/articleUser'
+ import('../stores/articleUser')
// @ts-ignore
export type { PageType, LoginStore } from '../stores/login'
import('../stores/login')
@@ -39,7 +44,7 @@ declare global {
export type { SystemStore } from '../stores/system'
import('../stores/system')
// @ts-ignore
- export type { UserInfo, UserState } from '../stores/user'
+ export type { ExampleUserInfo, UserInfo, UserState } from '../stores/user'
import('../stores/user')
// @ts-ignore
export type { APIResponse, APIResponseErrorException, IAPIResponse } from '../utils/APIResponse'
@@ -53,6 +58,7 @@ declare module 'vue' {
interface ComponentCustomProperties {
readonly APIResponse: UnwrapRef
readonly APIResponseErrorException: UnwrapRef
+ readonly ExampleUserInfo: UnwrapRef
readonly PageType: UnwrapRef
readonly acceptHMRUpdate: UnwrapRef
readonly createPinia: UnwrapRef
@@ -66,6 +72,7 @@ declare module 'vue' {
readonly setActivePinia: UnwrapRef
readonly setMapStoreSuffix: UnwrapRef
readonly storeToRefs: UnwrapRef
+ readonly useArticleStore: UnwrapRef
readonly useLoginStore: UnwrapRef
readonly usePeopleStore: UnwrapRef
readonly useSystemStore: UnwrapRef
diff --git a/package.json b/package.json
index b3f5092..f81d713 100644
--- a/package.json
+++ b/package.json
@@ -28,13 +28,15 @@
"@nuxtjs/tailwindcss": "^6.13.2",
"@pinia/nuxt": "^0.10.1",
"@unhead/vue": "^2.0.5",
+ "echarts": "^5.6.0",
+ "md-editor-v3": "^5.5.0",
"nuxt": "^3.16.2",
"pinia": "^3.0.2",
"tdesign-vue-next": "^1.11.5",
"unplugin-auto-import": "^19.1.2",
"unplugin-vue-components": "^28.4.1"
},
- "packageManager": "pnpm@10.9.0",
+ "packageManager": "pnpm@10.10.0",
"pnpm": {
"onlyBuiltDependencies": [
"@parcel/watcher",