449 lines
11 KiB
Vue
449 lines
11 KiB
Vue
<template>
|
|
<v-container class="py-0 newsVH px-0 bg-transparent overflow-auto">
|
|
|
|
<v-card
|
|
v-show="pages=='home'"
|
|
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>
|
|
<!-- :variant="x.scores.filter(e=> e.user==accountStore.user.id && e.score == true).length>0?'text':'tonal'" -->
|
|
<v-btn
|
|
:variant="x.scores.filter(e=> e.user==accountStore.user.id && e.score == true).length>0?'tonal':'text'"
|
|
icon='mdi-thumb-up-outline'
|
|
color="blue-darken-3"
|
|
@click="toggleIncrementLike(x.id, true)"
|
|
/>
|
|
{{x.scores.filter(e=> e.score==true).length}}
|
|
|
|
</v-col>
|
|
<v-col class=" ml-8">
|
|
<v-btn
|
|
variant="text"
|
|
icon="mdi-message-text-outline"
|
|
color="teal"
|
|
@click="openComent(x.id)"
|
|
/>
|
|
<span @click="x.showComment=!x.showComment"
|
|
class="pointer"
|
|
>
|
|
{{ x.comment.length }}
|
|
</span>
|
|
|
|
</v-col>
|
|
<v-col class="text-center pr-0">
|
|
<v-btn
|
|
:variant="x.scores.filter(e=> e.user==accountStore.user.id && e.score == false).length>0?'tonal':'text'"
|
|
icon='mdi-thumb-down-outline'
|
|
color="red-lighten-2"
|
|
@click="toggleIncrementLike(x.id, false)"
|
|
/>
|
|
|
|
{{x.scores.filter(e=> e.score==false).length}}
|
|
|
|
|
|
|
|
</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)}}
|
|
<v-btn
|
|
variant="text"
|
|
size="small"
|
|
icon='mdi-delete'
|
|
color="blue-grey-darken-1"
|
|
@click="deletComment(y.id, x.id)"
|
|
/>
|
|
</div>
|
|
|
|
<v-card
|
|
width="400"
|
|
:subtitle=splitname(y.author)
|
|
:text=y.text
|
|
elevation="1"
|
|
></v-card>
|
|
</div>
|
|
|
|
</div>
|
|
</v-expand-transition>
|
|
</v-card>
|
|
|
|
<!-- ---------------------------------------------------------------------------------- -->
|
|
|
|
<v-card v-show="pages=='news'"
|
|
class="mx-auto rounded-0"
|
|
|
|
v-for="(x, i) in newss" :key= i
|
|
>
|
|
<v-list-item class="w-100 pl-4 py-2 pt-3">
|
|
<template v-slot:prepend>
|
|
<v-avatar
|
|
|
|
color="grey-darken-3"
|
|
image="https://avataaars.io/?avatarStyle=Transparent&topType=ShortHairShortCurly&accessoriesType=Prescription02&hairColor=Black&facialHairType=Blank&clotheType=Hoodie&clotheColor=White&eyeType=Default&eyebrowType=DefaultNatural&mouthType=Default&skinColor=Light"
|
|
></v-avatar>
|
|
</template>
|
|
|
|
<v-list-item-title>{{x.author.fio}}</v-list-item-title>
|
|
|
|
<v-list-item-subtitle>Участник</v-list-item-subtitle>
|
|
</v-list-item>
|
|
|
|
<v-card-title class="pt-0 pb-1">
|
|
{{x.title}}
|
|
</v-card-title>
|
|
<v-img
|
|
:src="`${burl}${x.link}`"
|
|
height="350px"
|
|
width="96%"
|
|
class="mx-auto"
|
|
cover
|
|
/>
|
|
|
|
<v-list-item class="w-100">
|
|
|
|
<template v-slot:append>
|
|
<div class="justify-self-end">
|
|
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.id && 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="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>
|
|
{{x.text}}
|
|
</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 py-3"
|
|
>
|
|
<v-row>
|
|
<v-col class="text-subtitle-2">{{ splitname(y.author) }}</v-col>
|
|
<v-col class="flex-grow-0 text-subtitle-2 ">{{dateformat(y.cdate)}} </v-col>
|
|
<v-col class="flex-grow-0"> <v-btn
|
|
variant="text"
|
|
size="small"
|
|
icon='mdi-delete'
|
|
color="blue-grey-darken-1"
|
|
@click="deletComment(y.id, x.id)"
|
|
/></v-col>
|
|
</v-row>
|
|
<div class="text-subtitle-2">
|
|
|
|
|
|
</div>
|
|
|
|
<v-alert
|
|
|
|
class="comWy"
|
|
color="#f9f9f9"
|
|
|
|
:border="accountStore.user.login==y.author.login?'end':'start'"
|
|
:border-color="accountStore.user.login==y.author.login?'success':'deep-purple accent-4'"
|
|
elevation=""
|
|
>
|
|
|
|
{{ y.text }}
|
|
|
|
</v-alert>
|
|
|
|
<!-- <v-card
|
|
width="400"
|
|
:subtitle=splitname(y.author)
|
|
:text=y.text
|
|
elevation="1"
|
|
color="red"
|
|
></v-card> -->
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</v-expand-transition>
|
|
|
|
<!-- <v-card-actions > -->
|
|
<!-- <v-row >
|
|
<v-col>
|
|
|
|
<v-btn
|
|
:variant="x.scores.filter(e=> e.user==accountStore.user.id && e.score == true).length>0?'tonal':'text'"
|
|
icon='mdi-thumb-up-outline'
|
|
color="blue-darken-3"
|
|
@click="toggleIncrementLike(x.id, true)"
|
|
/>
|
|
|
|
|
|
</v-col>
|
|
<v-col class=" ml-8">
|
|
<v-btn
|
|
variant="text"
|
|
icon="mdi-message-text-outline"
|
|
color="teal"
|
|
|
|
/>
|
|
<span @click="x.showComment=!x.showComment"
|
|
class="pointer"
|
|
>
|
|
|
|
</span>
|
|
|
|
</v-col>
|
|
<v-col class="text-center pr-0">
|
|
<v-btn
|
|
:variant="x.scores.filter(e=> e.user==accountStore.user.id && e.score == false).length>0?'tonal':'text'"
|
|
icon='mdi-thumb-down-outline'
|
|
color="red-lighten-2"
|
|
@click="toggleIncrementLike(x.id, false)"
|
|
/>
|
|
|
|
{{x.scores.filter(e=> e.score==false).length}}
|
|
|
|
|
|
|
|
</v-col>
|
|
</v-row> -->
|
|
|
|
|
|
|
|
|
|
<!-- </v-card-actions> -->
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</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-model="textcomment"
|
|
|
|
></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="addComment"
|
|
>
|
|
Отправить
|
|
</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-dialog>
|
|
</v-row>
|
|
</v-container>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import { ref, 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 },
|
|
|
|
props: {
|
|
pages: {
|
|
type: String,
|
|
default: 'home'
|
|
}
|
|
},
|
|
|
|
|
|
setup(){
|
|
const newss=ref([])
|
|
const dialogCommentShow = ref(false)
|
|
const burl = baseURL.slice(0,-1)
|
|
const textcomment = ref('')
|
|
const idnews = ref(0)
|
|
|
|
const toggleIncrementLike = (news, scores) => {
|
|
axiosApiInstance.post(`api/navigation/news/`, {news: news, scores: scores}).then(result => {
|
|
newss.value[newss.value.findIndex(e=> e.id==news)].scores= result.data
|
|
// console.log(result.data, 'result.data-----------------')
|
|
})
|
|
}
|
|
|
|
const dateformat = (datas) => {
|
|
return format(new Date(datas), 'dd.MM.yyyy HH:mm')
|
|
}
|
|
|
|
const openComent = (news) => {
|
|
dialogCommentShow.value=!dialogCommentShow.value
|
|
idnews.value = news
|
|
|
|
|
|
}
|
|
|
|
const addComment = () => {
|
|
axiosApiInstance.post(`api/navigation/news/`, {news: idnews.value, text: textcomment.value}).then(result => {
|
|
dialogCommentShow.value=!dialogCommentShow.value
|
|
newss.value[newss.value.findIndex(e=> e.id==result.data['news'])].comment = result.data.comment
|
|
console.log(result.data, 'result.data-----------------')
|
|
})
|
|
|
|
}
|
|
|
|
const limitText=(text)=> {
|
|
return text.split(' ').slice(0, 10).join(' ')
|
|
}
|
|
|
|
const splitname = (name) => {
|
|
return name.familyname + ' ' + name.name[0] + '.' + name.parentname[0]+ '.'
|
|
}
|
|
|
|
getfromserver("api/navigation/news/", newss)
|
|
|
|
|
|
watch(()=>accountStore.cod2user ,(newValue,oldValue)=>{
|
|
if(newValue){
|
|
getfromserver("api/navigation/news/",newss)
|
|
}
|
|
}, {deep:true})
|
|
|
|
const deletComment = (id, news) => {
|
|
axiosApiInstance.post(`api/navigation/news/`, {delid: id, news: news}).then(result => {
|
|
// dialogCommentShow.value=!dialogCommentShow.value
|
|
newss.value[newss.value.findIndex(e=> e.id==result.data['news'])].comment = result.data.comment
|
|
console.log(result.data, 'result.data-----------------')
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
return {
|
|
newss,
|
|
burl,
|
|
limitText,
|
|
toggleIncrementLike,
|
|
dialogCommentShow,
|
|
accountStore,
|
|
dateformat,
|
|
splitname,
|
|
textcomment,
|
|
openComent,
|
|
addComment,
|
|
idnews,
|
|
deletComment
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.newsVH {
|
|
height: 93vh;
|
|
}
|
|
|
|
.comWy {
|
|
width: 96%;
|
|
}
|
|
</style> |