294 lines
6.9 KiB
Vue
294 lines
6.9 KiB
Vue
<template>
|
|
<v-container class="py-1 newsVH px-0 bg-transparent overflow-auto">
|
|
<my-helper
|
|
:pretext ="newss"
|
|
/>
|
|
<v-card
|
|
class="mx-auto mb-0 "
|
|
v-for="(x, i) in newss" :key= i
|
|
>
|
|
<v-img
|
|
:src="`${burl}${x.link}`"
|
|
height="164px"
|
|
cover
|
|
/>
|
|
|
|
<v-card-title>
|
|
{{x.title}}
|
|
</v-card-title>
|
|
|
|
<v-card-subtitle>
|
|
{{limitText(x.text)}}
|
|
</v-card-subtitle>
|
|
|
|
<v-card-actions>
|
|
<v-btn
|
|
color="teal-accent-4"
|
|
variant="text"
|
|
>
|
|
{{x.author.fio}}
|
|
|
|
</v-btn>
|
|
|
|
<v-spacer></v-spacer>
|
|
|
|
<v-btn
|
|
:icon="x.show ? 'mdi-chevron-up' : 'mdi-chevron-down'"
|
|
@click="x.show = !x.show"
|
|
></v-btn>
|
|
</v-card-actions>
|
|
|
|
<v-expand-transition>
|
|
<div v-show="x.show">
|
|
<v-divider/>
|
|
|
|
<v-card-text>
|
|
{{x.text}}
|
|
</v-card-text>
|
|
<v-divider/>
|
|
<v-card-actions >
|
|
<v-row >
|
|
<v-col>
|
|
<v-btn
|
|
variant="text"
|
|
:icon="x.scores.filter(e=> e.user==accountStore.user.id && e.score ==true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'"
|
|
color="blue-darken-3"
|
|
@click="toggleIncrementLike(x.id, true)"
|
|
/>
|
|
{{x.scores.filter(e=> e.score==true).length}}
|
|
<!-- {{ x.likes }} -->
|
|
</v-col>
|
|
<v-col class=" ml-8">
|
|
<v-btn
|
|
variant="text"
|
|
icon="mdi-message-text-outline"
|
|
color="teal"
|
|
@click="x.showComment=!x.showComment"
|
|
/>
|
|
{{ x.comment.length }}
|
|
<!-- @click="commentadd" -->
|
|
|
|
<!-- <v-btn
|
|
:icon="x.show ? 'mdi-chevron-up' : 'mdi-chevron-down'"
|
|
@click="x.show = !x.show"
|
|
></v-btn> -->
|
|
</v-col>
|
|
<v-col class="text-center pr-0">
|
|
<v-btn
|
|
variant="text"
|
|
:icon="x.scores.filter(e=> e.user==accountStore.user.id && e.score == false).length>0?'mdi-thumb-down':'mdi-thumb-down-outline'"
|
|
color="red-lighten-2"
|
|
@click="toggleIncrementLike(x.id, false)"
|
|
/>
|
|
{{x.scores.filter(e=> e.score==false).length}}
|
|
<!-- {{ x.dislikes }} -->
|
|
|
|
</v-col>
|
|
</v-row>
|
|
|
|
|
|
|
|
|
|
</v-card-actions>
|
|
<v-divider class="mb-2"/>
|
|
</div>
|
|
|
|
</v-expand-transition>
|
|
<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 align-center flex-column py-3"
|
|
>
|
|
<div class="text-subtitle-2">{{dateformat(y.cdate)}}</div>
|
|
|
|
<v-card
|
|
width="400"
|
|
:subtitle=y.author
|
|
:text=y.text
|
|
elevation="1"
|
|
></v-card>
|
|
</div>
|
|
|
|
</div>
|
|
</v-expand-transition>
|
|
</v-card>
|
|
<v-row justify="center">
|
|
<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-textarea>
|
|
</v-card-text>
|
|
<v-card-actions>
|
|
<v-spacer></v-spacer>
|
|
<v-btn
|
|
color="blue-darken-1"
|
|
variant="text"
|
|
@click="dialogCommentShow = false"
|
|
>
|
|
Отмена
|
|
</v-btn>
|
|
<v-btn
|
|
color="blue-darken-1"
|
|
variant="text"
|
|
@click="dialogCommentShow = false"
|
|
>
|
|
Отправить
|
|
</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-dialog>
|
|
</v-row>
|
|
</v-container>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import { ref,computed,watch } 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'
|
|
|
|
const accountStore = useAccountStore()
|
|
|
|
export default {
|
|
components: { myHelper },
|
|
|
|
setup(){
|
|
|
|
const newss=ref([])
|
|
const show=ref(false)
|
|
const incrementLikes = ref(0)
|
|
const derementLikes = ref(0)
|
|
const likes = ref(0)
|
|
const likedI = ref(false)
|
|
const likedD = ref(false)
|
|
const message = ref(0)
|
|
const commentShow = ref(false)
|
|
const dialogCommentShow = ref(false)
|
|
|
|
const toggleIncrementLike = (news, scores) => {
|
|
console.log(news, scores);
|
|
|
|
// let k = scores.find(e=>e.user==accountStore.user.id)
|
|
// // if (!k.score){
|
|
// console.log(k,'=============');
|
|
// // }
|
|
|
|
// if (likedI.value) {
|
|
// incrementLikes.value--
|
|
// }
|
|
// else {
|
|
// incrementLikes.value++
|
|
// if(likedD.value){
|
|
// derementLikes.value--
|
|
// likedD.value = false
|
|
// }
|
|
// }
|
|
// likedI.value=!likedI.value
|
|
// likes.value = incrementLikes.value
|
|
// console.log(incrementLikes.value, 'incrementLikes.value');
|
|
axiosApiInstance.post(`api/navigation/news/`, {news: news, scores: scores}).then(result => {
|
|
|
|
newss.value[newss.value.findIndex(e=> e.id==news)].scores= result.data
|
|
|
|
})
|
|
}
|
|
|
|
const dateformat = (datas) => {
|
|
|
|
return format(new Date(datas), 'dd.MM.yyyy')
|
|
}
|
|
|
|
const toggleDecrementLike = (idnews) => {
|
|
// if (likedD.value) {
|
|
// derementLikes.value--
|
|
// }
|
|
// else {
|
|
// derementLikes.value++
|
|
// if(likedI.value){
|
|
// incrementLikes.value--
|
|
// likedI.value = false
|
|
// }
|
|
// }
|
|
// likedD.value=!likedD.value
|
|
// likes.value = derementLikes.value
|
|
// console.log(derementLikes.value, 'derementLikes.value');
|
|
// axiosApiInstance.post(`api/navigation/news/`, {like: likes.value, idnews: idnews})
|
|
}
|
|
|
|
const burl = baseURL.slice(0,-1)
|
|
|
|
const limitText=(text)=> {
|
|
return text.split(' ').slice(0, 10).join(' ')
|
|
}
|
|
|
|
|
|
getfromserver("api/navigation/news/", newss)
|
|
|
|
|
|
watch(()=>accountStore.cod2user ,(newValue,oldValue)=>{
|
|
if(newValue){
|
|
getfromserver("api/navigation/news/",newss)
|
|
}
|
|
}, {deep:true})
|
|
|
|
|
|
// watch(()=>likes,(newValue,oldValue)=>{
|
|
// if(newValue){
|
|
// getfromserver("api/navigation/news/",newss)
|
|
// }
|
|
// }, {deep:true})
|
|
|
|
|
|
const commentadd = () => {
|
|
dialogCommentShow.value=!dialogCommentShow.value
|
|
// commentShow.value =!commentShow.value
|
|
}
|
|
|
|
|
|
return {
|
|
newss,
|
|
show,
|
|
burl,
|
|
limitText,
|
|
incrementLikes,
|
|
derementLikes,
|
|
message,
|
|
commentShow,
|
|
toggleIncrementLike,
|
|
toggleDecrementLike,
|
|
dialogCommentShow,
|
|
commentadd,
|
|
accountStore,
|
|
dateformat
|
|
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.newsVH {
|
|
height: 93vh;
|
|
}
|
|
</style> |