This commit is contained in:
nguyen van thai
2024-07-16 22:54:15 +07:00
parent 6f571d9549
commit 5f9525371d
6 changed files with 24 additions and 20 deletions
+12 -9
View File
@@ -15,14 +15,14 @@ const store = reactive({
});
const { currentPoll } = storeToRefs(store.poll);
const { currentPollOptions } = storeToRefs(store.pollOptions);
const { currentPollResponses } = storeToRefs(store.pollResponse);
// const { currentPollResponses } = storeToRefs(store.pollResponse);
const poll = reactive<Poll | any>({});
const options = ref<PollOption[] | any[]>([]);
async function loadData() {
await store.poll.fetchById(String(props.dataId));
await store.pollOptions.fetchByPollId(String(props.dataId));
await store.pollResponse.fetchByPollId(String(props.dataId));
// await store.pollResponse.fetchByPollId(String(props.dataId));
assignData();
}
@@ -78,14 +78,17 @@ async function submitVote() {
switch (poll.type) {
case 1:
if(singleSelect.value >= 0) {
totalResponses.value = options.value?.reduce((sum, option) => sum + Number(option.responseCount ?? 0), 1);
options?.value?.forEach((option: PollOption | any) => {
if (option.id === singleSelect.value) {
option.responseCount = (option.responseCount ?? 0) + 1;
const result = await store.pollResponse.create({ optionId: singleSelect.value })
if(result?.id) {
totalResponses.value = options.value?.reduce((sum, option) => sum + Number(option.responseCount ?? 0), 1);
options?.value?.forEach((option: PollOption | any) => {
if (option.id === singleSelect.value) {
option.responseCount = (option.responseCount ?? 0) + 1;
}
option.percentage = Number(((option.responseCount / totalResponses.value) * 100).toFixed(1));
alreadyVoted.value = true
});
}
option.percentage = Number(((option.responseCount / totalResponses.value) * 100).toFixed(1));
alreadyVoted.value = true
});
}
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ export default defineNuxtConfig({
runtimeConfig: {
public: {
apiUrl: "http://uat-api-portal.vpress.vn/api-v1",
apiUrl: "http://api-portal.vpress.vn/api-v1",
site: process.env.NUXT_PUBLIC_SITE_DEFAULT || "1",
},
authSecret: process.env.AUTH_SECRET||"vpress"
+2 -2
View File
@@ -9,7 +9,7 @@ import DynamicTemplate from "~/components/dynamic-page/page/templates/index.vue"
import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue";
const route = useRoute();
const site = useCookie("site")
const store = reactive({
dynamicPage: useDynamicPageStore(),
article: useArticleStore(),
@@ -20,7 +20,7 @@ import { useArticleStore } from '~/stores/articles';
const loadPage = async () => {
const article = await store.article.getArticleBySlug(String(route.params.slug));
console.log(article?.value, 'article')
site.value = article?.value.siteId
let isContentType
switch (article?.value?.contentType) {
case 1:
+2 -2
View File
@@ -11,12 +11,12 @@ const store = reactive({
});
//lấy danh sách categoryTree
await store.category.fetchBySiteId()
const site = useCookie('site')
const { data } = await useAsyncData('index', () => store.dynamicPage.fetchPageByCode(route.path === '/' ? 'trang-chu' : route.path.replace('/', '')))
const asycnCurrentPage = data.value && data.value.currentPage;
const asycnSectionPublished = data.value && data.value.sectionPublished;
const asycnComponentPublished = data.value && data.value.componentPublished;
site.value = data.value?.currentPage?.siteId
useHead({
title: () => 'Trang chủ',
description: () => 'Với công nghệ đột phá và giải pháp sáng tạo, Vpress sẽ là đối tác tin cậy của các tòa soạn báo, cùng nhau kiến tạo nên những giá trị bền vững trong kỷ nguyên chuyển đổi số báo chí.',
+3 -2
View File
@@ -1,5 +1,6 @@
import { H3Event } from 'h3';
import Base from './base'
import { useCookie } from 'nuxt/app';
export type PollOption = {
id?: number; // Mã định danh
@@ -22,8 +23,8 @@ export type PollOption = {
const { items }: PollOption[] | any = await $fetch(`${apiUrl}/cms/poll-option/poll:${pollId}`, {
method: 'GET',
headers: {
site: 1
}
site: Number(useCookie('site').value)
},
})
return items
+4 -4
View File
@@ -1,5 +1,6 @@
import { H3Event } from 'h3';
import Base from './base'
import { useCookie } from 'nuxt/app';
export type PollResponse = {
id?: number; // Mã định danh
@@ -18,7 +19,7 @@ export const create = async (event: H3Event) => {
const { item }: any = await $fetch(`${apiUrl}/cms/poll-response`, {
method: 'POST',
headers: {
site: 1
site: Number(useCookie('site').value)
},
body: payload
})
@@ -32,14 +33,13 @@ export const create = async (event: H3Event) => {
export const fetchByPollId = async (event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const { pollId }: any = getQuery(event)
const { items }: PollResponse[] | any = await $fetch(`${apiUrl}/cms/poll-response/poll:${pollId}`, {
method: 'GET',
headers: {
site: 1
}
site: Number(useCookie('site').value)
},
})
return items