Files
CRM_Montzar/apps/web/src/views/FaqSettingsView.vue
T
MahdiandCursor cc68b2d9f3 feat(web): add Ant workspace tabs and harden page chrome
Persist workspace tabs in the app shell with Ant Design styling aligned to the desktop top bar, and fix tab bar layout flicker on select. Add shared PageHeader components, query helpers, and missing header state across CRM views; improve mobile shell layout and Vite HMR stability on Windows.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-25 16:53:04 +03:30

252 lines
7.9 KiB
Vue

<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';
import {
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,
Tag as ATag,
Textarea as ATextarea,
Typography,
} from 'ant-design-vue';
import { DeleteOutlined, EditOutlined } from '@/icons/ant-bridge';
import { CrmSkeleton, CrmSkeletonList } from '@/components/skeleton';
import { PageHeader } from '@/components/page';
import { QuestionCircleOutlined } from '@/icons/ant-bridge';
const { Text: ATypographyText, Paragraph: ATypographyParagraph } =
Typography;
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>
<a-flex vertical :gap="16">
<PageHeader
title="پایگاه دانش و سؤالات متداول"
subtitle="مقاله‌ها و پاسخ‌های آماده برای تیم و مشتریان"
:icon="QuestionCircleOutlined"
/>
<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 = ''" />
<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>
<a-form-item label="پاسخ کامل" required>
<a-textarea
v-model:value="answer"
:rows="4"
placeholder="توضیحات و راهنمای گام‌به‌گام..."
style="width: 100%"
/>
</a-form-item>
<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>
<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>
<CrmSkeleton :loading="loading">
<CrmSkeletonList :rows="6">
<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>
</CrmSkeletonList>
</CrmSkeleton>
</a-flex>
</template>