fix notif
This commit is contained in:
@@ -16,6 +16,15 @@
|
||||
<BaseTable v-bind="tblProps" @register="submit" ref="tbl">
|
||||
<template #action="{ record }">
|
||||
<div class="flex justify-center gap-2">
|
||||
<a-tooltip placement="bottom">
|
||||
<template #title>بازدیدکنندگان</template>
|
||||
<Icon
|
||||
icon="vuesax-linear:people"
|
||||
color="#10913A"
|
||||
class="cursor-pointer"
|
||||
@click="emits('readers', record)"
|
||||
/>
|
||||
</a-tooltip>
|
||||
<a-tooltip placement="bottom">
|
||||
<template #title>ویرایش</template>
|
||||
<Icon
|
||||
@@ -28,7 +37,7 @@
|
||||
<a-tooltip placement="bottom">
|
||||
<template #title>{{ record.is_active ? 'غیرفعال کردن' : 'فعال کردن' }}</template>
|
||||
<Icon
|
||||
:icon="record.is_active ? 'vuesax-linear:eye-slash' : 'vuesax-linear:eye'"
|
||||
:icon="record.is_active ? 'vuesax-linear:close-circle' : 'vuesax-linear:tick-circle'"
|
||||
:color="record.is_active ? '#C53030' : '#25855A'"
|
||||
class="cursor-pointer"
|
||||
@click="emits('toggle', record)"
|
||||
@@ -65,6 +74,7 @@ const emits = defineEmits<{
|
||||
edit: [record: Record<string, unknown>]
|
||||
toggle: [record: Record<string, unknown>]
|
||||
delete: [id: number]
|
||||
readers: [record: Record<string, unknown>]
|
||||
}>()
|
||||
|
||||
const tblProps = {
|
||||
|
||||
@@ -49,6 +49,12 @@ export const cols: BaseTableColumn[] = [
|
||||
</CustomTag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'بازدیدکنندگان',
|
||||
dataIndex: 'reads_count',
|
||||
key: 'reads_count',
|
||||
customRender: ({ record }) => Number(record.reads_count ?? 0),
|
||||
},
|
||||
{
|
||||
title: 'تاریخ',
|
||||
dataIndex: 'created_at',
|
||||
@@ -59,5 +65,9 @@ export const cols: BaseTableColumn[] = [
|
||||
title: 'عملیات',
|
||||
dataIndex: 'action',
|
||||
key: 'action',
|
||||
slot: 'action',
|
||||
fixed: 'right',
|
||||
filterable: false,
|
||||
width: 160,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
@edit="openEdit"
|
||||
@toggle="toggleActive"
|
||||
@delete="deleteItem"
|
||||
@readers="openReaders"
|
||||
/>
|
||||
|
||||
<BasicActionSheet
|
||||
@@ -27,6 +28,43 @@
|
||||
<div v-if="isMobile" class="mb-3 text-base font-bold">{{ sheetTitle }}</div>
|
||||
<AppNotificationEditorFormBody ref="editorRef" :form="form" />
|
||||
</BasicActionSheet>
|
||||
|
||||
<BasicActionSheet
|
||||
v-model:visible="readersVisible"
|
||||
:title="readersTitle"
|
||||
modal-width="28rem"
|
||||
drawer-height="70vh"
|
||||
:loading="readersLoading"
|
||||
:show-button="true"
|
||||
:show-cancel="false"
|
||||
:show-ok="true"
|
||||
ok-text="بستن"
|
||||
@ok="readersVisible = false"
|
||||
@close="readersVisible = false"
|
||||
>
|
||||
<div v-if="isMobile" class="mb-3 text-base font-bold">{{ readersTitle }}</div>
|
||||
<a-spin :spinning="readersLoading">
|
||||
<div v-if="!readers.length" class="py-8 text-center text-gray-500">
|
||||
هنوز کسی این اعلان را بازدید نکرده است.
|
||||
</div>
|
||||
<div v-else class="readers-scroll flex flex-col gap-2">
|
||||
<div class="mb-1 text-xs text-gray-500">{{ readers.length }} بازدیدکننده</div>
|
||||
<div
|
||||
v-for="row in readers"
|
||||
:key="row.customer_id"
|
||||
class="flex items-center justify-between gap-3 rounded-lg border border-solid border-gray-100 px-3 py-2"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<div class="truncate font-bold">{{ row.name }}</div>
|
||||
<div class="text-xs text-gray-500" dir="ltr">{{ row.mobile || '—' }}</div>
|
||||
</div>
|
||||
<div class="shrink-0 text-xs text-gray-500">
|
||||
{{ row.read_at ? toJalali(row.read_at) : '—' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-spin>
|
||||
</BasicActionSheet>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -37,15 +75,17 @@ import { cloneDeep } from 'lodash'
|
||||
import tbl from './components/table.vue'
|
||||
import BasicActionSheet from '@/components/BasicActionSheet.vue'
|
||||
import AppNotificationEditorFormBody from './components/AppNotificationEditorFormBody.vue'
|
||||
import type { AppNotification } from '@/model/appNotifications'
|
||||
import type { AppNotification, AppNotificationReader } from '@/model/appNotifications'
|
||||
import {
|
||||
createAppNotification,
|
||||
deleteAppNotification,
|
||||
getAppNotificationReaders,
|
||||
toggleAppNotificationActive,
|
||||
updateAppNotification,
|
||||
} from '@/api/appNotifications'
|
||||
import { confirmDeleteItem } from '@/utils/confirmModal'
|
||||
import { isMobile } from '@core/utils/is'
|
||||
import { toJalali } from '@core/utils/useDataTime'
|
||||
|
||||
const tableRef = ref<null | { fetch: () => void }>(null)
|
||||
const editorRef = ref<{
|
||||
@@ -57,6 +97,11 @@ const loading = ref(false)
|
||||
const editorVisible = ref(false)
|
||||
const editId = ref<number | undefined>()
|
||||
|
||||
const readersVisible = ref(false)
|
||||
const readersLoading = ref(false)
|
||||
const readers = ref<AppNotificationReader[]>([])
|
||||
const readersNotifTitle = ref('')
|
||||
|
||||
const defaultForm = (): Partial<AppNotification> => ({
|
||||
title: '',
|
||||
body: '',
|
||||
@@ -67,6 +112,9 @@ const defaultForm = (): Partial<AppNotification> => ({
|
||||
const form = ref<Partial<AppNotification>>(defaultForm())
|
||||
|
||||
const sheetTitle = computed(() => (editId.value ? 'ویرایش اعلان' : 'افزودن اعلان'))
|
||||
const readersTitle = computed(() =>
|
||||
readersNotifTitle.value ? `بازدیدکنندگان — ${readersNotifTitle.value}` : 'بازدیدکنندگان اعلان'
|
||||
)
|
||||
|
||||
function refreshTable() {
|
||||
tableRef.value?.fetch()
|
||||
@@ -94,6 +142,24 @@ function openEdit(record: AppNotification) {
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
async function openReaders(record: AppNotification) {
|
||||
if (!record.id) return
|
||||
readersNotifTitle.value = record.title || ''
|
||||
readersVisible.value = true
|
||||
readersLoading.value = true
|
||||
readers.value = []
|
||||
try {
|
||||
const data = await getAppNotificationReaders(record.id)
|
||||
readers.value = Array.isArray(data?.readers) ? data.readers : []
|
||||
refreshTable()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
message.error('بارگذاری لیست بازدیدکنندگان ناموفق بود')
|
||||
} finally {
|
||||
readersLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
try {
|
||||
await editorRef.value?.validateFields?.()
|
||||
@@ -142,3 +208,11 @@ async function deleteItem(id: number) {
|
||||
confirmDeleteItem('اعلان', id, deleteAppNotification, refreshTable)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.readers-scroll {
|
||||
max-height: min(50vh, 28rem);
|
||||
overflow-y: auto;
|
||||
padding-inline-end: 0.25rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user