2026-08-29 21:06:30 +03:30
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import { api } from '@/lib/api';
|
|
|
|
|
import type {
|
|
|
|
|
CreateFaqArticleRequest,
|
|
|
|
|
FaqArticleDto,
|
|
|
|
|
UpdateFaqArticleRequest,
|
|
|
|
|
} from '@mento/shared';
|
2026-09-12 01:33:07 +03:30
|
|
|
import {
|
2026-11-04 10:01:11 +03:30
|
|
|
Alert as AAlert,
|
|
|
|
|
Button as AButton,
|
|
|
|
|
Card as ACard,
|
|
|
|
|
Checkbox as ACheckbox,
|
|
|
|
|
Col as ACol,
|
|
|
|
|
Empty as AEmpty,
|
|
|
|
|
Flex as AFlex,
|
|
|
|
|
Form as AForm,
|
|
|
|
|
FormItem as AFormItem,
|
|
|
|
|
Input as AInput,
|
|
|
|
|
InputNumber as AInputNumber,
|
|
|
|
|
Row as ARow,
|
|
|
|
|
Space as ASpace,
|
|
|
|
|
Spin as ASpin,
|
|
|
|
|
Tag as ATag,
|
|
|
|
|
Textarea as ATextarea,
|
|
|
|
|
Typography,
|
|
|
|
|
} from 'ant-design-vue';
|
|
|
|
|
import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue';
|
|
|
|
|
|
|
|
|
|
const { Title: ATypographyTitle, Text: ATypographyText, Paragraph: ATypographyParagraph } =
|
|
|
|
|
Typography;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
|
|
|
|
const loading = ref(false);
|
|
|
|
|
const saving = ref(false);
|
|
|
|
|
const error = ref('');
|
|
|
|
|
const ok = ref('');
|
|
|
|
|
const items = ref<FaqArticleDto[]>([]);
|
|
|
|
|
|
|
|
|
|
const editingId = ref<string | null>(null);
|
|
|
|
|
const question = ref('');
|
|
|
|
|
const answer = ref('');
|
|
|
|
|
const category = ref('');
|
|
|
|
|
const isPublished = ref(true);
|
|
|
|
|
const position = ref(0);
|
|
|
|
|
|
|
|
|
|
function resetForm() {
|
|
|
|
|
editingId.value = null;
|
|
|
|
|
question.value = '';
|
|
|
|
|
answer.value = '';
|
|
|
|
|
category.value = '';
|
|
|
|
|
isPublished.value = true;
|
|
|
|
|
position.value = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startEdit(row: FaqArticleDto) {
|
|
|
|
|
editingId.value = row.id;
|
|
|
|
|
question.value = row.question;
|
|
|
|
|
answer.value = row.answer;
|
|
|
|
|
category.value = row.category ?? '';
|
|
|
|
|
isPublished.value = row.isPublished;
|
|
|
|
|
position.value = row.position;
|
|
|
|
|
ok.value = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
|
loading.value = true;
|
|
|
|
|
error.value = '';
|
|
|
|
|
try {
|
|
|
|
|
const { data } = await api.get<FaqArticleDto[]>('/faq', {
|
|
|
|
|
params: { publishedOnly: false },
|
|
|
|
|
});
|
|
|
|
|
items.value = data;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (axios.isAxiosError(e) && !e.response) {
|
|
|
|
|
error.value = 'اتصال به API برقرار نشد.';
|
|
|
|
|
} else {
|
|
|
|
|
error.value = 'بارگذاری FAQ ناموفق بود.';
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function save() {
|
|
|
|
|
if (!question.value.trim() || !answer.value.trim()) {
|
|
|
|
|
error.value = 'سؤال و پاسخ را وارد کنید.';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
saving.value = true;
|
|
|
|
|
error.value = '';
|
|
|
|
|
ok.value = '';
|
|
|
|
|
try {
|
|
|
|
|
if (editingId.value) {
|
|
|
|
|
const body: UpdateFaqArticleRequest = {
|
|
|
|
|
question: question.value.trim(),
|
|
|
|
|
answer: answer.value.trim(),
|
|
|
|
|
category: category.value.trim() || null,
|
|
|
|
|
isPublished: isPublished.value,
|
|
|
|
|
position: position.value,
|
|
|
|
|
};
|
|
|
|
|
await api.patch(`/faq/${editingId.value}`, body);
|
|
|
|
|
ok.value = 'مقاله بهروز شد.';
|
|
|
|
|
} else {
|
|
|
|
|
const body: CreateFaqArticleRequest = {
|
|
|
|
|
question: question.value.trim(),
|
|
|
|
|
answer: answer.value.trim(),
|
|
|
|
|
category: category.value.trim() || undefined,
|
|
|
|
|
isPublished: isPublished.value,
|
|
|
|
|
position: position.value,
|
|
|
|
|
};
|
|
|
|
|
await api.post('/faq', body);
|
|
|
|
|
ok.value = 'مقاله اضافه شد.';
|
|
|
|
|
}
|
|
|
|
|
resetForm();
|
|
|
|
|
await load();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (axios.isAxiosError(e)) {
|
|
|
|
|
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
|
|
|
|
error.value = Array.isArray(msg)
|
|
|
|
|
? msg.join('، ')
|
|
|
|
|
: (msg ?? 'ذخیره ناموفق بود');
|
|
|
|
|
} else {
|
|
|
|
|
error.value = 'ذخیره ناموفق بود';
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
saving.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function remove(row: FaqArticleDto) {
|
|
|
|
|
if (!confirm(`حذف «${row.question}»؟`)) return;
|
|
|
|
|
await api.delete(`/faq/${row.id}`);
|
|
|
|
|
if (editingId.value === row.id) resetForm();
|
|
|
|
|
await load();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(load);
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-11-04 10:01:11 +03:30
|
|
|
<a-flex vertical :gap="16">
|
|
|
|
|
<a-typography-title :level="3" :style="{ margin: 0 }">
|
|
|
|
|
پایگاه دانش و سؤالات متداول
|
|
|
|
|
</a-typography-title>
|
2026-08-29 21:06:30 +03:30
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
<a-alert v-if="error" type="error" show-icon :message="error" closable @close="error = ''" />
|
|
|
|
|
<a-alert v-if="ok" type="success" show-icon :message="ok" closable @close="ok = ''" />
|
2026-08-29 21:06:30 +03:30
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
<a-card :title="editingId ? 'ویرایش مقاله' : 'مقاله جدید'" :bordered="false">
|
|
|
|
|
<a-form layout="vertical" @finish="save">
|
|
|
|
|
<a-form-item label="پرسش / عنوان مقاله" required>
|
|
|
|
|
<a-input
|
|
|
|
|
v-model:value="question"
|
|
|
|
|
:maxlength="500"
|
|
|
|
|
placeholder="مثلاً نحوه فعالسازی حساب کاربری..."
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
2026-09-12 01:33:07 +03:30
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
<a-form-item label="پاسخ کامل" required>
|
|
|
|
|
<a-textarea
|
|
|
|
|
v-model:value="answer"
|
|
|
|
|
:rows="4"
|
|
|
|
|
placeholder="توضیحات و راهنمای گامبهگام..."
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
2026-09-12 01:33:07 +03:30
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
<a-row :gutter="[16, 0]" align="bottom">
|
|
|
|
|
<a-col :xs="24" :md="10">
|
|
|
|
|
<a-form-item label="دستهبندی">
|
|
|
|
|
<a-input
|
|
|
|
|
v-model:value="category"
|
|
|
|
|
:maxlength="100"
|
|
|
|
|
placeholder="مثلاً مالی، فنی، نصب"
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="6">
|
|
|
|
|
<a-form-item label="ترتیب نمایش">
|
|
|
|
|
<a-input-number v-model:value="position" :min="0" style="width: 100%" />
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :md="8">
|
|
|
|
|
<a-form-item label=" ">
|
|
|
|
|
<a-checkbox v-model:checked="isPublished">منتشرشده در پورتال</a-checkbox>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
2026-09-12 01:33:07 +03:30
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
<a-form-item>
|
|
|
|
|
<a-space wrap>
|
|
|
|
|
<a-button type="primary" html-type="submit" :loading="saving">
|
|
|
|
|
{{ editingId ? 'ذخیره تغییرات' : 'افزودن مقاله' }}
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button v-if="editingId" @click="resetForm">انصراف</a-button>
|
|
|
|
|
</a-space>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-form>
|
|
|
|
|
</a-card>
|
2026-09-12 01:33:07 +03:30
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
<a-spin :spinning="loading">
|
|
|
|
|
<a-empty
|
|
|
|
|
v-if="!loading && !items.length"
|
|
|
|
|
description="هنوز مقالهای ثبت نشده است. با ثبت اولین سؤال و پاسخ، پایگاه دانش را تکمیل کنید."
|
|
|
|
|
/>
|
|
|
|
|
<a-flex v-else vertical :gap="12">
|
|
|
|
|
<a-card v-for="row in items" :key="row.id" :bordered="false">
|
|
|
|
|
<a-row :gutter="[16, 12]" align="top">
|
|
|
|
|
<a-col :xs="24" :lg="18">
|
|
|
|
|
<a-flex vertical :gap="8">
|
|
|
|
|
<a-space wrap>
|
|
|
|
|
<a-typography-text strong>{{ row.question }}</a-typography-text>
|
|
|
|
|
<a-tag :color="row.isPublished ? 'success' : 'default'" :bordered="false">
|
|
|
|
|
{{ row.isPublished ? 'منتشرشده' : 'پیشنویس' }}
|
|
|
|
|
</a-tag>
|
|
|
|
|
<a-tag v-if="row.category" color="processing" :bordered="false">
|
|
|
|
|
{{ row.category }}
|
|
|
|
|
</a-tag>
|
|
|
|
|
</a-space>
|
|
|
|
|
<a-typography-paragraph type="secondary" :style="{ marginBottom: 0, whiteSpace: 'pre-wrap' }">
|
|
|
|
|
{{ row.answer }}
|
|
|
|
|
</a-typography-paragraph>
|
|
|
|
|
</a-flex>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :xs="24" :lg="6">
|
|
|
|
|
<a-space wrap>
|
|
|
|
|
<a-button @click="startEdit(row)">
|
|
|
|
|
<template #icon><EditOutlined /></template>
|
|
|
|
|
ویرایش
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button danger @click="remove(row)">
|
|
|
|
|
<template #icon><DeleteOutlined /></template>
|
|
|
|
|
حذف
|
|
|
|
|
</a-button>
|
|
|
|
|
</a-space>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</a-card>
|
|
|
|
|
</a-flex>
|
|
|
|
|
</a-spin>
|
|
|
|
|
</a-flex>
|
2026-08-29 21:06:30 +03:30
|
|
|
</template>
|