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
+1057 -694

No files matched your search

+291 -152
View File
@@ -1,129 +1,106 @@
<template>
<v-card
class="rounded-lg h-100 flex-column d-flex"
min-height="400"
max-height="400"
style="box-shadow: none"
>
<v-card-title class="">
{{ news.title }}
</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-card class="nc" :ripple="false">
<!-- Изображение -->
<div class="nc__img" @click="openOneImg(news.link)">
<img
v-if="news.link && !imgError"
:src="`${burl}${news.link}`"
:alt="news.title"
@error="imgError = true"
/>
</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">
<v-col
class="py-1 pl-4"
lg=5
md=12
sm=12
>
<div class="nc__img-overlay" />
<span class="nc__date">{{ formatDate(news.cdate) }}</span>
</div>
<!-- Тело -->
<div class="nc__body">
<div class="nc__author">
<ico-user :author="news.author" />
</v-col>
<v-col
lg=7
md=12
sm=12
class="py-1 text-end pr-4">
<div class="justify-self-end">
<v-icon
size="x-small"
class="me-1"
color="teal-darken-4"
:icon="news.scores.filter(e=> e.user==accountStore.user.login && e.score == true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'"
@click="toggleIncrementLike(news.id, true)"
/>
<span class="subheading me-2">
{{ news.scores.filter(e => e.score == true).length }}
</span>
<span class="me-1">
·
</span>
<v-icon
size="x-small"
class="me-1"
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)"
/>
<span class="subheading me-2">
{{ news.scores.filter(e => e.score == false).length }}
</span>
<span class="me-1">
·
</span>
<v-icon
size="x-small"
class="me-1"
color="teal-darken-4"
icon="mdi-message-text-outline"
/>
<span class="subheading">
{{ news.comment.length }}
</span>
<span class="me-1">
·
</span>
<v-icon
size="x-small"
class="me-1 mb-1"
color="teal-darken-4"
icon="mdi-image"
/>
<span class="subheading">
{{ news.gallery.length }}
</span>
</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 class="nc__title">{{ news.title }}</div>
<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
color="teal-darken-4"
:to='`/newsfull?id=${news.id}`'
size="small"
rounded="xl"
append-icon="mdi-step-forward-2"
>
Подробнее
</v-btn>
<span class="text-caption align-self-center">{{ formatDate(news.cdate) }}</span>
</v-col>
</v-row>
<div class="nc__excerpt">
<span v-if="news.text.length > 0" v-html="limitText(news.text)" />
<span v-else class="nc__empty">Нет описания</span>
</div>
<!-- Футер -->
<div class="nc__foot">
<!-- Статистика -->
<div class="nc__stats">
<div>
<button
class="nc__stat"
:class="{ 'nc__stat--active-up': isLiked(true) }"
@click="toggleIncrementLike(news.id, true)"
>
<v-icon size="14">
{{ isLiked(true) ? 'mdi-thumb-up' : 'mdi-thumb-up-outline' }}
</v-icon>
{{ news.scores.filter(e => e.score === true).length }}
</button>
<button
class="nc__stat"
:class="{ 'nc__stat--active-down': isLiked(false) }"
@click="toggleIncrementLike(news.id, false)"
>
<v-icon size="14">
{{ isLiked(false) ? 'mdi-thumb-down' : 'mdi-thumb-down-outline' }}
</v-icon>
{{ news.scores.filter(e => e.score === false).length }}
</button>
<span class="nc__stat nc__stat--passive">
<v-icon size="14">mdi-message-text-outline</v-icon>
{{ news.comment.length }}
</span>
<span class="nc__stat nc__stat--passive">
<v-icon size="14">mdi-image-outline</v-icon>
{{ news.gallery.length }}
</span>
</div>
<div>
<v-btn
:to="`/newsfull?id=${news.id}`"
class="nc__btn"
variant="flat"
size="small"
rounded="xl"
append-icon="mdi-chevron-right"
>
Подробнее
</v-btn>
</div>
</div>
</div>
</div>
</v-card>
</template>
<script>
import { ref } from 'vue';
import { baseURL } from '@/utils/axios-api';
import { useAccountStore } from '@/store/AccountStore';
import { axiosApiInstance } from '@/utils/axios-api';
@@ -134,62 +111,224 @@ import defaultImage from '@/assets/emblem.png';
const accountStore = useAccountStore();
export default {
components: { icoUser },
name: 'NewsCard',
props: {
news: {
type: Object,
default: {},
},
news: { type: Object, default: () => ({}) },
},
setup(props, { emit }) {
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) => {
let parser = new DOMParser().parseFromString(text, 'text/html');
let doc = parser.body.textContent || '';
doc = doc.replaceAll('src="/media/uploads', `src="${baseURL}media/uploads`);
const t = doc.split(' ').slice(0, 50);
return `${doc.split(' ').slice(0, 50).join(' ')} ${t.length < 50 ? '' : '...'}`;
const doc = new DOMParser().parseFromString(text, 'text/html').body.textContent || '';
const words = doc.split(' ');
return words.slice(0, 50).join(' ') + (words.length > 50 ? '…' : '');
};
const toggleIncrementLike = (newss, scores) => {
axiosApiInstance.post(`api/navigation/newscrossroad/`, { news: newss, scores: scores }).then(result => {
props.news.scores = result.data;
});
const toggleIncrementLike = (id, score) => {
axiosApiInstance
.post('api/navigation/newscrossroad/', { news: id, scores: score })
.then(r => {
props.news.scores = r.data;
});
};
const openOneImg = () => {
emit('openOneImg');
};
function formatDate(date) {
return moment(date).format('DD.MM.YYYY');
}
const openOneImg = () => emit('openOneImg');
const formatDate = (date) => moment(date).format('DD.MM.YYYY');
return {
accountStore,
burl,
limitText,
splitname,
toggleIncrementLike,
openOneImg,
formatDate,
defaultImage,
accountStore, burl, isLiked,
limitText, splitname,
toggleIncrementLike, openOneImg,
formatDate, defaultImage, imgError,
};
},
};
</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>
File diff suppressed because it is too large. Load diff
+12 -4
View File
@@ -27,9 +27,17 @@ export default {
<style>
.bg {
min-height: 100vh;
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-size: 80px 80px;
background-repeat: repeat;
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-color: rgb(244, 249, 249);
background-size: 80px 80px;
background-repeat: repeat;
}
}
</style>