diff --git a/src/api/login.ts b/src/api/login.ts index b8322e4..132fe7f 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -3,12 +3,12 @@ import request from '@/utils/request' interface LoginParamsType { name?: string // 姓名 email: string // 邮箱 - password: string // 密码 + password?: string // 密码 operationType: 'REGISTER' | 'LOGIN' | 'FORGET_PWD' verifyCode?: string // 验证码 } -export const precheckAndSendEmail = (data: LoginParamsType) => { +export const precheckAndSendEmail = (data: LoginParamsType): Promise => { return request({ url: '/api/auth/precheckAndSendEmail', method: 'post', @@ -16,7 +16,7 @@ export const precheckAndSendEmail = (data: LoginParamsType) => { }) } -export const fetchLogin = (data: LoginParamsType) => { +export const fetchRegisterOrLogin = (data: LoginParamsType): Promise => { return request({ url: '/api/auth/registerOrLogin', method: 'post', @@ -24,10 +24,17 @@ export const fetchLogin = (data: LoginParamsType) => { }) } -export const resetPassword = (data: LoginParamsType) => { +export const resetPassword = (data: LoginParamsType): Promise => { return request({ url: '/api/auth/forgotPwd', method: 'post', data }) } + +export const checkLoginStatus = (): Promise> => { + return request({ + url: '/api/auth/checkLoginStatus', + method: 'get' + }) +} \ No newline at end of file diff --git a/src/api/workshop.ts b/src/api/workshop.ts index 2f8bbaa..2816953 100644 --- a/src/api/workshop.ts +++ b/src/api/workshop.ts @@ -98,3 +98,16 @@ export function getTryOnEffectStyleList(styleId: string | number) { method: 'get', }) } + + +interface CustomerInfo { + name: string + email: string +} +export const customerCheckin = (data: CustomerInfo) => { + return request({ + url: '/api/customers/checkIn', + method: 'get', + params: data, + }) +} \ No newline at end of file diff --git a/src/stores/modules/generate.ts b/src/stores/modules/generate.ts index d66b3ed..11c4fa8 100644 --- a/src/stores/modules/generate.ts +++ b/src/stores/modules/generate.ts @@ -2,114 +2,122 @@ import { defineStore } from 'pinia' import { useUserInfoStore } from './userInfo' export const useGenerateStore = defineStore({ - id: 'generate', // 必须指明唯一的pinia仓库的id - state: () => { - return { - style: { - id: '', - oldId: '',//表示从生成页面返回回来,需要调整的样式id - }, - model: { - id: '', - }, - originalTryOn: {//生成穿好衣服的回参 - id: '', - isLike: false,//是否喜欢 - tryOnUrl:'', - }, - isGenerate: false,//点击继续按钮后是否需要生成 + id: 'generate', // 必须指明唯一的pinia仓库的id + state: () => { + return { + style: { + id: '', + oldId: '' //表示从生成页面返回回来,需要调整的样式id + }, + model: { + id: '' + }, + originalTryOn: { + //生成穿好衣服的回参 + id: '', + isLike: false, //是否喜欢 + tryOnUrl: '' + }, + isGenerate: false, //点击继续按钮后是否需要生成 - /** 顾客照片信息 */ - photoInfo: { - id: "", - url: "", - file: null, - }, - /** AI魔改信息 */ - customizeInfo: { - inputText: "", + /** 顾客照片信息 */ + photoInfo: { + id: '', + url: '', + file: null + }, + /** AI魔改信息 */ + customizeInfo: { + inputText: '', - tryOnId: "", - tryOnUrl: "", - styleUrl: "", - isRegenerated: "", - isFavorite: false, - }, - } - }, - getters: { - /** 顾客id */ - customerId: (state) => useUserInfoStore().state.customerId, - /** 进店记录id */ - visitRecordId: (state) => useUserInfoStore().state.visitRecordId, - /** 服装id */ - styleId: (state) => state.style.id || state.style.oldId, - /** 模特照片id */ - modelPhotoId: (state) => state.model.id, - /** 原始试穿id-优先AI魔改 */ - originalTryOnId: (state) => state.customizeInfo.tryOnId || state.originalTryOn.id, - /** 顾客照片id */ - customerPhotoId: (state) => state.photoInfo.id, - }, - actions: { - selectStyle(data: any) { - this.style.id = data.id - console.log(this) - }, - //生成后去掉id 设置oldId来修改样式 - useStyleGenerate() { - if(!this.style.id)return - this.style.oldId = this.style.id - this.style.id = '' - }, - updateStyle(data) { - console.log(data) - if (data.id == this.style.oldId) { - this.style.oldId = '' - } - }, - //模特相关 - selectModel(data: any) { - this.model.id = data.id - }, - setIsGenerate(isGenerate: boolean) { - this.isGenerate = isGenerate - }, - clearProductData(){ - this.style = { - id: '', - oldId: '', - } - this.model = { - id: '', - } - this.originalTryOn = { - id: '', - isLike: false, - tryOnUrl:'', - } - this.isGenerate = false - }, - /** 更新顾客照片信息 */ - updatePhotoInfo(data: any) { - this.photoInfo.id = data.id || "" - if (!data.photoUrl) this.photoInfo.url = "" - this.photoInfo.file = null - }, - /** 清空 AI魔改信息 */ - clearCustomizeInfo() { - this.customizeInfo.inputText = "" - this.customizeInfo.tryOnId = "" - this.customizeInfo.tryOnUrl = "" - this.customizeInfo.styleUrl = "" - this.customizeInfo.isRegenerated = "" - this.customizeInfo.isFavorite = false - }, - //设置默认数据 - clearGenerateData() { - this.clearProductData() - this.updatePhotoInfo() - this.clearCustomizeInfo() - } - } -}) \ No newline at end of file + tryOnId: '', + tryOnUrl: '', + styleUrl: '', + isRegenerated: '', + isFavorite: false + }, + customerInfo: { + customerId: '', + visitRecordId: '' + } + } + }, + getters: { + /** 顾客id */ + customerId: (state) => state.customerInfo.customerId, + /** 进店记录id */ + visitRecordId: (state) => state.customerInfo.visitRecordId, + /** 服装id */ + styleId: (state) => state.style.id || state.style.oldId, + /** 模特照片id */ + modelPhotoId: (state) => state.model.id, + /** 原始试穿id-优先AI魔改 */ + originalTryOnId: (state) => state.customizeInfo.tryOnId || state.originalTryOn.id, + /** 顾客照片id */ + customerPhotoId: (state) => state.photoInfo.id + }, + actions: { + selectStyle(data: any) { + this.style.id = data.id + console.log(this) + }, + //生成后去掉id 设置oldId来修改样式 + useStyleGenerate() { + if (!this.style.id) return + this.style.oldId = this.style.id + this.style.id = '' + }, + updateStyle(data) { + console.log(data) + if (data.id == this.style.oldId) { + this.style.oldId = '' + } + }, + //模特相关 + selectModel(data: any) { + this.model.id = data.id + }, + setIsGenerate(isGenerate: boolean) { + this.isGenerate = isGenerate + }, + clearProductData() { + this.style = { + id: '', + oldId: '' + } + this.model = { + id: '' + } + this.originalTryOn = { + id: '', + isLike: false, + tryOnUrl: '' + } + this.isGenerate = false + }, + /** 更新顾客照片信息 */ + updatePhotoInfo(data: any) { + this.photoInfo.id = data.id || '' + if (!data.photoUrl) this.photoInfo.url = '' + this.photoInfo.file = null + }, + /** 清空 AI魔改信息 */ + clearCustomizeInfo() { + this.customizeInfo.inputText = '' + this.customizeInfo.tryOnId = '' + this.customizeInfo.tryOnUrl = '' + this.customizeInfo.styleUrl = '' + this.customizeInfo.isRegenerated = '' + this.customizeInfo.isFavorite = false + }, + //设置默认数据 + clearGenerateData() { + this.clearProductData() + this.updatePhotoInfo({}) + this.clearCustomizeInfo() + }, + setCustomerInfo(data: any) { + this.customerInfo = data + } + } +}) diff --git a/src/stores/modules/userInfo.ts b/src/stores/modules/userInfo.ts index 0cc3f03..d642325 100644 --- a/src/stores/modules/userInfo.ts +++ b/src/stores/modules/userInfo.ts @@ -1,6 +1,7 @@ // 每一个存储的模块,命名规则use开头,store结尾 import { defineStore } from 'pinia' import { ref, computed } from 'vue' +import { removeLocal, setLocal } from '@/utils/local' export const useUserInfoStore = defineStore('userInfo', () => { const state = ref({ @@ -27,6 +28,7 @@ export const useUserInfoStore = defineStore('userInfo', () => { const setToken = (data: string) => { state.value.token = data + setLocal(data, 'token') } const getGenerateParams = () => { @@ -45,16 +47,13 @@ export const useUserInfoStore = defineStore('userInfo', () => { } } - const login = async (data: any) => { - return new Promise((resolve, reject) => {}) - } - const logOut = () => { // 处理退出登录的一些逻辑 return new Promise((resolve) => { state.value.token = '' state.value.userInfo = {} state.value.customerId = '' + removeLocal('token') resetGenerateParams() resolve('') }) @@ -69,7 +68,6 @@ export const useUserInfoStore = defineStore('userInfo', () => { setGenerateParams, getGenerateParams, resetGenerateParams, - logOut, - login + logOut } }) diff --git a/src/types/api.d.ts b/src/types/api.d.ts new file mode 100644 index 0000000..d267c32 --- /dev/null +++ b/src/types/api.d.ts @@ -0,0 +1,45 @@ +// 全局API响应类型定义 +declare global { + // 基础API响应结构 + interface ApiResponse { + success: boolean + message: string + data?: T + code?: number + errMsg?: string + } + + // 登录/注册相关响应 + interface LoginResponse { + token?: string + user?: { + id: string + name: string + email: string + } + } + + // 通用列表响应 + interface ListResponse { + list: T[] + total: number + page: number + pageSize: number + } + + // 分页参数 + interface PaginationParams { + page: number + pageSize: number + } + + // 通用错误响应 + interface ErrorResponse { + success: false + message: string + code?: number + errMsg?: string + } +} + +export {} diff --git a/src/utils/request.ts b/src/utils/request.ts index c0f3648..032a0e9 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -6,20 +6,31 @@ import { getLocal } from '@/utils/local' import router from '@/router/index' import { useOverallStore, useGenerateStore } from '@/stores' +// 扩展 AxiosRequestConfig 接口 +declare module 'axios' { + interface AxiosRequestConfig { + loading?: boolean + loadingDom?: any + repeatRequest?: boolean + meta?: { + responseAll?: boolean + } + } +} // 创建axios实例 // console.log(import.meta.env,123) const service = axios.create({ -// baseURL: import.meta.env.VITE_APP_URL, // api的base_url - timeout: 20000, // 请求超时时间 + // baseURL: import.meta.env.VITE_APP_URL, // api的base_url + timeout: 20000 // 请求超时时间 }) -if(import.meta.env.MODE != 'development'){ +if (import.meta.env.MODE != 'development') { service.defaults.baseURL = import.meta.env.VITE_APP_URL } -axios.defaults.headers.post["Content-Type"] = "application/json"; -axios.defaults.headers.post['lang'] = 'en'; //配置语言请求头 -axios.defaults.withCredentials = true; //跨域携带cookie +axios.defaults.headers.post['Content-Type'] = 'application/json' +axios.defaults.headers.post['lang'] = 'en' //配置语言请求头 +axios.defaults.withCredentials = true //跨域携带cookie // request拦截器 service.interceptors.request.use( @@ -36,9 +47,9 @@ service.interceptors.request.use( } // 如果登录了,有token,则请求携带token // Do something before request is sent - if (store.token) { + if (store.state.token) { config.headers.Authorization = getLocal('token') // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改 - // config.headers['X-Token'] = getLocal('token') // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改 + // config.headers['X-Token'] = getLocal('token') // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改 } return config }, @@ -65,14 +76,15 @@ service.interceptors.response.use( } const res = response.data // 处理异常的情况 - console.log(res) + console.log(res) if (res.code != 0) { showToast({ - message: res.errMsg, - type: 'fail', - duration: 5000 + message: res.errMsg || res.message, + // type: 'fail', + duration: 5000, + position:'top' }) - + return Promise.reject(new Error('error')) } else { // 默认只返回data,不返回状态码和message @@ -165,14 +177,13 @@ const LoadingInstance: { _count: number } = { _count: 0 } function openLoading(loadingDom: any) { - useOverallStore().setLoading(true) + useOverallStore().setLoading(true) } function closeLoading() { if (LoadingInstance._count > 0) LoadingInstance._count-- if (LoadingInstance._count === 0) { - useOverallStore().setLoading(false) + useOverallStore().setLoading(false) } - } export default service diff --git a/src/views/login/LoginPage.vue b/src/views/login/LoginPage.vue index 52140bf..4cfe512 100644 --- a/src/views/login/LoginPage.vue +++ b/src/views/login/LoginPage.vue @@ -46,14 +46,16 @@