UNPKG

@tencentcloud/ai-desk-customer-wechat

Version:

AI Desk customer UIKit for wechat mini program

138 lines (137 loc) 6.09 kB
"use strict"; const common_vendor = require("../../../common/vendor.js"); const aiDeskCustomerUniapp_adapterVue = require("../../adapter-vue.js"); const aiDeskCustomerUniapp_utils_env = require("../../utils/env.js"); const aiDeskCustomerUniapp_utils_index = require("../../utils/index.js"); const aiDeskCustomerUniapp_utils_logger = require("../../utils/logger.js"); if (!Math) { (MessageList + MessageToolbarButton + MessageInputToolbar + MessageInput)(); } const MessageList = () => "./message-list/index-uniapp.js"; const MessageInput = () => "./message-input/index-uniapp.js"; const MessageInputToolbar = () => "./message-input-toolbar/index-uniapp.js"; const MessageToolbarButton = () => "./message-toolbar-button/index.js"; const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({ __name: "index-uniapp", props: { robotLang: { default: "" }, toolbarButtonList: { default: () => [] } }, emits: ["closeChat"], setup(__props, { emit: __emit }) { const { ref, onMounted, onUnmounted, computed } = aiDeskCustomerUniapp_adapterVue.vue; const currentConversationID = ref(); const inputToolbarDisplayType = ref("none"); const messageInputRef = ref(); const messageListRef = ref(); const isUniFormShow = ref(false); const props = __props; onMounted(() => { const logPrefix = "CustomerServiceChat onMounted."; aiDeskCustomerUniapp_utils_logger.Log.l(`${logPrefix} engineReady:${common_vendor.qt.isReady()} `); if (props.robotLang && !aiDeskCustomerUniapp_utils_index.isSupportedLang(props.robotLang)) { aiDeskCustomerUniapp_utils_logger.Log.w(`${logPrefix} robotLang:${props.robotLang} is not supported`); } common_vendor.Jt.watch(common_vendor.o$1.CONV, { currentConversationID: onCurrentConversationIDUpdate }); }); onUnmounted(() => { common_vendor.Jt.unwatch(common_vendor.o$1.CONV, { currentConversationID: onCurrentConversationIDUpdate }); }); const isInputToolbarShow = computed(() => { return aiDeskCustomerUniapp_utils_env.isUniFrameWork ? inputToolbarDisplayType.value !== "none" : true; }); const insertEmoji = (emojiObj) => { var _a; (_a = messageInputRef.value) == null ? void 0 : _a.insertEmoji(emojiObj); }; const handleEditor = (message, type) => { var _a, _b, _c; if (!message || !type) return; switch (type) { case "reference": break; case "reply": break; case "reedit": if ((_a = message == null ? void 0 : message.payload) == null ? void 0 : _a.text) { (_c = messageInputRef == null ? void 0 : messageInputRef.value) == null ? void 0 : _c.reEdit((_b = message == null ? void 0 : message.payload) == null ? void 0 : _b.text); } break; } }; function changeToolbarDisplayType(type) { inputToolbarDisplayType.value = inputToolbarDisplayType.value === type ? "none" : type; if (inputToolbarDisplayType.value !== "none" && aiDeskCustomerUniapp_utils_env.isUniFrameWork) { common_vendor.index.$emit("scroll-to-bottom"); } } function scrollToLatestMessage() { var _a; (_a = messageListRef.value) == null ? void 0 : _a.scrollToLatestMessage(); } function onCurrentConversationIDUpdate(conversationID) { if (!conversationID) { return; } if (currentConversationID.value === conversationID) { return; } currentConversationID.value = conversationID; common_vendor.R.callService({ serviceName: common_vendor.E.TUICustomerServicePlugin.SERVICE.NAME, method: common_vendor.E.TUICustomerServicePlugin.SERVICE.METHOD.ACTIVE_CONVERSATION, params: { conversationID, robotLang: props.robotLang && aiDeskCustomerUniapp_utils_index.isSupportedLang(props.robotLang) ? props.robotLang : void 0 } }); } function handleShowFormPopup(data) { isUniFormShow.value = data; } return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.unref(currentConversationID) }, common_vendor.unref(currentConversationID) ? common_vendor.e({ b: common_vendor.sr(messageListRef, "d41d01da-0", { "k": "messageListRef" }), c: common_vendor.o(handleEditor), d: common_vendor.o(() => changeToolbarDisplayType("none")), e: common_vendor.o(handleShowFormPopup), f: common_vendor.p({ toolbarButtonList: props.toolbarButtonList }), g: common_vendor.unref(isInputToolbarShow) }, common_vendor.unref(isInputToolbarShow) ? { h: common_vendor.n(common_vendor.unref(aiDeskCustomerUniapp_utils_env.isUniFrameWork) && "tui-chat-uni-message-input-toolbar"), i: common_vendor.o(insertEmoji), j: common_vendor.o(changeToolbarDisplayType), k: common_vendor.o(scrollToLatestMessage), l: common_vendor.p({ displayType: common_vendor.unref(inputToolbarDisplayType) }) } : {}, { m: common_vendor.sr(messageInputRef, "d41d01da-3", { "k": "messageInputRef" }), n: common_vendor.n(common_vendor.unref(aiDeskCustomerUniapp_utils_env.isUniFrameWork) && !common_vendor.unref(aiDeskCustomerUniapp_utils_env.isH5) && "tui-chat-uni-message-input"), o: common_vendor.n(common_vendor.unref(aiDeskCustomerUniapp_utils_env.isWeChat) && "tui-chat-wx-message-input"), p: common_vendor.n(common_vendor.unref(isUniFormShow) && "tui-chat-uni-message-input-hide"), q: common_vendor.o(changeToolbarDisplayType), r: common_vendor.p({ isMuted: false, muteText: common_vendor.unref(common_vendor.Wt).t("TUIChat.您已被管理员禁言"), inputToolbarDisplayType: common_vendor.unref(inputToolbarDisplayType) }) }) : {}); }; } }); const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-d41d01da"]]); wx.createComponent(Component);