"use strict"; const common_vendor = require("../../common/vendor.js"); const config_host = require("../../config/host.js"); const utils_functions = require("../../utils/functions.js"); const api_chat = require("../../api/chat.js"); const utils_log = require("../../utils/log.js"); require("../../utils/qqmap-wx-jssdk.min.js"); require("../../api/other.js"); require("../../utils/request.js"); const HeaderNav = () => "../../components/HeaderNav/Index.js"; const MzButton = () => "../../components/MzButton/Index.js"; const _sfc_main = { components: { HeaderNav, MzButton }, data: { windowHeihgt: 1e3, staticImage: { wallpaperBgImage: config_host.imghost + "/static/image/background.png" }, user: { avatar: config_host.imghost + "/static/image/banner.png", nickname: "清晨的风", background: config_host.imghost + "/static/image/banner.png", sex: "女", phone: "15012345678", coupons: 221, id: 88685, birthday: "2002-05-11" }, ableChat: false, message: "", chat_id: 0, type: 0, user_id: 0, messageList: [] }, onLoad(options) { this.getToken(options.id); }, methods: { getToken(order_id) { api_chat.getToken(order_id, this.$store.state.userInfo.store_id ? 2 : 1).then((data) => { this.chat_id = data.data.chat_id; this.type = data.data.type; this.user_id = data.data.user_id; common_vendor.index.connectSocket({ url: data.data.chat_url }); common_vendor.index.onSocketOpen((res) => { this.ableChat = true; console.log("WebSocket连接已打开!"); }); common_vendor.index.onSocketClose((res) => { this.ableChat = false; console.log("WebSocket 已关闭!"); }); common_vendor.index.onSocketMessage((res) => { this.newMessage(res); }); }); }, newMessage(messages) { utils_log.log(messages); messages = JSON.parse(messages.data); utils_log.log(messages); if (messages.do_type === "init") { this.messageList = messages.data; return; } this.messageList.push(messages); utils_log.log(this.messageList); }, sendMessage() { if (!this.message) { return common_vendor.index.showToast({ title: "消息不能为空", icon: "error" }); } common_vendor.index.showLoading({ title: "消息发送中...", mask: true }); if (!this.ableChat) { setInterval((t) => { if (!this.ableChat) { return; } clearInterval(t); common_vendor.index.sendSocketMessage({ data: this.message }); common_vendor.index.hideLoading(); }, 50); } else { common_vendor.index.sendSocketMessage({ data: JSON.stringify({ do_type: "add", info: this.message, msg_type: 1, send_user_id: this.user_id, type: this.type, chat_id: this.chat_id }) }); common_vendor.index.hideLoading(); this.message = ""; } } }, onPageScroll(res) { }, onUnload() { try { common_vendor.index.closeSocket(); } catch { } }, created() { this.windowHeihgt = utils_functions.api.navHeight().windowHeihgt; } }; if (!Array) { const _component_HeaderNav = common_vendor.resolveComponent("HeaderNav"); const _component_MzButton = common_vendor.resolveComponent("MzButton"); (_component_HeaderNav + _component_MzButton)(); } function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: common_vendor.p({ title: "2023.5.3订单", ["is-back"]: true }), b: "url(" + _ctx.staticImage.wallpaperBgImage + ")", c: common_vendor.f(_ctx.messageList, (item, index, i0) => { return common_vendor.e({ a: item.send_user_id !== _ctx.user_id }, item.send_user_id !== _ctx.user_id ? { b: item.avatar ? item.avatar : _ctx.user.avatar } : {}, { c: common_vendor.t(item.create_time), d: common_vendor.t(item.info), e: item.send_user_id === _ctx.user_id }, item.send_user_id === _ctx.user_id ? { f: item.avatar ? item.avatar : _ctx.user.avatar } : {}, { g: common_vendor.n(item.send_user_id === _ctx.user_id ? "chat-item my-chat row" : "chat-item other-chat row") }); }), d: _ctx.message, e: common_vendor.o(($event) => _ctx.message = $event.detail.value), f: common_vendor.o($options.sendMessage), g: common_vendor.p({ title: "发送", ["font-color"]: "#fff", ["button-color"]: "#4DC3B8", ["button-width"]: "auto" }), h: _ctx.windowHeihgt - 40 + "px" }; } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "E:/Project/pet_uni/pages/ChatDetail/index.vue"]]); _sfc_main.__runtimeHooks = 1; wx.createPage(MiniProgramPage);