2026-08-29 21:06:30 +03:30
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { computed, onMounted, ref } from 'vue';
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
import { api } from '@/lib/api';
|
|
|
|
|
|
import type {
|
|
|
|
|
|
CreateCustomFieldRequest,
|
|
|
|
|
|
CustomFieldDefinitionDto,
|
|
|
|
|
|
CustomFieldEntity,
|
|
|
|
|
|
CustomFieldType,
|
|
|
|
|
|
} from '@mento/shared';
|
|
|
|
|
|
|
|
|
|
|
|
const loading = ref(false);
|
|
|
|
|
|
const saving = ref(false);
|
|
|
|
|
|
const error = ref('');
|
|
|
|
|
|
const fields = ref<CustomFieldDefinitionDto[]>([]);
|
|
|
|
|
|
const filter = ref<'all' | CustomFieldEntity>('all');
|
|
|
|
|
|
|
|
|
|
|
|
const label = ref('');
|
|
|
|
|
|
const entityType = ref<CustomFieldEntity>('person');
|
|
|
|
|
|
const fieldType = ref<CustomFieldType>('text');
|
|
|
|
|
|
const optionsRaw = ref('');
|
|
|
|
|
|
const required = ref(false);
|
|
|
|
|
|
|
|
|
|
|
|
const entityLabels: Record<CustomFieldEntity, string> = {
|
|
|
|
|
|
person: 'شخص',
|
|
|
|
|
|
company: 'شرکت',
|
|
|
|
|
|
deal: 'معامله',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const typeLabels: Record<CustomFieldType, string> = {
|
|
|
|
|
|
text: 'متن',
|
|
|
|
|
|
number: 'عدد',
|
|
|
|
|
|
date: 'تاریخ',
|
|
|
|
|
|
boolean: 'بله/خیر',
|
|
|
|
|
|
select: 'لیست انتخابی',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const visible = computed(() =>
|
|
|
|
|
|
filter.value === 'all'
|
|
|
|
|
|
? fields.value
|
|
|
|
|
|
: fields.value.filter((f) => f.entityType === filter.value),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
|
|
loading.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
try {
|
|
|
|
|
|
fields.value = (await api.get<CustomFieldDefinitionDto[]>('/custom-fields')).data;
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (axios.isAxiosError(e) && !e.response) {
|
|
|
|
|
|
error.value = 'اتصال به API برقرار نشد.';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error.value = 'بارگذاری فیلدها ناموفق بود.';
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function createField() {
|
|
|
|
|
|
if (!label.value.trim()) {
|
|
|
|
|
|
error.value = 'عنوان فیلد را وارد کنید.';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
saving.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
try {
|
|
|
|
|
|
const payload: CreateCustomFieldRequest = {
|
|
|
|
|
|
entityType: entityType.value,
|
|
|
|
|
|
label: label.value.trim(),
|
|
|
|
|
|
fieldType: fieldType.value,
|
|
|
|
|
|
required: required.value,
|
|
|
|
|
|
options:
|
|
|
|
|
|
fieldType.value === 'select'
|
|
|
|
|
|
? optionsRaw.value
|
|
|
|
|
|
.split(/[,،\n]/)
|
|
|
|
|
|
.map((o) => o.trim())
|
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
|
: undefined,
|
|
|
|
|
|
};
|
|
|
|
|
|
await api.post('/custom-fields', payload);
|
|
|
|
|
|
label.value = '';
|
|
|
|
|
|
optionsRaw.value = '';
|
|
|
|
|
|
required.value = false;
|
|
|
|
|
|
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 toggleActive(field: CustomFieldDefinitionDto) {
|
|
|
|
|
|
await api.patch(`/custom-fields/${field.id}`, { isActive: !field.isActive });
|
|
|
|
|
|
await load();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function removeField(field: CustomFieldDefinitionDto) {
|
|
|
|
|
|
if (!confirm(`فیلد «${field.label}» حذف شود؟`)) return;
|
|
|
|
|
|
await api.delete(`/custom-fields/${field.id}`);
|
|
|
|
|
|
await load();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(load);
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<section class="page">
|
|
|
|
|
|
<header class="page-head">
|
2026-09-05 02:29:41 +03:30
|
|
|
|
<div class="head-copy">
|
2026-08-29 21:06:30 +03:30
|
|
|
|
<h1>فیلدهای سفارشی</h1>
|
2026-09-05 02:29:41 +03:30
|
|
|
|
<p class="lead">
|
2026-08-29 21:06:30 +03:30
|
|
|
|
فیلدهای اختصاصی سازمان را برای شخص، شرکت یا معامله تعریف کنید.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
<form class="panel" @submit.prevent="createField">
|
2026-08-29 21:06:30 +03:30
|
|
|
|
<h2>فیلد جدید</h2>
|
|
|
|
|
|
<div class="grid">
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label for="cf-label">عنوان</label>
|
|
|
|
|
|
<input id="cf-label" v-model="label" required placeholder="مثلاً صنعت" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label for="cf-entity">روی چه چیزی؟</label>
|
|
|
|
|
|
<select id="cf-entity" v-model="entityType">
|
|
|
|
|
|
<option value="person">شخص</option>
|
|
|
|
|
|
<option value="company">شرکت</option>
|
|
|
|
|
|
<option value="deal">معامله</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field">
|
|
|
|
|
|
<label for="cf-type">نوع</label>
|
|
|
|
|
|
<select id="cf-type" v-model="fieldType">
|
|
|
|
|
|
<option value="text">متن</option>
|
|
|
|
|
|
<option value="number">عدد</option>
|
|
|
|
|
|
<option value="date">تاریخ</option>
|
|
|
|
|
|
<option value="boolean">بله/خیر</option>
|
|
|
|
|
|
<option value="select">لیست انتخابی</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="field check-field">
|
|
|
|
|
|
<label class="check">
|
|
|
|
|
|
<input v-model="required" type="checkbox" />
|
|
|
|
|
|
اجباری
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-if="fieldType === 'select'" class="field wide">
|
|
|
|
|
|
<label for="cf-options">گزینهها (با کاما جدا کنید)</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
id="cf-options"
|
|
|
|
|
|
v-model="optionsRaw"
|
|
|
|
|
|
placeholder="مثلاً فناوری، تولید، خدمات"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-09-05 02:29:41 +03:30
|
|
|
|
<button class="btn primary" type="submit" :disabled="saving">
|
2026-08-29 21:06:30 +03:30
|
|
|
|
{{ saving ? 'در حال ثبت…' : 'افزودن فیلد' }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="toolbar">
|
|
|
|
|
|
<select v-model="filter">
|
|
|
|
|
|
<option value="all">همه</option>
|
|
|
|
|
|
<option value="person">شخص</option>
|
|
|
|
|
|
<option value="company">شرکت</option>
|
|
|
|
|
|
<option value="deal">معامله</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
<button class="btn btn-ghost" type="button" @click="load">بروزرسانی</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<p v-if="error" class="error">{{ error }}</p>
|
|
|
|
|
|
<p v-if="loading" class="muted">در حال بارگذاری…</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-else class="list">
|
|
|
|
|
|
<article v-for="field in visible" :key="field.id" class="row">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<strong>{{ field.label }}</strong>
|
|
|
|
|
|
<p class="meta">
|
|
|
|
|
|
{{ entityLabels[field.entityType] }} · {{ typeLabels[field.fieldType] }}
|
|
|
|
|
|
· کلید: <code>{{ field.key }}</code>
|
|
|
|
|
|
<span v-if="!field.isActive"> · غیرفعال</span>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="actions">
|
|
|
|
|
|
<button class="btn btn-ghost" type="button" @click="toggleActive(field)">
|
|
|
|
|
|
{{ field.isActive ? 'غیرفعال' : 'فعال' }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="btn btn-danger" type="button" @click="removeField(field)">
|
|
|
|
|
|
حذف
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</article>
|
|
|
|
|
|
<p v-if="!visible.length" class="muted">هنوز فیلدی تعریف نشده است.</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.page {
|
|
|
|
|
|
display: grid;
|
2026-09-05 02:29:41 +03:30
|
|
|
|
gap: 1rem;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
max-width: 920px;
|
2026-09-05 02:29:41 +03:30
|
|
|
|
min-width: 0;
|
|
|
|
|
|
overflow-x: clip;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.page-head {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
|
flex-wrap: wrap;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.head-copy {
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
|
|
margin: 0 0 0.3rem;
|
|
|
|
|
|
font-size: clamp(1.45rem, 2.5vw, 1.85rem);
|
|
|
|
|
|
font-weight: 800;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.lead,
|
|
|
|
|
|
.muted,
|
|
|
|
|
|
.meta {
|
2026-08-29 21:06:30 +03:30
|
|
|
|
margin: 0;
|
2026-09-05 02:29:41 +03:30
|
|
|
|
color: #64748b;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.error {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
color: #b91c1c;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.panel,
|
2026-08-29 21:06:30 +03:30
|
|
|
|
.row {
|
2026-09-05 02:29:41 +03:30
|
|
|
|
background: #fff;
|
|
|
|
|
|
border: 1px solid #e2e8f0;
|
|
|
|
|
|
border-radius: 18px;
|
|
|
|
|
|
box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
|
2026-08-29 21:06:30 +03:30
|
|
|
|
padding: 1.1rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.panel {
|
2026-08-29 21:06:30 +03:30
|
|
|
|
display: grid;
|
|
|
|
|
|
gap: 0.9rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.panel h2 {
|
2026-08-29 21:06:30 +03:30
|
|
|
|
margin: 0;
|
|
|
|
|
|
font-size: 1.05rem;
|
2026-09-05 02:29:41 +03:30
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
color: #0f172a;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.grid {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
|
|
|
|
gap: 0.85rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.wide {
|
|
|
|
|
|
grid-column: 1 / -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.field label {
|
|
|
|
|
|
color: #64748b;
|
|
|
|
|
|
font-size: 0.9rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-29 21:06:30 +03:30
|
|
|
|
select,
|
|
|
|
|
|
input[type='text'] {
|
2026-09-05 02:29:41 +03:30
|
|
|
|
border: 1px solid #e2e8f0;
|
2026-09-10 23:45:11 +03:30
|
|
|
|
border-radius: var(--radius);
|
|
|
|
|
|
min-height: var(--control-h);
|
|
|
|
|
|
padding: 0 0.95rem;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
background: #fff;
|
|
|
|
|
|
font: inherit;
|
|
|
|
|
|
width: 100%;
|
2026-09-10 23:45:11 +03:30
|
|
|
|
box-sizing: border-box;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.check-field {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: end;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.check {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 0.45rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.toolbar {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 0.6rem;
|
|
|
|
|
|
align-items: center;
|
2026-09-05 02:29:41 +03:30
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.toolbar select {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.btn {
|
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2026-09-10 23:45:11 +03:30
|
|
|
|
min-height: var(--control-h);
|
|
|
|
|
|
padding: 0 0.95rem;
|
|
|
|
|
|
border-radius: var(--radius);
|
2026-09-05 02:29:41 +03:30
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
border: 1px solid transparent;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
font: inherit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.btn.primary {
|
|
|
|
|
|
background: #14b8a6;
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
box-shadow: 0 8px 18px rgba(20, 184, 166, 0.24);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.btn-ghost {
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
color: #0f766e;
|
|
|
|
|
|
border: 1px solid #99f6e4;
|
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.btn-danger {
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
color: #b91c1c;
|
|
|
|
|
|
border: 1px solid #fecaca;
|
|
|
|
|
|
box-shadow: none;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.list {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
gap: 0.7rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.row {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.meta {
|
2026-09-05 02:29:41 +03:30
|
|
|
|
margin-top: 0.25rem;
|
2026-08-29 21:06:30 +03:30
|
|
|
|
font-size: 0.92rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.actions {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 0.45rem;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
code {
|
|
|
|
|
|
font-family: Consolas, monospace;
|
|
|
|
|
|
font-size: 0.85em;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@media (max-width: 700px) {
|
2026-09-05 02:29:41 +03:30
|
|
|
|
.grid {
|
2026-08-29 21:06:30 +03:30
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.row {
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
|
}
|
2026-09-05 02:29:41 +03:30
|
|
|
|
|
|
|
|
|
|
.actions,
|
|
|
|
|
|
.toolbar {
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
|
}
|
2026-08-29 21:06:30 +03:30
|
|
|
|
}
|
|
|
|
|
|
</style>
|