From be9d75d89fb41a917ceb789787dee2f9872d6865 Mon Sep 17 00:00:00 2001 From: JunYong Sun Date: Tue, 23 Jan 2024 17:45:10 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[ADD]=20=EC=84=A0=EB=AC=BC=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=ED=94=84=EB=A1=A0=ED=8A=B8=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 10 ++++++---- src/App.vue | 10 ++++++++-- src/stores/order/OrderStore.ts | 22 ++++++++++++++++++++++ src/views/OrderResultView.vue | 31 ++++++++++++++++++++++++++++++- src/views/OrderView.vue | 15 +++++++++++++-- 5 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 src/stores/order/OrderStore.ts diff --git a/index.html b/index.html index f7b05732..5b03499b 100644 --- a/index.html +++ b/index.html @@ -1,9 +1,9 @@ - + - - - + + + DailyOn @@ -11,3 +11,5 @@ + + diff --git a/src/App.vue b/src/App.vue index 9726054e..7b3db4a7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,7 +4,13 @@ import { computed, provide, ref } from 'vue' import HeaderComponent from '@/components/HeaderComponent.vue' import FooterComponent from '@/components/FooterComponent.vue' import { debounce } from 'lodash' - +declare global { + interface Window { + Kakao: any + } +} +const KAKAO_KEY = import.meta.env.VITE_KAKAO_KEY +window.Kakao.init(KAKAO_KEY) let isScrollEnd = ref(false) const route = useRoute() const displayHeader = computed(() => !route.path.startsWith('/order-success')) @@ -42,4 +48,4 @@ provide('isScrollEnd', isScrollEnd) display: flex; justify-content: center; } - \ No newline at end of file + diff --git a/src/stores/order/OrderStore.ts b/src/stores/order/OrderStore.ts new file mode 100644 index 00000000..744a89d6 --- /dev/null +++ b/src/stores/order/OrderStore.ts @@ -0,0 +1,22 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' +import type { OrderSheet } from '@/apis/order/orderDto' + +export const useOrderStore = defineStore( + 'order', + () => { + const order = ref() + + const setOrder = (orderInfo: any) => { + order.value = orderInfo + } + return { order, setOrder } + }, + { + persist: { + key: 'order', + storage: sessionStorage, + paths: ['order'] + } + } +) diff --git a/src/views/OrderResultView.vue b/src/views/OrderResultView.vue index 2e569f1f..0356b988 100644 --- a/src/views/OrderResultView.vue +++ b/src/views/OrderResultView.vue @@ -3,15 +3,41 @@ import { Result, Button } from 'ant-design-vue' import { useRoute } from 'vue-router' import { ref, onMounted } from 'vue' import { useProductStore } from '@/stores/product/ProductStore' +import { useMemberStore } from '@/stores/member/MemberStore' +import { useOrderStore } from '@/stores/order/OrderStore' import { getMember } from '@/apis/member/member' import router from '@/router' +import { storeToRefs } from 'pinia' + +const baseImgUrl = import.meta.env.VITE_STATIC_IMG_URL +const memberStore = useMemberStore() +const orderStore = useOrderStore() const productStore = useProductStore() const route = useRoute() const orderId = ref(route.params.orderId) +const { order } = storeToRefs(orderStore) +const { orderType } = storeToRefs(productStore) onMounted(async () => { - productStore.deletePinia() + // productStore.deletePinia() await getMember() }) +const kakao = () => { + console.log(baseImgUrl + order.value.imgUrl) + window.Kakao.Link.sendCustom({ + templateId: 103359, + templateArgs: { + nickname: memberStore.nickname, + productsName: order.value.productName, + receiver: order.value.receiver, + postCode: order.value.postCode, + roadAddress: order.value.roadAddress, + detailAddress: order.value.detailAddress, + imgUrl: baseImgUrl + order.value.imgUrl + '?w=480&h=480&q=95&f=jpg', + productPrice: order.value.totalOrderPrice, + productId: order.value.productId + } + }) +} diff --git a/src/views/OrderView.vue b/src/views/OrderView.vue index 396d6171..b400cc31 100644 --- a/src/views/OrderView.vue +++ b/src/views/OrderView.vue @@ -12,9 +12,11 @@ import { storeToRefs } from 'pinia' import { useProductStore } from '@/stores/product/ProductStore' import { useMemberStore } from '@/stores/member/MemberStore' import { useNotificationStore } from '@/stores/notification/NotificationStore' +import { useOrderStore } from '@/stores/order/OrderStore' import router from '@/router' import { warningModal } from '@/utils/Modal' const productStore = useProductStore() +const orderStore = useOrderStore() const { products, orderType, giftInfo, referralCode, auctionId } = storeToRefs(productStore) const { point } = storeToRefs(useMemberStore()) @@ -37,7 +39,6 @@ const totalDiscountAmount = computed((): number => { return prev + (current.discountAmount ? current.discountAmount : 0) }, 0) }) - const usedPoints = ref(0) const usePoints = async () => { usedPoints.value = Math.min(Number(point.value), totalOrderPrice.value) @@ -112,7 +113,17 @@ const doOrder = async () => { auctionId: auctionId.value } redirectUrl.value = await order(orderSheet) - + const orderInfo = { + productName: products.value[0].productName, + imgUrl: products.value[0].imgUrl, + receiver: deliveryInfo.value.receiver, + postCode: deliveryInfo.value.postCode, + roadAddress: deliveryInfo.value.roadAddress, + detailAddress: deliveryInfo.value.detailAddress, + productPrice: totalOrderPrice.value, + productId: products.value[0].productId + } + orderStore.setOrder(orderInfo) if (redirectUrl.value) { const width = 500 const height = 500 From bad98cccbd48e0cba922934ff09eb63d7b580a0c Mon Sep 17 00:00:00 2001 From: wakkpu Date: Wed, 24 Jan 2024 12:28:10 +0900 Subject: [PATCH 2/3] [FEAT] search with gpt --- src/apis/product/ProductClient.ts | 27 +++ src/apis/product/ProductDto.ts | 4 + src/components/HeaderComponent.vue | 5 +- src/components/SpinnerComponent.vue | 26 +++ src/router/index.ts | 9 +- src/views/ProductListView.vue | 6 +- src/views/ProductSearchView.vue | 264 ++++++++++++++++++++++++++++ 7 files changed, 331 insertions(+), 10 deletions(-) create mode 100644 src/components/SpinnerComponent.vue create mode 100644 src/views/ProductSearchView.vue diff --git a/src/apis/product/ProductClient.ts b/src/apis/product/ProductClient.ts index 1e1336d5..a746596b 100644 --- a/src/apis/product/ProductClient.ts +++ b/src/apis/product/ProductClient.ts @@ -3,6 +3,7 @@ import { defaultAxiosInstance } from '@/apis/utils' import type { ReadCacheProductListResponse, ReadProductDetailResponse, + ReadProductSearchResponse, ReadProductSliceResponse } from '@/apis/product/ProductDto' import { openInternalServerErrorNotification } from '@/utils/Toast' @@ -11,6 +12,32 @@ import { warningModal } from '@/utils/Modal' const PRODUCT_SERVICE_PREFIX: string = '/product-service' const PRODUCT_PREFIX: string = '/products' +export const searchProducts = async (query: string): Promise => { + try { + const { data } = await defaultAxiosInstance.get( + `${PRODUCT_SERVICE_PREFIX}${PRODUCT_PREFIX}/search`, + { + params: { query: query } + } + ) + return data + } catch (error) { + if (error instanceof AxiosError) { + if (error.response) { + if (error.response.status >= 400 && error.response.status < 500) { + await warningModal('알림', error.response.data.message) + console.error(`Client Error=${error.response.data.message}`) + } + if (error.response.status >= 500) { + openInternalServerErrorNotification() + console.error('Internal Server Error') + } + } + } + throw error + } +} + export const getProductSlice = async ( brandId: number | null, categoryId: number | null, diff --git a/src/apis/product/ProductDto.ts b/src/apis/product/ProductDto.ts index d23a6e37..57b58b85 100644 --- a/src/apis/product/ProductDto.ts +++ b/src/apis/product/ProductDto.ts @@ -3,6 +3,10 @@ export interface ReadProductSliceResponse { productResponses: ReadProductResponse[] } +export interface ReadProductSearchResponse { + productResponses: ReadProductResponse[] +} + export interface ExtendedReadProductResponse extends ReadProductResponse { categoryId: number } diff --git a/src/components/HeaderComponent.vue b/src/components/HeaderComponent.vue index 8f6b8869..c37c34b3 100644 --- a/src/components/HeaderComponent.vue +++ b/src/components/HeaderComponent.vue @@ -17,7 +17,6 @@ const notificationStore = useNotificationStore() const { notifications, unreadNotificationCount } = storeToRefs(notificationStore) const memberStore = useMemberStore() -// const { } = storeToRefs(memberStore) const categoryStore = useCategoryStore() const brandStore = useBrandStore() @@ -46,7 +45,7 @@ const routeSearch = () => { if (searchQuery.value === null) { infoModal('알림', '검색 키워드를 입력해주세요.') } else { - window.location.href = `/product-list?query=${searchQuery.value}` + window.location.href = `/product-search?query=${searchQuery.value}` searchQuery.value = null } } @@ -275,4 +274,4 @@ onMounted(async () => { \ No newline at end of file + diff --git a/src/components/SpinnerComponent.vue b/src/components/SpinnerComponent.vue new file mode 100644 index 00000000..4e2353ab --- /dev/null +++ b/src/components/SpinnerComponent.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/src/router/index.ts b/src/router/index.ts index 0c020b4b..34353963 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -26,6 +26,11 @@ const router = createRouter({ name: 'productList', component: () => import('@/views/ProductListView.vue') }, + { + path: '/product-search', + name: 'productSearch', + component: () => import('@/views/ProductSearchView.vue') + }, { path: '/products/:id', name: 'productDetails', @@ -223,8 +228,8 @@ router.beforeEach((to, from, next) => { }) const isLoggedIn = () => { - const token = localStorage.getItem('accessToken') - return !!token + const token = localStorage.getItem('accessToken') + return !!token } export default router diff --git a/src/views/ProductListView.vue b/src/views/ProductListView.vue index 010c16cb..d31ea827 100644 --- a/src/views/ProductListView.vue +++ b/src/views/ProductListView.vue @@ -36,10 +36,6 @@ const initData = async () => { categoryId.value = Number(route.query.category) } - if (route.query.query) { - query.value = String(route.query.query) - } - const response: ReadProductSliceResponse = await getProductSlice( brandId.value, categoryId.value, @@ -643,4 +639,4 @@ const getProductMaxDiscountPercentage = (product: ReadProductResponse) => { width: 10vw; height: 19.5vh; } - \ No newline at end of file + diff --git a/src/views/ProductSearchView.vue b/src/views/ProductSearchView.vue new file mode 100644 index 00000000..c6e0bdf7 --- /dev/null +++ b/src/views/ProductSearchView.vue @@ -0,0 +1,264 @@ + + + + + From d12996c90c4bc9aa80e088c9eefde1f1fcc54d56 Mon Sep 17 00:00:00 2001 From: wakkpu Date: Wed, 24 Jan 2024 12:30:27 +0900 Subject: [PATCH 3/3] [FIX] type error --- src/views/ProductSearchView.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/ProductSearchView.vue b/src/views/ProductSearchView.vue index c6e0bdf7..a7cfcdc2 100644 --- a/src/views/ProductSearchView.vue +++ b/src/views/ProductSearchView.vue @@ -11,7 +11,7 @@ const VITE_STATIC_IMG_URL = ref(import.meta.env.VITE_STATIC_IMG_URL) const route = useRoute() -const query = ref(null) +const query = ref('') const products = ref([]) const loading = ref(true)