diff --git a/src/front/src/components/UI/NewsCard.vue b/src/front/src/components/UI/NewsCard.vue index 7a32119b6..0003a4f1e 100755 --- a/src/front/src/components/UI/NewsCard.vue +++ b/src/front/src/components/UI/NewsCard.vue @@ -1,129 +1,106 @@ - - - {{ news.title }} - - - - + + + + - - + + + + + + + + + + + + + + Без фото + - - + + {{ formatDate(news.cdate) }} + + + + - - - - - - {{ news.scores.filter(e => e.score == true).length }} - - - · - - - - {{ news.scores.filter(e => e.score == false).length }} - - - · - - - - {{ news.comment.length }} - - - · - - - - {{ news.gallery.length }} - - + - - - - - - + {{ news.title }} - - Без - описания - - - - - - - - - Подробнее - - {{ formatDate(news.cdate) }} - - + + + Нет описания + + + + + + + + + + {{ isLiked(true) ? 'mdi-thumb-up' : 'mdi-thumb-up-outline' }} + + {{ news.scores.filter(e => e.score === true).length }} + + + + + {{ isLiked(false) ? 'mdi-thumb-down' : 'mdi-thumb-down-outline' }} + + {{ news.scores.filter(e => e.score === false).length }} + + + + mdi-message-text-outline + {{ news.comment.length }} + + + + mdi-image-outline + {{ news.gallery.length }} + + + + + Подробнее + + + + + + + - - diff --git a/src/front/src/components/news-full.vue b/src/front/src/components/news-full.vue index 3eb034173..8bf75c5d1 100755 --- a/src/front/src/components/news-full.vue +++ b/src/front/src/components/news-full.vue @@ -1,441 +1,227 @@ - - - - - - - - - - {{ newsFull.title }} - - - - - - - - - {{ newsFull.comment.length }} - - - Чат - - - - - - - - {{ newsFull.gallery.length }} - - - Галерея - - - - - - + - - - - - - - - - - - - - - - - - {{ - newsFull.scores.filter((e) => e.score == true).length - }} - - · + + - - - {{ - newsFull.scores.filter((e) => e.score == false).length - }} - - - - - - - - - - - - - Без описания - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{ e.likes.length }} - - - - - - - - У новости нет фотографий - - - - - - + + + {{ newsFull.title }} - - - - + + mdi-message-text-outline + {{ newsFull.comment.length }} + Комментарии + + + mdi-image-outline + {{ newsFull.gallery.length }} + Галерея + + + + + + + + + + + + + + + + + + + + Без фото + + + + + + + + + + + + + {{ isLiked(true) ? 'mdi-thumb-up' : 'mdi-thumb-up-outline' }} + + {{ newsFull.scores.filter(e => e.score === true).length }} + + + + {{ isLiked(false) ? 'mdi-thumb-down' : 'mdi-thumb-down-outline' }} + + {{ newsFull.scores.filter(e => e.score === false).length }} + + + + + + + + Нет описания + + + + + + + + + + + + + - - - - - - {{ - accountStore.user.login == y.author.login - ? "" - : splitname(y.author) - }} - - - {{ dateformat(y.cdate) }} - - - {{ - accountStore.user.login != y.author.login - ? "" - : splitname(y.author) - }} - - + + {{ heartIcoAll(e) ? 'mdi-heart' : 'mdi-heart-outline' }} + + {{ e.likes.length }} + + + + + В галерее нет изображений + - - - - - {{ y.text }} - - - - - - - - - - - - + + + + + + + {{ splitname(y.author) }} + + {{ dateformat(y.cdate) }} + + + {{ y.text }} + - Оставьте первый комментарий - - - - - - - - - - - - - - - - - + + + + + mdi-send + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{ galleryimges.likes.length }} - - - + + + + + mdi-close + + + + mdi-chevron-left + + + + mdi-chevron-right + + + + + {{ heartIco() ? 'mdi-heart' : 'mdi-heart-outline' }} + {{ galleryimges.likes?.length }} + + + - - - - - - - - - - - - - + + + + + mdi-close + + + + + @@ -450,7 +236,6 @@ import { spravURL } from "@/utils/axios-api"; import { useAccountStore } from "@/store/AccountStore"; import { format } from "date-fns"; import icoUser from "@/components/UI/fiousercard/icoUser.vue"; -import defaultImage from '@/assets/emblem.png'; const accountStore = useAccountStore(); @@ -458,167 +243,598 @@ export default { components: { icoUser }, setup() { - const textcomment = ref(""); - const route = useRoute(); - const newsFull = ref([]); - const gallery = ref(false); - - const burl = baseURL.slice(0, -1); + const textcomment = ref(''); + const route = useRoute(); + const newsFull = ref([]); + const gallery = ref(false); + const imgError = ref(false); + const burl = baseURL.slice(0, -1); const loadNews = () => { axiosApiInstance .get(`api/navigation/newscrossroad/?id=${route.query.id}`) - .then((result) => { + .then(result => { newsFull.value = result.data.result[0]; - - if (newsFull.value.gallery.length > 0) { - gallery.value = true; - } + if (newsFull.value.gallery.length > 0) gallery.value = true; }); }; - loadNews(); - const splitname = (name) => { - return ( - name.familyname + " " + name.name[0] + "." + name.parentname[0] + "." + const isLiked = (score) => + newsFull.value.scores?.some( + e => e.user === accountStore.user.login && e.score === score ); - }; - const formatText = (text) => { - return text.replaceAll( - 'src="/media/uploads', - `src="${baseURL}media/uploads` - ); - }; + const splitname = (name) => + `${name.familyname} ${name.name[0]}.${name.parentname[0]}.`; - const dateformat = (datas) => { - return format(new Date(datas), "dd.MM.yyyy HH:mm"); - }; + const formatText = (text) => + text.replaceAll('src="/media/uploads', `src="${baseURL}media/uploads`); - const addComment = (idnew) => { + const dateformat = (d) => format(new Date(d), 'dd.MM.yyyy HH:mm'); + + const addComment = (id) => { axiosApiInstance - .post(`api/navigation/newscrossroad/`, { - news: idnew, - text: textcomment.value, - }) - .then((result) => { - newsFull.value.comment = result.data.comment; - }); - textcomment.value = ""; + .post('api/navigation/newscrossroad/', { news: id, text: textcomment.value }) + .then(r => { newsFull.value.comment = r.data.comment; }); + textcomment.value = ''; }; const deletComment = (id, news) => { axiosApiInstance - .post(`api/navigation/newscrossroad/`, { delid: id, news: news }) - .then((result) => { - newsFull.value.comment = result.data.comment; - }); + .post('api/navigation/newscrossroad/', { delid: id, news }) + .then(r => { newsFull.value.comment = r.data.comment; }); }; - const heartIcoAll = (image) => { - return ( - image.likes.filter((e) => e.user == accountStore.user.login).length == 1 - ); - }; + const heartIcoAll = (image) => + image.likes.filter(e => e.user === accountStore.user.login).length === 1; - // ------------------------------ Галерея - const galleryimges = ref([]); - const dialogfoto = ref(false); + const galleryimges = ref({}); + const dialogfoto = ref(false); const dialogfotoOne = ref(false); - const indximg = ref(""); + const indximg = ref(0); const openImg = (idimg) => { + indximg.value = newsFull.value.gallery.findIndex(e => e.id === idimg); + galleryimges.value = newsFull.value.gallery[indximg.value]; dialogfoto.value = true; - indximg.value = newsFull.value.gallery.findIndex((e) => e.id == idimg); }; - const openOneImg = (idimg) => { + const openOneImg = (link) => { + if (!link) return; + galleryimges.value = link; dialogfotoOne.value = true; - galleryimges.value = idimg; }; - watch( - () => indximg, - (newValue, oldValue) => { - if (newValue) { - galleryimges.value = newsFull.value.gallery[newValue.value]; - } - }, - { deep: true } - ); - - // Лайки на фотографии + watch(indximg, (val) => { + galleryimges.value = newsFull.value.gallery[val]; + }); const toggleLike = (idimage) => { axiosApiInstance - .post(`api/navigation/gallery/`, { image: idimage }) - .then((result) => { - galleryimges.value.likes = result.data; - }); + .post('api/navigation/gallery/', { image: idimage }) + .then(r => { galleryimges.value.likes = r.data; }); }; const toggleLikeAll = (idimage) => { axiosApiInstance - .post(`api/navigation/gallery/`, { image: idimage }) - .then((result) => { - newsFull.value.gallery.filter((e) => e.id == idimage)[0].likes = - result.data; + .post('api/navigation/gallery/', { image: idimage }) + .then(r => { + newsFull.value.gallery.find(e => e.id === idimage).likes = r.data; }); }; - const heartIco = () => { - return ( - galleryimges.value.likes.filter( - (e) => e.user == accountStore.user.login - ).length == 1 - ); - }; + + const heartIco = () => + galleryimges.value.likes?.filter( + e => e.user === accountStore.user.login + ).length === 1; const toggleIncrementLike = (news, scores) => { axiosApiInstance - .post(`api/navigation/newscrossroad/`, { news: news, scores: scores }) - .then((result) => { - newsFull.value.scores = result.data; - }); + .post('api/navigation/newscrossroad/', { news, scores }) + .then(r => { newsFull.value.scores = r.data; }); }; return { - route, - newsFull, - gallery, - burl, - checkremote, - spravURL, - splitname, - accountStore, - defaultImage, - formatText, - dateformat, - textcomment, - addComment, - deletComment, - heartIcoAll, - heartIco, - toggleLikeAll, - toggleLike, - openImg, - dialogfoto, - galleryimges, - indximg, - toggleIncrementLike, - openOneImg, - dialogfotoOne, + route, newsFull, gallery, imgError, burl, + checkremote, spravURL, splitname, accountStore, + formatText, dateformat, textcomment, + addComment, deletComment, + heartIcoAll, heartIco, + toggleLikeAll, toggleLike, + openImg, dialogfoto, galleryimges, indximg, + toggleIncrementLike, openOneImg, dialogfotoOne, + isLiked, }; }, }; - diff --git a/src/front/src/views/NewsPage.vue b/src/front/src/views/NewsPage.vue index 84a983bac..9e72beae1 100755 --- a/src/front/src/views/NewsPage.vue +++ b/src/front/src/views/NewsPage.vue @@ -27,9 +27,17 @@ export default {