auth-web/src/views/message-management/message-detail/utils/hooks.ts

73 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-11-02 17:03:59 +08:00
import { ref } from 'vue';
import { messageBox } from '@/utils/message';
import { $t } from '@/plugins/i18n';
import { useMessageUserStore } from '@/store/message/messageUser';
// 删除ids
export const selectids = ref([]);
const messageUserStore = useMessageUserStore();
/** 搜索初始化系统消息 */
export const onSearch = async (messageType?: string) => {
messageUserStore.loading = true;
if (messageType) {
messageUserStore.form.messageType = messageType;
}
await messageUserStore.getMessageList();
messageUserStore.loading = false;
};
/** 删除系统消息 */
export const onDelete = async () => {
const ids = selectids.value;
// 是否确认删除
const result = await messageBox({
title: $t('confirmDelete'),
showMessage: false,
confirmMessage: undefined,
cancelMessage: $t('cancel_delete'),
});
if (!result) return;
// 删除数据
await messageUserStore.deleteUserMessageByIds(ids);
await onSearch();
};
/** 标为已读 */
export const markAsRead = async () => {
const ids = selectids.value;
// 是否确认标为已读
const result = await messageBox({
title: $t('markAsRead'),
showMessage: false,
confirmMessage: undefined,
cancelMessage: $t('cancel'),
});
if (!result) return;
// 标为已读
await messageUserStore.updateUserMarkAsRead(ids);
await onSearch();
};
/** 全部标为已读 */
export const markAsAllRead = async () => {
2024-11-03 18:56:28 +08:00
const ids = messageUserStore.datalist.map(message => message.messageReceivedId);
2024-11-02 17:03:59 +08:00
// 是否确认标为已读
const result = await messageBox({
title: $t('allMarkAsRead'),
showMessage: false,
confirmMessage: undefined,
cancelMessage: $t('cancel'),
});
if (!result) return;
// 标为已读
await messageUserStore.updateUserMarkAsRead(ids);
await onSearch();
};