Files
web/src/layouts/AppLayout.vue
T

250 lines
5.3 KiB
Vue
Raw Normal View History

2026-07-23 10:24:50 +03:30
<script setup lang="ts">
2026-08-10 15:30:26 +03:30
import { computed, onMounted, ref } from 'vue'
2026-07-23 10:24:50 +03:30
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
2026-07-23 10:24:50 +03:30
import { LogoutOutlined, HomeOutlined } from '@ant-design/icons-vue'
import { useAuthStore } from '@/stores/auth'
import api from '@/api/http'
2026-07-23 10:24:50 +03:30
const auth = useAuthStore()
const router = useRouter()
const adminSmsEnabled = ref(true)
const smsToggleLoading = ref(false)
2026-08-10 15:30:26 +03:30
const canSettingsWrite = computed(() => auth.can('settings:write'))
2026-07-23 10:24:50 +03:30
function goHome() {
router.push({ name: 'home' })
}
function logout() {
auth.logout()
router.push({ name: 'login' })
}
async function loadSmsToggle() {
2026-08-10 15:30:26 +03:30
if (!canSettingsWrite.value) return
try {
const { data } = await api.get('/settings/admin-sms')
adminSmsEnabled.value = data.adminSmsEnabled !== false
} catch {
// keep default on; non-blocking for layout
}
}
async function onSmsToggle(checked: boolean) {
2026-08-10 15:30:26 +03:30
if (!canSettingsWrite.value) return
smsToggleLoading.value = true
const previous = adminSmsEnabled.value
adminSmsEnabled.value = checked
try {
const { data } = await api.patch('/settings/admin-sms', { enabled: checked })
adminSmsEnabled.value = data.adminSmsEnabled !== false
message.success(
adminSmsEnabled.value ? 'پیامک هشدار روشن شد' : 'پیامک هشدار خاموش شد',
)
} catch (e: any) {
adminSmsEnabled.value = previous
message.error(e?.response?.data?.message || 'تغییر وضعیت پیامک ناموفق')
} finally {
smsToggleLoading.value = false
}
}
onMounted(loadSmsToggle)
2026-07-23 10:24:50 +03:30
</script>
<template>
<div class="shell">
<header class="topbar">
<button type="button" class="brand-btn" @click="goHome">
<span class="brand-dot" />
<span>
<strong>Super Admin</strong>
<small>آبشده</small>
</span>
</button>
<div class="topbar-actions">
2026-08-10 15:30:26 +03:30
<div
v-if="canSettingsWrite"
class="sms-toggle"
:class="{ off: !adminSmsEnabled }"
>
<span class="sms-toggle-label">پیامک هشدار</span>
<a-switch
:checked="adminSmsEnabled"
:loading="smsToggleLoading"
checked-children="روشن"
un-checked-children="خاموش"
@change="onSmsToggle"
/>
</div>
2026-07-23 10:24:50 +03:30
<button type="button" class="icon-btn" title="داشبورد" @click="goHome">
<HomeOutlined />
</button>
<div class="user-chip">
<span class="avatar">{{ auth.user?.name?.slice(0, 1) || 'S' }}</span>
<span class="user-name">{{ auth.user?.name }}</span>
</div>
<button type="button" class="icon-btn" title="خروج" @click="logout">
<LogoutOutlined />
</button>
</div>
</header>
<main class="content">
<RouterView />
</main>
</div>
</template>
<style scoped>
.shell {
min-height: 100vh;
max-width: 100%;
2026-07-23 10:24:50 +03:30
background: #eef2f7;
padding-top: 64px;
2026-07-23 10:24:50 +03:30
}
.topbar {
position: fixed;
2026-07-23 10:24:50 +03:30
top: 0;
right: 0;
left: 0;
z-index: 100;
2026-07-23 10:24:50 +03:30
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 14px 16px;
background: rgba(255, 255, 255, 0.96);
2026-07-23 10:24:50 +03:30
backdrop-filter: blur(12px);
border-bottom: 1px solid #e8eef5;
}
.brand-btn {
appearance: none;
border: none;
background: transparent;
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
font-family: inherit;
color: #2d3748;
padding: 0;
}
.brand-dot {
width: 36px;
height: 36px;
border-radius: 12px;
background: linear-gradient(145deg, #3ad4b0, #20c997);
box-shadow: 0 8px 18px rgba(32, 201, 151, 0.28);
}
.brand-btn strong {
display: block;
font-size: 0.95rem;
font-weight: 800;
}
.brand-btn small {
display: block;
margin-top: 2px;
color: #8b95a8;
font-size: 0.75rem;
}
.topbar-actions {
display: flex;
align-items: center;
gap: 8px;
}
.sms-toggle {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border-radius: 999px;
background: #e8f8f1;
border: 1px solid #b7ebd4;
}
.sms-toggle.off {
background: #fff1f0;
border-color: #ffccc7;
}
.sms-toggle-label {
font-size: 0.8rem;
font-weight: 700;
color: #334155;
white-space: nowrap;
}
2026-07-23 10:24:50 +03:30
.icon-btn {
width: 40px;
height: 40px;
border-radius: 12px;
border: none;
background: #f3f6fb;
color: #5b6b7c;
cursor: pointer;
display: grid;
place-items: center;
font-size: 16px;
}
.user-chip {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 10px 4px 4px;
border-radius: 999px;
background: #f3f6fb;
}
.avatar {
width: 32px;
height: 32px;
border-radius: 50%;
display: grid;
place-items: center;
background: linear-gradient(145deg, #9b7cff, #7c5cfc);
color: #fff;
font-weight: 800;
font-size: 0.85rem;
}
.user-name {
font-size: 0.85rem;
font-weight: 700;
color: #2d3748;
max-width: 120px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.content {
padding: 12px;
width: 100%;
min-width: 0;
2026-07-23 10:24:50 +03:30
}
@media (min-width: 768px) {
.shell { padding-top: 72px; }
2026-07-23 10:24:50 +03:30
.topbar { padding: 16px 24px; }
.content { padding: 24px; }
}
@media (max-width: 640px) {
.sms-toggle-label { display: none; }
2026-07-23 10:24:50 +03:30
.user-name { display: none; }
.topbar { gap: 8px; padding: 12px; }
.brand-btn small { display: none; }
2026-07-23 10:24:50 +03:30
}
</style>