Отправка в базу

This commit is contained in:
iriska-gri committed 2023-10-04 16:45:39 +03:00
1 parent 74071cdf39
commit c7add1d73a
4 files changed
+73 -94

No files matched your search

+45 -83
View File
@@ -56,22 +56,21 @@
@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"
@click="openComent(x.id)"
/>
<span @click="x.showComment=!x.showComment"
class="pointer"
>
{{ x.comment.length }}
<!-- @click="commentadd" -->
<!-- <v-btn
:icon="x.show ? 'mdi-chevron-up' : 'mdi-chevron-down'"
@click="x.show = !x.show"
></v-btn> -->
</span>
</v-col>
<v-col class="text-center pr-0">
<v-btn
@@ -80,9 +79,11 @@
color="red-lighten-2"
@click="toggleIncrementLike(x.id, false)"
/>
{{x.scores.filter(e=> e.score==false).length}}
<!-- {{ x.dislikes }} -->
{{x.scores.filter(e=> e.score==false).length}}
</v-col>
</v-row>
@@ -107,7 +108,7 @@
<v-card
width="400"
:subtitle=y.author
:subtitle=splitname(y.author)
:text=y.text
elevation="1"
></v-card>
@@ -131,6 +132,7 @@
variant="solo"
hide-details
rows="5"
v-model="textcomment"
></v-textarea>
</v-card-text>
@@ -146,7 +148,7 @@
<v-btn
color="blue-darken-1"
variant="text"
@click="dialogCommentShow = false"
@click="addComment"
>
Отправить
</v-btn>
@@ -160,7 +162,7 @@
<script>
import { ref,computed,watch } from 'vue'
import { ref, watch } from 'vue'
import {useAccountStore} from '@/store/AccountStore'
import {getfromserver} from '@/utils/universal_functions'
import { baseURL } from '@/utils/axios-api'
@@ -174,74 +176,46 @@ 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 burl = baseURL.slice(0,-1)
const textcomment = ref('')
const idnews = ref(0)
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
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')
return format(new Date(datas), 'dd.MM.yyyy HH:mm')
}
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 openComent = (news) => {
dialogCommentShow.value=!dialogCommentShow.value
idnews.value = news
}
const burl = baseURL.slice(0,-1)
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)
@@ -253,34 +227,22 @@ export default {
}, {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
dateformat,
splitname,
textcomment,
openComent,
addComment,
idnews
}
}