Poll
This commit is contained in:
@@ -15,14 +15,14 @@ const store = reactive({
|
|||||||
});
|
});
|
||||||
const { currentPoll } = storeToRefs(store.poll);
|
const { currentPoll } = storeToRefs(store.poll);
|
||||||
const { currentPollOptions } = storeToRefs(store.pollOptions);
|
const { currentPollOptions } = storeToRefs(store.pollOptions);
|
||||||
const { currentPollResponses } = storeToRefs(store.pollResponse);
|
// const { currentPollResponses } = storeToRefs(store.pollResponse);
|
||||||
const poll = reactive<Poll | any>({});
|
const poll = reactive<Poll | any>({});
|
||||||
const options = ref<PollOption[] | any[]>([]);
|
const options = ref<PollOption[] | any[]>([]);
|
||||||
|
|
||||||
async function loadData() {
|
async function loadData() {
|
||||||
await store.poll.fetchById(String(props.dataId));
|
await store.poll.fetchById(String(props.dataId));
|
||||||
await store.pollOptions.fetchByPollId(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();
|
assignData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +78,8 @@ async function submitVote() {
|
|||||||
switch (poll.type) {
|
switch (poll.type) {
|
||||||
case 1:
|
case 1:
|
||||||
if(singleSelect.value >= 0) {
|
if(singleSelect.value >= 0) {
|
||||||
|
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);
|
totalResponses.value = options.value?.reduce((sum, option) => sum + Number(option.responseCount ?? 0), 1);
|
||||||
options?.value?.forEach((option: PollOption | any) => {
|
options?.value?.forEach((option: PollOption | any) => {
|
||||||
if (option.id === singleSelect.value) {
|
if (option.id === singleSelect.value) {
|
||||||
@@ -88,6 +90,7 @@ async function submitVote() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ export default defineNuxtConfig({
|
|||||||
|
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
public: {
|
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",
|
site: process.env.NUXT_PUBLIC_SITE_DEFAULT || "1",
|
||||||
},
|
},
|
||||||
authSecret: process.env.AUTH_SECRET||"vpress"
|
authSecret: process.env.AUTH_SECRET||"vpress"
|
||||||
|
|||||||
@@ -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";
|
import DynamicSection from "~/components/dynamic-page/page-section/templates/index.vue";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const site = useCookie("site")
|
||||||
const store = reactive({
|
const store = reactive({
|
||||||
dynamicPage: useDynamicPageStore(),
|
dynamicPage: useDynamicPageStore(),
|
||||||
article: useArticleStore(),
|
article: useArticleStore(),
|
||||||
@@ -20,7 +20,7 @@ import { useArticleStore } from '~/stores/articles';
|
|||||||
|
|
||||||
const loadPage = async () => {
|
const loadPage = async () => {
|
||||||
const article = await store.article.getArticleBySlug(String(route.params.slug));
|
const article = await store.article.getArticleBySlug(String(route.params.slug));
|
||||||
console.log(article?.value, 'article')
|
site.value = article?.value.siteId
|
||||||
let isContentType
|
let isContentType
|
||||||
switch (article?.value?.contentType) {
|
switch (article?.value?.contentType) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
+2
-2
@@ -11,12 +11,12 @@ const store = reactive({
|
|||||||
});
|
});
|
||||||
//lấy danh sách categoryTree
|
//lấy danh sách categoryTree
|
||||||
await store.category.fetchBySiteId()
|
await store.category.fetchBySiteId()
|
||||||
|
const site = useCookie('site')
|
||||||
const { data } = await useAsyncData('index', () => store.dynamicPage.fetchPageByCode(route.path === '/' ? 'trang-chu' : route.path.replace('/', '')))
|
const { data } = await useAsyncData('index', () => store.dynamicPage.fetchPageByCode(route.path === '/' ? 'trang-chu' : route.path.replace('/', '')))
|
||||||
const asycnCurrentPage = data.value && data.value.currentPage;
|
const asycnCurrentPage = data.value && data.value.currentPage;
|
||||||
const asycnSectionPublished = data.value && data.value.sectionPublished;
|
const asycnSectionPublished = data.value && data.value.sectionPublished;
|
||||||
const asycnComponentPublished = data.value && data.value.componentPublished;
|
const asycnComponentPublished = data.value && data.value.componentPublished;
|
||||||
|
site.value = data.value?.currentPage?.siteId
|
||||||
useHead({
|
useHead({
|
||||||
title: () => 'Trang chủ',
|
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í.',
|
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í.',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { H3Event } from 'h3';
|
import { H3Event } from 'h3';
|
||||||
import Base from './base'
|
import Base from './base'
|
||||||
|
import { useCookie } from 'nuxt/app';
|
||||||
|
|
||||||
export type PollOption = {
|
export type PollOption = {
|
||||||
id?: number; // Mã định danh
|
id?: number; // Mã định danh
|
||||||
@@ -22,8 +23,8 @@ export type PollOption = {
|
|||||||
const { items }: PollOption[] | any = await $fetch(`${apiUrl}/cms/poll-option/poll:${pollId}`, {
|
const { items }: PollOption[] | any = await $fetch(`${apiUrl}/cms/poll-option/poll:${pollId}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
site: 1
|
site: Number(useCookie('site').value)
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { H3Event } from 'h3';
|
import { H3Event } from 'h3';
|
||||||
import Base from './base'
|
import Base from './base'
|
||||||
|
import { useCookie } from 'nuxt/app';
|
||||||
|
|
||||||
export type PollResponse = {
|
export type PollResponse = {
|
||||||
id?: number; // Mã định danh
|
id?: number; // Mã định danh
|
||||||
@@ -18,7 +19,7 @@ export const create = async (event: H3Event) => {
|
|||||||
const { item }: any = await $fetch(`${apiUrl}/cms/poll-response`, {
|
const { item }: any = await $fetch(`${apiUrl}/cms/poll-response`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
site: 1
|
site: Number(useCookie('site').value)
|
||||||
},
|
},
|
||||||
body: payload
|
body: payload
|
||||||
})
|
})
|
||||||
@@ -32,14 +33,13 @@ export const create = async (event: H3Event) => {
|
|||||||
|
|
||||||
export const fetchByPollId = async (event: H3Event) => {
|
export const fetchByPollId = async (event: H3Event) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const { apiUrl } = useRuntimeConfig().public
|
const { apiUrl } = useRuntimeConfig().public
|
||||||
const { pollId }: any = getQuery(event)
|
const { pollId }: any = getQuery(event)
|
||||||
const { items }: PollResponse[] | any = await $fetch(`${apiUrl}/cms/poll-response/poll:${pollId}`, {
|
const { items }: PollResponse[] | any = await $fetch(`${apiUrl}/cms/poll-response/poll:${pollId}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
site: 1
|
site: Number(useCookie('site').value)
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|||||||
Reference in New Issue
Block a user