-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathindex.vue
More file actions
127 lines (114 loc) · 3.89 KB
/
index.vue
File metadata and controls
127 lines (114 loc) · 3.89 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
<template>
<div>
<div class="secondary-notification">
<t-tabs v-model="tabValue">
<t-tab-panel v-for="(tab, tabIndex) in TAB_LIST" :key="tabIndex" :value="tab.value" :label="tab.label">
<t-list v-if="msgDataList.length > 0" class="secondary-msg-list" :split="true">
<t-list-item v-for="(item, index) in msgDataList" :key="index">
<p :class="['content', { unread: item.status }]" @click="setReadStatus(item)">
<t-tag size="medium" :theme="NOTIFICATION_TYPES.get(item.quality)" variant="light">
{{ item.type }}
</t-tag>
{{ item.content }}
</p>
<template #action>
<span class="msg-date">{{ item.date }}</span>
<div class="msg-action">
<t-tooltip
class="set-read-icon"
:overlay-style="{ margin: '6px' }"
:content="item.status ? t('pages.detailSecondary.setRead') : t('pages.detailSecondary.setUnread')"
>
<span class="msg-action-icon" @click="setReadStatus(item)">
<t-icon v-if="!!item.status" name="queue" size="16px" />
<t-icon v-else name="chat" />
</span>
</t-tooltip>
<t-tooltip :content="t('pages.detailSecondary.delete')" :overlay-style="{ margin: '6px' }">
<span @click="handleClickDeleteBtn(item)">
<t-icon name="delete" size="16px" />
</span>
</t-tooltip>
</div>
</template>
</t-list-item>
</t-list>
<div v-else class="secondary-msg-list__empty-list">
<empty-icon></empty-icon>
<p>{{ t('pages.detailSecondary.empty') }}</p>
</div>
</t-tab-panel>
</t-tabs>
</div>
<t-dialog
v-model:visible="visible"
header="删除通知"
:body="`确认删除通知:${selectedItem && selectedItem.content}吗?`"
:on-confirm="deleteMsg"
/>
</div>
</template>
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { computed, ref } from 'vue';
import EmptyIcon from '@/assets/assets-empty.svg?component';
import { NOTIFICATION_TYPES } from '@/constants';
import { t } from '@/locales';
import { useNotificationStore } from '@/store';
import type { NotificationItem } from '@/types/interface';
defineOptions({
name: 'DetailSecondary',
});
const TAB_LIST = [
{
label: t('pages.detailSecondary.all'),
value: 'msgData',
},
{
label: t('pages.detailSecondary.unread'),
value: 'unreadMsg',
},
{
label: t('pages.detailSecondary.read'),
value: 'readMsg',
},
];
const tabValue = ref('msgData');
const visible = ref(false);
const selectedItem = ref<NotificationItem>();
const store = useNotificationStore();
const { msgData, unreadMsg, readMsg } = storeToRefs(store);
const msgDataList = computed(() => {
if (tabValue.value === 'msgData') return msgData.value;
if (tabValue.value === 'unreadMsg') return unreadMsg.value;
if (tabValue.value === 'readMsg') return readMsg.value;
return [];
});
const handleClickDeleteBtn = (item: NotificationItem) => {
visible.value = true;
selectedItem.value = item;
};
const setReadStatus = (item: NotificationItem) => {
const changeMsg = msgData.value;
changeMsg.forEach((e: NotificationItem) => {
if (e.id === item.id) {
e.status = !e.status;
}
});
store.setMsgData(changeMsg);
};
const deleteMsg = () => {
const item = selectedItem.value;
const changeMsg = msgData.value;
changeMsg.forEach((e: NotificationItem, index: number) => {
if (e.id === item?.id) {
changeMsg.splice(index, 1);
}
});
visible.value = false;
store.setMsgData(changeMsg);
};
</script>
<style lang="less" scoped>
@import './index.less';
</style>