193 lines
6.5 KiB
JavaScript
193 lines
6.5 KiB
JavaScript
"use strict";
|
|
var __async = (__this, __arguments, generator) => {
|
|
return new Promise((resolve, reject) => {
|
|
var fulfilled = (value) => {
|
|
try {
|
|
step(generator.next(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var rejected = (value) => {
|
|
try {
|
|
step(generator.throw(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
});
|
|
};
|
|
const common_vendor = require("../../../common/vendor.js");
|
|
const sheep_index = require("../../../sheep/index.js");
|
|
const modules_mall_chat_util_constants = require("./util/constants.js");
|
|
const sheep_api_infra_file = require("../../../sheep/api/infra/file.js");
|
|
const sheep_api_promotion_kefu = require("../../../sheep/api/promotion/kefu.js");
|
|
const sheep_hooks_useWebSocket = require("../../../sheep/hooks/useWebSocket.js");
|
|
if (!Array) {
|
|
const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
|
|
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
|
|
(_easycom_s_layout2 + _component_layout_default_uni)();
|
|
}
|
|
const _easycom_s_layout = () => "../../../sheep/components/s-layout/s-layout.js";
|
|
if (!Math) {
|
|
(MessageInput + MessageList + ToolsPopup + SelectPopup + _easycom_s_layout)();
|
|
}
|
|
const MessageList = () => "./components/messageList.js";
|
|
const ToolsPopup = () => "./components/toolsPopup.js";
|
|
const MessageInput = () => "./components/messageInput.js";
|
|
const SelectPopup = () => "./components/select-popup.js";
|
|
const _sfc_main = {
|
|
__name: "index",
|
|
setup(__props) {
|
|
const sys_navBar = sheep_index.sheep.$platform.navbar;
|
|
const chat = common_vendor.reactive({
|
|
msg: "",
|
|
scrollInto: "",
|
|
showTools: false,
|
|
toolsMode: "",
|
|
showSelect: false,
|
|
selectMode: ""
|
|
});
|
|
function onSendMessage() {
|
|
return __async(this, null, function* () {
|
|
if (!chat.msg)
|
|
return;
|
|
try {
|
|
const data = {
|
|
contentType: modules_mall_chat_util_constants.KeFuMessageContentTypeEnum.TEXT,
|
|
content: chat.msg
|
|
};
|
|
yield sheep_api_promotion_kefu.KeFuApi.sendKefuMessage(data);
|
|
yield messageListRef.value.refreshMessageList();
|
|
chat.msg = "";
|
|
} finally {
|
|
chat.showTools = false;
|
|
}
|
|
});
|
|
}
|
|
const messageListRef = common_vendor.ref();
|
|
function handleToolsClose() {
|
|
chat.showTools = false;
|
|
chat.toolsMode = "";
|
|
}
|
|
function onEmoji(item) {
|
|
chat.msg += item.name;
|
|
}
|
|
function onTools(mode) {
|
|
if (isReconnecting.value) {
|
|
sheep_index.sheep.$helper.toast("您已掉线!请返回重试");
|
|
return;
|
|
}
|
|
if (!chat.toolsMode || chat.toolsMode === mode) {
|
|
chat.showTools = !chat.showTools;
|
|
}
|
|
chat.toolsMode = mode;
|
|
if (!chat.showTools) {
|
|
chat.toolsMode = "";
|
|
}
|
|
}
|
|
function onShowSelect(mode) {
|
|
chat.showTools = false;
|
|
chat.showSelect = true;
|
|
chat.selectMode = mode;
|
|
}
|
|
function onSelect(_0) {
|
|
return __async(this, arguments, function* ({ type, data }) {
|
|
let msg;
|
|
switch (type) {
|
|
case "image":
|
|
const res = yield sheep_api_infra_file.FileApi.uploadFile(data.tempFiles[0].path);
|
|
msg = {
|
|
contentType: modules_mall_chat_util_constants.KeFuMessageContentTypeEnum.IMAGE,
|
|
content: res.data
|
|
};
|
|
break;
|
|
case "goods":
|
|
msg = {
|
|
contentType: modules_mall_chat_util_constants.KeFuMessageContentTypeEnum.PRODUCT,
|
|
content: JSON.stringify(data)
|
|
};
|
|
break;
|
|
case "order":
|
|
msg = {
|
|
contentType: modules_mall_chat_util_constants.KeFuMessageContentTypeEnum.ORDER,
|
|
content: JSON.stringify(data)
|
|
};
|
|
break;
|
|
}
|
|
if (msg) {
|
|
yield sheep_api_promotion_kefu.KeFuApi.sendKefuMessage(msg);
|
|
yield messageListRef.value.refreshMessageList();
|
|
chat.showTools = false;
|
|
chat.showSelect = false;
|
|
chat.selectMode = "";
|
|
}
|
|
});
|
|
}
|
|
const { options } = sheep_hooks_useWebSocket.useWebSocket({
|
|
// 连接成功
|
|
onConnected: () => __async(this, null, function* () {
|
|
}),
|
|
// 收到消息
|
|
onMessage: (data) => __async(this, null, function* () {
|
|
const type = data.type;
|
|
if (!type) {
|
|
console.error("未知的消息类型:" + data.value);
|
|
return;
|
|
}
|
|
if (type === modules_mall_chat_util_constants.WebSocketMessageTypeConstants.KEFU_MESSAGE_TYPE) {
|
|
yield messageListRef.value.refreshMessageList(JSON.parse(data.content));
|
|
return;
|
|
}
|
|
if (type === modules_mall_chat_util_constants.WebSocketMessageTypeConstants.KEFU_MESSAGE_ADMIN_READ) {
|
|
console.log("管理员已读消息");
|
|
}
|
|
})
|
|
});
|
|
const isReconnecting = common_vendor.toRefs(options).isReconnecting;
|
|
return (_ctx, _cache) => {
|
|
return {
|
|
a: common_vendor.unref(sys_navBar) + "px",
|
|
b: common_vendor.o(onTools),
|
|
c: common_vendor.o(onSendMessage),
|
|
d: common_vendor.o(($event) => chat.msg = $event),
|
|
e: common_vendor.p({
|
|
modelValue: chat.msg
|
|
}),
|
|
f: common_vendor.sr(messageListRef, "f587ab81-2,f587ab81-1", {
|
|
"k": "messageListRef"
|
|
}),
|
|
g: common_vendor.o(onTools),
|
|
h: common_vendor.o(onSendMessage),
|
|
i: common_vendor.o(($event) => chat.msg = $event),
|
|
j: common_vendor.p({
|
|
modelValue: chat.msg
|
|
}),
|
|
k: common_vendor.o(handleToolsClose),
|
|
l: common_vendor.o(onEmoji),
|
|
m: common_vendor.o(onSelect),
|
|
n: common_vendor.o(onShowSelect),
|
|
o: common_vendor.p({
|
|
["show-tools"]: chat.showTools,
|
|
["tools-mode"]: chat.toolsMode
|
|
}),
|
|
p: common_vendor.o(onSelect),
|
|
q: common_vendor.o(($event) => chat.showSelect = false),
|
|
r: common_vendor.p({
|
|
mode: chat.selectMode,
|
|
show: chat.showSelect
|
|
}),
|
|
s: common_vendor.p({
|
|
title: !common_vendor.unref(isReconnecting) ? "连接客服成功" : "会话重连中",
|
|
navbar: "inner"
|
|
})
|
|
};
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f587ab81"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=index.js.map
|