2026-09-30 18:42:28 +03:30
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h1>تنظیمات سایت</h1>
|
|
|
|
|
|
<form v-if="form" class="card" @submit.prevent="save">
|
|
|
|
|
|
<div class="grid-2">
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label class="label">نام برند</label>
|
|
|
|
|
|
<input v-model="form.brandName" class="input" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label class="label">تگلاین</label>
|
|
|
|
|
|
<input v-model="form.tagline" class="input" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label class="label">ایمیل</label>
|
|
|
|
|
|
<input v-model="form.email" class="input" dir="ltr" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label class="label">تلفن</label>
|
|
|
|
|
|
<input v-model="form.phone" class="input" dir="ltr" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label class="label">آدرس</label>
|
|
|
|
|
|
<input v-model="form.address" class="input" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
2026-09-30 21:06:33 +03:30
|
|
|
|
<label class="label">منطقه زمانی</label>
|
|
|
|
|
|
<input v-model="form.timezone" class="input" dir="ltr" placeholder="Asia/Tehran" />
|
2026-09-30 18:42:28 +03:30
|
|
|
|
</div>
|
2026-09-30 21:06:33 +03:30
|
|
|
|
<div class="field" style="grid-column: 1 / -1">
|
|
|
|
|
|
<label class="label">آدرس لوگو</label>
|
|
|
|
|
|
<input v-model="form.logoUrl" class="input" dir="ltr" placeholder="از بخش رسانه آپلود کنید و آدرس را اینجا بگذارید" />
|
2026-09-30 18:42:28 +03:30
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-09-30 21:06:33 +03:30
|
|
|
|
|
|
|
|
|
|
<h2 style="margin: 1.25rem 0 0.75rem; font-size: 1rem">شبکههای اجتماعی</h2>
|
|
|
|
|
|
<div v-for="(s, i) in socials" :key="i" class="item-box">
|
|
|
|
|
|
<div class="row" style="justify-content: space-between; margin-bottom: 0.5rem">
|
|
|
|
|
|
<strong>مورد {{ i + 1 }}</strong>
|
|
|
|
|
|
<button type="button" class="btn danger" @click="socials.splice(i, 1)">حذف</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="grid-2">
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label class="label">نام (مثلاً لینکدین)</label>
|
|
|
|
|
|
<input v-model="s.label" class="input" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label class="label">آدرس لینک</label>
|
|
|
|
|
|
<input v-model="s.url" class="input" dir="ltr" placeholder="https://..." />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-09-30 18:42:28 +03:30
|
|
|
|
</div>
|
2026-09-30 21:06:33 +03:30
|
|
|
|
<button type="button" class="btn ghost" @click="socials.push({ label: '', url: '' })">+ افزودن شبکه اجتماعی</button>
|
|
|
|
|
|
|
|
|
|
|
|
<p v-if="msg" class="muted" style="margin-top: 1rem">{{ msg }}</p>
|
|
|
|
|
|
<button class="btn" style="margin-top: 0.75rem">ذخیره</button>
|
2026-09-30 18:42:28 +03:30
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-09-30 21:06:33 +03:30
|
|
|
|
import { onMounted, reactive, ref } from "vue";
|
2026-09-30 18:42:28 +03:30
|
|
|
|
import { api } from "../lib/api";
|
|
|
|
|
|
|
2026-09-30 21:06:33 +03:30
|
|
|
|
const form = ref<{
|
|
|
|
|
|
brandName: string;
|
|
|
|
|
|
tagline: string;
|
|
|
|
|
|
email: string;
|
|
|
|
|
|
phone: string;
|
|
|
|
|
|
address: string;
|
|
|
|
|
|
timezone: string;
|
|
|
|
|
|
logoUrl: string;
|
|
|
|
|
|
} | null>(null);
|
|
|
|
|
|
|
|
|
|
|
|
const socials = reactive<Array<{ label: string; url: string }>>([]);
|
2026-09-30 18:42:28 +03:30
|
|
|
|
const msg = ref("");
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
const { data } = await api.get("/admin/settings");
|
2026-09-30 21:06:33 +03:30
|
|
|
|
form.value = {
|
|
|
|
|
|
brandName: data.brandName || "",
|
|
|
|
|
|
tagline: data.tagline || "",
|
|
|
|
|
|
email: data.email || "",
|
|
|
|
|
|
phone: data.phone || "",
|
|
|
|
|
|
address: data.address || "",
|
|
|
|
|
|
timezone: data.timezone || "Asia/Tehran",
|
|
|
|
|
|
logoUrl: data.logoUrl || "",
|
|
|
|
|
|
};
|
|
|
|
|
|
socials.splice(0, socials.length, ...(Array.isArray(data.socials) ? data.socials : []));
|
|
|
|
|
|
if (!socials.length) socials.push({ label: "", url: "" });
|
2026-09-30 18:42:28 +03:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
async function save() {
|
2026-09-30 21:06:33 +03:30
|
|
|
|
if (!form.value) return;
|
2026-09-30 18:42:28 +03:30
|
|
|
|
msg.value = "";
|
|
|
|
|
|
try {
|
2026-09-30 21:06:33 +03:30
|
|
|
|
const payload = {
|
|
|
|
|
|
brandName: form.value.brandName,
|
|
|
|
|
|
tagline: form.value.tagline,
|
|
|
|
|
|
email: form.value.email,
|
|
|
|
|
|
phone: form.value.phone,
|
|
|
|
|
|
address: form.value.address,
|
|
|
|
|
|
timezone: form.value.timezone,
|
|
|
|
|
|
logoUrl: form.value.logoUrl || null,
|
|
|
|
|
|
socials: socials.filter((s) => s.label.trim() || s.url.trim()),
|
|
|
|
|
|
};
|
|
|
|
|
|
const { data } = await api.put("/admin/settings", payload);
|
|
|
|
|
|
form.value.logoUrl = data.logoUrl || "";
|
2026-09-30 18:42:28 +03:30
|
|
|
|
msg.value = "ذخیره شد.";
|
2026-09-30 21:06:33 +03:30
|
|
|
|
} catch (e: any) {
|
|
|
|
|
|
const detail = e?.response?.data?.message;
|
|
|
|
|
|
msg.value = Array.isArray(detail)
|
|
|
|
|
|
? `خطا: ${detail.join("، ")}`
|
|
|
|
|
|
: detail
|
|
|
|
|
|
? `خطا: ${detail}`
|
|
|
|
|
|
: "خطا در ذخیره.";
|
2026-09-30 18:42:28 +03:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
2026-09-30 21:06:33 +03:30
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.item-box {
|
|
|
|
|
|
border: 1px solid var(--border);
|
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
|
padding: 0.9rem;
|
|
|
|
|
|
margin-bottom: 0.9rem;
|
|
|
|
|
|
background: #12151b;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|