club home redesign; deal card menu: delete with confirmation

This commit is contained in:
2026-10-12 12:39:52 +03:30
parent b43ed68e82
commit 8af78047d9
17 changed files with 569 additions and 470 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

+355 -291
View File
@@ -8,23 +8,68 @@ import { toFaDigits } from '@/lib/jalali';
import { faNum, signedFa, timeAgo, txIcon } from '@/lib/gamification'; import { faNum, signedFa, timeAgo, txIcon } from '@/lib/gamification';
import ClubLeaderboard from './ClubLeaderboard.vue'; import ClubLeaderboard from './ClubLeaderboard.vue';
import { useClub } from './club-context'; import { useClub } from './club-context';
import medalImg from '@/assets/club/medal.png';
import boltImg from '@/assets/club/bolt.png';
import coinImg from '@/assets/club/coin.png';
import giftImg from '@/assets/club/gift.png';
import starImg from '@/assets/club/star.png';
import trophyImg from '@/assets/club/trophy.png';
import crownImg from '@/assets/club/crown.png';
import chestImg from '@/assets/club/chest.png';
import fireImg from '@/assets/club/fire.png';
const emit = defineEmits<{ go: ['store' | 'history' | 'badges' | 'teams'] }>(); const emit = defineEmits<{ go: ['store' | 'history' | 'badges' | 'teams'] }>();
const { me } = useClub(); const { me } = useClub();
const rewards = ref<GamificationRewardDto[]>([]); const rewards = ref<GamificationRewardDto[]>([]);
const feed = ref<GamificationTxDto[]>([]);
onMounted(async () => { onMounted(async () => {
const [r, f] = await Promise.allSettled([ try {
api.get<GamificationRewardDto[]>('/gamification/rewards'), const { data } = await api.get<GamificationRewardDto[]>('/gamification/rewards');
api.get<GamificationTxDto[]>('/gamification/feed'), rewards.value = data.slice(0, 3);
]); } catch {
if (r.status === 'fulfilled') rewards.value = r.value.data.slice(0, 3); rewards.value = [];
if (f.status === 'fulfilled') feed.value = f.value.data.slice(0, 8); }
}); });
const level = computed(() => me.value?.level ?? null); const level = computed(() => me.value?.level ?? null);
const recent = computed(() => (me.value?.recent ?? []).slice(0, 5));
const REWARD_IMAGES: Record<string, string> = {
gift: giftImg,
star: starImg,
trophy: trophyImg,
medal: medalImg,
crown: crownImg,
bag: chestImg,
fire: fireImg,
};
const REWARD_TINTS = ['#fef3c7', '#ffedd5', '#f3e8ff'];
function rewardImage(r: GamificationRewardDto): string | null {
return REWARD_IMAGES[r.icon] ?? null;
}
const TX_TINTS: Record<string, string> = {
trophy: '#f97316',
dollar: '#f97316',
briefcase: '#f97316',
'user-plus': '#14b8a6',
building: '#14b8a6',
phone: '#14b8a6',
funnel: '#f59e0b',
trend: '#f59e0b',
chat: '#f59e0b',
document: '#8b5cf6',
calendar: '#8b5cf6',
check: '#8b5cf6',
refresh: '#8b5cf6',
};
function txTint(tx: GamificationTxDto): string {
if (tx.score < 0) return '#ef4444';
return TX_TINTS[txIcon(tx)] ?? '#6366f1';
}
/** پیام انگیزشی؛ همیشه مثبت و بدون مقایسهٔ تحقیرآمیز */ /** پیام انگیزشی؛ همیشه مثبت و بدون مقایسهٔ تحقیرآمیز */
const motivation = computed(() => { const motivation = computed(() => {
@@ -33,94 +78,94 @@ const motivation = computed(() => {
if (m.rank === 1 && m.periodScore > 0) { if (m.rank === 1 && m.periodScore > 0) {
return { title: 'عالی!', text: 'تو صدرنشین این ماهی. جایگاهت را حفظ کن!' }; return { title: 'عالی!', text: 'تو صدرنشین این ماهی. جایگاهت را حفظ کن!' };
} }
if (m.gapToNext != null && m.gapToNext > 0 && m.rank) {
return {
title: 'عالی!',
text: `فقط ${faNum(m.gapToNext)} امتیاز تا رتبهٔ ${toFaDigits(m.rank - 1)} فاصله داری.`,
};
}
if (m.periodScore > 0 && m.periodScore >= m.personalBest) { if (m.periodScore > 0 && m.periodScore >= m.personalBest) {
return { title: 'رکورد جدید!', text: `${faNum(m.periodScore)} امتیاز — بهترین ماه تو تا امروز.` }; return { title: 'رکورد جدید!', text: `${faNum(m.periodScore)} امتیاز — بهترین ماه تو تا امروز.` };
} }
if (m.streakDays >= 2) { if (m.streakDays >= 2) {
return { title: 'عالی!', text: `${toFaDigits(m.streakDays)} روز پیاپی همهٔ کارهای روتین را کامل کردی.` }; return { title: 'عالی!', text: `${toFaDigits(m.streakDays)} روز پیاپی همهٔ کارهای روتین را کامل کردی.` };
} }
if (m.gapToNext != null && m.gapToNext > 0 && m.rank) {
return {
title: 'نزدیکی!',
text: `فقط ${faNum(m.gapToNext)} امتیاز تا رتبهٔ ${toFaDigits(m.rank - 1)} فاصله داری.`,
};
}
if (m.todayScore > 0) { if (m.todayScore > 0) {
return { title: 'آفرین!', text: `امروز ${faNum(m.todayScore)} امتیاز گرفتی. ادامه بده!` }; return { title: 'آفرین!', text: `امروز ${faNum(m.todayScore)} امتیاز گرفتی. ادامه بده!` };
} }
return { title: 'شروع کن!', text: 'با ثبت تماس، پیگیری یا یک لید جدید اولین امتیاز امروز را بگیر.' }; return { title: 'شروع کن!', text: 'با ثبت تماس، پیگیری یا یک لید جدید اولین امتیاز امروز را بگیر.' };
}); });
function rewardProgress(r: GamificationRewardDto) { const cheerProgress = computed(() => {
const coins = me.value?.coins ?? 0; const m = me.value;
return Math.min(100, Math.round((coins / Math.max(1, r.cost)) * 100)); if (!m) return 0;
} if (m.rank === 1 && m.periodScore > 0) return 100;
if (m.gapToNext != null && m.gapToNext > 0) {
return Math.round((m.periodScore / (m.periodScore + m.gapToNext)) * 100);
}
return m.periodScore > 0 ? 100 : 0;
});
</script> </script>
<template> <template>
<div class="home"> <div class="home">
<aside class="col side"> <aside class="col">
<section class="card level-card"> <section class="card level-card">
<header class="card-h"> <h3 class="card-t">سطح و پیشرفت شما</h3>
<h3>سطح و پیشرفت شما</h3>
<button type="button" class="link" @click="emit('go', 'badges')">نشان‌ها</button>
</header>
<div v-if="level" class="level"> <div v-if="level" class="level">
<div class="ring" :style="{ '--p': `${level.progress}` }"> <img :src="medalImg" alt="" class="medal" />
<span>
<small>سطح</small>
<b>{{ toFaDigits(level.level) }}</b>
</span>
</div>
<div class="level-info"> <div class="level-info">
<strong>{{ level.name }}</strong> <b>سطح {{ toFaDigits(level.level) }}</b>
<span>{{ toFaDigits(level.progress) }}٪ تا سطح بعد</span> <span>{{ level.name }}</span>
<small v-if="level.toNext != null">
تا «{{ level.nextName }}»: {{ faNum(level.toNext) }} امتیاز
</small>
<small v-else>بالاترین سطح باشگاه!</small>
</div> </div>
</div> </div>
<div class="mini-stats"> <div v-if="level" class="lv-bar">
<div> <span class="bar"><i :style="{ width: `${level.progress}%` }" /></span>
<b>{{ faNum(me?.personalBest ?? 0) }}</b> <em>{{ toFaDigits(level.progress) }}٪</em>
<span>رکورد ماهانه</span>
</div>
<div>
<b>{{ toFaDigits(me?.streakDays ?? 0) }}</b>
<span>روز پیاپی</span>
</div>
<div>
<b>{{ toFaDigits(me?.badgesEarned ?? 0) }}</b>
<span>نشان</span>
</div>
</div> </div>
<p v-if="level" class="lv-next">
<template v-if="level.toNext != null">تا سطح بعدی: <b>{{ faNum(level.toNext) }} امتیاز</b></template>
<template v-else>بالاترین سطح باشگاه!</template>
</p>
</section> </section>
<section class="card"> <section class="card">
<header class="card-h"> <header class="card-h">
<h3>پاداش‌های قابل دریافت</h3> <h3 class="card-t">پاداش‌های قابل دریافت</h3>
<button type="button" class="link" @click="emit('go', 'store')">همه</button> <button type="button" class="link" @click="emit('go', 'store')">
مشاهده همه <UiIcon name="chevron-left" :size="13" />
</button>
</header> </header>
<ul class="rewards"> <ul class="rewards">
<li v-for="r in rewards" :key="r.id" :style="{ '--c': r.color }"> <li
<span class="r-ic"><UiIcon :name="r.icon as never" :size="18" /></span> v-for="(r, i) in rewards"
<span class="r-body"> :key="r.id"
<b>{{ r.name }}</b> :style="{ '--tint': REWARD_TINTS[i % REWARD_TINTS.length], '--c': r.color }"
<span class="r-bar"><i :style="{ width: `${rewardProgress(r)}%` }" /></span> role="button"
tabindex="0"
@click="emit('go', 'store')"
@keydown.enter="emit('go', 'store')"
>
<span class="r-art">
<img v-if="rewardImage(r)" :src="rewardImage(r)!" alt="" />
<span v-else class="r-ic"><UiIcon :name="r.icon as never" :size="22" /></span>
</span> </span>
<em>{{ faNum(r.cost) }}<small>سکه</small></em> <b>{{ r.name }}</b>
<small>{{ faNum(r.cost) }} سکه</small>
</li> </li>
<li v-if="!rewards.length" class="empty">هنوز پاداشی تعریف نشده است.</li> <li v-if="!rewards.length" class="empty">هنوز پاداشی تعریف نشده است.</li>
</ul> </ul>
</section> </section>
<section v-if="motivation" class="card cheer"> <section v-if="motivation" class="card cheer">
<UiIcon name="sparkle" :size="22" /> <div class="cheer-top">
<div> <img :src="boltImg" alt="" />
<strong>{{ motivation.title }}</strong> <div>
<p>{{ motivation.text }}</p> <strong>{{ motivation.title }}</strong>
<p>{{ motivation.text }}</p>
</div>
</div> </div>
<span class="bar gold"><i :style="{ width: `${cheerProgress}%` }" /></span>
</section> </section>
</aside> </aside>
@@ -128,51 +173,37 @@ function rewardProgress(r: GamificationRewardDto) {
<ClubLeaderboard /> <ClubLeaderboard />
</div> </div>
<aside class="col side"> <aside class="col">
<section class="card"> <section class="card">
<header class="card-h"> <header class="card-h">
<h3>آخرین امتیازات شما</h3> <h3 class="card-t">آخرین امتیازات شما</h3>
<button type="button" class="link" @click="emit('go', 'history')">تاریخچه</button> <button type="button" class="link" @click="emit('go', 'history')">
مشاهده همه <UiIcon name="chevron-left" :size="13" />
</button>
</header> </header>
<ul class="feed"> <ul class="feed">
<li v-for="tx in me?.recent ?? []" :key="tx.id" :class="{ pending: tx.status === 'pending' }"> <li v-for="tx in recent" :key="tx.id" :class="{ pending: tx.status === 'pending' }">
<span class="f-ic" :class="tx.kind"><UiIcon :name="txIcon(tx)" :size="15" /></span> <span class="f-ic" :style="{ '--c': txTint(tx) }"><UiIcon :name="txIcon(tx)" :size="17" /></span>
<span class="f-body"> <span class="f-body">
<b>{{ tx.title }}</b> <b>{{ tx.title }}</b>
<small> <small v-if="tx.entityTitle || tx.status === 'pending'">
<RouterLink v-if="tx.link && tx.entityTitle" :to="tx.link">{{ tx.entityTitle }}</RouterLink> <RouterLink v-if="tx.link && tx.entityTitle" :to="tx.link">{{ tx.entityTitle }}</RouterLink>
<template v-else-if="tx.entityTitle">{{ tx.entityTitle }}</template> <template v-else-if="tx.entityTitle">{{ tx.entityTitle }}</template>
<template v-if="tx.entityTitle"> · </template>{{ timeAgo(tx.createdAt) }} <template v-if="tx.status === 'pending'">{{ tx.entityTitle ? ' · ' : '' }}در انتظار تأیید</template>
<template v-if="tx.status === 'pending'"> · در انتظار تأیید</template>
</small> </small>
</span> </span>
<span class="f-pts"> <span class="f-pts">
<b v-if="tx.score" :class="{ neg: tx.score < 0 }">{{ signedFa(tx.score) }}</b> <span class="pts" :class="{ neg: tx.score < 0 }">
<small v-if="tx.coins" class="coin" :class="{ neg: tx.coins < 0 }">{{ signedFa(tx.coins) }} سکه</small> <img :src="coinImg" alt="" />{{ signedFa(tx.score || tx.coins) }}
</span>
<small>{{ timeAgo(tx.createdAt) }}</small>
</span> </span>
</li> </li>
<li v-if="!me?.recent.length" class="empty"> <li v-if="!recent.length" class="empty">
هنوز امتیازی نگرفته‌ای. ثبت لید، تماس یا انجام کارهای روتین امتیاز دارد. هنوز امتیازی نگرفته‌ای. ثبت لید، تماس یا انجام کارهای روتین امتیاز دارد.
</li> </li>
</ul> </ul>
</section> </section>
<section class="card">
<header class="card-h">
<h3>فعالیت همکاران</h3>
</header>
<ul class="feed compact">
<li v-for="tx in feed" :key="tx.id">
<span class="f-ic" :class="tx.kind"><UiIcon :name="txIcon(tx)" :size="14" /></span>
<span class="f-body">
<b>{{ tx.userName }}</b>
<small>{{ tx.title }} · {{ timeAgo(tx.createdAt) }}</small>
</span>
<span class="f-pts"><b>{{ signedFa(tx.score) }}</b></span>
</li>
<li v-if="!feed.length" class="empty">هنوز فعالیتی ثبت نشده است.</li>
</ul>
</section>
</aside> </aside>
</div> </div>
</template> </template>
@@ -180,7 +211,7 @@ function rewardProgress(r: GamificationRewardDto) {
<style scoped> <style scoped>
.home { .home {
display: grid; display: grid;
grid-template-columns: minmax(250px, 300px) minmax(0, 1fr) minmax(250px, 320px); grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(220px, 280px);
gap: var(--sp-4); gap: var(--sp-4);
align-items: start; align-items: start;
} }
@@ -194,11 +225,9 @@ function rewardProgress(r: GamificationRewardDto) {
.card { .card {
background: var(--surface); background: var(--surface);
border: 1px solid var(--line); border: 1px solid var(--line);
border-radius: calc(var(--radius) + 4px); border-radius: 16px;
padding: var(--sp-4); padding: 1rem 1.05rem;
box-shadow: var(--shadow-xs); box-shadow: var(--shadow-xs);
display: grid;
gap: var(--sp-3);
min-width: 0; min-width: 0;
} }
@@ -206,214 +235,250 @@ function rewardProgress(r: GamificationRewardDto) {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
gap: var(--sp-2); gap: 0.5rem;
margin-bottom: 0.85rem;
} }
.card-h h3 { .card-t {
margin: 0; margin: 0;
font-size: var(--fs-md); font-size: 0.95rem;
font-weight: var(--fw-bold); font-weight: 800;
color: var(--ink); color: #0f172a;
}
.level-card .card-t {
margin-bottom: 0.6rem;
} }
.link { .link {
display: inline-flex;
align-items: center;
gap: 2px;
border: 0; border: 0;
background: none; background: none;
color: var(--accent-hover); padding: 0;
font: inherit; font: inherit;
font-size: var(--fs-xs); font-size: 0.76rem;
font-weight: 700; font-weight: 600;
color: #64748b;
cursor: pointer; cursor: pointer;
white-space: nowrap;
} }
.link:hover {
color: var(--accent);
}
/* سطح */
.level { .level {
display: flex; display: flex;
align-items: center; align-items: center;
gap: var(--sp-3); gap: 0.85rem;
} }
.ring { .medal {
--p: 0; width: 76px;
width: 84px; height: 76px;
height: 84px; object-fit: contain;
border-radius: 50%;
flex: 0 0 auto; flex: 0 0 auto;
display: grid; filter: drop-shadow(0 6px 10px rgb(245 158 11 / 0.25));
place-items: center;
background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--accent-soft) 0);
}
.ring span {
width: 66px;
height: 66px;
border-radius: 50%;
background: var(--surface);
display: grid;
place-items: center;
align-content: center;
line-height: 1.1;
}
.ring small {
font-size: 0.68rem;
color: var(--muted);
}
.ring b {
font-size: 1.4rem;
font-weight: 800;
color: var(--accent-deep);
} }
.level-info { .level-info {
display: grid; display: grid;
gap: 2px; gap: 2px;
min-width: 0;
} }
.level-info strong { .level-info b {
font-size: 1.05rem; font-size: 1.35rem;
color: var(--ink); font-weight: 900;
color: #0f172a;
line-height: 1.2;
} }
.level-info span { .level-info span {
font-size: var(--fs-sm); font-size: 0.9rem;
color: var(--accent-deep); font-weight: 600;
font-weight: 700; color: #475569;
} }
.level-info small { .bar {
font-size: var(--fs-xs); display: block;
color: var(--muted); flex: 1;
height: 8px;
border-radius: 999px;
background: #ede9fe;
overflow: hidden;
} }
.mini-stats { .bar i {
display: block;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #a78bfa, #7c3aed);
transition: width 0.5s ease;
}
.lv-bar {
display: flex;
align-items: center;
gap: 0.6rem;
margin-top: 0.9rem;
}
.lv-bar em {
font-style: normal;
font-size: 0.8rem;
font-weight: 800;
color: #7c3aed;
}
.lv-next {
margin: 0.55rem 0 0;
font-size: 0.78rem;
color: #64748b;
}
.lv-next b {
color: #0f172a;
}
/* پاداش‌ها */
.rewards {
list-style: none;
margin: 0;
padding: 0;
display: grid; display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--sp-2); gap: 0.5rem;
border-top: 1px solid var(--line-light);
padding-top: var(--sp-3);
text-align: center;
} }
.mini-stats div { .rewards li {
display: grid; display: grid;
justify-items: center;
gap: 2px;
text-align: center;
cursor: pointer;
min-width: 0;
} }
.mini-stats b { .r-art {
font-size: var(--fs-md); width: 100%;
color: var(--ink); aspect-ratio: 1;
border-radius: 12px;
background: var(--tint);
display: grid;
place-items: center;
margin-bottom: 0.35rem;
transition: transform 0.15s ease;
} }
.mini-stats span { .rewards li:hover .r-art {
transform: translateY(-2px);
}
.r-art img {
width: 72%;
height: 72%;
object-fit: contain;
}
.r-ic {
width: 2.6rem;
height: 2.6rem;
border-radius: 12px;
display: grid;
place-items: center;
color: #fff;
background: var(--c, var(--accent));
}
.rewards b {
font-size: 0.76rem;
font-weight: 700;
color: #0f172a;
max-width: 100%;
line-height: 1.5;
}
.rewards small {
font-size: 0.7rem; font-size: 0.7rem;
color: var(--muted); color: #64748b;
} }
.rewards, .rewards .empty {
grid-column: 1 / -1;
cursor: default;
}
/* انگیزشی */
.cheer {
background: #eef2ff;
border-color: #e0e7ff;
display: grid;
gap: 0.75rem;
}
.cheer-top {
display: flex;
align-items: center;
gap: 0.75rem;
}
.cheer-top img {
width: 52px;
height: 52px;
object-fit: contain;
flex: 0 0 auto;
}
.cheer strong {
display: block;
font-size: 1rem;
font-weight: 900;
color: #1e1b4b;
}
.cheer p {
margin: 2px 0 0;
font-size: 0.8rem;
line-height: 1.6;
color: #475569;
}
.bar.gold {
flex: none;
background: #fff;
}
.bar.gold i {
background: linear-gradient(90deg, #fcd34d, #f59e0b);
}
/* آخرین امتیازات */
.feed { .feed {
list-style: none; list-style: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
display: grid; display: grid;
gap: var(--sp-2);
}
.rewards li {
--c: var(--accent);
display: flex;
align-items: center;
gap: var(--sp-2);
padding: var(--sp-2);
border-radius: 10px;
border: 1px solid var(--line-light);
background: color-mix(in srgb, var(--c) 6%, var(--surface));
}
.r-ic {
width: 34px;
height: 34px;
border-radius: 10px;
display: grid;
place-items: center;
flex: 0 0 auto;
color: var(--c);
background: color-mix(in srgb, var(--c) 16%, transparent);
}
.r-body {
flex: 1;
min-width: 0;
display: grid;
gap: 5px;
}
.r-body b {
font-size: var(--fs-sm);
color: var(--ink);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.r-bar {
height: 5px;
border-radius: 999px;
background: var(--line-light);
overflow: hidden;
}
.r-bar i {
display: block;
height: 100%;
background: var(--c);
border-radius: inherit;
}
.rewards em {
font-style: normal;
font-weight: 800;
font-size: var(--fs-sm);
color: #b45309;
display: grid;
text-align: center;
line-height: 1.1;
}
.rewards em small {
font-size: 0.65rem;
font-weight: 600;
color: var(--muted);
}
.cheer {
grid-template-columns: auto minmax(0, 1fr);
align-items: center;
background: linear-gradient(145deg, #ecfdf5, #ccfbf1);
border-color: #99f6e4;
color: var(--accent-deep);
}
.cheer strong {
font-size: var(--fs-md);
}
.cheer p {
margin: 2px 0 0;
font-size: var(--fs-sm);
color: #115e59;
} }
.feed li { .feed li {
display: flex; display: flex;
align-items: center; align-items: center;
gap: var(--sp-2); gap: 0.7rem;
padding: var(--sp-2) 0; padding: 0.7rem 0;
border-bottom: 1px dashed var(--line-light); border-bottom: 1px solid #f1f5f9;
min-width: 0;
}
.feed li:first-child {
padding-top: 0;
} }
.feed li:last-child { .feed li:last-child {
border-bottom: 0; border-bottom: 0;
padding-bottom: 0;
} }
.feed li.pending { .feed li.pending {
@@ -421,42 +486,27 @@ function rewardProgress(r: GamificationRewardDto) {
} }
.f-ic { .f-ic {
width: 30px; width: 2.4rem;
height: 30px; height: 2.4rem;
border-radius: 9px; border-radius: 12px;
flex: 0 0 auto;
display: grid; display: grid;
place-items: center; place-items: center;
flex: 0 0 auto; color: var(--c);
background: var(--accent-subtle); background: color-mix(in srgb, var(--c) 14%, #fff);
color: var(--accent-deep);
}
.f-ic.bonus,
.f-ic.achievement {
background: #fef3c7;
color: #b45309;
}
.f-ic.redeem,
.f-ic.refund {
background: #ede9fe;
color: #6d28d9;
}
.f-ic.adjust {
background: var(--surface-subtle);
color: var(--ink-secondary);
} }
.f-body { .f-body {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
display: grid; display: grid;
gap: 2px;
} }
.f-body b { .f-body b {
font-size: var(--fs-sm); font-size: 0.82rem;
color: var(--ink); font-weight: 700;
color: #0f172a;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@@ -464,59 +514,69 @@ function rewardProgress(r: GamificationRewardDto) {
.f-body small { .f-body small {
font-size: 0.72rem; font-size: 0.72rem;
color: var(--muted); color: #64748b;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.f-body a { .f-body small a {
color: var(--accent-hover); color: inherit;
text-decoration: none;
}
.f-body small a:hover {
color: var(--accent);
} }
.f-pts { .f-pts {
display: grid; display: grid;
text-align: end; justify-items: end;
gap: 2px;
flex: 0 0 auto; flex: 0 0 auto;
} }
.f-pts b { .pts {
display: inline-flex;
align-items: center;
gap: 3px;
direction: ltr;
font-size: 0.86rem;
font-weight: 800; font-weight: 800;
color: var(--success-deep); color: #16a34a;
font-size: var(--fs-sm);
} }
.f-pts .coin { .pts.neg {
color: #ef4444;
}
.pts img {
width: 16px;
height: 16px;
object-fit: contain;
}
.f-pts small {
font-size: 0.68rem; font-size: 0.68rem;
color: #b45309; color: #94a3b8;
font-weight: 700; white-space: nowrap;
}
.f-pts .neg {
color: var(--danger);
}
.feed.compact li {
padding: 6px 0;
} }
.empty { .empty {
color: var(--muted); color: var(--muted);
font-size: var(--fs-sm); font-size: var(--fs-sm);
justify-content: center;
text-align: center; text-align: center;
padding: 0.6rem 0;
border: 0 !important; border: 0 !important;
background: none !important;
} }
@media (max-width: 1200px) { @media (max-width: 1100px) {
.home { .home {
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
} }
.center { .home > .col:last-child {
grid-column: 1 / -1; grid-column: 1 / -1;
order: -1;
} }
} }
@@ -524,5 +584,9 @@ function rewardProgress(r: GamificationRewardDto) {
.home { .home {
grid-template-columns: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
} }
.center {
order: -1;
}
} }
</style> </style>
@@ -1,14 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'; import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import type { GamificationLeaderboardDto, GamificationLeaderEntryDto, GamificationPeriod } from '@mento/shared'; import type { GamificationLeaderboardDto, GamificationLeaderEntryDto, GamificationPeriod } from '@mento/shared';
import { GAMIFICATION_PERIOD_LABELS } from '@mento/shared';
import UiIcon from '@/components/UiIcon.vue';
import UserAvatar from '@/components/UserAvatar.vue'; import UserAvatar from '@/components/UserAvatar.vue';
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import { toFaDigits } from '@/lib/jalali'; import { toFaDigits } from '@/lib/jalali';
import { apiError, faNum } from '@/lib/gamification'; import { apiError, faNum } from '@/lib/gamification';
import crownImg from '@/assets/club/crown.png';
const PERIODS: GamificationPeriod[] = ['today', 'week', 'month', 'quarter', 'year', 'all']; const PERIODS: Array<{ value: GamificationPeriod; label: string }> = [
{ value: 'today', label: 'امروز' },
{ value: 'month', label: 'این ماه' },
{ value: 'all', label: 'همه زمان‌ها' },
];
const period = ref<GamificationPeriod>('month'); const period = ref<GamificationPeriod>('month');
const board = ref<GamificationLeaderboardDto | null>(null); const board = ref<GamificationLeaderboardDto | null>(null);
@@ -38,90 +41,82 @@ onMounted(() => {
onBeforeUnmount(() => window.removeEventListener('gamification:updated', load)); onBeforeUnmount(() => window.removeEventListener('gamification:updated', load));
const top3 = computed(() => (board.value?.items ?? []).slice(0, 3).filter((x) => x.score > 0)); const top3 = computed(() => (board.value?.items ?? []).slice(0, 3).filter((x) => x.score > 0));
/** ترتیب نمایش از راست: سوم، اول، دوم */
const podium = computed(() => {
const [a, b, c] = top3.value;
return [c, a, b].filter((x): x is GamificationLeaderEntryDto => !!x);
});
const rest = computed(() => { const rest = computed(() => {
const items = board.value?.items ?? []; const items = board.value?.items ?? [];
return top3.value.length ? items.slice(top3.value.length) : items; return top3.value.length ? items.slice(top3.value.length) : items;
}); });
function chgClass(change: number | null) {
return change && change > 0 ? 'up' : change && change < 0 ? 'down' : '';
}
const meOutside = computed(() => { const meOutside = computed(() => {
const b = board.value; const b = board.value;
if (!b?.me) return null; if (!b?.me) return null;
return b.items.some((i) => i.userId === b.me!.userId) ? null : b.me; return b.items.some((i) => i.userId === b.me!.userId) ? null : b.me;
}); });
function changeLabel(e: GamificationLeaderEntryDto) {
if (!e.change) return '';
return `${toFaDigits(Math.abs(e.change))}`;
}
const MEDALS = ['#f59e0b', '#94a3b8', '#c2410c'];
</script> </script>
<template> <template>
<section class="board"> <section class="board">
<header class="b-head"> <div class="periods" role="tablist" aria-label="بازهٔ جدول امتیازات">
<div> <button
<h3><UiIcon name="trophy" :size="18" /> جدول امتیازات</h3> v-for="p in PERIODS"
<small v-if="board">{{ toFaDigits(board.totalUsers) }} همکار در رقابت</small> :key="p.value"
</div> type="button"
<div class="periods" role="tablist"> role="tab"
<button :aria-selected="period === p.value"
v-for="p in PERIODS" :class="{ on: period === p.value }"
:key="p" @click="period = p.value"
type="button" >
role="tab" {{ p.label }}
:aria-selected="period === p" </button>
:class="{ on: period === p }" </div>
@click="period = p"
>
{{ GAMIFICATION_PERIOD_LABELS[p] }}
</button>
</div>
</header>
<p v-if="error" class="err">{{ error }}</p> <p v-if="error" class="err">{{ error }}</p>
<div v-if="top3.length" class="top3" :class="{ loading }"> <div v-if="podium.length" class="top3" :class="{ loading }">
<div <div
v-for="(e, i) in top3" v-for="e in podium"
:key="e.userId" :key="e.userId"
class="t-card" class="t-card"
:class="{ me: e.isMe }" :class="[`r${e.rank}`, { me: e.isMe }]"
:style="{ '--m': MEDALS[i] }"
> >
<span class="t-rank">{{ toFaDigits(e.rank) }}</span> <img v-if="e.rank === 1" :src="crownImg" alt="" class="t-crown" />
<UserAvatar :user-id="e.userId" :has-avatar="e.hasAvatar" :name="e.fullName" :size="46" /> <span class="t-ava">
<UserAvatar :user-id="e.userId" :has-avatar="e.hasAvatar" :name="e.fullName" :size="e.rank === 1 ? 50 : 46" />
</span>
<strong>{{ e.isMe ? 'شما' : e.fullName }}</strong> <strong>{{ e.isMe ? 'شما' : e.fullName }}</strong>
<small>{{ e.levelName }}</small> <small>{{ faNum(e.score) }} امتیاز</small>
<b>{{ faNum(e.score) }} <span>امتیاز</span></b>
</div> </div>
</div> </div>
<ol class="rows" :class="{ loading }"> <ol class="rows" :class="{ loading }">
<li v-for="e in rest" :key="e.userId" :class="{ me: e.isMe }"> <li v-for="e in rest" :key="e.userId" :class="{ me: e.isMe }">
<span class="rank">{{ toFaDigits(e.rank) }}</span> <span class="chg" :class="chgClass(e.change)">
<UserAvatar :user-id="e.userId" :has-avatar="e.hasAvatar" :name="e.fullName" :size="32" /> <template v-if="e.change">{{ e.change > 0 ? '▲' : '▼' }} {{ toFaDigits(Math.abs(e.change)) }}</template>
<span class="who">
<b>{{ e.isMe ? 'شما' : e.fullName }}</b>
<small>{{ e.levelName }}</small>
</span>
<span v-if="e.change" class="chg" :class="e.change > 0 ? 'up' : 'down'">
{{ e.change > 0 ? '▲' : '▼' }}{{ changeLabel(e) }}
</span> </span>
<span class="score">{{ faNum(e.score) }}</span> <span class="score">{{ faNum(e.score) }}</span>
<b class="who">{{ e.isMe ? 'شما' : e.fullName }}</b>
<UserAvatar :user-id="e.userId" :has-avatar="e.hasAvatar" :name="e.fullName" :size="28" />
<span class="rank">{{ toFaDigits(e.rank) }}</span>
</li> </li>
<template v-if="meOutside"> <template v-if="meOutside">
<li class="sep" aria-hidden="true">⋯</li> <li class="sep" aria-hidden="true">⋯</li>
<li class="me"> <li class="me">
<span class="rank">{{ toFaDigits(meOutside.rank) }}</span> <span class="chg" :class="chgClass(meOutside.change)">
<UserAvatar :user-id="meOutside.userId" :has-avatar="meOutside.hasAvatar" :name="meOutside.fullName" :size="32" /> <template v-if="meOutside.change">
<span class="who"> {{ meOutside.change > 0 ? '▲' : '▼' }} {{ toFaDigits(Math.abs(meOutside.change)) }}
<b>شما</b> </template>
<small>{{ meOutside.levelName }}</small>
</span>
<span v-if="meOutside.change" class="chg" :class="meOutside.change > 0 ? 'up' : 'down'">
{{ meOutside.change > 0 ? '▲' : '▼' }}{{ changeLabel(meOutside) }}
</span> </span>
<span class="score">{{ faNum(meOutside.score) }}</span> <span class="score">{{ faNum(meOutside.score) }}</span>
<b class="who">شما</b>
<UserAvatar :user-id="meOutside.userId" :has-avatar="meOutside.hasAvatar" :name="meOutside.fullName" :size="28" />
<span class="rank">{{ toFaDigits(meOutside.rank) }}</span>
</li> </li>
</template> </template>
<li v-if="board && !board.items.length" class="empty">هنوز کسی در این بازه امتیاز نگرفته است.</li> <li v-if="board && !board.items.length" class="empty">هنوز کسی در این بازه امتیاز نگرفته است.</li>
@@ -133,73 +128,40 @@ const MEDALS = ['#f59e0b', '#94a3b8', '#c2410c'];
.board { .board {
background: var(--surface); background: var(--surface);
border: 1px solid var(--line); border: 1px solid var(--line);
border-radius: calc(var(--radius) + 4px); border-radius: 16px;
padding: var(--sp-4); padding: 0.75rem 0.9rem 0.5rem;
box-shadow: var(--shadow-xs); box-shadow: var(--shadow-xs);
display: grid; display: grid;
gap: var(--sp-3); grid-template-columns: minmax(0, 1fr);
gap: 0.9rem;
min-width: 0; min-width: 0;
} }
.b-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--sp-2);
flex-wrap: wrap;
}
.b-head h3 {
margin: 0;
display: flex;
align-items: center;
gap: 6px;
font-size: var(--fs-md);
color: var(--ink);
}
.b-head h3 :deep(svg) {
color: #f59e0b;
}
.b-head small {
font-size: var(--fs-xs);
color: var(--muted);
}
.periods { .periods {
display: flex; display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 4px; gap: 4px;
background: var(--surface-subtle);
border-radius: 999px;
padding: 3px; padding: 3px;
max-width: 100%; border-radius: 12px;
overflow-x: auto; background: #f8fafc;
scrollbar-width: none;
}
.periods::-webkit-scrollbar {
display: none;
} }
.periods button { .periods button {
border: 0; border: 0;
background: none; background: none;
border-radius: 999px; border-radius: 10px;
padding: 0.3rem 0.7rem; padding: 0.5rem 0.6rem;
font: inherit; font: inherit;
font-size: var(--fs-xs); font-size: 0.82rem;
font-weight: 700; font-weight: 700;
color: var(--muted); color: #64748b;
cursor: pointer; cursor: pointer;
white-space: nowrap; white-space: nowrap;
flex: 0 0 auto;
} }
.periods button.on { .periods button.on {
background: var(--surface); background: #e0e7ff;
color: var(--accent-deep); color: #1e1b4b;
box-shadow: var(--shadow-xs);
} }
.err { .err {
@@ -211,45 +173,69 @@ const MEDALS = ['#f59e0b', '#94a3b8', '#c2410c'];
.top3 { .top3 {
display: grid; display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--sp-2); gap: 0.6rem;
align-items: end;
padding-top: 0.8rem;
} }
.t-card { .t-card {
--m: #f59e0b; --bg: #e0e7ff;
--ring: #a5b4fc;
position: relative; position: relative;
display: grid; display: grid;
justify-items: center; justify-items: center;
gap: 3px; gap: 4px;
padding: var(--sp-3) var(--sp-2); padding: 0 0.4rem 0.7rem;
border-radius: 12px; border-radius: 14px;
border: 1px solid color-mix(in srgb, var(--m) 35%, transparent); background: var(--bg);
background: linear-gradient(180deg, color-mix(in srgb, var(--m) 12%, var(--surface)), var(--surface));
text-align: center; text-align: center;
min-width: 0; min-width: 0;
margin-top: 1.6rem;
}
.t-card.r1 {
--bg: #fef3c7;
--ring: #f59e0b;
padding-bottom: 1rem;
margin-top: 0;
}
.t-card.r3 {
--bg: #ffedd5;
--ring: #fb923c;
} }
.t-card.me { .t-card.me {
box-shadow: 0 0 0 2px var(--accent); box-shadow: 0 0 0 2px var(--accent);
} }
.t-rank { .t-crown {
position: absolute; position: absolute;
top: 8px; top: -1.55rem;
inset-inline-start: 8px; width: 30px;
width: 22px; height: 30px;
height: 22px; object-fit: contain;
border-radius: 50%; z-index: 1;
}
.t-ava {
margin-top: -1.4rem;
padding: 3px;
border-radius: 999px;
background: #fff;
box-shadow: 0 0 0 3px var(--ring);
display: grid; display: grid;
place-items: center; }
background: var(--m);
color: #fff; .t-card.r1 .t-ava {
font-size: 0.75rem; margin-top: -0.4rem;
font-weight: 800;
} }
.t-card strong { .t-card strong {
font-size: var(--fs-sm); margin-top: 0.3rem;
color: var(--ink); font-size: 0.92rem;
font-weight: 800;
color: #0f172a;
max-width: 100%; max-width: 100%;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
@@ -257,20 +243,13 @@ const MEDALS = ['#f59e0b', '#94a3b8', '#c2410c'];
} }
.t-card small { .t-card small {
font-size: 0.7rem; font-size: 0.76rem;
color: var(--muted); color: #475569;
} }
.t-card b { .t-card.r1 small {
font-size: var(--fs-md); color: #b45309;
font-weight: 800; font-weight: 700;
color: var(--ink);
}
.t-card b span {
font-size: 0.68rem;
font-weight: 600;
color: var(--muted);
} }
.rows { .rows {
@@ -278,81 +257,78 @@ const MEDALS = ['#f59e0b', '#94a3b8', '#c2410c'];
margin: 0; margin: 0;
padding: 0; padding: 0;
display: grid; display: grid;
gap: 4px;
} }
.rows li { .rows li {
display: flex; display: flex;
align-items: center; align-items: center;
gap: var(--sp-2); gap: 0.6rem;
padding: 7px var(--sp-2); padding: 0.6rem 0.7rem;
border-radius: 10px; border-bottom: 1px solid #f1f5f9;
transition: background 0.15s ease;
} }
.rows li:hover { .rows li:last-child {
background: var(--surface-hover); border-bottom: 0;
} }
.rows li.me { .rows li.me {
background: var(--accent-subtle); background: #fef9e7;
box-shadow: inset 0 0 0 1px var(--accent-soft); border-radius: 10px;
border-bottom-color: transparent;
}
.rows li.me .score,
.rows li.me .who {
font-weight: 800;
} }
.rows li.sep { .rows li.sep {
justify-content: center; justify-content: center;
color: var(--muted-light); color: var(--muted-light);
padding: 0; padding: 0;
border: 0;
} }
.rank { .chg {
width: 26px; min-width: 1.8rem;
text-align: center; font-size: 0.74rem;
font-weight: 800; font-weight: 800;
color: var(--muted); flex: 0 0 auto;
font-size: var(--fs-sm); }
.chg.up {
color: #16a34a;
}
.chg.down {
color: #ef4444;
}
.score {
min-width: 2.8rem;
font-size: 0.84rem;
font-weight: 600;
color: #0f172a;
flex: 0 0 auto; flex: 0 0 auto;
} }
.who { .who {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
display: grid; text-align: end;
} font-size: 0.84rem;
font-weight: 600;
.who b { color: #0f172a;
font-size: var(--fs-sm);
color: var(--ink);
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.who small { .rank {
font-size: 0.68rem; width: 1.6rem;
color: var(--muted); text-align: center;
} font-size: 0.82rem;
color: #64748b;
.chg {
font-size: 0.7rem;
font-weight: 800;
flex: 0 0 auto;
}
.chg.up {
color: var(--success-deep);
}
.chg.down {
color: var(--muted-light);
}
.score {
font-weight: 800;
color: var(--ink);
font-size: var(--fs-sm);
min-width: 52px;
text-align: end;
flex: 0 0 auto; flex: 0 0 auto;
} }
@@ -364,6 +340,7 @@ const MEDALS = ['#f59e0b', '#94a3b8', '#c2410c'];
justify-content: center; justify-content: center;
color: var(--muted); color: var(--muted);
font-size: var(--fs-sm); font-size: var(--fs-sm);
border: 0 !important;
} }
@media (max-width: 520px) { @media (max-width: 520px) {
@@ -371,8 +348,8 @@ const MEDALS = ['#f59e0b', '#94a3b8', '#c2410c'];
gap: 6px; gap: 6px;
} }
.t-card { .t-card strong {
padding: var(--sp-2) 4px; font-size: 0.8rem;
} }
} }
</style> </style>
+58
View File
@@ -406,6 +406,39 @@ async function confirmDeleteStage() {
} }
} }
const deleteDealId = ref<string | null>(null);
const dealDeleting = ref(false);
const deleteDealTitle = computed(() => {
const id = deleteDealId.value;
for (const s of stages.value) {
const d = s.deals.find((x) => x.id === id);
if (d) return d.title;
}
return '';
});
function askDeleteDeal(dealId: string) {
menuOpenId.value = null;
deleteDealId.value = dealId;
}
async function confirmDeleteDeal() {
const id = deleteDealId.value;
if (!id || dealDeleting.value) return;
dealDeleting.value = true;
error.value = '';
try {
await api.delete(`/deals/${id}`);
deleteDealId.value = null;
await load();
} catch (e) {
error.value = apiMessage(e, 'حذف معامله ناموفق بود.');
} finally {
dealDeleting.value = false;
}
}
async function onDealSaved() { async function onDealSaved() {
dealModal.value = null; dealModal.value = null;
await load(); await load();
@@ -597,6 +630,9 @@ defineExpose({ updateDealStage: applyUpdateDealStage });
> >
ویرایش ویرایش
</button> </button>
<button type="button" role="menuitem" class="danger" @click="askDeleteDeal(menuOpenId)">
حذف
</button>
<button type="button" role="menuitem" @click="menuOpenId = null">بستن</button> <button type="button" role="menuitem" @click="menuOpenId = null">بستن</button>
</div> </div>
@@ -654,6 +690,24 @@ defineExpose({ updateDealStage: applyUpdateDealStage });
</template> </template>
</UiModal> </UiModal>
<UiModal
:open="Boolean(deleteDealId)"
title="حذف معامله"
@close="deleteDealId = null"
>
<p class="delete-copy">
معاملهٔ «{{ deleteDealTitle }}» حذف شود؟ این کار قابل بازگشت نیست.
</p>
<template #footer>
<UiButton type="button" :disabled="dealDeleting" @click="confirmDeleteDeal">
{{ dealDeleting ? 'در حال حذف…' : 'حذف' }}
</UiButton>
<UiButton variant="ghost" type="button" @click="deleteDealId = null">
انصراف
</UiButton>
</template>
</UiModal>
<UiModal <UiModal
:open="Boolean(dealModal)" :open="Boolean(dealModal)"
:title="dealModal?.dealId ? 'ویرایش معامله' : 'ایجاد معامله جدید'" :title="dealModal?.dealId ? 'ویرایش معامله' : 'ایجاد معامله جدید'"
@@ -737,4 +791,8 @@ defineExpose({ updateDealStage: applyUpdateDealStage });
color: var(--ink); color: var(--ink);
text-align: right; text-align: right;
} }
.menu-pop button.danger {
color: var(--danger);
}
</style> </style>