добавление функционала жалоб
This commit is contained in:
parent
0b98b8a37d
commit
0156b554e7
246
backend/controllers/reportController.js
Normal file
246
backend/controllers/reportController.js
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
const Report = require('../models/Report');
|
||||||
|
const User = require('../models/User');
|
||||||
|
|
||||||
|
// @desc Подать жалобу на пользователя
|
||||||
|
// @route POST /api/reports
|
||||||
|
// @access Private
|
||||||
|
const createReport = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const { reportedUserId, reason, description } = req.body;
|
||||||
|
const reporterId = req.user._id;
|
||||||
|
|
||||||
|
// Проверяем, что пользователь не подает жалобу на самого себя
|
||||||
|
if (reporterId.equals(reportedUserId)) {
|
||||||
|
const error = new Error('Вы не можете подать жалобу на самого себя');
|
||||||
|
error.statusCode = 400;
|
||||||
|
return next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем, существует ли пользователь, на которого подается жалоба
|
||||||
|
const reportedUser = await User.findById(reportedUserId);
|
||||||
|
if (!reportedUser) {
|
||||||
|
const error = new Error('Пользователь не найден');
|
||||||
|
error.statusCode = 404;
|
||||||
|
return next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем, нет ли уже жалобы от этого пользователя на этого же пользователя
|
||||||
|
const existingReport = await Report.findOne({
|
||||||
|
reporter: reporterId,
|
||||||
|
reportedUser: reportedUserId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existingReport) {
|
||||||
|
const error = new Error('Вы уже подавали жалобу на этого пользователя');
|
||||||
|
error.statusCode = 400;
|
||||||
|
return next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создаем новую жалобу
|
||||||
|
const newReport = new Report({
|
||||||
|
reporter: reporterId,
|
||||||
|
reportedUser: reportedUserId,
|
||||||
|
reason,
|
||||||
|
description: description || ''
|
||||||
|
});
|
||||||
|
|
||||||
|
await newReport.save();
|
||||||
|
|
||||||
|
console.log(`[REPORT_CTRL] Создана жалоба ${newReport._id} от пользователя ${reporterId} на пользователя ${reportedUserId}`);
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
message: 'Жалоба успешно подана. Мы рассмотрим её в ближайшее время.',
|
||||||
|
reportId: newReport._id
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[REPORT_CTRL] Ошибка при создании жалобы:', error.message);
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// @desc Получить список всех жалоб (для админов)
|
||||||
|
// @route GET /api/admin/reports
|
||||||
|
// @access Admin
|
||||||
|
const getAllReports = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const { page = 1, limit = 20, status = 'all' } = req.query;
|
||||||
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
|
// Строим фильтр
|
||||||
|
let filter = {};
|
||||||
|
if (status !== 'all') {
|
||||||
|
filter.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получаем жалобы с информацией о пользователях
|
||||||
|
const reports = await Report.find(filter)
|
||||||
|
.populate('reporter', 'name email')
|
||||||
|
.populate('reportedUser', 'name email isActive')
|
||||||
|
.populate('reviewedBy', 'name email')
|
||||||
|
.skip(skip)
|
||||||
|
.limit(parseInt(limit))
|
||||||
|
.sort({ createdAt: -1 });
|
||||||
|
|
||||||
|
// Получаем общее количество жалоб
|
||||||
|
const total = await Report.countDocuments(filter);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
reports,
|
||||||
|
pagination: {
|
||||||
|
page: parseInt(page),
|
||||||
|
limit: parseInt(limit),
|
||||||
|
total,
|
||||||
|
pages: Math.ceil(total / limit)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[REPORT_CTRL] Ошибка при получении списка жалоб:', error.message);
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// @desc Получить детали жалобы
|
||||||
|
// @route GET /api/admin/reports/:id
|
||||||
|
// @access Admin
|
||||||
|
const getReportById = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
|
||||||
|
const report = await Report.findById(id)
|
||||||
|
.populate('reporter', 'name email photos')
|
||||||
|
.populate('reportedUser', 'name email photos isActive')
|
||||||
|
.populate('reviewedBy', 'name email');
|
||||||
|
|
||||||
|
if (!report) {
|
||||||
|
const error = new Error('Жалоба не найдена');
|
||||||
|
error.statusCode = 404;
|
||||||
|
return next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(report);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[REPORT_CTRL] Ошибка при получении деталей жалобы:', error.message);
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// @desc Обновить статус жалобы
|
||||||
|
// @route PUT /api/admin/reports/:id
|
||||||
|
// @access Admin
|
||||||
|
const updateReportStatus = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { status, adminComment, actionTaken } = req.body;
|
||||||
|
const adminId = req.user._id;
|
||||||
|
|
||||||
|
const report = await Report.findById(id);
|
||||||
|
if (!report) {
|
||||||
|
const error = new Error('Жалоба не найдена');
|
||||||
|
error.statusCode = 404;
|
||||||
|
return next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновляем жалобу
|
||||||
|
report.status = status;
|
||||||
|
report.reviewedBy = adminId;
|
||||||
|
report.reviewedAt = new Date();
|
||||||
|
|
||||||
|
if (adminComment) {
|
||||||
|
report.adminComment = adminComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionTaken) {
|
||||||
|
report.actionTaken = actionTaken;
|
||||||
|
}
|
||||||
|
|
||||||
|
await report.save();
|
||||||
|
|
||||||
|
// Если было предпринято действие, применяем его к пользователю
|
||||||
|
if (actionTaken && actionTaken !== 'none') {
|
||||||
|
const reportedUser = await User.findById(report.reportedUser);
|
||||||
|
if (reportedUser) {
|
||||||
|
switch (actionTaken) {
|
||||||
|
case 'temporary_ban':
|
||||||
|
case 'permanent_ban':
|
||||||
|
case 'profile_removal':
|
||||||
|
reportedUser.isActive = false;
|
||||||
|
await reportedUser.save();
|
||||||
|
console.log(`[REPORT_CTRL] Пользователь ${reportedUser._id} заблокирован по жалобе ${id}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[REPORT_CTRL] Жалоба ${id} обновлена администратором ${adminId}`);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
message: 'Жалоба успешно обновлена',
|
||||||
|
report: await Report.findById(id)
|
||||||
|
.populate('reporter', 'name email')
|
||||||
|
.populate('reportedUser', 'name email isActive')
|
||||||
|
.populate('reviewedBy', 'name email')
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[REPORT_CTRL] Ошибка при обновлении жалобы:', error.message);
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// @desc Получить статистику жалоб
|
||||||
|
// @route GET /api/admin/reports/stats
|
||||||
|
// @access Admin
|
||||||
|
const getReportsStats = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
// Общее количество жалоб
|
||||||
|
const totalReports = await Report.countDocuments();
|
||||||
|
|
||||||
|
// Жалобы по статусам
|
||||||
|
const pendingReports = await Report.countDocuments({ status: 'pending' });
|
||||||
|
const reviewedReports = await Report.countDocuments({ status: 'reviewed' });
|
||||||
|
const resolvedReports = await Report.countDocuments({ status: 'resolved' });
|
||||||
|
const dismissedReports = await Report.countDocuments({ status: 'dismissed' });
|
||||||
|
|
||||||
|
// Жалобы за последние 30 дней
|
||||||
|
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
|
||||||
|
const recentReports = await Report.countDocuments({
|
||||||
|
createdAt: { $gte: thirtyDaysAgo }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Топ причин жалоб
|
||||||
|
const topReasons = await Report.aggregate([
|
||||||
|
{ $group: { _id: '$reason', count: { $sum: 1 } } },
|
||||||
|
{ $sort: { count: -1 } },
|
||||||
|
{ $limit: 5 }
|
||||||
|
]);
|
||||||
|
|
||||||
|
const stats = {
|
||||||
|
total: totalReports,
|
||||||
|
byStatus: {
|
||||||
|
pending: pendingReports,
|
||||||
|
reviewed: reviewedReports,
|
||||||
|
resolved: resolvedReports,
|
||||||
|
dismissed: dismissedReports
|
||||||
|
},
|
||||||
|
recent: recentReports,
|
||||||
|
topReasons
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json(stats);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[REPORT_CTRL] Ошибка при получении статистики жалоб:', error.message);
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
createReport,
|
||||||
|
getAllReports,
|
||||||
|
getReportById,
|
||||||
|
updateReportStatus,
|
||||||
|
getReportsStats
|
||||||
|
};
|
80
backend/models/Report.js
Normal file
80
backend/models/Report.js
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
|
const reportSchema = new mongoose.Schema({
|
||||||
|
// Кто подает жалобу
|
||||||
|
reporter: {
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: 'User',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
|
||||||
|
// На кого подается жалоба
|
||||||
|
reportedUser: {
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: 'User',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
|
||||||
|
// Причина жалобы
|
||||||
|
reason: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
enum: [
|
||||||
|
'inappropriate_content',
|
||||||
|
'fake_profile',
|
||||||
|
'harassment',
|
||||||
|
'spam',
|
||||||
|
'offensive_behavior',
|
||||||
|
'underage',
|
||||||
|
'other'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Дополнительное описание
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 500
|
||||||
|
},
|
||||||
|
|
||||||
|
// Статус жалобы
|
||||||
|
status: {
|
||||||
|
type: String,
|
||||||
|
enum: ['pending', 'reviewed', 'resolved', 'dismissed'],
|
||||||
|
default: 'pending'
|
||||||
|
},
|
||||||
|
|
||||||
|
// Администратор, который рассмотрел жалобу
|
||||||
|
reviewedBy: {
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: 'User'
|
||||||
|
},
|
||||||
|
|
||||||
|
// Дата рассмотрения
|
||||||
|
reviewedAt: {
|
||||||
|
type: Date
|
||||||
|
},
|
||||||
|
|
||||||
|
// Комментарий администратора
|
||||||
|
adminComment: {
|
||||||
|
type: String,
|
||||||
|
maxlength: 500
|
||||||
|
},
|
||||||
|
|
||||||
|
// Действие, предпринятое администратором
|
||||||
|
actionTaken: {
|
||||||
|
type: String,
|
||||||
|
enum: ['none', 'warning', 'temporary_ban', 'permanent_ban', 'profile_removal']
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
timestamps: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Индексы для оптимизации запросов
|
||||||
|
reportSchema.index({ reporter: 1, reportedUser: 1 });
|
||||||
|
reportSchema.index({ reportedUser: 1, status: 1 });
|
||||||
|
reportSchema.index({ status: 1, createdAt: -1 });
|
||||||
|
|
||||||
|
// Предотвращаем дублирование жалоб от одного пользователя на другого
|
||||||
|
reportSchema.index({ reporter: 1, reportedUser: 1 }, { unique: true });
|
||||||
|
|
||||||
|
module.exports = mongoose.model('Report', reportSchema);
|
@ -3,6 +3,12 @@ const router = express.Router();
|
|||||||
const adminController = require('../controllers/adminController');
|
const adminController = require('../controllers/adminController');
|
||||||
const { protect } = require('../middleware/authMiddleware');
|
const { protect } = require('../middleware/authMiddleware');
|
||||||
const adminMiddleware = require('../middleware/adminMiddleware');
|
const adminMiddleware = require('../middleware/adminMiddleware');
|
||||||
|
const {
|
||||||
|
getAllReports,
|
||||||
|
getReportById,
|
||||||
|
updateReportStatus,
|
||||||
|
getReportsStats
|
||||||
|
} = require('../controllers/reportController');
|
||||||
|
|
||||||
// Все маршруты защищены middleware для проверки авторизации и прав администратора
|
// Все маршруты защищены middleware для проверки авторизации и прав администратора
|
||||||
router.use(protect, adminMiddleware);
|
router.use(protect, adminMiddleware);
|
||||||
@ -15,6 +21,12 @@ router.put('/users/:id/toggle-active', adminController.toggleUserActive);
|
|||||||
// Маршруты для просмотра статистики
|
// Маршруты для просмотра статистики
|
||||||
router.get('/statistics', adminController.getAppStatistics);
|
router.get('/statistics', adminController.getAppStatistics);
|
||||||
|
|
||||||
|
// Маршруты для управления жалобами
|
||||||
|
router.get('/reports', getAllReports);
|
||||||
|
router.get('/reports/stats', getReportsStats);
|
||||||
|
router.get('/reports/:id', getReportById);
|
||||||
|
router.put('/reports/:id', updateReportStatus);
|
||||||
|
|
||||||
// Маршруты для просмотра диалогов и сообщений
|
// Маршруты для просмотра диалогов и сообщений
|
||||||
router.get('/conversations', adminController.getAllConversations);
|
router.get('/conversations', adminController.getAllConversations);
|
||||||
router.get('/conversations/:id/messages', adminController.getConversationMessages);
|
router.get('/conversations/:id/messages', adminController.getConversationMessages);
|
||||||
|
13
backend/routes/reportRoutes.js
Normal file
13
backend/routes/reportRoutes.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const { protect } = require('../middleware/authMiddleware');
|
||||||
|
const {
|
||||||
|
createReport
|
||||||
|
} = require('../controllers/reportController');
|
||||||
|
|
||||||
|
// @desc Подать жалобу на пользователя
|
||||||
|
// @route POST /api/reports
|
||||||
|
// @access Private
|
||||||
|
router.post('/', protect, createReport);
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -14,6 +14,7 @@ const authRoutes = require('./routes/authRoutes'); // <--- 1. РАСКОММЕН
|
|||||||
const userRoutes = require('./routes/userRoutes'); // 1. Импортируем userRoutes
|
const userRoutes = require('./routes/userRoutes'); // 1. Импортируем userRoutes
|
||||||
const actionRoutes = require('./routes/actionRoutes'); // 1. Импортируем actionRoutes
|
const actionRoutes = require('./routes/actionRoutes'); // 1. Импортируем actionRoutes
|
||||||
const adminRoutes = require('./routes/adminRoutes'); // Импортируем маршруты админа
|
const adminRoutes = require('./routes/adminRoutes'); // Импортируем маршруты админа
|
||||||
|
const reportRoutes = require('./routes/reportRoutes'); // Импортируем маршруты для жалоб
|
||||||
const Message = require('./models/Message'); // Импорт модели Message
|
const Message = require('./models/Message'); // Импорт модели Message
|
||||||
const Conversation = require('./models/Conversation'); // Импорт модели Conversation
|
const Conversation = require('./models/Conversation'); // Импорт модели Conversation
|
||||||
const initAdminAccount = require('./utils/initAdmin'); // Импорт инициализации админ-аккаунта
|
const initAdminAccount = require('./utils/initAdmin'); // Импорт инициализации админ-аккаунта
|
||||||
@ -79,6 +80,7 @@ app.use('/api/auth', authRoutes);
|
|||||||
app.use('/api/users', userRoutes); // 2. Подключаем userRoutes с префиксом /api/users
|
app.use('/api/users', userRoutes); // 2. Подключаем userRoutes с префиксом /api/users
|
||||||
app.use('/api/actions', actionRoutes);
|
app.use('/api/actions', actionRoutes);
|
||||||
app.use('/api/conversations', conversationRoutes);
|
app.use('/api/conversations', conversationRoutes);
|
||||||
|
app.use('/api/reports', reportRoutes); // Подключаем маршруты для жалоб
|
||||||
app.use('/api/admin', adminRoutes); // Подключаем маршруты для админ-панели
|
app.use('/api/admin', adminRoutes); // Подключаем маршруты для админ-панели
|
||||||
|
|
||||||
// Socket.IO логика
|
// Socket.IO логика
|
||||||
|
352
src/components/ReportModal.vue
Normal file
352
src/components/ReportModal.vue
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="isVisible" class="report-modal-overlay" @click="closeModal">
|
||||||
|
<div class="report-modal" @click.stop>
|
||||||
|
<div class="modal-header">
|
||||||
|
<h3>Пожаловаться на пользователя</h3>
|
||||||
|
<button class="close-btn" @click="closeModal">
|
||||||
|
<i class="bi-x"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-content">
|
||||||
|
<div v-if="error" class="error-message">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="success" class="success-message">
|
||||||
|
{{ success }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form @submit.prevent="submitReport" v-if="!success">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="reason">Причина жалобы *</label>
|
||||||
|
<select id="reason" v-model="reportData.reason" required>
|
||||||
|
<option value="">Выберите причину</option>
|
||||||
|
<option value="inappropriate_content">Неподходящий контент</option>
|
||||||
|
<option value="fake_profile">Поддельный профиль</option>
|
||||||
|
<option value="harassment">Домогательства</option>
|
||||||
|
<option value="spam">Спам</option>
|
||||||
|
<option value="offensive_behavior">Оскорбительное поведение</option>
|
||||||
|
<option value="underage">Несовершеннолетний</option>
|
||||||
|
<option value="other">Другое</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="description">Дополнительная информация</label>
|
||||||
|
<textarea
|
||||||
|
id="description"
|
||||||
|
v-model="reportData.description"
|
||||||
|
placeholder="Опишите подробнее, что произошло (необязательно)"
|
||||||
|
rows="4"
|
||||||
|
maxlength="500"
|
||||||
|
></textarea>
|
||||||
|
<div class="char-count">
|
||||||
|
{{ reportData.description.length }}/500
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="button" class="btn btn-secondary" @click="closeModal" :disabled="loading">
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button type="submit" class="btn btn-primary" :disabled="loading || !reportData.reason">
|
||||||
|
<span v-if="loading" class="spinner"></span>
|
||||||
|
{{ loading ? 'Отправка...' : 'Отправить жалобу' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div v-if="success" class="success-actions">
|
||||||
|
<button class="btn btn-primary" @click="closeModal">
|
||||||
|
Закрыть
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, reactive, watch } from 'vue';
|
||||||
|
import api from '@/services/api';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
isVisible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
reportedUserId: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
reportedUserName: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(['close', 'reported']);
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const error = ref('');
|
||||||
|
const success = ref('');
|
||||||
|
|
||||||
|
const reportData = reactive({
|
||||||
|
reason: '',
|
||||||
|
description: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
// Сброс формы при открытии модального окна
|
||||||
|
watch(() => props.isVisible, (newValue) => {
|
||||||
|
if (newValue) {
|
||||||
|
reportData.reason = '';
|
||||||
|
reportData.description = '';
|
||||||
|
error.value = '';
|
||||||
|
success.value = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
emit('close');
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitReport = async () => {
|
||||||
|
if (!reportData.reason) {
|
||||||
|
error.value = 'Пожалуйста, выберите причину жалобы';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true;
|
||||||
|
error.value = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await api.createReport({
|
||||||
|
reportedUserId: props.reportedUserId,
|
||||||
|
reason: reportData.reason,
|
||||||
|
description: reportData.description.trim()
|
||||||
|
});
|
||||||
|
|
||||||
|
success.value = response.data.message;
|
||||||
|
emit('reported');
|
||||||
|
|
||||||
|
// Закрываем модальное окно через 2 секунды
|
||||||
|
setTimeout(() => {
|
||||||
|
closeModal();
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Ошибка при отправке жалобы:', err);
|
||||||
|
error.value = err.response?.data?.message || 'Произошла ошибка при отправке жалобы';
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.report-modal-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 1000;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.report-modal {
|
||||||
|
background: white;
|
||||||
|
border-radius: 16px;
|
||||||
|
max-width: 500px;
|
||||||
|
width: 100%;
|
||||||
|
max-height: 90vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 1.5rem 1.5rem 0;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header h3 {
|
||||||
|
margin: 0;
|
||||||
|
color: #333;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #666;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn:hover {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-content {
|
||||||
|
padding: 0 1.5rem 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
background-color: #ffebee;
|
||||||
|
border-left: 4px solid #f44336;
|
||||||
|
color: #d32f2f;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.success-message {
|
||||||
|
background-color: #e8f5e8;
|
||||||
|
border-left: 4px solid #4caf50;
|
||||||
|
color: #2e7d32;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group select,
|
||||||
|
.form-group textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: 2px solid #e1e1e1;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: border-color 0.2s ease;
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group select:focus,
|
||||||
|
.form-group textarea:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #667eea;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group textarea {
|
||||||
|
resize: vertical;
|
||||||
|
min-height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.char-count {
|
||||||
|
text-align: right;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #666;
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-actions,
|
||||||
|
.success-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
justify-content: flex-end;
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary:hover:not(:disabled) {
|
||||||
|
background-color: #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background: linear-gradient(45deg, #667eea, #764ba2);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover:not(:disabled) {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 2px solid transparent;
|
||||||
|
border-top: 2px solid currentColor;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Адаптивные стили */
|
||||||
|
@media (max-width: 576px) {
|
||||||
|
.report-modal {
|
||||||
|
margin: 1rem;
|
||||||
|
max-width: calc(100% - 2rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
padding: 1rem 1rem 0;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-content {
|
||||||
|
padding: 0 1rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-actions {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -121,5 +121,27 @@ export default {
|
|||||||
// Новый метод для записи просмотра профиля
|
// Новый метод для записи просмотра профиля
|
||||||
recordProfileView(userId, source = 'other') {
|
recordProfileView(userId, source = 'other') {
|
||||||
return apiClient.post(`/users/${userId}/view`, { source });
|
return apiClient.post(`/users/${userId}/view`, { source });
|
||||||
|
},
|
||||||
|
|
||||||
|
// Методы для работы с жалобами
|
||||||
|
createReport(reportData) {
|
||||||
|
return apiClient.post('/reports', reportData);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Админские методы для жалоб
|
||||||
|
getReports(params = {}) {
|
||||||
|
return apiClient.get('/admin/reports', { params });
|
||||||
|
},
|
||||||
|
|
||||||
|
getReportById(reportId) {
|
||||||
|
return apiClient.get(`/admin/reports/${reportId}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
updateReportStatus(reportId, updateData) {
|
||||||
|
return apiClient.put(`/admin/reports/${reportId}`, updateData);
|
||||||
|
},
|
||||||
|
|
||||||
|
getReportsStats() {
|
||||||
|
return apiClient.get('/admin/reports/stats');
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -140,6 +140,15 @@
|
|||||||
<h3 class="user-name">{{ user.name }}<span class="user-age">, {{ user.age || '?' }}</span></h3>
|
<h3 class="user-name">{{ user.name }}<span class="user-age">, {{ user.age || '?' }}</span></h3>
|
||||||
<p class="user-gender">{{ formatGender(user.gender) }}</p>
|
<p class="user-gender">{{ formatGender(user.gender) }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Report Button -->
|
||||||
|
<button
|
||||||
|
class="report-btn"
|
||||||
|
@click.stop="openReportModal(user)"
|
||||||
|
title="Пожаловаться"
|
||||||
|
>
|
||||||
|
<i class="bi-flag"></i>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- User Details Section -->
|
<!-- User Details Section -->
|
||||||
@ -181,6 +190,15 @@
|
|||||||
class="overlay"
|
class="overlay"
|
||||||
@click="continueSearching"
|
@click="continueSearching"
|
||||||
></div>
|
></div>
|
||||||
|
|
||||||
|
<!-- Report Modal -->
|
||||||
|
<ReportModal
|
||||||
|
:isVisible="showReportModal"
|
||||||
|
:reportedUserId="selectedUserForReport?._id || ''"
|
||||||
|
:reportedUserName="selectedUserForReport?.name || ''"
|
||||||
|
@close="closeReportModal"
|
||||||
|
@reported="handleReportSubmitted"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -189,6 +207,7 @@ import { ref, onMounted, computed, reactive, watch, onUnmounted, nextTick } from
|
|||||||
import api from '@/services/api';
|
import api from '@/services/api';
|
||||||
import { useAuth } from '@/auth';
|
import { useAuth } from '@/auth';
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
|
import ReportModal from '@/components/ReportModal.vue';
|
||||||
|
|
||||||
const { isAuthenticated, logout } = useAuth();
|
const { isAuthenticated, logout } = useAuth();
|
||||||
|
|
||||||
@ -202,6 +221,10 @@ const matchOccurred = ref(false);
|
|||||||
const matchedUserId = ref(null);
|
const matchedUserId = ref(null);
|
||||||
const swipeArea = ref(null);
|
const swipeArea = ref(null);
|
||||||
|
|
||||||
|
// Для системы жалоб
|
||||||
|
const showReportModal = ref(false);
|
||||||
|
const selectedUserForReport = ref(null);
|
||||||
|
|
||||||
// Для карусели фото
|
// Для карусели фото
|
||||||
const currentPhotoIndex = reactive({});
|
const currentPhotoIndex = reactive({});
|
||||||
|
|
||||||
@ -797,6 +820,22 @@ watch(currentUserToSwipe, async (newUser, oldUser) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Методы для работы с модальным окном жалоб
|
||||||
|
const openReportModal = (user) => {
|
||||||
|
selectedUserForReport.value = user;
|
||||||
|
showReportModal.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeReportModal = () => {
|
||||||
|
showReportModal.value = false;
|
||||||
|
selectedUserForReport.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReportSubmitted = () => {
|
||||||
|
// Просто закрываем модальное окно, оно само покажет сообщение об успехе
|
||||||
|
console.log('[SwipeView] Жалоба отправлена');
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@ -1171,6 +1210,36 @@ watch(currentUserToSwipe, async (newUser, oldUser) => {
|
|||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Кнопка жалобы */
|
||||||
|
.report-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 16px;
|
||||||
|
right: 16px;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: white;
|
||||||
|
font-size: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
z-index: 6;
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.report-btn:hover {
|
||||||
|
background: rgba(220, 53, 69, 0.8);
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.report-btn:active {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
|
||||||
/* Секция с деталями */
|
/* Секция с деталями */
|
||||||
.card-details-section {
|
.card-details-section {
|
||||||
background: white;
|
background: white;
|
||||||
|
@ -158,6 +158,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<span>Нравится</span>
|
<span>Нравится</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="action-btn report-btn"
|
||||||
|
@click="openReportModal"
|
||||||
|
title="Пожаловаться"
|
||||||
|
>
|
||||||
|
<div class="btn-icon">
|
||||||
|
<i class="bi-flag"></i>
|
||||||
|
</div>
|
||||||
|
<span>Жалоба</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@ -188,6 +199,15 @@
|
|||||||
class="overlay"
|
class="overlay"
|
||||||
@click="goBack"
|
@click="goBack"
|
||||||
></div>
|
></div>
|
||||||
|
|
||||||
|
<!-- Report Modal -->
|
||||||
|
<ReportModal
|
||||||
|
:isVisible="showReportModal"
|
||||||
|
:reportedUserId="user?._id || ''"
|
||||||
|
:reportedUserName="user?.name || ''"
|
||||||
|
@close="closeReportModal"
|
||||||
|
@reported="handleReportSubmitted"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -195,6 +215,7 @@
|
|||||||
import { ref, onMounted, computed } from 'vue';
|
import { ref, onMounted, computed } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import api from '@/services/api';
|
import api from '@/services/api';
|
||||||
|
import ReportModal from '@/components/ReportModal.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -207,6 +228,9 @@ const error = ref('');
|
|||||||
const currentPhotoIndex = ref(0);
|
const currentPhotoIndex = ref(0);
|
||||||
const matchOccurred = ref(false);
|
const matchOccurred = ref(false);
|
||||||
|
|
||||||
|
// Для системы жалоб
|
||||||
|
const showReportModal = ref(false);
|
||||||
|
|
||||||
// Computed properties
|
// Computed properties
|
||||||
const userAge = computed(() => {
|
const userAge = computed(() => {
|
||||||
if (!user.value?.dateOfBirth) return null;
|
if (!user.value?.dateOfBirth) return null;
|
||||||
@ -334,6 +358,20 @@ const onImageError = (event) => {
|
|||||||
console.warn('[UserProfileView] Ошибка загрузки изображения:', event.target.src);
|
console.warn('[UserProfileView] Ошибка загрузки изображения:', event.target.src);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Report modal methods
|
||||||
|
const openReportModal = () => {
|
||||||
|
showReportModal.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeReportModal = () => {
|
||||||
|
showReportModal.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReportSubmitted = () => {
|
||||||
|
// Просто закрываем модальное окно, оно само покажет сообщение об успехе
|
||||||
|
console.log('[UserProfileView] Жалоба отправлена');
|
||||||
|
};
|
||||||
|
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadUser();
|
loadUser();
|
||||||
@ -770,6 +808,11 @@ onMounted(() => {
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.report-btn .btn-icon {
|
||||||
|
background: linear-gradient(45deg, #007bff, #0056b3);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
.pass-btn {
|
.pass-btn {
|
||||||
color: #dc3545;
|
color: #dc3545;
|
||||||
}
|
}
|
||||||
@ -778,6 +821,10 @@ onMounted(() => {
|
|||||||
color: #28a745;
|
color: #28a745;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.report-btn {
|
||||||
|
color: #007bff;
|
||||||
|
}
|
||||||
|
|
||||||
/* Всплывающее окно совпадения */
|
/* Всплывающее окно совпадения */
|
||||||
.match-popup {
|
.match-popup {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user