diff --git a/src/apis/session.ts b/src/apis/session.ts index 404acfc..1bd1e0d 100644 --- a/src/apis/session.ts +++ b/src/apis/session.ts @@ -1,9 +1,16 @@ import { cloudService } from './index' import type { ISession } from '@/types/auth' -export const loginApi = (name: string, password: string): Promise => +export const loginApi = (username: string, password: string): Promise => cloudService({ url: '/food-service/session', method: 'post', - params: { name, password } + params: { username, password } + }) + +export const logoutApi = (username: string): Promise => + cloudService({ + url: '/food-service/session', + method: 'delete', + params: { username } }) diff --git a/src/apis/user.ts b/src/apis/user.ts new file mode 100644 index 0000000..d3e0c14 --- /dev/null +++ b/src/apis/user.ts @@ -0,0 +1,9 @@ +import { cloudService } from './index' +import type { ISession, IUser } from '@/types/auth' + +export const registerApi = (user: IUser): Promise => + cloudService({ + url: '/food-service/user', + method: 'post', + data: user + }) diff --git a/src/components/Food/FoodDailyItem.vue b/src/components/Food/FoodDailyItem.vue index 69aef6f..efa7615 100644 --- a/src/components/Food/FoodDailyItem.vue +++ b/src/components/Food/FoodDailyItem.vue @@ -1,5 +1,5 @@ + + diff --git a/src/components/Login/EmailLogin.vue b/src/components/Login/EmailLogin.vue new file mode 100644 index 0000000..5e05176 --- /dev/null +++ b/src/components/Login/EmailLogin.vue @@ -0,0 +1,79 @@ + + + diff --git a/src/components/Login/LoginAuth.vue b/src/components/Login/LoginAuth.vue new file mode 100644 index 0000000..3b0d288 --- /dev/null +++ b/src/components/Login/LoginAuth.vue @@ -0,0 +1,182 @@ + + + + + diff --git a/src/components/Login/PhoneLogin.vue b/src/components/Login/PhoneLogin.vue new file mode 100644 index 0000000..bc5a302 --- /dev/null +++ b/src/components/Login/PhoneLogin.vue @@ -0,0 +1,79 @@ + + + diff --git a/src/components/Login/Register.vue b/src/components/Login/Register.vue new file mode 100644 index 0000000..9af479a --- /dev/null +++ b/src/components/Login/Register.vue @@ -0,0 +1,95 @@ + + + diff --git a/src/components/Stats/FoodStats.vue b/src/components/Stats/FoodStats.vue index f5f260f..43082d5 100644 --- a/src/components/Stats/FoodStats.vue +++ b/src/components/Stats/FoodStats.vue @@ -30,24 +30,10 @@ onMounted(async () => { }) const getAverageCount = () => { - if (foodStore.queryDateType === 'month') { - return foodStore.recordList.length - } else { - const result = {} - - // 遍历数据,按月统计出现次数 - foodStore.recordList.forEach((item) => { - const date = new Date(item.date) - const month = String(date.getMonth() + 1) - - if (result[month]) { - result[month].count += 1 - } else { - result[month] = { count: 1 } - } - }) - - return foodStore.recordList.length / Object.keys(result).length + if (foodStore.recordStats.length === 0) { + return 0 } + const sum = foodStore.recordStats.map((item) => item.value).reduce((acc, curr) => acc + curr, 0) + return (sum / foodStore.recordStats.length).toFixed(2) } diff --git a/src/layout/index.vue b/src/layout/index.vue index 51d12e3..b2eb9c8 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -28,7 +28,15 @@ const checkIsShow = (): boolean => { return false } - return route.path.includes('record') || route.path.includes('moment') + if (route.path.includes('moment')) { + return true + } + + if (route.path.includes('record') && foodStore.recordSegment !== 'timeline') { + return true + } + + return false } const addClick = () => { diff --git a/src/store/auth.ts b/src/store/auth.ts index e2f676b..0107730 100644 --- a/src/store/auth.ts +++ b/src/store/auth.ts @@ -1,14 +1,15 @@ import { defineStore } from 'pinia' -import type { ILoginType, ISession } from '@/types/auth' -import { loginApi } from '@/apis/session' +import type { ILoginType, ISession, IUser } from '@/types/auth' +import { loginApi, logoutApi } from '@/apis/session' import { ElMessage } from 'element-plus' import { emailPattern, phonePattern } from '@/utils/element/elRules' +import { registerApi } from '@/apis/user.ts' export const useAuthStore = defineStore('auth', { state: () => ({ loginForm: { - username: '132', - password: '123', + username: '', + password: '', isRemember: false }, phoneLoginForm: { @@ -19,14 +20,18 @@ export const useAuthStore = defineStore('auth', { email: '', code: '' }, + registerForm: { + username: '', + password: '', + confirmPassword: '' + }, loginType: 'common' as ILoginType, loginLoading: false, - loginAdminLoading: false, isVerified: false, isGettingCode: false, getCodeCountdown: 60, getCodeTimer: null as NodeJS.Timeout | null, - homeSession: {} as ISession + session: {} as ISession }), actions: { changeLoginType(type: ILoginType) { @@ -83,19 +88,30 @@ export const useAuthStore = defineStore('auth', { const { email, code: emailCode } = this.emailLoginForm switch (type) { case 'common': - this.homeSession = await loginApi(username, password) + this.session = await loginApi(username, password) break case 'phone': - this.homeSession = await loginApi(phoneNumber, phoneCode) + this.session = await loginApi(phoneNumber, phoneCode) break case 'email': - this.homeSession = await loginApi(email, emailCode) + this.session = await loginApi(email, emailCode) break default: break } ElMessage.success('登录成功') }, + async handleRegister() { + const user: IUser = { + username: this.registerForm.username, + password: this.registerForm.password + } + await registerApi(user) + }, + async handleLogout(username: string) { + await logoutApi(username) + ElMessage.success('退出登录成功') + }, resetLoginForm() { switch (this.loginType) { case 'common': @@ -117,6 +133,13 @@ export const useAuthStore = defineStore('auth', { code: '' } break + case 'register': + this.registerForm = { + username: '', + password: '', + confirmPassword: '' + } + break default: break } diff --git a/src/store/food.ts b/src/store/food.ts index 4bf2ec2..f8ef8f8 100644 --- a/src/store/food.ts +++ b/src/store/food.ts @@ -1,7 +1,7 @@ import { defineStore } from 'pinia' import type { IRecipe, IMaterial, IStep, - IStats, IRecord, IMoment, IFoodSegment, IComment + IStats, IRecord, IMoment, IFoodSegment } from '@/types/food' import { addRecipeApi, @@ -78,7 +78,7 @@ export const useFoodStore = defineStore('food', { content: '' } as IMoment, momentApiType: 'ADD' as IHandleApi, - imagePath: 'food', + imagePath: 'food-hub', rateColorList: ['#E2DEDC', '#F7BA2A', '#009FA8'], pageInfo: { currentPage: 1, @@ -223,7 +223,7 @@ export const useFoodStore = defineStore('food', { }, getEmptyRecord(): IRecord { return { - person: 0, + person: '', category: '', date: '', id: 0, diff --git a/src/store/user.ts b/src/store/user.ts index c4d5884..2145cc2 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -7,9 +7,8 @@ export const useUserStore = defineStore('user', { state: () => ({ userInfo: { id: 0, - accountId: 0, - accountName: '', username: '', + password: '', gender: 0, idNumber: '', phoneNumber: '', @@ -36,8 +35,8 @@ export const useUserStore = defineStore('user', { }, handleSession(session: ISession) { this.setToken(session.saToken.tokenValue) - // this.setUserId(session.userInfo.id) - // this.userInfo = session.userInfo + this.setUserId(session.userInfo?.id as number) + this.userInfo = session.userInfo }, async queryUser() { // this.userInfo = await queryUserApi(Number(this.getUserId())) @@ -46,7 +45,7 @@ export const useUserStore = defineStore('user', { // await updateUserApi(this.userInfo.id, this.userInfo) }, async updateAccountPassword(oldPassword: string, newPassword: string) { - console.log(this.userInfo.accountId) + // await updateAccountPasswordApi(this.userInfo.accountId, oldPassword, newPassword) }, setToken(token: string) { diff --git a/src/types/auth.ts b/src/types/auth.ts index 8f0cd2e..e73d281 100644 --- a/src/types/auth.ts +++ b/src/types/auth.ts @@ -1,23 +1,22 @@ -export type ILoginType = 'common' | 'phone' | 'email' | 'admin' +export type ILoginType = 'common' | 'phone' | 'email' | 'admin' | 'register' export type IAccountType = 'QQ' | 'WeChat' | 'Phone' | 'EMail' export interface IUser { - id: number; - accountId: number; - accountName: string; + id?: number; username: string; - gender: number; - idNumber: string; - phoneNumber: string; - email: string; - birthDate: string; - avatar: string; - description: string; - area: string[]; - address: string; - job: string; - tags: string[]; + password: string; + gender?: number; + idNumber?: string; + phoneNumber?: string; + email?: string; + birthDate?: string; + avatar?: string; + description?: string; + area?: string[]; + address?: string; + job?: string; + tags?: string[]; } export interface ISession { diff --git a/src/types/food.ts b/src/types/food.ts index c4092b9..0755063 100644 --- a/src/types/food.ts +++ b/src/types/food.ts @@ -25,7 +25,7 @@ export interface IRecord { id: number; name: string; category: string; - person: number; + person: string; date: string; imageUrl: string; } diff --git a/src/utils/element/elRules.ts b/src/utils/element/elRules.ts index 641172b..1e2a57c 100644 --- a/src/utils/element/elRules.ts +++ b/src/utils/element/elRules.ts @@ -67,6 +67,9 @@ export const foodRecordRules = { ], person: [ { required: true, message: '请选择完成人', trigger: 'change' } + ], + imageUrl: [ + { required: true, message: '请选择图片', trigger: 'change' } ] } diff --git a/src/views/login/index.vue b/src/views/login/index.vue index a900032..ebc0f6a 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,30 +1,156 @@ - diff --git a/src/views/moment/index.vue b/src/views/moment/index.vue index b2f6661..c7a1dcd 100644 --- a/src/views/moment/index.vue +++ b/src/views/moment/index.vue @@ -1,7 +1,11 @@ @@ -22,5 +26,11 @@ onMounted(async () => { display: flex; flex-direction: column; gap: 10px; + + .moment-list { + display: flex; + flex-direction: column; + gap: 10px; + } } diff --git a/src/views/profile/index.vue b/src/views/profile/index.vue index aece50f..5240f2d 100644 --- a/src/views/profile/index.vue +++ b/src/views/profile/index.vue @@ -14,17 +14,22 @@ diff --git a/src/views/record/recordForm.vue b/src/views/record/recordForm.vue index 6fca9f3..6a1e34d 100644 --- a/src/views/record/recordForm.vue +++ b/src/views/record/recordForm.vue @@ -23,7 +23,7 @@ value-format="YYYY-MM-DD"/> - +