XRoomDashboardFront/xroom-dashboard/src/components/TeamDetails.vue

513 lines
11 KiB
Vue
Raw Normal View History

<template>
<div class="tab-content">
2025-06-07 23:29:17 +00:00
<!-- Team Logo Section -->
2025-05-29 23:02:44 +00:00
<div class="team-logo">
<div class="card-title">
<h2>لوگوی تیم</h2>
2025-06-07 23:29:17 +00:00
<p>این لوگو در اتاقهای شما نمایش داده میشود. توصیه میشود از تصویر شفاف با نسبت 2:1 استفاده کنید.</p>
2025-05-29 23:02:44 +00:00
</div>
<div class="logo-info">
<img :src="teamLogo || require('@/assets/img/team-logo.jpg')" alt="team logo" />
<label for="file-upload">
<span>
<svg
xmlns="http://www.w3.org/2000/svg"
width="19"
height="19"
viewBox="0 0 16 16"
fill="none"
>
2025-06-07 23:29:17 +00:00
<path
d="M2.66602 11.3333V12.6666C2.66602 13.0202 2.80649 13.3593 3.05654 13.6094C3.30659 13.8594 3.64573 13.9999 3.99935 13.9999H11.9993C12.353 13.9999 12.6921 13.8594 12.9422 13.6094C13.1922 13.3593 13.3327 13.0202 13.3327 12.6666V11.3333"
stroke="white"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M4.66602 6.00008L7.99935 2.66675L11.3327 6.00008"
stroke="white"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M8 2.66675V10.6667"
stroke="white"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
2025-05-29 23:02:44 +00:00
</svg>
</span>
<span>آپلود</span>
</label>
<input
id="file-upload"
type="file"
accept="image/*"
style="display: none;"
@change="handleLogoUpload"
ref="fileUpload"
/>
</div>
<div class="logo-sample">
<div class="logo-sample-title">
<h2>نمونه</h2>
2025-06-07 23:29:17 +00:00
<span>نمایش لوگوی تیم شما در اتاقها به این شکل خواهد بود.</span>
2025-05-29 23:02:44 +00:00
</div>
<div class="sample-logos">
<img
v-for="(logo, index) in sampleLogos"
:key="index"
:src="require(`@/assets${logo.path}`)"
:alt="logo.alt"
/>
</div>
</div>
</div>
2025-06-07 23:29:17 +00:00
<!-- Team Info Section -->
2025-05-29 23:02:44 +00:00
<div class="team-info">
<div class="card-title">
<h2>جزئیات تیم</h2>
<form @submit.prevent="submitForm">
<div class="form-group">
<label for="team_name">نام تیم</label>
<input
id="team_name"
type="text"
v-model="form.teamName"
/>
</div>
<div class="form-group">
2025-06-07 23:29:17 +00:00
<label for="type_activity">نوع فعالیت</label>
2025-05-29 23:02:44 +00:00
<input
id="type_activity"
type="text"
v-model="form.activityType"
/>
</div>
<button type="submit" class="submit-btn">تایید</button>
</form>
</div>
</div>
</div>
</template>
<script>
2025-06-05 17:33:09 +00:00
import axios from 'axios';
export default {
name: 'TeamDetails',
2025-05-29 23:02:44 +00:00
data() {
return {
form: {
teamName: '',
activityType: '',
2025-06-05 17:33:09 +00:00
teamId: null,
2025-05-29 23:02:44 +00:00
},
teamLogo: null,
uploadedLogoFile: null,
sampleLogos: [
{ path: '/img/sample-logo.png', alt: 'نمونه لوگو' },
{ path: '/img/sample-logo.png', alt: 'نمونه لوگو' },
{ path: '/img/sample-logo.png', alt: 'نمونه لوگو' },
],
2025-06-05 17:33:09 +00:00
baseUrl: 'http://my.xroomapp.com:8000',
2025-05-29 23:02:44 +00:00
};
},
2025-06-05 17:33:09 +00:00
created() {
this.fetchTeamData();
},
2025-05-29 23:02:44 +00:00
methods: {
2025-06-05 17:33:09 +00:00
async fetchTeamData() {
try {
const token = localStorage.getItem('token');
2025-06-07 23:29:17 +00:00
if (!token) throw new Error('توکن احراز هویت یافت نشد.');
2025-06-05 17:33:09 +00:00
const response = await axios.get(`${this.baseUrl}/get_team`, {
2025-06-07 23:29:17 +00:00
headers: { Authorization: `Token ${token}`, 'Content-Type': 'application/json' },
2025-06-05 17:33:09 +00:00
});
const team = response.data.teams[0];
if (team) {
this.form.teamName = team.name || '';
this.form.activityType = team.description || '';
this.form.teamId = team.id;
2025-06-07 23:29:17 +00:00
this.teamLogo = team.logo ? `${this.baseUrl}${team.logo}` : null;
2025-06-05 17:33:09 +00:00
} else {
alert('هیچ اطلاعاتی برای تیم یافت نشد.');
}
2025-06-07 23:29:17 +00:00
} catch {
alert('خطا در بارگذاری اطلاعات تیم.');
2025-06-05 17:33:09 +00:00
}
},
2025-05-29 23:02:44 +00:00
handleLogoUpload(event) {
2025-06-07 23:29:17 +00:00
this.uploadedLogoFile = event.target.files[0];
if (this.uploadedLogoFile) {
this.teamLogo = URL.createObjectURL(this.uploadedLogoFile);
2025-05-29 23:02:44 +00:00
}
},
2025-06-05 17:33:09 +00:00
async submitForm() {
2025-06-07 23:29:17 +00:00
if (!this.form.teamName && !this.form.activityType && !this.uploadedLogoFile) {
alert('لطفاً حداقل یک فیلد یا لوگو وارد کنید.');
2025-05-29 23:02:44 +00:00
return;
}
2025-06-05 17:33:09 +00:00
try {
2025-06-07 23:29:17 +00:00
const formData = new FormData();
if (this.form.teamName) formData.append('name', this.form.teamName);
if (this.form.activityType) formData.append('description', this.form.activityType);
if (this.uploadedLogoFile) formData.append('logo', this.uploadedLogoFile);
2025-06-05 17:33:09 +00:00
const token = localStorage.getItem('token');
2025-06-07 23:29:17 +00:00
if (!token) throw new Error('توکن احراز هویت یافت نشد.');
2025-06-05 17:33:09 +00:00
await axios.patch(`${this.baseUrl}/update_team/${this.form.teamId}/`, formData, {
2025-06-07 23:29:17 +00:00
headers: { Authorization: `Token ${token}`, 'Content-Type': 'multipart/form-data' },
2025-06-05 17:33:09 +00:00
});
2025-06-07 23:29:17 +00:00
this.$emit('update:team-data', {
2025-06-05 17:33:09 +00:00
teamName: this.form.teamName,
activityType: this.form.activityType,
teamLogo: this.uploadedLogoFile,
});
2025-06-07 23:29:17 +00:00
alert('اطلاعات تیم با موفقیت به‌روزرسانی شد.');
this.resetForm();
2025-06-05 17:33:09 +00:00
await this.fetchTeamData();
2025-06-07 23:29:17 +00:00
} catch {
alert('خطا در به‌روزرسانی اطلاعات تیم.');
}
},
resetForm() {
this.form.teamName = '';
this.form.activityType = '';
this.teamLogo = null;
this.uploadedLogoFile = null;
if (this.$refs.fileUpload) {
this.$refs.fileUpload.value = '';
2025-05-29 23:02:44 +00:00
}
},
},
};
</script>
<style scoped>
.tab-content {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
2025-05-29 23:02:44 +00:00
.team-logo,
.team-info {
2025-06-12 14:59:00 +00:00
background: #ffffff;
2025-05-29 23:02:44 +00:00
border: none;
border-radius: 16px;
padding: 1.5rem;
}
.team-logo {
display: flex;
flex-direction: column;
gap: 2.5rem;
}
.card-title,
.logo-sample-title {
display: flex;
flex-direction: column;
gap: 2rem;
}
.card-title h2,
.logo-sample-title h2 {
color: #101010;
font-weight: 600;
font-size: 20px;
}
.card-title p,
.logo-sample-title span {
color: #5a6678;
font-weight: 500;
font-size: 17px;
line-height: 190%;
max-width: 90%;
}
.logo-sample-title {
gap: 1rem !important;
}
.logo-sample {
margin-top: 1rem;
display: flex;
flex-direction: column;
gap: 1.5rem !important;
}
.logo-info {
display: flex;
align-items: center;
gap: 3rem;
}
.logo-info img {
border-radius: 12px;
height: 150px;
max-width: 150px;
width: 100%;
object-fit: cover;
}
.logo-info label {
display: flex;
align-items: center;
gap: 0.5rem;
background-color: #6dc993;
padding: 10px 26px;
border-radius: 10px;
border: none;
font-size: 18px;
color: #fff;
cursor: pointer;
}
.sample-logos {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.sample-logos img {
height: 110px;
width: 110px;
border-radius: 12px;
2025-05-29 23:02:44 +00:00
}
.form-group {
margin-bottom: 2.5rem;
display: flex;
align-items: center;
justify-content: space-between;
}
.form-group label {
font-weight: 500;
width: 70%;
font-size: 16px;
}
.form-group input {
width: 100%;
padding: 8px;
border: 1px solid #718096;
border-radius: 8px;
font-size: 1rem;
}
.form-group input:focus {
outline: none;
}
.submit-btn {
background-color: #3a57e8;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
height: 50px;
width: 60%;
font-weight: 500;
font-size: 18px;
text-align: center;
float: left;
margin-top: 0.5rem;
}
2025-06-12 14:59:00 +00:00
/* Mobile (max-width: 600px) */
@media (max-width: 600px) {
.tab-content {
flex-direction: column;
gap: 12px;
}
.team-logo {
gap: 1rem;
}
.team-logo,
.team-info {
width: 100%;
padding: 1rem;
}
.card-title h2,
.logo-sample-title h2 {
font-size: 16px;
}
.card-title p,
.logo-sample-title span {
font-size: 14px;
max-width: 100%;
}
.logo-info {
flex-direction: row;
gap: 1rem;
align-items: center;
}
.logo-info img {
height: 100px;
max-width: 100px;
}
.logo-info label {
font-size: 16px;
padding: 8px 20px;
}
.sample-logos {
justify-content: center;
}
.sample-logos img {
height: 90px;
width: 30%;
object-fit: cover;
}
.form-group label {
font-size: 14px;
width: 100%;
}
.form-group input {
font-size: 14px;
padding: 6px;
}
.submit-btn {
width: 100%;
font-size: 16px;
height: 40px;
}
}
/* Tablet (min-width: 600px - max-width: 1024px) */
@media (min-width: 600px) and (max-width: 1024px) {
.tab-content {
flex-direction: column;
gap: 14px;
}
.team-logo,
.team-info {
width: 100%;
padding: 1.25rem;
}
.card-title h2,
.logo-sample-title h2 {
font-size: 18px;
}
.card-title p,
.logo-sample-title span {
font-size: 15px;
max-width: 95%;
}
.logo-info {
gap: 2rem;
}
.logo-info img {
height: 120px;
max-width: 120px;
}
.logo-info label {
font-size: 16px;
padding: 9px 22px;
}
.sample-logos img {
height: 120px;
width: 120px;
}
.form-group label {
font-size: 15px;
width: 80%;
}
.form-group input {
font-size: 15px;
padding: 7px;
}
.submit-btn {
width: 100%;
font-size: 17px;
height: 45px;
}
}
/* Small Laptop (min-width: 1024px - max-width: 1280px) */
@media (min-width: 1024px) and (max-width: 1280px) {
.team-logo,
.team-info {
width: 100%;
padding: 1.25rem;
}
.card-title h2,
.logo-sample-title h2 {
font-size: 19px;
}
.card-title p,
.logo-sample-title span {
font-size: 16px;
max-width: 90%;
}
.logo-info img {
height: 130px;
max-width: 130px;
}
.logo-info label {
font-size: 17px;
padding: 9px 24px;
}
.sample-logos img {
height: 100px;
width: 100px;
}
.form-group label {
font-size: 15px;
}
.form-group input {
font-size: 15px;
padding: 7px;
}
.submit-btn {
width: 70%;
font-size: 17px;
height: 45px;
}
}
/* Desktop (min-width: 1280px) */
@media (min-width: 1280px) {
.team-logo,
.team-info {
width: 49%;
}
}
</style>