index.vue
6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<script setup lang="ts">
import useLoading from '@/hooks/loading';
import { computed, onActivated, ref } from 'vue';
import useNotificationApi from '@/http/notification';
import { AnyObject } from '@/types/global';
import EnumTableColumn from '@/components/filter/enum-table-column.vue';
import UserTableColumn from '@/components/filter/user-table-column.vue';
import { useRoute, useRouter } from 'vue-router';
import NumberTableColumn from '@/components/filter/number-table-column.vue';
import { createModalVNode } from '@/utils/createVNode';
import { Notification } from '@/utils/model';
import { promiseToBoolean } from '@/utils';
import SpaceTableColumn from '@/components/filter/space-table-column.vue';
import usePermission from '@/hooks/permission';
const { loading, setLoading } = useLoading(false);
const { typeOption, statusOption, get, send, cancel, rollback } = useNotificationApi;
const filter = ref({ title: '', userNickName: '', type: '', status: '', createBetween: [], setWith: ['user:id,nick_name'] });
const tableRef = ref();
const router = useRouter();
const onQuery = async (params: AnyObject) => {
setLoading(true);
return get({ ...filter.value, ...params, sortBy: 'created_at', sortType: 'desc' }).finally(() => setLoading(false));
};
const onSearch = () => tableRef.value?.onPageChange(1);
const onReset = () => {
filter.value = { title: '', userNickName: '', type: '', status: '', createBetween: [], setWith: ['user:id,nick_name'] };
onSearch();
};
const onShow = (record: Notification) => router.push({ name: 'operation-notification-show', params: { id: record.id } });
const onCreate = () => router.push({ name: 'operation-notification-create' });
const onUpdate = (record: Notification) => router.push({ name: 'operation-notification-update', params: { id: record.id } });
const onSend = (record: Notification) =>
createModalVNode(`确认立即发送通知《${record.title}》`, {
title: '更新操作',
onBeforeOk: () => promiseToBoolean(send(record.id)),
onOk: () => tableRef.value?.onFetch(),
});
const onCancel = (record: Notification) =>
createModalVNode(`确认取消发送通知《${record.title}》`, {
title: '取消操作',
onBeforeOk: () => promiseToBoolean(cancel(record.id)),
onOk: () => tableRef.value?.onFetch(),
});
onActivated(() => (useRoute().meta.reload ? onReset() : tableRef.value?.onFetch()));
const onRollback = (record: Notification) =>
createModalVNode(`确认撤回发送通知《${record.title}》`, {
title: '撤回操作',
onBeforeOk: () => promiseToBoolean(rollback(record.id)),
onOk: () => tableRef.value?.onFetch(),
});
const hasOperationPermission = computed(() => {
return usePermission().checkPermission(['operation-notification-show', 'operation-notification-edit', 'operation-notification-send']);
});
</script>
<template>
<page-view has-bread has-card>
<filter-search :loading="loading" :model="filter" @search="onSearch" @reset="onReset">
<filter-search-item label="通知标题">
<a-input v-model="filter.title" placeholder="请输入" allow-clear />
</filter-search-item>
<filter-search-item label="创建人">
<a-input v-model="filter.userNickName" placeholder="请输入" allow-clear />
</filter-search-item>
<filter-search-item label="类型">
<a-select v-model="filter.type" :options="typeOption" placeholder="请选择" allow-clear />
</filter-search-item>
<filter-search-item field="createBetween" label="创建时间">
<a-range-picker v-model="filter.createBetween" show-time :time-picker-props="{ defaultValue: ['00:00:00', '23:59:59'] }" />
</filter-search-item>
<filter-search-item label="状态">
<a-select v-model="filter.status" :options="statusOption" placeholder="请选择" allow-clear />
</filter-search-item>
</filter-search>
<filter-table ref="tableRef" :loading="loading" :on-query="onQuery">
<template #tool>
<icon-button v-permission="['operation-notification-create']" type="primary" icon="plus" label="新增" @click="onCreate" />
</template>
<filter-table-column title="通知标题" data-index="title" :width="260" />
<enum-table-column title="类型" data-index="type" :option="typeOption" :width="100" />
<number-table-column title="接收人数" data-index="items_count" :width="120" />
<number-table-column title="查看人数" data-index="read_count" :width="120" />
<user-table-column title="创建人" data-index="user_id" user="user" :width="140" />
<filter-table-column title="创建时间" data-index="created_at" :width="160" />
<filter-table-column title="发送时间" data-index="publish_at" :width="160" />
<enum-table-column title="状态" data-index="status" :option="statusOption" :width="100" />
<space-table-column v-if="hasOperationPermission" title="操作" :width="120">
<template #default="{ record }: { record: Notification }">
<a-link
v-if="[-1, 0, 1, 2, 3].includes(record.status)"
v-permission="['operation-notification-show']"
:hoverable="false"
class="link-hover"
@click="onShow(record)"
>
查看
</a-link>
<a-link
v-if="[-2, 3].includes(record.status)"
v-permission="['operation-notification-edit']"
:hoverable="false"
class="link-hover"
@click="onUpdate(record)"
>
修改
</a-link>
<a-link
v-if="record.status === 2"
v-permission="['operation-notification-send']"
:hoverable="false"
class="link-hover"
@click="onRollback(record)"
>
撤回
</a-link>
<a-link
v-if="[-1, 0].includes(record.status)"
v-permission="['operation-notification-send']"
:hoverable="false"
class="link-hover"
@click="onSend(record)"
>
{{ record.status === -1 ? '重试' : '发送' }}
</a-link>
<a-link
v-if="record.status === 0"
v-permission="['operation-notification-send']"
:hoverable="false"
class="link-hover"
@click="onCancel(record)"
>
取消
</a-link>
</template>
</space-table-column>
</filter-table>
</page-view>
</template>
<style scoped lang="less"></style>