feat(customer-vue): 알림 체크박스 및 개수 화면 구현

- 알림 페이지 체크박스 클릭 시 읽음 처리 및 읽음 해제 처리
- App bar 읽지 않은 알림 개수 표시
- 알림 읽었을 시에
앱바 알림 개수 연동
This commit is contained in:
bum12ark
2022-03-10 10:43:38 +09:00
parent d385f5b22a
commit 9426f03cc8
4 changed files with 49 additions and 20 deletions

View File

@@ -1,9 +1,19 @@
import axios from "axios";
const url = process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL + "/notification-service/notification";
const url = process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL + "/notification-service";
export default {
requestNotification() {
return axios.get(url);
return axios.get(url + "/notifications");
},
patchNotification(id, isRead) {
const body = {
read: isRead
}
return axios.patch(url + "/notification/" + id, body)
},
countsNotification() {
return axios.get(url + "/api/notification/counts");
}
}

View File

@@ -20,8 +20,8 @@
@click="goNotification"
>
<v-badge
:content="notificationCount"
:value="notificationCount"
:content="notificationCounts"
:value="notificationCounts"
color="orange"
overlap
>
@@ -34,17 +34,9 @@
<script>
export default {
name: "AppNavigation",
mounted() {
console.log("[AppNavigation] mounted!");
},
data: function() {
return {
notificationCount: 0
}
},
props: ["notificationCounts"],
methods: {
goNotification: function() {
console.log("여기!");
this.$router.push('/notification');
}
}

View File

@@ -1,9 +1,12 @@
<template>
<v-app>
<app-navigation></app-navigation>
<app-navigation
v-bind:notificationCounts="notificationCounts"></app-navigation>
<v-main>
<v-container class="px-8 py-8">
<router-view></router-view>
<router-view
v-on:plusCount="notificationCounts++"
v-on:minusCount="notificationCounts--"></router-view>
</v-container>
</v-main>
<bottom-navigation></bottom-navigation>
@@ -13,12 +16,27 @@
<script>
import AppNavigation from "../../components/AppNavigation.vue";
import BottomNavigation from "../../components/BottomNavigation.vue";
import notificationApi from "../../api/notification";
export default {
name: "HomeLayout",
components: {
'app-navigation': AppNavigation,
"bottom-navigation": BottomNavigation
},
mounted() {
this.searchNotificationCounts();
},
data: function() {
return {
notificationCounts: 0
}
},
methods: {
searchNotificationCounts: async function() {
const response = await notificationApi.countsNotification();
this.notificationCounts = response.data.data;
}
}
}
</script>

View File

@@ -16,13 +16,13 @@
<v-list-item-action>
<v-checkbox
disabled
v-if="item.read"
v-if="item.prevRead"
v-model="item.read"
hide-details></v-checkbox>
<v-checkbox
v-else
v-model="item.read"
@click="clickRead(item.id)"
@click="clickRead(item.id, item.read)"
hide-details></v-checkbox>
</v-list-item-action>
</v-list-item>
@@ -35,7 +35,7 @@
</template>
<script>
import notificationApi from "../api/notification";
import notificationApi from "@/api/notification";
export default {
name: "NotificationView",
@@ -59,12 +59,21 @@ export default {
id: notification.id,
message: notification.message,
title: notification.title,
prevRead: notification.read,
read: notification.read
});
});
},
clickRead: function(id) {
console.log("clickRead", id);
clickRead: async function(id, isRead) {
await notificationApi.patchNotification(id, isRead);
if (isRead) {
alert("해당 알림은 읽음 처리되었습니다.");
this.$emit("minusCount");
} else {
alert("해당 알림은 읽음 해제 처리되었습니다.");
this.$emit("plusCount");
}
}
}
}