diff --git a/src/api/login.ts b/src/api/login.ts index 3856d97..132fe7f 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -3,7 +3,7 @@ import request from '@/utils/request' interface LoginParamsType { name?: string // 姓名 email: string // 邮箱 - password: string // 密码 + password?: string // 密码 operationType: 'REGISTER' | 'LOGIN' | 'FORGET_PWD' verifyCode?: string // 验证码 } 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 ca779a2..bc3ed67 100644 --- a/src/stores/modules/generate.ts +++ b/src/stores/modules/generate.ts @@ -4,43 +4,48 @@ export const useGenerateStore = defineStore({ id: 'generate', // 必须指明唯一的pinia仓库的id state: () => { return { - style: { - id: '', - oldId: '',//表示从生成页面返回回来,需要调整的样式id - }, - model: { - id: '', - }, - originalTryOn:{//生成穿好衣服的回参 - id: '', - isLike: false,//是否喜欢 - tryOnUrl:'', - }, - isGenerate: false,//点击继续按钮后是否需要生成 + 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, - }, - } + tryOnId: '', + tryOnUrl: '', + styleUrl: '', + isRegenerated: '', + isFavorite: false + }, + customerInfo: { + customerId: '', + visitRecordId:'' + } + } }, getters: { /** 顾客id */ - customerId: (state) => 1, + customerId: (state) => state.customerInfo.customerId, /** 进店记录id */ - visitRecordId: (state) => 1, + visitRecordId: (state) => state.customerInfo.visitRecordId, /** 服装id */ styleId: (state) => state.style.id || state.style.oldId, /** 模特照片id */ @@ -89,5 +94,8 @@ export const useGenerateStore = defineStore({ this.customizeInfo.isRegenerated = "" this.customizeInfo.isFavorite = false }, + setCustomerInfo(data: any) { + this.customerInfo = data + } } }) \ No newline at end of file diff --git a/src/stores/modules/userInfo.ts b/src/stores/modules/userInfo.ts index 5f6c984..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 = () => { @@ -51,6 +53,7 @@ export const useUserInfoStore = defineStore('userInfo', () => { state.value.token = '' state.value.userInfo = {} state.value.customerId = '' + removeLocal('token') resetGenerateParams() resolve('') }) diff --git a/src/utils/request.ts b/src/utils/request.ts index d1b7fbf..07a3761 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -18,20 +18,19 @@ declare module 'axios' { } } - // 创建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( @@ -50,7 +49,7 @@ service.interceptors.request.use( // Do something before request is sent 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 }, @@ -77,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 @@ -98,33 +98,35 @@ service.interceptors.response.use( } }, (error) => { - if(error?.response){ - if(error?.response?.status === 401){//如果是记录浏览器页面就不跳转login - // showConfirmDialog({ - // title: '确定登出', - // message: '你已被登出,可以取消继续留在该页面,或者重新登录', - // confirmButtonText: '重新登录', - // cancelButtonText: '取消' - // }).then(() => { - // store.loginOut().then(() => { - // location.reload() // 为了重新实例化vue-router对象 避免bug - // }) - // }) - router.replace('/login') - return Promise.reject(error) - } - error.config && removePending(error.config) - // 关闭loading - if (error.config?.loading) { - closeLoading() - } - console.log('err' + error) // for debug - showToast({ - message: error.message, - type: 'fail', - duration: 5000 - }) - } + if (error?.response) { + if (error?.response?.status === 401) { + //如果是记录浏览器页面就不跳转login + // showConfirmDialog({ + // title: '确定登出', + // message: '你已被登出,可以取消继续留在该页面,或者重新登录', + // confirmButtonText: '重新登录', + // cancelButtonText: '取消' + // }).then(() => { + // store.loginOut().then(() => { + // location.reload() // 为了重新实例化vue-router对象 避免bug + // }) + // }) + router.replace('/login') + return Promise.reject(error) + } + error.config && removePending(error.config) + // 关闭loading + if (error.config?.loading) { + closeLoading() + } + console.log('err' + error) // for debug + showToast({ + message: error.message, + // type: 'fail', + duration: 5000, + position:'top' + }) + } return Promise.reject(error) } ) @@ -175,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/stylist/customer.vue b/src/views/stylist/customer.vue index 04a6235..2b64ffb 100644 --- a/src/views/stylist/customer.vue +++ b/src/views/stylist/customer.vue @@ -26,11 +26,16 @@
- +
- +
@@ -42,10 +47,12 @@