Files
PORTAL_COD2/src/front/src/components/news-list-news.vue
T

950 lines
34 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<v-row class="justify-center">
<v-col
v-if="route.path == '/news' && 'id' in route.query?false:true"
class="flex-column"
lg="6"
>
<div class="d-flex flex-column py-3 h-100 ">
<v-row class=" flex-grow-1 d-flex h-0 overflow-auto">
<v-col class="pa-0 ">
<v-card
class=" rounded-0"
v-for="(x, i) in newss.result" :key=i
>
<v-card-title class="pt-0 pb-1">
{{x.title}}
</v-card-title>
<!-- :to='`/news?id=${x.id}`' -->
<v-btn
color="more_details_btn"
variant="text"
@click="nextnews(x.id)"
size="small"
append-icon="mdi-step-forward-2"
>
Подробнее
</v-btn>
<v-img
:src="`${burl}${x.link}`"
height="350px"
width="96%"
class="mx-auto"
cover
/>
<v-list-item class="w-100">
<template v-slot:prepend>
<v-avatar
color="loading_avatar"
:image="checkremote( `${spravURL}${x.author.login}.jpg`)"
size="25"
>
</v-avatar>
<v-list-item-title class="text-caption">{{splitname(x.author)}}</v-list-item-title>
</template>
<template v-slot:append>
<div class="justify-self-end">
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'" @click="toggleIncrementLike(x.id, true)"></v-icon>
<span class="subheading me-2">{{x.scores.filter(e=> e.score==true).length}}</span>
<span class="me-1">·</span>
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == false).length>0?'mdi-thumb-down':'mdi-thumb-down-outline'" @click="toggleIncrementLike(x.id, false)"/>
<span class="subheading me-2">{{x.scores.filter(e=> e.score==false).length}}</span>
<span class="me-1">·</span>
<v-icon class="me-1" icon="mdi-message-text-outline" @click="openComent(x.id)"/>
<span @click="x.showComment=!x.showComment" class="pointer subheading">{{ x.comment.length }}</span>
</div>
</template>
</v-list-item>
<div >
<v-divider/>
<v-card-text>
<div v-html=formatText(x.text)>
</div>
</v-card-text>
<v-divider/>
<v-expand-transition>
<div v-show="x.showComment" v-if="x.comment.length>0">
<div
v-for = "(y, key) in x.comment"
:key="key"
class="d-flex flex-column pa-3"
>
<v-row
class="justify-space-between ma-0 align-center bgchat mr-7"
:class="accountStore.user.login==y.author.login?'bgchatnot':'bgchat'"
>
<v-col class="flex-grow-1 text-subtitle-2 pl-2 pa-0 "
>
{{ accountStore.user.login==y.author.login?'':splitname(y.author) }}
</v-col>
<v-col class="pa-0 text-center text-subtitle-2 ">
{{dateformat(y.cdate)}}
</v-col>
<v-col class="pa-0 pr-2 text-end text-subtitle-2 ">
{{ accountStore.user.login!=y.author.login?'':splitname(y.author) }}
</v-col>
</v-row>
<div class="text-subtitle-2">
</div>
<v-row>
<v-col class="pr-0">
<v-alert
color="bg_white"
rounded=0
:border="accountStore.user.login==y.author.login?'end':'start'"
:border-color="accountStore.user.login==y.author.login?'success':'deep-purple accent-4'"
elevation=0
>
{{ y.text }}
</v-alert>
</v-col>
<v-col class="flex-grow-0 d-flex pa-0 align-center"
:class="accountStore.user.login==y.author.login?'pa-0':'pa-5'"
>
<v-btn
v-if="accountStore.user.login==y.author.login"
variant="text"
size="small"
icon='mdi-delete'
color="delete_btn"
@click="deletComment(y.id, x.id)"
/>
</v-col>
</v-row>
</div>
</div>
</v-expand-transition>
</div>
</v-card>
</v-col>
</v-row>
<v-row class="flex-grow-0" v-show="route.path == '/news' && 'id' in route.query?false:true">
<v-col class="ma-0 pa-0 pt-2">
<v-pagination
v-model="page"
:length="newss.allnews"
prev-icon="mdi-menu-left"
next-icon="mdi-menu-right"
@click="pagelistNews"
/>
</v-col>
<v-col class="ma-0 flex-grow-0 mwidth mt-1 pa-0">
<v-select
hide-details
density="compact"
v-model="selecnews"
variant="underlined"
:items="['10', '20', '30', '40', '100']"
/>
</v-col>
</v-row>
</div>
</v-col>
<v-col v-else class="flex-column d-flex" v-for="(x, i) in newss.result" :key=i>
<v-row>
<!-- <v-col class=" flex-column d-flex">
<v-row class="flex-grow-0">
<v-col class="pb-0 pr-0">
<v-card
height="350px"
class="rounded-b-0"
>
<v-card-title class="pt-0 pb-1 flex-column d-flex">
<v-row>
<v-col lg=10 class="pt-4"> {{x.title}}</v-col>
<v-col class="pa-0 pr-3 pt-1 flex-grow-1 d-flex flex-column flex-wrap " >
<v-switch v-model="gallery"
class="align-self-end comgal"
hide-details
>
<template v-slot:prepend>
<v-tooltip location="top">
<template v-slot:activator="{ props }">
<v-icon
v-bind="props"
icon='mdi-message-text-outline'
color="pink-darken-4"
/>
</template>
<span>Чат</span>
</v-tooltip>
</template>
<template v-slot:append>
<v-tooltip location="top">
<template v-slot:activator="{ props }">
<v-icon
v-bind="props"
:icon="'mdi-image'"
color="teal-darken-2"
/>
</template>
<span>Галерея</span>
</v-tooltip>
</template>
</v-switch>
</v-col>
</v-row>
</v-card-title>
<v-img
:src="`${burl}${x.link}`"
height="450px"
width="96%"
class="mx-auto"
cover
/>
</v-card>
</v-col>
</v-row>
<v-row>
<v-col class="pt-0 pr-0">
<v-card
class="rounded-t-0 flex-column d-flex h-100 "
>
<v-list-item class="w-100">
<template v-slot:prepend>
<v-avatar
color="loading_avatar"
:image="checkremote( `${spravURL}${x.author.login}.jpg`)"
size="25"
>
</v-avatar>
<v-list-item-title class="text-caption">{{splitname(x.author)}}</v-list-item-title>
</template>
<template v-slot:append>
<div class="justify-self-end">
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'" @click="toggleIncrementLike(x.id, true)"></v-icon>
<span class="subheading me-2">{{x.scores.filter(e=> e.score==true).length}}</span>
<span class="me-1">·</span>
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == false).length>0?'mdi-thumb-down':'mdi-thumb-down-outline'" @click="toggleIncrementLike(x.id, false)"/>
<span class="subheading me-2">{{x.scores.filter(e=> e.score==false).length}}</span>
<span class="me-1">·</span>
<v-icon class="me-1" icon="mdi-message-text-outline"/>
<span class="subheading">{{ x.comment.length }}</span>
</div>
</template>
</v-list-item>
<v-divider/>
<v-row class="ma-0 my-3 overflow-auto h-0">
<v-col class="pa-0">
<v-card-text class="pt-0">
<div v-if="x.text" v-html=formatText(x.text)>
</div>
<div v-else>
<v-row>
<v-col
class="text-h6 text-grey text-center align-self-center text--lighten-1 font-weight-light"
>
Без описания
</v-col>
</v-row>
</div>
</v-card-text>
</v-col>
</v-row>
</v-card>
</v-col>
</v-row>
</v-col>
<v-col class="flex-column d-flex "
>
<v-row
class="d-flex flex-column "
v-if="gallery"
>
<v-col class="d-flex flex-column">
<v-card
class="h-100 flex-column d-flex overflow-auto overflow-x-hidden"
>
<div
class="flex-column d-flex ma-3"
>
<v-row style="height:250px" class="justify-space-between " v-if="x.gallery.length>0">
<v-col
v-for="e in x.gallery" :key=e
:lg="Math.floor(Math.random() * (Math.floor(5) - Math.ceil(3)) + Math.ceil(2))"
class="flex-column d-flex pa-0 pb-3"
>
<div
class='h-100 w-100 flex-column d-flex'
>
<v-row>
<v-col class="d-flex">
<v-img
cover
class=" pointer"
:src="`${burl}${e.img}`"
@click="openImg(e.id)"
/>
</v-col>
</v-row>
<v-row class="flex-grow-0 mt-0 align-self-center ">
<v-col class="pa-0 flex-grow-0">
<v-btn
density="compact"
variant="text"
size="small"
:color="heartIcoAll(e)?'red':'black'"
:icon= "heartIcoAll(e)?'mdi-heart':'mdi-heart-outline'"
@click = toggleLikeAll(e.id)
/>
</v-col>
<v-col class="pa-0 pl-1" >
{{e.likes.length}}
</v-col>
</v-row>
</div>
</v-col>
</v-row>
<v-row v-else>
<v-col
class="text-h6 text-grey text-center align-self-center text--lighten-1 font-weight-light"
>
У новости нет фотографий
</v-col>
</v-row>
</div>
</v-card>
</v-col>
</v-row>
<v-row v-else>
<v-col class="">
<v-card
class="h-100 flex-column d-flex"
>
<v-row class="ma-0 my-3 overflow-auto h-0" v-if="x.comment.length>0">
<v-col class="pa-0">
<v-card-text class="pt-0">
<div
v-for = "(y, key) in x.comment"
:key="key"
class="d-flex flex-column pa-3"
>
<v-row
class="justify-space-between ma-0 align-center bgchat mr-7"
:class="accountStore.user.login==y.author.login?'bgchatnot':'bgchat'"
>
<v-col class="flex-grow-1 text-subtitle-2 pl-2 pa-0 "
>
{{ accountStore.user.login==y.author.login?'':splitname(y.author) }}
</v-col>
<v-col class="pa-0 text-center text-subtitle-2 ">
{{dateformat(y.cdate)}}
</v-col>
<v-col class="pa-0 pr-2 text-end text-subtitle-2 ">
{{ accountStore.user.login!=y.author.login?'':splitname(y.author) }}
</v-col>
</v-row>
<div class="text-subtitle-2">
</div>
<v-row>
<v-col class="pr-0">
<v-alert
color="bg_white"
rounded=0
:border="accountStore.user.login==y.author.login?'end':'start'"
:border-color="accountStore.user.login==y.author.login?'success':'deep-purple accent-4'"
elevation=0
>
{{ y.text }}
</v-alert>
</v-col>
<v-col class="flex-grow-0 d-flex pa-0 align-center"
:class="accountStore.user.login==y.author.login?'pa-0':'pa-5'"
>
<v-btn
v-if="accountStore.user.login==y.author.login"
variant="text"
size="small"
icon='mdi-delete'
color="delete_btn"
@click="deletComment(y.id, x.id)"
/>
</v-col>
</v-row>
</div>
</v-card-text>
</v-col>
</v-row>
<v-row v-else>
<v-col
class="text-h6 text-grey text-center align-self-center text--lighten-1 font-weight-light"
>
Оставьте первый комментарий
</v-col>
</v-row>
<v-divider/>
<v-row class="flex-grow-0 ma-1">
<v-col>
<v-textarea
label="Комментарий"
no-resize
variant="underlined"
rows="2"
row-height="25"
shaped
hide-details
v-model="textcomment"
/>
</v-col>
<v-col class="flex-grow-0 pl-0 py-0 align-self-center">
<v-btn
variant="text"
density="compact"
icon="mdi-google-play"
color="teal-darken-4"
:disabled="textcomment==''"
@click="addComment(x.id)"
/>
</v-col>
</v-row>
</v-card>
</v-col>
</v-row>
</v-col> -->
</v-row>
</v-col>
<v-dialog
v-model="dialogCommentShow"
persistent
width="550"
>
<v-card>
<v-card-title class="text-h5">
Прокоментировать новость
</v-card-title>
<v-card-text>
<v-textarea
variant="solo"
hide-details
rows="5"
v-model="textcomment"
></v-textarea>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="modal_btn"
variant="text"
@click="dialogCommentShow = false"
>
Отмена
</v-btn>
<v-btn
color="modal_btn"
variant="text"
@click="addComment(idnews)"
>
Отправить
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog
v-model="dialogfoto"
width="w-100"
height="900"
class="flex-column "
>
<v-card class="pa-4 h-100 flex-column d-flex">
<v-row class="flex-grow-0 justify-space-between">
<v-col class="py-0 flex-grow-0">
<v-btn
density="compact"
variant="text"
icon="mdi-cloud-download"
/>
</v-col>
<v-col class="pa-0 flex-grow-0">
<v-btn
density="compact"
variant="text"
icon="mdi-close"
@click="dialogfoto = false"
/>
</v-col>
</v-row>
<v-row>
<v-col class="flex-grow-0 align-self-center">
<v-btn
density="compact"
variant="text"
icon="mdi-chevron-left"
@click = "indximg !=0? indximg -=1:indximg=newss.result[0].gallery.length-1"
/>
</v-col>
<v-col class="flex-column h_cards pa-0">
<v-img
class="d-flex"
:src="`${burl}${galleryimges.img}`"
/>
</v-col>
<v-col class="d-flex flex-column flex-grow-0">
<v-row>
<v-col class="flex-column d-flex align-end align-self-center">
<v-btn
density="compact"
variant="text"
icon="mdi-chevron-right"
@click = "indximg !=newss.result[0].gallery.length-1? indximg +=1:indximg=0"
/>
</v-col>
</v-row>
</v-col>
</v-row>
<v-row class="flex-grow-1 align-self-center d-flex placeIt">
<v-col class="pa-0">
<v-btn
density="compact"
variant="text"
:color="heartIco()?'red':'black'"
:icon= "heartIco()?'mdi-heart':'mdi-heart-outline'"
@click = toggleLike(galleryimges.id)
/>
</v-col>
<v-col class="pa-0 text-overline">
{{galleryimges.likes.length}}
</v-col>
</v-row>
</v-card>
</v-dialog>
</v-row>
</template>
<script>
import {checkremote} from '@/utils/universal_functions'
import { ref, watch, onBeforeUpdate, onMounted } from 'vue'
import {useAccountStore} from '@/store/AccountStore'
import {getfromserver} from '@/utils/universal_functions'
import { baseURL } from '@/utils/axios-api'
import myHelper from './UI/my-helper.vue'
import { axiosApiInstance } from '@/utils/axios-api'
import { format } from 'date-fns'
import { useRoute } from 'vue-router'
import { spravURL } from '@/utils/axios-api'
const accountStore = useAccountStore()
export default {
components: { myHelper},
setup(){
const divs = ref([])
onBeforeUpdate(() => {
divs.value = []
})
const newss=ref([])
const dialogCommentShow = ref(false)
const gallery = ref(false)
const burl = baseURL.slice(0,-1)
const textcomment = ref('')
const idnews = ref(0)
const page = ref(1)
const selecnews = ref(6)
const route = useRoute()
const colors = []
const switchComGal =ref(false)
let str = `api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}`
if (route.path == '/news' && 'id' in route.query){
str = `api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}&id=${route.query.id}`
}
getfromserver(str, newss)
const loadNews = (path) => {
axiosApiInstance.get(path).then(result => {
newss.value= result.data
if (newss.value.result[0].gallery.length > 0) {
newss.value.result[0].gallery.forEach(e=>
e.bg=colors[Math.floor(Math.random() * colors.length)
]
)
gallery.value = true
}
})
}
loadNews(str)
const toggleIncrementLike = (news, scores) => {
axiosApiInstance.post(`api/navigation/news/`, {news: news, scores: scores}).then(result => {
newss.value.result[newss.value.result.findIndex(e=> e.id==news)].scores= result.data
})
}
const addComment = (idnew) => {
axiosApiInstance.post(`api/navigation/news/`, {news: idnew, text: textcomment.value}).then(result => {
dialogCommentShow.value=false
newss.value.result[newss.value.result.findIndex(e=> e.id==result.data['news'])].comment = result.data.comment
})
textcomment.value=""
}
const deletComment = (id, news) => {
axiosApiInstance.post(`api/navigation/news/`, {delid: id, news: news}).then(result => {
newss.value.result[newss.value.result.findIndex(e=> e.id==result.data['news'])].comment = result.data.comment
})
}
const pagelistNews =() => {
getfromserver(`api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}`, newss)
}
watch(()=>route.query,(newValue,oldValue)=>{
if(newValue){
str = `api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}`
getfromserver(str, newss)
}
}, {deep:true})
watch(()=>selecnews ,(newValue,oldValue)=>{
if(newValue){
getfromserver(`api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${newValue.value}`, newss)
}
}, {deep:true})
watch(()=>accountStore.cod2user ,(newValue,oldValue)=>{
if(newValue){
getfromserver(`api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}`,newss)
}
}, {deep:true})
const dateformat = (datas) => {
return format(new Date(datas), 'dd.MM.yyyy HH:mm')
}
const openComent = (news) => {
dialogCommentShow.value=!dialogCommentShow.value
idnews.value = news
}
const formatText= (text) => {
return text.replaceAll('src="/media/uploads', `src="${baseURL}media/uploads`)
}
const nextnews = (idnews) => {
console.log(route);
}
const limitText=(text)=> {
const t = text.split(' ').slice(0, 25)
return `${text.split(' ').slice(0, 25).join(' ')} ${t.length<25?'':'...'}`
}
const splitname = (name) => {
return name.familyname + ' ' + name.name[0] + '.' + name.parentname[0]+ '.'
}
// ------------------------------ Галерея
const galleryimges=ref([])
const dialogfoto = ref(false)
const indximg = ref('')
const openImg = (idimg) => {
dialogfoto.value = true
indximg.value = newss.value.result[0].gallery.findIndex(e=>e.id == idimg)
}
watch(()=>indximg ,(newValue,oldValue)=>{
if(newValue){
galleryimges.value = newss.value.result[0].gallery[newValue.value]
}
}, {deep:true})
const imagesIn = () => {
return newss.value.result[0].gallery.length
}
// Лайки на фотографии
const toggleLike = (idimage) => {
axiosApiInstance.post(`api/navigation/gallery/`, {image: idimage}).then(result => {
galleryimges.value.likes= result.data
})
}
const toggleLikeAll = (idimage) => {
axiosApiInstance.post(`api/navigation/gallery/`, {image: idimage}).then(result => {
newss.value.result[0].gallery.filter(e=>e.id ==idimage)[0].likes = result.data
})
}
const heartIco = () => {
return galleryimges.value.likes.filter(e=>e.user==accountStore.user.login).length==1
}
const heartIcoAll = (image) => {
return image.likes.filter(e=>e.user==accountStore.user.login).length==1
}
return {
newss,
burl,
limitText,
toggleIncrementLike,
dialogCommentShow,
accountStore,
dateformat,
splitname,
textcomment,
openComent,
addComment,
idnews,
deletComment,
pagelistNews,
divs,
page,
selecnews,
checkremote,
route,
spravURL,
formatText,
gallery,
openImg,
dialogfoto,
galleryimges,
indximg,
toggleLike,
heartIco,
heartIcoAll,
toggleLikeAll,
imagesIn,
switchComGal,
nextnews
}
}
}
</script>
<style >
.comgal .v-switch__thumb {
color: white!important;
}
.posFooter {
position: sticky;
margin-top: 12px;
background-color: transparent;
bottom: 5px;
}
.newsVH {
height: 92vh;
}
.bgchat {
background-color: #efe9f98a;
}
.bgchatnot {
background-color: #eef9efad;
}
.mwidth {
min-width: 50px;
}
/* .bgf {
background: url("@/assets/message.jpg") repeat-y;
} */
.heigCard {
height: 46vh;
}
.commentHeight {
height: 91.5vh;
}
.h_cards {
height: 86vh;
}
.place-it{
place-items: center;
}
</style>