Files
orion-visor/orion-ops-ui/src/components/system/message-box/index.vue

129 lines
3.2 KiB
Vue
Raw Normal View History

2023-07-24 10:05:07 +08:00
<template>
<a-spin style="display: block" :loading="loading">
<a-tabs v-model:activeKey="messageType" type="rounded" destroy-on-hide>
<a-tab-pane v-for="item in tabList" :key="item.key">
<template #title>
<span> {{ item.title }}{{ formatUnreadLength(item.key) }} </span>
</template>
<a-result v-if="!renderList.length" status="404">
2023-09-25 22:05:48 +08:00
<template #subtitle>暂无内容</template>
2023-07-24 10:05:07 +08:00
</a-result>
2023-09-25 22:05:48 +08:00
<List :render-list="renderList"
:unread-count="unreadCount"
@item-click="handleItemClick" />
2023-07-24 10:05:07 +08:00
</a-tab-pane>
<template #extra>
<a-button type="text" @click="emptyList">
2023-09-25 22:05:48 +08:00
清空
2023-07-24 10:05:07 +08:00
</a-button>
</template>
</a-tabs>
</a-spin>
</template>
<script lang="ts" setup>
2023-10-25 10:26:14 +08:00
import type { MessageRecord, MessageListType } from '@/api/system/message';
2023-07-24 10:05:07 +08:00
import { ref, reactive, toRefs, computed } from 'vue';
2023-10-25 10:26:14 +08:00
import { queryMessageList, setMessageStatus } from '@/api/system/message';
2023-07-24 10:05:07 +08:00
import useLoading from '@/hooks/loading';
import List from './list.vue';
interface TabItem {
key: string;
title: string;
avatar?: string;
}
2023-08-03 14:21:27 +08:00
2023-07-24 10:05:07 +08:00
const { loading, setLoading } = useLoading(true);
const messageType = ref('message');
const messageData = reactive<{
renderList: MessageRecord[];
messageList: MessageRecord[];
}>({
renderList: [],
messageList: [],
});
toRefs(messageData);
const tabList: TabItem[] = [
{
key: 'message',
2023-09-25 22:05:48 +08:00
title: '消息',
2023-07-24 10:05:07 +08:00
},
{
key: 'notice',
2023-09-25 22:05:48 +08:00
title: '通知',
2023-07-24 10:05:07 +08:00
},
{
key: 'todo',
2023-09-25 22:05:48 +08:00
title: '待办',
2023-07-24 10:05:07 +08:00
},
];
2023-08-03 14:21:27 +08:00
2023-07-24 10:05:07 +08:00
async function fetchSourceData() {
setLoading(true);
try {
const { data } = await queryMessageList();
messageData.messageList = data;
} catch (err) {
// you can report use errorHandler or other
} finally {
setLoading(false);
}
}
2023-08-03 14:21:27 +08:00
2023-07-24 10:05:07 +08:00
async function readMessage(data: MessageListType) {
const ids = data.map((item) => item.id);
await setMessageStatus({ ids });
2023-09-24 23:28:02 +08:00
await fetchSourceData();
2023-07-24 10:05:07 +08:00
}
2023-08-03 14:21:27 +08:00
2023-07-24 10:05:07 +08:00
const renderList = computed(() => {
return messageData.messageList.filter(
(item) => messageType.value === item.type
);
});
const unreadCount = computed(() => {
return renderList.value.filter((item) => !item.status).length;
});
const getUnreadList = (type: string) => {
const list = messageData.messageList.filter(
(item) => item.type === type && !item.status
);
return list;
};
const formatUnreadLength = (type: string) => {
const list = getUnreadList(type);
2023-09-25 00:07:51 +08:00
return list.length ? `(${list.length})` : '';
2023-07-24 10:05:07 +08:00
};
const handleItemClick = (items: MessageListType) => {
if (renderList.value.length) readMessage([...items]);
};
const emptyList = () => {
messageData.messageList = [];
};
fetchSourceData();
</script>
2023-10-25 10:26:14 +08:00
<style lang="less" scoped>
2023-07-24 10:05:07 +08:00
:deep(.arco-popover-popup-content) {
padding: 0;
}
:deep(.arco-list-item-meta) {
align-items: flex-start;
}
2023-08-03 14:21:27 +08:00
2023-07-24 10:05:07 +08:00
:deep(.arco-tabs-nav) {
padding: 14px 0 12px 16px;
border-bottom: 1px solid var(--color-neutral-3);
}
2023-08-03 14:21:27 +08:00
2023-07-24 10:05:07 +08:00
:deep(.arco-tabs-content) {
padding-top: 0;
2023-08-03 14:21:27 +08:00
2023-07-24 10:05:07 +08:00
.arco-result-subtitle {
color: rgb(var(--gray-6));
}
}
</style>