acdr-ui/dist/dev/mp-weixin/store/message.js

50 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
const common_vendor = require("../common/vendor.js");
const initState = {
unreadMessages: [],
// 未读消息列表
readMessages: []
// 已读消息列表
};
const useMessageStore = common_vendor.defineStore("message", () => {
const messages = common_vendor.ref(__spreadValues({}, initState));
const setUnreadMessages = (newMessages) => {
messages.value.unreadMessages = newMessages;
};
const markMessageAsRead = (messageId) => {
const index = messages.value.unreadMessages.findIndex((msg) => msg.id === messageId);
if (index !== -1) {
const readMessage = messages.value.unreadMessages.splice(index, 1)[0];
messages.value.readMessages.push(readMessage);
}
};
const unreadCount = common_vendor.computed(() => messages.value.unreadMessages.length);
const clearMessages = () => {
messages.value = __spreadValues({}, initState);
};
return {
messages,
setUnreadMessages,
markMessageAsRead,
unreadCount,
clearMessages
};
});
exports.useMessageStore = useMessageStore;