优化页面

This commit is contained in:
pengxiaolong
2025-06-11 22:16:44 +08:00
parent 3c2d7e5959
commit 931d867c09
806 changed files with 87462 additions and 331 deletions

View File

@@ -0,0 +1,446 @@
"use strict";
const common_vendor = require("../../../../common/vendor.js");
require("../../../adapter-vue.js");
const TUIKit_components_TUISearch_searchTypeList = require("../search-type-list.js");
const common_assets = require("../../../../common/assets.js");
const TUIKit_components_TUISearch_utils = require("../utils.js");
const TUIKit_utils_enableSampleTaskStatus = require("../../../utils/enableSampleTaskStatus.js");
const TUIKit_utils_env = require("../../../utils/env.js");
if (!Math) {
(SearchResultLoading + SearchResultDefault + SearchResultItem + Icon)();
}
const SearchResultItem = () => "./search-result-item/index.js";
const SearchResultDefault = () => "./search-result-default/index.js";
const SearchResultLoading = () => "./search-result-loading/index.js";
const Icon = () => "../../common/Icon.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "index",
props: {
searchType: {
type: String,
default: "global",
// "global" / "conversation"
validator(value) {
return ["global", "conversation"].includes(value);
}
}
},
setup(__props) {
var _a, _b;
const props = __props;
const keywordList = common_vendor.ref([]);
const messageTypeList = common_vendor.ref(
(_a = TUIKit_components_TUISearch_searchTypeList.searchMessageTypeDefault[props.searchType]) == null ? void 0 : _a.value
);
const timePosition = common_vendor.ref(0);
const timePeriod = common_vendor.ref(0);
const keywordListMatchType = common_vendor.ref("and");
const currentSearchTabKey = common_vendor.ref(
(_b = TUIKit_components_TUISearch_searchTypeList.searchMessageTypeDefault[props.searchType]) == null ? void 0 : _b.key
);
const searchResult = common_vendor.ref({});
const searchAllMessageList = common_vendor.ref([]);
const searchAllMessageTotalCount = common_vendor.ref(0);
const currentSearchConversationID = common_vendor.ref("");
const searchConversationResult = common_vendor.ref();
const searchConversationMessageList = common_vendor.ref([]);
const searchConversationMessageTotalCount = common_vendor.ref();
const searchConversationResultGroupByDate = common_vendor.ref([]);
const isResultDetailShow = common_vendor.ref(false);
const isLoading = common_vendor.ref(false);
const isSearchDetailLoading = common_vendor.ref(false);
const isSearchDefaultShow = common_vendor.computed(() => {
var _a2, _b2, _c;
if (isLoading.value) {
return false;
}
if (props.searchType === "global") {
if (!((_a2 = keywordList == null ? void 0 : keywordList.value) == null ? void 0 : _a2.length) || ((_b2 = Object == null ? void 0 : Object.keys(searchResult.value)) == null ? void 0 : _b2.length)) {
return false;
} else {
return true;
}
} else {
if ((_c = searchConversationMessageList == null ? void 0 : searchConversationMessageList.value) == null ? void 0 : _c.length) {
return false;
} else {
return true;
}
}
});
function onCurrentConversationIDUpdate(id) {
props.searchType === "conversation" && (currentSearchConversationID.value = id);
}
function onCurrentSearchInputValueUpdate(obj) {
if ((obj == null ? void 0 : obj.searchType) === (props == null ? void 0 : props.searchType)) {
keywordList.value = (obj == null ? void 0 : obj.value) ? obj.value.trim().split(/\s+/) : [];
}
}
function onCurrentSearchMessageTypeUpdate(typeObject) {
var _a2, _b2, _c, _d;
if ((typeObject == null ? void 0 : typeObject.searchType) === (props == null ? void 0 : props.searchType)) {
currentSearchTabKey.value = ((_a2 = typeObject == null ? void 0 : typeObject.value) == null ? void 0 : _a2.key) || ((_b2 = TUIKit_components_TUISearch_searchTypeList.searchMessageTypeDefault[props.searchType]) == null ? void 0 : _b2.key);
messageTypeList.value = ((_c = typeObject == null ? void 0 : typeObject.value) == null ? void 0 : _c.value) || ((_d = TUIKit_components_TUISearch_searchTypeList.searchMessageTypeDefault[props.searchType]) == null ? void 0 : _d.value);
}
}
function onCurrentSearchMessageTimeUpdate(timeObject) {
var _a2, _b2, _c, _d;
if ((timeObject == null ? void 0 : timeObject.searchType) === (props == null ? void 0 : props.searchType)) {
timePosition.value = (_b2 = (_a2 = timeObject == null ? void 0 : timeObject.value) == null ? void 0 : _a2.value) == null ? void 0 : _b2.timePosition;
timePeriod.value = (_d = (_c = timeObject == null ? void 0 : timeObject.value) == null ? void 0 : _c.value) == null ? void 0 : _d.timePeriod;
}
}
common_vendor.onMounted(() => {
common_vendor.Jt.watch(common_vendor.o.CONV, {
currentConversationID: onCurrentConversationIDUpdate
});
common_vendor.Jt.watch(common_vendor.o.SEARCH, {
currentSearchInputValue: onCurrentSearchInputValueUpdate,
currentSearchMessageType: onCurrentSearchMessageTypeUpdate,
currentSearchMessageTime: onCurrentSearchMessageTimeUpdate
});
});
common_vendor.onUnmounted(() => {
common_vendor.Jt.unwatch(common_vendor.o.CONV, {
currentConversationID: onCurrentConversationIDUpdate
});
common_vendor.Jt.unwatch(common_vendor.o.SEARCH, {
currentSearchInputValue: onCurrentSearchInputValueUpdate,
currentSearchMessageType: onCurrentSearchMessageTypeUpdate,
currentSearchMessageTime: onCurrentSearchMessageTimeUpdate
});
});
const setMessageSearchResultList = (option) => {
var _a2;
TUIKit_components_TUISearch_utils.searchCloudMessages(
{
keywordList: ((_a2 = keywordList == null ? void 0 : keywordList.value) == null ? void 0 : _a2.length) ? keywordList.value : void 0,
messageTypeList: typeof messageTypeList.value === "string" ? [messageTypeList.value] : messageTypeList.value,
timePosition: timePosition.value,
timePeriod: timePeriod.value,
conversationID: (option == null ? void 0 : option.conversationID) || void 0,
cursor: (option == null ? void 0 : option.cursor) || void 0,
keywordListMatchType: keywordListMatchType.value
}
).then((res) => {
var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
TUIKit_utils_enableSampleTaskStatus.enableSampleTaskStatus("searchCloudMessage");
if (!(option == null ? void 0 : option.conversationID)) {
(option == null ? void 0 : option.cursor) ? searchAllMessageList.value = [
...searchAllMessageList.value,
...res.data.searchResultList
] : searchAllMessageList.value = (_a3 = res == null ? void 0 : res.data) == null ? void 0 : _a3.searchResultList;
searchAllMessageTotalCount.value = (_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.totalCount;
const key = currentSearchTabKey.value === "all" ? "allMessage" : currentSearchTabKey.value;
if (((_c = searchAllMessageList == null ? void 0 : searchAllMessageList.value) == null ? void 0 : _c.length) && currentSearchTabKey.value !== "contact" && currentSearchTabKey.value !== "group") {
searchResult.value = Object.assign({}, searchResult.value, {
[key]: {
key,
label: TUIKit_components_TUISearch_searchTypeList.searchMessageTypeList[key].label,
list: currentSearchTabKey.value === "all" ? (_d = searchAllMessageList == null ? void 0 : searchAllMessageList.value) == null ? void 0 : _d.slice(0, 3) : searchAllMessageList == null ? void 0 : searchAllMessageList.value,
cursor: ((_e = res == null ? void 0 : res.data) == null ? void 0 : _e.cursor) || null
}
});
} else {
searchResult == null ? true : delete searchResult.value[key];
}
} else {
searchConversationResult.value = res == null ? void 0 : res.data;
(option == null ? void 0 : option.cursor) ? searchConversationMessageList.value = [
...searchConversationMessageList.value,
...(_g = (_f = res == null ? void 0 : res.data) == null ? void 0 : _f.searchResultList[0]) == null ? void 0 : _g.messageList
] : searchConversationMessageList.value = (_i = (_h = res == null ? void 0 : res.data) == null ? void 0 : _h.searchResultList[0]) == null ? void 0 : _i.messageList;
searchConversationMessageTotalCount.value = (_j = res == null ? void 0 : res.data) == null ? void 0 : _j.totalCount;
if ((props == null ? void 0 : props.searchType) === "conversation" && (currentSearchTabKey.value === "fileMessage" || currentSearchTabKey.value === "imageMessage")) {
searchConversationResultGroupByDate.value = groupResultListByDate(
searchConversationMessageList.value
);
} else {
searchConversationResultGroupByDate.value = [];
}
}
isLoading.value = false;
isSearchDetailLoading.value = false;
});
};
const setMessageSearchResultListDebounce = TUIKit_components_TUISearch_utils.debounce(setMessageSearchResultList, 500);
const resetSearchResult = () => {
searchResult.value = {};
searchConversationResult.value = {};
searchConversationMessageList.value = [];
searchConversationResultGroupByDate.value = [];
};
common_vendor.watch(
() => [keywordList.value, currentSearchTabKey.value, timePosition.value, timePeriod.value],
(newValue, oldValue) => {
var _a2, _b2, _c;
if (newValue === oldValue) {
return;
}
if (!((_a2 = keywordList == null ? void 0 : keywordList.value) == null ? void 0 : _a2.length) && (props == null ? void 0 : props.searchType) === "global") {
resetSearchResult();
return;
}
isLoading.value = true;
if (props.searchType === "conversation") {
resetSearchResult();
setMessageSearchResultList({
conversationID: currentSearchConversationID.value
});
} else {
if (oldValue && oldValue[1] === "all" && newValue && newValue[1] === "allMessage") {
((_b2 = searchResult == null ? void 0 : searchResult.value["allMessage"]) == null ? void 0 : _b2.list) && (searchResult.value["allMessage"].list = searchAllMessageList == null ? void 0 : searchAllMessageList.value);
(_c = Object == null ? void 0 : Object.keys(searchResult == null ? void 0 : searchResult.value)) == null ? void 0 : _c.forEach((key) => {
if (key !== "allMessage") {
searchResult == null ? true : delete searchResult.value[key];
}
});
isLoading.value = false;
return;
} else {
isResultDetailShow.value = false;
resetSearchResult();
}
setMessageSearchResultListDebounce();
}
},
{ immediate: true }
);
const getMoreResult = (result) => {
if (currentSearchTabKey.value === "all") {
common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchMessageType", {
value: TUIKit_components_TUISearch_searchTypeList.searchMessageTypeList[result.key],
searchType: props.searchType
});
} else {
setMessageSearchResultList({ cursor: (result == null ? void 0 : result.cursor) || void 0 });
}
};
const getMoreResultInConversation = () => {
var _a2;
setMessageSearchResultList({
cursor: (_a2 = searchConversationResult == null ? void 0 : searchConversationResult.value) == null ? void 0 : _a2.cursor,
conversationID: currentSearchConversationID == null ? void 0 : currentSearchConversationID.value
});
};
const showResultDetail = (isShow, targetType, targetResult) => {
var _a2;
isResultDetailShow.value = isShow;
if (targetType) {
common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchMessageType", {
value: TUIKit_components_TUISearch_searchTypeList.searchMessageTypeList[targetType],
searchType: props.searchType
});
}
currentSearchConversationID.value = ((_a2 = targetResult == null ? void 0 : targetResult.conversation) == null ? void 0 : _a2.conversationID) || "";
searchConversationMessageTotalCount.value = targetResult == null ? void 0 : targetResult.messageCount;
if (targetResult) {
isSearchDetailLoading.value = true;
setMessageSearchResultListDebounce({
conversationID: currentSearchConversationID.value
});
}
};
const generateListItemClass = (item) => {
var _a2;
return currentSearchConversationID.value === ((_a2 = item == null ? void 0 : item.conversation) == null ? void 0 : _a2.conversationID) ? ["list-item", "list-item-selected"] : ["list-item"];
};
const generateResultItemDisplayType = () => {
if (props.searchType === "conversation" && currentSearchTabKey.value === "fileMessage") {
return "file";
} else if (props.searchType === "conversation" && currentSearchTabKey.value === "imageMessage") {
return "image";
} else if (TUIKit_utils_env.isPC) {
return "bubble";
} else {
return "info";
}
};
const groupResultListByDate = (messageList) => {
var _a2, _b2, _c, _d;
const result = [];
if (!(messageList == null ? void 0 : messageList.length)) {
return result;
} else if ((messageList == null ? void 0 : messageList.length) === 1) {
result.push({ date: TUIKit_components_TUISearch_utils.generateSearchResultYMD((_a2 = messageList[0]) == null ? void 0 : _a2.time), list: messageList });
return result;
}
let prevYMD = "";
let currYMD = "";
for (let i = 0; i < (messageList == null ? void 0 : messageList.length); i++) {
currYMD = TUIKit_components_TUISearch_utils.generateSearchResultYMD((_b2 = messageList[i]) == null ? void 0 : _b2.time);
if (prevYMD !== currYMD) {
result.push({ date: currYMD, list: [messageList[i]] });
} else {
(_d = (_c = result[(result == null ? void 0 : result.length) - 1]) == null ? void 0 : _c.list) == null ? void 0 : _d.push(messageList[i]);
}
prevYMD = currYMD;
}
return result;
};
const navigateToChatPosition = (message) => {
var _a2;
if (props.searchType === "global") {
common_vendor.Jt.update(common_vendor.o.SEARCH, "currentSearchingStatus", {
isSearching: false,
searchType: props.searchType
});
common_vendor.Xt.switchConversation(message == null ? void 0 : message.conversationID).then(() => {
var _a3;
common_vendor.Jt.update(common_vendor.o.CHAT, "messageSource", message);
TUIKit_utils_env.isUniFrameWork && ((_a3 = common_vendor.i) == null ? void 0 : _a3.navigateTo({
url: "/TUIKit/components/TUIChat/index"
}));
});
} else if (props.searchType === "conversation") {
common_vendor.Jt.update(common_vendor.o.SEARCH, "isShowInConversationSearch", false);
common_vendor.Jt.update(common_vendor.o.CHAT, "messageSource", message);
TUIKit_utils_env.isUniFrameWork && ((_a2 = common_vendor.i) == null ? void 0 : _a2.navigateBack());
}
};
const generateVueRenderKey = (value) => {
return `${currentSearchTabKey}-${value}`;
};
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(isLoading)
}, common_vendor.unref(isLoading) ? {
b: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "search-result-loading-h5")
} : common_vendor.unref(isSearchDefaultShow) ? {
d: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "search-result-default-h5")
} : common_vendor.e({
e: props.searchType !== "conversation" && (common_vendor.unref(TUIKit_utils_env.isPC) || !common_vendor.unref(isResultDetailShow))
}, props.searchType !== "conversation" && (common_vendor.unref(TUIKit_utils_env.isPC) || !common_vendor.unref(isResultDetailShow)) ? {
f: common_vendor.f(common_vendor.unref(searchResult), (result, k0, i0) => {
return common_vendor.e(props.searchType === "global" ? {
a: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(`TUISearch.${result.label}`))
} : {}, {
b: common_vendor.f(result.list, (item, k1, i1) => {
return common_vendor.e({
a: result.key === "contact" || result.key === "group" || item.conversation
}, result.key === "contact" || result.key === "group" || item.conversation ? {
b: common_vendor.o$1(showResultDetail, item.conversation.conversationID),
c: common_vendor.o$1(navigateToChatPosition, item.conversation.conversationID),
d: "90555b56-2-" + i0 + "-" + i1,
e: common_vendor.p({
listItem: item,
type: result.key,
displayType: "info",
keywordList: common_vendor.unref(keywordList)
})
} : {}, {
f: item.conversation.conversationID,
g: common_vendor.n(generateListItemClass(item))
});
}),
c: common_vendor.unref(currentSearchTabKey) === "all" || result.cursor
}, common_vendor.unref(currentSearchTabKey) === "all" || result.cursor ? {
d: "90555b56-3-" + i0,
e: common_vendor.p({
file: common_vendor.unref(common_assets.searchIcon),
width: "12px",
height: "12px"
}),
f: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUISearch.查看更多")),
g: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(`TUISearch.${result.label}`)),
h: common_vendor.o$1(($event) => getMoreResult(result), result.key)
} : {}, {
i: result.key
});
}),
g: props.searchType === "global"
} : {}, {
h: common_vendor.unref(isResultDetailShow) || props.searchType === "conversation"
}, common_vendor.unref(isResultDetailShow) || props.searchType === "conversation" ? common_vendor.e({
i: common_vendor.unref(isSearchDetailLoading)
}, common_vendor.unref(isSearchDetailLoading) ? {
j: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "search-result-loading-h5")
} : {}, {
k: !common_vendor.unref(isSearchDetailLoading) && common_vendor.unref(isResultDetailShow) && props.searchType !== "conversation"
}, !common_vendor.unref(isSearchDetailLoading) && common_vendor.unref(isResultDetailShow) && props.searchType !== "conversation" ? {
l: common_vendor.t(common_vendor.unref(searchConversationMessageTotalCount)),
m: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUISearch.条与")),
n: common_vendor.f(common_vendor.unref(keywordList), (keyword, index, i0) => {
return {
a: common_vendor.t(keyword),
b: index
};
}),
o: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUISearch.相关的")),
p: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(`TUISearch.${common_vendor.unref(currentSearchTabKey) === "allMessage" ? "结果" : common_vendor.unref(TUIKit_components_TUISearch_searchTypeList.searchMessageTypeList)[common_vendor.unref(currentSearchTabKey)].label}`)),
q: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUISearch.进入聊天")),
r: common_vendor.p({
file: common_vendor.unref(common_assets.rightIcon),
width: "14px",
height: "14px"
}),
s: common_vendor.o$1(($event) => common_vendor.unref(TUIKit_components_TUISearch_utils.enterConversation)({
conversationID: common_vendor.unref(currentSearchConversationID)
}))
} : {}, {
t: !common_vendor.unref(isSearchDetailLoading) && common_vendor.unref(searchConversationMessageList) && common_vendor.unref(searchConversationMessageList)[0]
}, !common_vendor.unref(isSearchDetailLoading) && common_vendor.unref(searchConversationMessageList) && common_vendor.unref(searchConversationMessageList)[0] ? common_vendor.e({
v: props.searchType === "global" || common_vendor.unref(currentSearchTabKey) !== "imageMessage" && common_vendor.unref(currentSearchTabKey) !== "fileMessage"
}, props.searchType === "global" || common_vendor.unref(currentSearchTabKey) !== "imageMessage" && common_vendor.unref(currentSearchTabKey) !== "fileMessage" ? {
w: common_vendor.f(common_vendor.unref(searchConversationMessageList), (item, k0, i0) => {
return {
a: common_vendor.o$1(showResultDetail, generateVueRenderKey(item.ID)),
b: common_vendor.o$1(navigateToChatPosition, generateVueRenderKey(item.ID)),
c: "90555b56-6-" + i0,
d: common_vendor.p({
listItem: item,
listItemContent: item.getMessageContent(),
type: common_vendor.unref(currentSearchTabKey),
displayType: generateResultItemDisplayType(),
keywordList: common_vendor.unref(keywordList)
}),
e: generateVueRenderKey(item.ID)
};
})
} : {
x: common_vendor.f(common_vendor.unref(searchConversationResultGroupByDate), (group, k0, i0) => {
return {
a: common_vendor.t(group.date),
b: common_vendor.f(group.list, (item, k1, i1) => {
return {
a: common_vendor.o$1(showResultDetail, generateVueRenderKey(item.ID)),
b: common_vendor.o$1(navigateToChatPosition, generateVueRenderKey(item.ID)),
c: "90555b56-7-" + i0 + "-" + i1,
d: common_vendor.p({
listItem: item,
listItemContent: item.getMessageContent(),
type: common_vendor.unref(currentSearchTabKey),
displayType: generateResultItemDisplayType(),
keywordList: common_vendor.unref(keywordList)
}),
e: generateVueRenderKey(item.ID)
};
}),
c: generateVueRenderKey(group.date)
};
}),
y: common_vendor.n(common_vendor.unref(currentSearchTabKey) === "fileMessage" ? "list-group-file" : "list-group-image")
}, {
z: common_vendor.unref(searchConversationResult) && common_vendor.unref(searchConversationResult).cursor
}, common_vendor.unref(searchConversationResult) && common_vendor.unref(searchConversationResult).cursor ? {
A: common_vendor.p({
file: common_vendor.unref(common_assets.searchIcon),
width: "12px",
height: "12px"
}),
B: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUISearch.查看更多历史记录")),
C: common_vendor.o$1(getMoreResultInConversation)
} : {}) : {}, {
D: common_vendor.n(props.searchType === "conversation" && "tui-search-result-in-conversation")
}) : {}, {
E: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-search-result-h5"),
F: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isPC) && common_vendor.unref(isResultDetailShow) && "tui-search-result-with-border")
}), {
c: common_vendor.unref(isSearchDefaultShow)
});
};
}
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-90555b56"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUISearch/search-result/index.js.map