217 lines
9.8 KiB
JavaScript
217 lines
9.8 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("./common/vendor.js");
|
|
require("./TUIKit/adapter-vue.js");
|
|
const common_assets = require("./common/assets.js");
|
|
const TUIKit_utils_env = require("./TUIKit/utils/env.js");
|
|
if (!Math) {
|
|
(ActionsMenu + Avatar + Icon)();
|
|
}
|
|
const Icon = () => "./TUIKit/components/common/Icon.js";
|
|
const Avatar = () => "./TUIKit/components/common/Avatar/index.js";
|
|
const ActionsMenu = () => "./TUIKit/components/TUIConversation/actions-menu/index.js";
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
__name: "index",
|
|
emits: ["handleSwitchConversation", "getPassingRef"],
|
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
const emits = __emit;
|
|
const currentConversation = common_vendor.ref();
|
|
const currentConversationID = common_vendor.ref();
|
|
const currentConversationDomRect = common_vendor.ref();
|
|
const isShowOverlay = common_vendor.ref(false);
|
|
const conversationList = common_vendor.ref([]);
|
|
const conversationListDomRef = common_vendor.ref();
|
|
const conversationListInnerDomRef = common_vendor.ref();
|
|
const actionsMenuPosition = common_vendor.ref({
|
|
top: 0,
|
|
left: void 0,
|
|
conversationHeight: void 0
|
|
});
|
|
const displayOnlineStatus = common_vendor.ref(false);
|
|
const userOnlineStatusMap = common_vendor.ref();
|
|
let lastestOpenActionsMenuTime = null;
|
|
common_vendor.onMounted(() => {
|
|
common_vendor.Jt.watch(common_vendor.o.CONV, {
|
|
currentConversationID: onCurrentConversationIDUpdated,
|
|
conversationList: onConversationListUpdated,
|
|
currentConversation: onCurrentConversationUpdated
|
|
});
|
|
common_vendor.Jt.watch(common_vendor.o.USER, {
|
|
displayOnlineStatus: onDisplayOnlineStatusUpdated,
|
|
userStatusList: onUserStatusListUpdated
|
|
});
|
|
if (!TUIKit_utils_env.isUniFrameWork && common_vendor.f$1 && !TUIKit_utils_env.isPC) {
|
|
addLongPressHandler();
|
|
}
|
|
});
|
|
common_vendor.onUnmounted(() => {
|
|
common_vendor.Jt.unwatch(common_vendor.o.CONV, {
|
|
currentConversationID: onCurrentConversationIDUpdated,
|
|
conversationList: onConversationListUpdated,
|
|
currentConversation: onCurrentConversationUpdated
|
|
});
|
|
common_vendor.Jt.unwatch(common_vendor.o.USER, {
|
|
displayOnlineStatus: onDisplayOnlineStatusUpdated,
|
|
userStatusList: onUserStatusListUpdated
|
|
});
|
|
});
|
|
const isShowUserOnlineStatus = (conversation) => {
|
|
return displayOnlineStatus.value && conversation.type === common_vendor.qt.TYPES.CONV_C2C;
|
|
};
|
|
const showConversationActionMenu = (event, conversation, index, isContextMenuEvent) => {
|
|
if (isContextMenuEvent) {
|
|
event.preventDefault();
|
|
if (TUIKit_utils_env.isUniFrameWork) {
|
|
return;
|
|
}
|
|
}
|
|
currentConversation.value = conversation;
|
|
lastestOpenActionsMenuTime = Date.now();
|
|
getActionsMenuPosition(event, index);
|
|
};
|
|
const closeConversationActionMenu = () => {
|
|
if (lastestOpenActionsMenuTime && Date.now() - lastestOpenActionsMenuTime > 300) {
|
|
currentConversation.value = void 0;
|
|
isShowOverlay.value = false;
|
|
}
|
|
};
|
|
const getActionsMenuPosition = (event, index) => {
|
|
var _a, _b;
|
|
if (TUIKit_utils_env.isUniFrameWork) {
|
|
if (typeof conversationListDomRef.value === "undefined") {
|
|
emits("getPassingRef", conversationListDomRef);
|
|
}
|
|
const query = (_a = common_vendor.i) == null ? void 0 : _a.createSelectorQuery().in(conversationListDomRef.value);
|
|
query.select(`#convlistitem-${index}`).boundingClientRect((data) => {
|
|
if (data) {
|
|
actionsMenuPosition.value = {
|
|
// The uni-page-head of uni-h5 is not considered a member of the viewport, so the height of the head is manually increased.
|
|
top: data.bottom + (TUIKit_utils_env.isH5 ? 44 : 0),
|
|
// @ts-expect-error in uniapp event has touches property
|
|
left: event.touches[0].pageX,
|
|
conversationHeight: data.height
|
|
};
|
|
isShowOverlay.value = true;
|
|
}
|
|
}).exec();
|
|
} else {
|
|
const rect = ((_b = event.currentTarget || event.target) == null ? void 0 : _b.getBoundingClientRect()) || {};
|
|
if (rect) {
|
|
actionsMenuPosition.value = {
|
|
top: rect.bottom,
|
|
left: TUIKit_utils_env.isPC ? event.clientX : void 0,
|
|
conversationHeight: rect.height
|
|
};
|
|
}
|
|
isShowOverlay.value = true;
|
|
}
|
|
};
|
|
const enterConversationChat = (conversationID) => {
|
|
emits("handleSwitchConversation", conversationID);
|
|
common_vendor.Xt.switchConversation(conversationID);
|
|
};
|
|
function addLongPressHandler() {
|
|
if (!conversationListInnerDomRef.value) {
|
|
return;
|
|
}
|
|
common_vendor.k({
|
|
element: conversationListInnerDomRef.value,
|
|
onLongPress: (event, target) => {
|
|
const index = Array.from(conversationListInnerDomRef.value.children).indexOf(target);
|
|
showConversationActionMenu(event, conversationList.value[index], index);
|
|
},
|
|
options: {
|
|
eventDelegation: {
|
|
subSelector: ".tui-conversation-content"
|
|
}
|
|
}
|
|
});
|
|
}
|
|
function onCurrentConversationUpdated(conversation) {
|
|
currentConversation.value = conversation;
|
|
}
|
|
function onConversationListUpdated(list) {
|
|
conversationList.value = list;
|
|
}
|
|
function onCurrentConversationIDUpdated(id) {
|
|
currentConversationID.value = id;
|
|
}
|
|
function onDisplayOnlineStatusUpdated(status) {
|
|
displayOnlineStatus.value = status;
|
|
}
|
|
function onUserStatusListUpdated(list) {
|
|
if (list.size !== 0) {
|
|
userOnlineStatusMap.value = [...list.entries()].reduce(
|
|
(obj, [key, value]) => {
|
|
obj[key] = value;
|
|
return obj;
|
|
},
|
|
{}
|
|
);
|
|
}
|
|
}
|
|
__expose({ closeChildren: closeConversationActionMenu });
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: common_vendor.unref(isShowOverlay)
|
|
}, common_vendor.unref(isShowOverlay) ? {
|
|
b: common_vendor.o$1(closeConversationActionMenu),
|
|
c: common_vendor.p({
|
|
selectedConversation: common_vendor.unref(currentConversation),
|
|
actionsMenuPosition: common_vendor.unref(actionsMenuPosition),
|
|
selectedConversationDomRect: common_vendor.unref(currentConversationDomRect)
|
|
})
|
|
} : {}, {
|
|
d: common_vendor.f(common_vendor.unref(conversationList), (conversation, index, i0) => {
|
|
return common_vendor.e({
|
|
a: "4ef42c1d-1-" + i0,
|
|
b: common_vendor.p({
|
|
useSkeletonAnimation: true,
|
|
url: conversation.getAvatar(),
|
|
size: "30px"
|
|
}),
|
|
c: common_vendor.unref(userOnlineStatusMap) && isShowUserOnlineStatus(conversation)
|
|
}, common_vendor.unref(userOnlineStatusMap) && isShowUserOnlineStatus(conversation) ? {
|
|
d: common_vendor.n(Object.keys(common_vendor.unref(userOnlineStatusMap)).length > 0 && Object.keys(common_vendor.unref(userOnlineStatusMap)).includes(conversation.userProfile.userID) && common_vendor.unref(userOnlineStatusMap)[conversation.userProfile.userID].statusType === 1 ? "online-status-online" : "online-status-offline")
|
|
} : {}, {
|
|
e: conversation.unreadCount > 0 && !conversation.isMuted
|
|
}, conversation.unreadCount > 0 && !conversation.isMuted ? {
|
|
f: common_vendor.t(conversation.unreadCount > 99 ? "99+" : conversation.unreadCount)
|
|
} : {}, {
|
|
g: conversation.unreadCount > 0 && conversation.isMuted
|
|
}, conversation.unreadCount > 0 && conversation.isMuted ? {} : {}, {
|
|
h: common_vendor.t(conversation.getShowName()),
|
|
i: conversation.draftText && conversation.conversationID !== common_vendor.unref(currentConversationID)
|
|
}, conversation.draftText && conversation.conversationID !== common_vendor.unref(currentConversationID) ? {
|
|
j: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.[草稿]"))
|
|
} : conversation.type === "GROUP" && conversation.groupAtInfoList && conversation.groupAtInfoList.length > 0 ? {
|
|
l: common_vendor.t(conversation.getGroupAtInfo())
|
|
} : {}, {
|
|
k: conversation.type === "GROUP" && conversation.groupAtInfoList && conversation.groupAtInfoList.length > 0,
|
|
m: common_vendor.t(conversation.getLastMessage("text")),
|
|
n: common_vendor.t(conversation.getLastMessage("time")),
|
|
o: conversation.isMuted
|
|
}, conversation.isMuted ? {
|
|
p: "4ef42c1d-2-" + i0,
|
|
q: common_vendor.p({
|
|
file: common_vendor.unref(common_assets.muteIcon)
|
|
})
|
|
} : {}, {
|
|
r: common_vendor.n(common_vendor.unref(currentConversationID) === conversation.conversationID && "tui-conversation-item-selected"),
|
|
s: common_vendor.n(conversation.isPinned && "tui-conversation-item-pinned"),
|
|
t: common_vendor.o$1(($event) => enterConversationChat(conversation.conversationID), index),
|
|
v: common_vendor.o$1(($event) => showConversationActionMenu($event, conversation, index), index),
|
|
w: common_vendor.o$1(($event) => showConversationActionMenu($event, conversation, index, true), index),
|
|
x: `convlistitem-${index}`,
|
|
y: index
|
|
});
|
|
}),
|
|
e: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isPC) && "isPC"),
|
|
f: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isMobile) && "tui-conversation-content-h5 disable-select")
|
|
});
|
|
};
|
|
}
|
|
});
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4ef42c1d"]]);
|
|
exports.MiniProgramPage = MiniProgramPage;
|
|
//# sourceMappingURL=../.sourcemap/mp-weixin/index.js.map
|