213 lines
5.7 KiB
Vue
213 lines
5.7 KiB
Vue
<template>
|
|
<div>
|
|
<v-card
|
|
:ref="i"
|
|
class="mx-auto px-3 pt-3"
|
|
:class="i>0?'mt-1':''"
|
|
v-for="(x, i) in newss.result" :key= i
|
|
>
|
|
|
|
<v-card-title class="py-1">
|
|
{{x.title}}
|
|
</v-card-title>
|
|
<v-img
|
|
:src="`${burl}${x.link}`"
|
|
height="164px"
|
|
cover
|
|
width="92%"
|
|
class="mx-auto"
|
|
/>
|
|
<v-list-item class="w-100">
|
|
<div class="justify-self-start mt-1">
|
|
<v-icon size="x-small" class="me-1" icon="mdi-account" ></v-icon>
|
|
<span class="text-caption me-2">{{splitname(x.author)}}</span>
|
|
</div>
|
|
|
|
<template v-slot:append>
|
|
<div class="justify-self-end">
|
|
<v-icon size="x-small" 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 size="x-small" 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 size="x-small" class="me-1" icon="mdi-message-text-outline" @click="openComent(x.id)"/>
|
|
<span class="pointer subheading">{{ x.comment.length }}</span>
|
|
</div>
|
|
</template>
|
|
</v-list-item>
|
|
<v-divider/>
|
|
|
|
<v-card-text class="pb-0">
|
|
{{limitText(x.text)}}
|
|
</v-card-text>
|
|
|
|
<div class="pt-1 pl-1 pb-2">
|
|
<v-btn
|
|
color="more_details_btn"
|
|
variant="text"
|
|
:to='`/news?id=${x.id}`'
|
|
size="small"
|
|
append-icon="mdi-step-forward-2"
|
|
>
|
|
Подробнее
|
|
</v-btn>
|
|
</div>
|
|
</v-card>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
|
|
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'
|
|
|
|
const accountStore = useAccountStore()
|
|
|
|
export default {
|
|
components: { myHelper },
|
|
|
|
|
|
|
|
setup(){
|
|
const divs = ref([])
|
|
onBeforeUpdate(() => {
|
|
divs.value = []
|
|
})
|
|
const newss=ref([])
|
|
const dialogCommentShow = ref(false)
|
|
const burl = baseURL.slice(0,-1)
|
|
const textcomment = ref('')
|
|
const idnews = ref(0)
|
|
const page = ref(1)
|
|
const selecnews = ref(2)
|
|
const route = useRoute()
|
|
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 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 = () => {
|
|
axiosApiInstance.post(`api/navigation/news/`, {news: idnews.value, text: textcomment.value}).then(result => {
|
|
dialogCommentShow.value=!dialogCommentShow.value
|
|
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(()=>accountStore.cod2user ,(newValue,oldValue)=>{
|
|
if(newValue){
|
|
getfromserver(`api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}`,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})
|
|
|
|
|
|
|
|
const dateformat = (datas) => {
|
|
return format(new Date(datas), 'dd.MM.yyyy HH:mm')
|
|
}
|
|
|
|
|
|
const openComent = (news) => {
|
|
dialogCommentShow.value=!dialogCommentShow.value
|
|
idnews.value = news
|
|
}
|
|
|
|
|
|
|
|
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]+ '.'
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
newss,
|
|
burl,
|
|
limitText,
|
|
toggleIncrementLike,
|
|
dialogCommentShow,
|
|
accountStore,
|
|
dateformat,
|
|
splitname,
|
|
textcomment,
|
|
openComent,
|
|
addComment,
|
|
idnews,
|
|
deletComment,
|
|
pagelistNews,
|
|
divs,
|
|
page,
|
|
selecnews,
|
|
route
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.pagination {
|
|
display: flex;
|
|
}
|
|
.newsVH {
|
|
height: 90vh;
|
|
}
|
|
|
|
.bgchat {
|
|
background-color: #efe9f98a;
|
|
}
|
|
|
|
.bgchatnot {
|
|
background-color: #eef9efad;
|
|
}
|
|
|
|
/* .bgf {
|
|
background: url("@/assets/message.jpg") repeat-y;
|
|
|
|
} */
|
|
|
|
</style> |