fix [P-224]: обновил новость

This commit is contained in:
denzel committed 2026-05-26 11:37:49 +03:00
1 parent c388b0a9d9
commit e31506135e
3 files changed
+1011 -648

No files matched your search

+278 -139
View File
@@ -1,129 +1,106 @@
<template> <template>
<v-card <v-card class="nc" :ripple="false">
class="rounded-lg h-100 flex-column d-flex" <!-- Изображение -->
min-height="400" <div class="nc__img" @click="openOneImg(news.link)">
max-height="400" <img
style="box-shadow: none" v-if="news.link && !imgError"
> :src="`${burl}${news.link}`"
<v-card-title class=""> :alt="news.title"
{{ news.title }} @error="imgError = true"
</v-card-title>
<v-row class="flex-grow-0">
<v-col class="d-flex flex-column ">
<v-img
:src="news.link ? `${burl}${news.link}` : defaultImage"
height="170px"
width="92%"
class="mx-auto"
cover
@click="openOneImg(news.link)"
/> />
</v-col> <!-- Заглушка: нет ссылки ИЛИ картинка не загрузилась -->
</v-row> <div v-else class="nc__placeholder">
<svg width="56" height="56" viewBox="0 0 56 56" fill="none">
<rect x="4" y="8" width="48" height="40" rx="4" stroke="white" stroke-width="2" />
<rect x="8" y="12" width="40" height="11" rx="2" fill="white" />
<rect x="8" y="27" width="18" height="2.5" rx="1" fill="white" />
<rect x="8" y="32" width="18" height="2.5" rx="1" fill="white" />
<rect x="8" y="37" width="18" height="2.5" rx="1" fill="white" />
<rect x="30" y="27" width="18" height="2.5" rx="1" fill="white" />
<rect x="30" y="32" width="13" height="2.5" rx="1" fill="white" />
<rect x="30" y="37" width="16" height="2.5" rx="1" fill="white" />
<rect x="8" y="43" width="40" height="2" rx="1" fill="white" />
</svg>
<span>Без фото</span>
</div>
<v-row class="ma-0 flex-grow-0"> <div class="nc__img-overlay" />
<v-col <span class="nc__date">{{ formatDate(news.cdate) }}</span>
class="py-1 pl-4" </div>
lg=5
md=12
sm=12
>
<!-- Тело -->
<div class="nc__body">
<div class="nc__author">
<ico-user :author="news.author" /> <ico-user :author="news.author" />
</v-col> </div>
<v-col
lg=7 <div class="nc__title">{{ news.title }}</div>
md=12
sm=12 <div class="nc__excerpt">
class="py-1 text-end pr-4"> <span v-if="news.text.length > 0" v-html="limitText(news.text)" />
<div class="justify-self-end"> <span v-else class="nc__empty">Нет описания</span>
<v-icon </div>
size="x-small"
class="me-1" <!-- Футер -->
color="teal-darken-4" <div class="nc__foot">
:icon="news.scores.filter(e=> e.user==accountStore.user.login && e.score == true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'" <!-- Статистика -->
<div class="nc__stats">
<div>
<button
class="nc__stat"
:class="{ 'nc__stat--active-up': isLiked(true) }"
@click="toggleIncrementLike(news.id, true)" @click="toggleIncrementLike(news.id, true)"
/> >
<span class="subheading me-2"> <v-icon size="14">
{{ news.scores.filter(e => e.score == true).length }} {{ isLiked(true) ? 'mdi-thumb-up' : 'mdi-thumb-up-outline' }}
</span> </v-icon>
<span class="me-1"> {{ news.scores.filter(e => e.score === true).length }}
· </button>
</span>
<v-icon <button
size="x-small" class="nc__stat"
class="me-1" :class="{ 'nc__stat--active-down': isLiked(false) }"
color="teal-darken-4"
:icon="news.scores.filter(e=> e.user==accountStore.user.login && e.score == false).length>0?'mdi-thumb-down':'mdi-thumb-down-outline'"
@click="toggleIncrementLike(news.id, false)" @click="toggleIncrementLike(news.id, false)"
/> >
<span class="subheading me-2"> <v-icon size="14">
{{ news.scores.filter(e => e.score == false).length }} {{ isLiked(false) ? 'mdi-thumb-down' : 'mdi-thumb-down-outline' }}
</span> </v-icon>
<span class="me-1"> {{ news.scores.filter(e => e.score === false).length }}
· </button>
</span>
<v-icon <span class="nc__stat nc__stat--passive">
size="x-small" <v-icon size="14">mdi-message-text-outline</v-icon>
class="me-1"
color="teal-darken-4"
icon="mdi-message-text-outline"
/>
<span class="subheading">
{{ news.comment.length }} {{ news.comment.length }}
</span> </span>
<span class="me-1">
· <span class="nc__stat nc__stat--passive">
</span> <v-icon size="14">mdi-image-outline</v-icon>
<v-icon
size="x-small"
class="me-1 mb-1"
color="teal-darken-4"
icon="mdi-image"
/>
<span class="subheading">
{{ news.gallery.length }} {{ news.gallery.length }}
</span> </span>
</div> </div>
<div>
</v-col>
</v-row>
<v-divider class="mx-4" />
<v-row class="ma-0 overflow-auto">
<v-col
class="py-0"
:class="news.text.length==0?'align-self-center':'my-3'"
>
<v-card-text class="py-0 px-2">
<div v-if="news.text.length>0" v-html=limitText(news.text)></div>
<div v-else class="text-h6 text-grey text-center align-self-center text--lighten-1 font-weight-light">Без
описания
</div>
</v-card-text>
</v-col>
</v-row>
<v-divider class="mx-4" />
<v-row class="flex-grow-0 ma-0">
<v-col class="d-flex justify-space-between">
<v-btn <v-btn
color="teal-darken-4" :to="`/newsfull?id=${news.id}`"
:to='`/newsfull?id=${news.id}`' class="nc__btn"
variant="flat"
size="small" size="small"
rounded="xl" rounded="xl"
append-icon="mdi-step-forward-2" append-icon="mdi-chevron-right"
> >
Подробнее Подробнее
</v-btn> </v-btn>
<span class="text-caption align-self-center">{{ formatDate(news.cdate) }}</span> </div>
</v-col>
</v-row>
</v-card>
</div>
</div>
</div>
</v-card>
</template> </template>
<script> <script>
import { ref } from 'vue';
import { baseURL } from '@/utils/axios-api'; import { baseURL } from '@/utils/axios-api';
import { useAccountStore } from '@/store/AccountStore'; import { useAccountStore } from '@/store/AccountStore';
import { axiosApiInstance } from '@/utils/axios-api'; import { axiosApiInstance } from '@/utils/axios-api';
@@ -134,62 +111,224 @@ import defaultImage from '@/assets/emblem.png';
const accountStore = useAccountStore(); const accountStore = useAccountStore();
export default { export default {
components: { icoUser }, components: { icoUser },
name: 'NewsCard', name: 'NewsCard',
props: { props: {
news: { news: { type: Object, default: () => ({}) },
type: Object,
default: {},
}, },
},
setup(props, { emit }) { setup(props, { emit }) {
const burl = baseURL.slice(0, -1); const burl = baseURL.slice(0, -1);
const imgError = ref(false);
const isLiked = (score) =>
props.news.scores.some(
e => e.user === accountStore.user.login && e.score === score,
);
const limitText = (text) => { const limitText = (text) => {
let parser = new DOMParser().parseFromString(text, 'text/html'); const doc = new DOMParser().parseFromString(text, 'text/html').body.textContent || '';
let doc = parser.body.textContent || ''; const words = doc.split(' ');
doc = doc.replaceAll('src="/media/uploads', `src="${baseURL}media/uploads`); return words.slice(0, 50).join(' ') + (words.length > 50 ? '…' : '');
const t = doc.split(' ').slice(0, 50);
return `${doc.split(' ').slice(0, 50).join(' ')} ${t.length < 50 ? '' : '...'}`;
}; };
const toggleIncrementLike = (id, score) => {
const toggleIncrementLike = (newss, scores) => { axiosApiInstance
axiosApiInstance.post(`api/navigation/newscrossroad/`, { news: newss, scores: scores }).then(result => { .post('api/navigation/newscrossroad/', { news: id, scores: score })
props.news.scores = result.data; .then(r => {
props.news.scores = r.data;
}); });
}; };
const openOneImg = () => { const openOneImg = () => emit('openOneImg');
emit('openOneImg'); const formatDate = (date) => moment(date).format('DD.MM.YYYY');
};
function formatDate(date) {
return moment(date).format('DD.MM.YYYY');
}
return { return {
accountStore, accountStore, burl, isLiked,
burl, limitText, splitname,
limitText, toggleIncrementLike, openOneImg,
splitname, formatDate, defaultImage, imgError,
toggleIncrementLike,
openOneImg,
formatDate,
defaultImage,
}; };
}, },
}; };
</script> </script>
<style> <style scoped lang="scss">
.nc {
border-radius: 16px !important;
min-height: 30rem;
overflow: hidden;
display: flex;
flex-direction: column;
box-shadow: 0 1px 3px rgba(0, 0, 0, .05), 0 4px 16px rgba(25, 42, 43, .07) !important;
transition: transform .2s, box-shadow .2s;
border: 1px solid rgba(25, 42, 43, .07);
&:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, .07), 0 12px 28px rgba(25, 42, 43, .12) !important;
}
}
/* Картинка */
.nc__img {
position: relative;
height: 176px;
overflow: hidden;
flex-shrink: 0;
img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
transition: transform .4s cubic-bezier(.22, 1, .36, 1);
}
.nc:hover & img {
transform: scale(1.04);
}
}
.nc__img-overlay {
position: absolute;
inset: 0;
background: linear-gradient(to top, rgba(15, 25, 26, .5) 0%, transparent 55%);
pointer-events: none;
}
.nc__date {
position: absolute;
bottom: 10px;
right: 12px;
font-size: 11px;
font-weight: 500;
color: rgba(255, 255, 255, .88);
letter-spacing: .03em;
}
/* Тело */
.nc__body {
flex: 1;
padding: 14px 16px 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.nc__title {
font-size: 15px;
font-weight: 600;
line-height: 1.42;
color: #0f191a;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.nc__excerpt {
font-size: 13px;
line-height: 1.65;
color: #3d5354;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
flex: 1;
}
.nc__empty {
color: #9ab4b5;
font-style: italic;
}
/* Статистика */
.nc__stats {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 0;
border-top: 1px solid rgba(25, 42, 43, .07);
}
.nc__stat {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 12px;
font-weight: 500;
color: #7a9394;
background: none;
border: none;
cursor: pointer;
padding: 4px 6px;
border-radius: 8px;
transition: background .15s, color .15s;
&:hover {
background: rgba(25, 42, 43, .06);
}
&--passive {
cursor: default;
&:hover {
background: none;
}
}
&--active-up {
color: #0f6e56;
}
&--active-down {
color: #c0392b;
}
}
/* Футер */
.nc__foot {
display: flex;
padding: 10px 16px 14px;
}
.nc__btn {
margin-left: auto;
background: #192a2b !important;
color: #fff !important;
font-size: 12px !important;
font-weight: 600 !important;
letter-spacing: .03em !important;
text-transform: none !important;
&:hover {
background: #335455 !important;
}
}
.nc__placeholder {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
background: linear-gradient(145deg, #1e3233 0%, #2d4d4e 40%, #1a2f30 100%);
cursor: default;
svg {
opacity: .35;
}
span {
font-size: 11px;
font-weight: 600;
letter-spacing: .1em;
color: rgba(255, 255, 255, .28);
text-transform: uppercase;
}
}
</style> </style>
File diff suppressed because it is too large. Load diff
+9 -1
View File
@@ -27,9 +27,17 @@ export default {
<style> <style>
.bg { .bg {
min-height: 100vh; position: relative;
height: 100vh;
&::before {
content: '';
position: fixed;
inset: 0;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cg transform='rotate(-35 40 40)' opacity='0.13'%3E%3Crect x='10' y='8' width='60' height='64' rx='4' fill='none' stroke='%23192a2b' stroke-width='2'/%3E%3Crect x='14' y='12' width='52' height='14' rx='2' fill='%23192a2b'/%3E%3Crect x='14' y='30' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='36' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='42' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='42' y='30' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='42' y='36' width='18' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='42' y='42' width='21' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='50' width='52' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='56' width='40' height='3' rx='1' fill='%23192a2b'/%3E%3C/g%3E%3C/svg%3E"); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cg transform='rotate(-35 40 40)' opacity='0.13'%3E%3Crect x='10' y='8' width='60' height='64' rx='4' fill='none' stroke='%23192a2b' stroke-width='2'/%3E%3Crect x='14' y='12' width='52' height='14' rx='2' fill='%23192a2b'/%3E%3Crect x='14' y='30' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='36' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='42' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='42' y='30' width='24' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='42' y='36' width='18' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='42' y='42' width='21' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='50' width='52' height='3' rx='1' fill='%23192a2b'/%3E%3Crect x='14' y='56' width='40' height='3' rx='1' fill='%23192a2b'/%3E%3C/g%3E%3C/svg%3E");
background-color: rgb(244, 249, 249);
background-size: 80px 80px; background-size: 80px 80px;
background-repeat: repeat; background-repeat: repeat;
}
} }
</style> </style>