Skip to content

Commit

Permalink
front update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariiiii committed Dec 7, 2024
1 parent 07fe244 commit 6151aa3
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 39 deletions.
3 changes: 2 additions & 1 deletion backend/app/routes/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def login():
return jsonify({"message": "Admin logged in successfully",
"userId": str(admin.id),
"userType": "admin",
"token": token}), 200
"token": token,
"userName": admin.name}), 200

print(client.password, password)
if client and client.password == password:
Expand Down
4 changes: 3 additions & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM node:14.21.3
WORKDIR /app
COPY . .
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "run", "serve"]
10 changes: 7 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
"dependencies": {
"axios": "^0.21.1",
"vue": "^3.0.0",
"vue-router": "^4.0.0"
"vue-router": "^4.0.0",
"chart.js": "^3.7.1"
},
"devDependencies": {
"@vue/cli-service": "~4.5.0"
"@vue/cli-service": "~4.5.0",
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"babel-loader": "^8.2.2"
}
}
}
2 changes: 2 additions & 0 deletions frontend/src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<li v-if="isAdmin"><router-link to="/admin/main">SCAM-BANK</router-link></li>
<li v-if="isClient"><router-link to="/client/credit">Кредиты</router-link></li>
<li v-if="isClient"><router-link to="/client/request">Заявки</router-link></li>
<li v-if="isAdmin"><router-link to="/admin/statistics">Cтатистика</router-link></li>
<li v-if="isAdmin"><router-link to="/admin/request">Заявки</router-link></li>
<li v-if="isAdmin"><router-link to="/admin/main">История</router-link></li>
<li v-if="isClient && !isOnProfilePage"><router-link to="/client/profile">{{ userName }}</router-link></li>
<li v-if="isAdmin && !isOnProfilePage"><router-link to="/admin/profile">{{ userName }}</router-link></li>
<li v-if="isClient && isOnProfilePage"><a href="#" @click.prevent="logout">Выход</a></li>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import AdminRequest from '../views/admin/Request.vue';
import ClientProfile from '../views/client/Profile.vue';
import AdminProfile from '../views/admin/Profile.vue';
import ClientLoanApplication from '../views/client/LoanApplication.vue';
import Statistics from '../views/admin/Statistics.vue';

const routes = [
// { path: '/', redirect: '/login' },
Expand All @@ -21,6 +22,7 @@ const routes = [
{ path: '/admin/request', component: AdminRequest },
{ path: '/client/profile', component: ClientProfile },
{ path: '/admin/profile', component: AdminProfile },
{ path: '/admin/statistics', component: Statistics },
{ path: '/client/loan-application', component: ClientLoanApplication },
];

Expand Down
1 change: 0 additions & 1 deletion frontend/src/views/admin/Main.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div class="main-container">
<h1>Добро пожаловать, admin!</h1>
<h2>Оформление кредита</h2>
<h2>У вас есть непросмотренные заявки!</h2>
<h2>Вы можете посмотреть их здесь.</h2>
</div>
Expand Down
210 changes: 210 additions & 0 deletions frontend/src/views/admin/Statistics.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<template>
<div class="statistics-container">
<main>
<h1>Статистика</h1>
<div class="filters-and-chart">
<div class="filters">
<div class="filter">
<label for="client">Сотрудник/клиент</label>
<select id="client" v-model="selectedClientType">
<option value="employee">Сотрудник</option>
<option value="client">Клиент</option>
</select>
</div>
<div class="filter">
<label for="name">ФИО</label>
<input type="text" id="name" v-model="selectedName">
</div>
<div class="filter">
<label for="credit">Название кредита</label>
<select id="credit" v-model="selectedCreditType">
<option value="credit1">Кредит 1</option>
<option value="credit2">Кредит 2</option>
</select>
</div>
<div class="filter">
<label for="filter">Фильтр</label>
<select id="filter" v-model="selectedFilter">
<option value="all">Все</option>
<option value="openDate">Дата открытия кредита</option>
<option value="creditSum">Сумма кредита</option>
<option value="creditTerm">Срок кредита</option>
<option value="monthlyPayment">Ежемесячный платеж</option>
<option value="creditStatus">Статус кредита</option>
</select>
</div>
<div class="buttons">
<Button text="Экспортировать" @click="exportData" />
<Button text="Импортировать" @click="importData" />
<Button text="Построить" @click="buildChart" />
</div>
</div>
<div class="chart-container">
<canvas id="creditChart"></canvas>
</div>
</div>
</main>
<Notification
:message="notificationMessage"
:type="notificationType"
:visible="showNotification"
@close="closeNotification"
/>
</div>
</template>

<script>
import Button from '../../components/Button.vue';
import Notification from '../../components/Notification.vue';
import Chart from 'chart.js/auto';
export default {
name: 'Statistics',
components: {
Button,
Notification
},
data() {
return {
selectedClientType: 'employee',
selectedName: '',
selectedCreditType: 'credit1',
selectedFilter: 'all',
notificationMessage: '',
notificationType: 'info',
showNotification: false,
userName: localStorage.getItem('userName') || 'Пользователь'
};
},
methods: {
exportData() {
// Логика экспорта данных
this.showNotification = true;
this.notificationMessage = 'Данные экспортированы';
this.notificationType = 'success';
},
importData() {
// Логика импорта данных
this.showNotification = true;
this.notificationMessage = 'Данные импортированы';
this.notificationType = 'success';
},
buildChart() {
const ctx = document.getElementById('creditChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
datasets: [{
label: 'Сумма кредита',
data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4],
backgroundColor: [
'rgba(255, 192, 203, 0.5)',
'rgba(139, 0, 139, 0.5)',
'rgba(255, 192, 203, 0.5)',
'rgba(139, 0, 139, 0.5)',
'rgba(255, 192, 203, 0.5)',
'rgba(139, 0, 139, 0.5)',
'rgba(255, 192, 203, 0.5)',
'rgba(139, 0, 139, 0.5)',
'rgba(255, 192, 203, 0.5)',
'rgba(139, 0, 139, 0.5)',
'rgba(255, 192, 203, 0.5)',
'rgba(139, 0, 139, 0.5)'
],
borderColor: [
'rgba(255, 192, 203, 1)',
'rgba(139, 0, 139, 1)',
'rgba(255, 192, 203, 1)',
'rgba(139, 0, 139, 1)',
'rgba(255, 192, 203, 1)',
'rgba(139, 0, 139, 1)',
'rgba(255, 192, 203, 1)',
'rgba(139, 0, 139, 1)',
'rgba(255, 192, 203, 1)',
'rgba(139, 0, 139, 1)',
'rgba(255, 192, 203, 1)',
'rgba(139, 0, 139, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
},
closeNotification() {
this.showNotification = false;
}
}
};
</script>

<style scoped>
.statistics-container {
display: flex;
flex-direction: column;
align-items: center;
}
main {
padding: 20px;
width: 100%;
}
h1 {
margin-top: 0;
}
.filters-and-chart {
display: flex;
width: 100%;
}
.filters {
display: flex;
flex-direction: column;
width: 30%;
margin-right: 20px;
}
.filter {
margin-bottom: 10px;
}
.filter label {
display: block;
margin-bottom: 5px;
}
.filter select, .filter input {
padding: 5px;
width: 100%;
}
.buttons {
display: flex;
flex-direction: column;
gap: 10px;
}
.buttons button {
padding: 0.5em 1em;
font-size: 0.9em;
}
.chart-container {
width: 70%;
}
.chart {
width: 100%;
max-width: 800px;
margin: 0 auto;
}
</style>
19 changes: 12 additions & 7 deletions frontend/src/views/client/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,19 @@ export default {
};
},
created() {
this.fetchProfile();
this.getProfile();
},
methods: {
async fetchProfile() {
async getProfile() {
const userId = localStorage.getItem("userId");
const userType = localStorage.getItem("userType");
try {
const response = await axios.get(
`http://127.0.0.1:5000/profile?client_id=${userId}`
);
const response = await axios.get('http://127.0.0.1:5000/get_profile', {
params: {
userId: userId,
userType: userType
}
});
this.profile = response.data;
} catch (error) {
console.error("Ошибка при получении профиля:", error);
Expand All @@ -165,12 +169,13 @@ export default {
}
const userId = localStorage.getItem("userId");
try {
await axios.post(`http://127.0.0.1:5000/profile`, {
await axios.post(`http://127.0.0.1:5000/client_profile_change`, {
client_id: userId,
...this.profile,
});
this.isEditing = false;
alert("Профиль успешно сохранен!");
this.getProfile()
} catch (error) {
console.error("Ошибка при сохранении профиля:", error);
alert("Произошла ошибка при сохранении профиля.");
Expand Down Expand Up @@ -236,7 +241,7 @@ h1 {
.profile-form {
display: flex;
justify-content: space-between;
gap: 50px; /* Увеличенное расстояние между столбцами */
gap: 50px;
}
.profile-column {
Expand Down
Loading

0 comments on commit 6151aa3

Please sign in to comment.