index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const pages_chat_emoji = require("./emoji.js");
  5. const pages_chat_socket = require("./socket.js");
  6. require("../../sheep/url/index.js");
  7. require("../../sheep/store/index.js");
  8. require("../../sheep/store/app.js");
  9. require("../../sheep/api/promotion/diy.js");
  10. require("../../sheep/request/index.js");
  11. require("../../sheep/config/index.js");
  12. require("../../sheep/platform/index.js");
  13. require("../../sheep/platform/provider/wechat/index.js");
  14. require("../../sheep/platform/provider/wechat/miniProgram.js");
  15. require("../../sheep/api/member/auth.js");
  16. require("../../sheep/api/member/social.js");
  17. require("../../sheep/api/member/user.js");
  18. require("../../sheep/platform/provider/apple/index.js");
  19. require("../../sheep/platform/share.js");
  20. require("../../sheep/router/index.js");
  21. require("../../sheep/hooks/useModal.js");
  22. require("../../sheep/helper/index.js");
  23. require("../../sheep/helper/test.js");
  24. require("../../sheep/helper/digit.js");
  25. require("../../sheep/api/member/signin.js");
  26. require("../../sheep/helper/throttle.js");
  27. require("../../sheep/platform/pay.js");
  28. require("../../sheep/api/pay/order.js");
  29. require("../../sheep/store/user.js");
  30. require("../../sheep/store/cart.js");
  31. require("../../sheep/api/trade/cart.js");
  32. require("../../sheep/api/pay/wallet.js");
  33. require("../../sheep/api/trade/order.js");
  34. require("../../sheep/api/promotion/coupon.js");
  35. require("../../sheep/store/sys.js");
  36. require("../../sheep/store/modal.js");
  37. require("../../sheep/config/zIndex.js");
  38. if (!Array) {
  39. const _easycom_su_image2 = common_vendor.resolveComponent("su-image");
  40. const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  41. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  42. const _easycom_s_uploader2 = common_vendor.resolveComponent("s-uploader");
  43. const _easycom_su_popup2 = common_vendor.resolveComponent("su-popup");
  44. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  45. (_easycom_su_image2 + _easycom_uni_easyinput2 + _easycom_su_fixed2 + _easycom_s_uploader2 + _easycom_su_popup2 + _easycom_s_layout2)();
  46. }
  47. const _easycom_su_image = () => "../../sheep/ui/su-image/su-image.js";
  48. const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
  49. const _easycom_su_fixed = () => "../../sheep/ui/su-fixed/su-fixed.js";
  50. const _easycom_s_uploader = () => "../../sheep/components/s-uploader/s-uploader.js";
  51. const _easycom_su_popup = () => "../../sheep/ui/su-popup/su-popup.js";
  52. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  53. if (!Math) {
  54. (_easycom_su_image + GoodsItem + OrderItem + _easycom_uni_easyinput + _easycom_su_fixed + _easycom_s_uploader + _easycom_su_popup + SelectPopup + _easycom_s_layout)();
  55. }
  56. const SelectPopup = () => "./components/select-popup.js";
  57. const GoodsItem = () => "./components/goods.js";
  58. const OrderItem = () => "./components/order.js";
  59. const _sfc_main = {
  60. __name: "index",
  61. setup(__props) {
  62. const {
  63. socketInit,
  64. state: chatData,
  65. socketSendMsg,
  66. formatChatInput,
  67. socketHistoryList,
  68. onDrop,
  69. onPaste,
  70. getFocus,
  71. // upload,
  72. getUserToken,
  73. // socketTest,
  74. showTime,
  75. formatTime
  76. } = pages_chat_socket.useChatWebSocket();
  77. const chatList = common_vendor.toRefs(chatData).chatList;
  78. const customerServiceInfo = common_vendor.toRefs(chatData).customerServerInfo;
  79. const chatHistoryPagination = common_vendor.toRefs(chatData).chatHistoryPagination;
  80. const customerUserInfo = common_vendor.toRefs(chatData).customerUserInfo;
  81. const socketState = common_vendor.toRefs(chatData).socketState;
  82. const sys_navBar = sheep_index.sheep.$platform.navbar;
  83. const chatConfig = common_vendor.computed(() => sheep_index.sheep.$store("app").chat);
  84. const { screenHeight, safeAreaInsets, safeArea, screenWidth } = sheep_index.sheep.$platform.device;
  85. const pageHeight = safeArea.height - 44 - 35 - 50;
  86. const loadingMap = {
  87. loadmore: {
  88. title: "查看更多",
  89. icon: "el-icon-d-arrow-left"
  90. },
  91. nomore: {
  92. title: "没有更多了",
  93. icon: ""
  94. },
  95. loading: {
  96. title: "加载中... ",
  97. icon: "el-icon-loading"
  98. }
  99. };
  100. const onLoadMore = () => {
  101. chatHistoryPagination.value.page < chatHistoryPagination.value.lastPage && socketHistoryList();
  102. };
  103. const chat = common_vendor.reactive({
  104. msg: "",
  105. scrollInto: "",
  106. showTools: false,
  107. toolsMode: "",
  108. showSelect: false,
  109. selectMode: "",
  110. chatStyle: {
  111. mode: "inner",
  112. color: "#F8270F",
  113. type: "color",
  114. alwaysShow: 1,
  115. src: "",
  116. list: {}
  117. }
  118. });
  119. function onTools(mode) {
  120. if (!socketState.value.isConnect) {
  121. sheep_index.sheep.$helper.toast(socketState.value.tip || "您已掉线!请返回重试");
  122. return;
  123. }
  124. if (!chat.toolsMode || chat.toolsMode === mode) {
  125. chat.showTools = !chat.showTools;
  126. }
  127. chat.toolsMode = mode;
  128. if (!chat.showTools) {
  129. chat.toolsMode = "";
  130. }
  131. }
  132. function onShowSelect(mode) {
  133. chat.showTools = false;
  134. chat.showSelect = true;
  135. chat.selectMode = mode;
  136. }
  137. async function onSelect({ type, data }) {
  138. let msg = "";
  139. switch (type) {
  140. case "image":
  141. const { path, fullurl } = await sheep_index.sheep.$api.app.upload(data.tempFiles[0].path, "default");
  142. msg = {
  143. from: "customer",
  144. mode: "image",
  145. date: (/* @__PURE__ */ new Date()).getTime(),
  146. content: {
  147. url: fullurl,
  148. path
  149. }
  150. };
  151. break;
  152. case "goods":
  153. msg = {
  154. from: "customer",
  155. mode: "goods",
  156. date: (/* @__PURE__ */ new Date()).getTime(),
  157. content: {
  158. item: {
  159. id: data.goods.id,
  160. title: data.goods.title,
  161. image: data.goods.image,
  162. price: data.goods.price,
  163. stock: data.goods.stock
  164. }
  165. }
  166. };
  167. break;
  168. case "order":
  169. msg = {
  170. from: "customer",
  171. mode: "order",
  172. date: (/* @__PURE__ */ new Date()).getTime(),
  173. content: {
  174. item: {
  175. id: data.id,
  176. order_sn: data.order_sn,
  177. create_time: data.create_time,
  178. pay_fee: data.pay_fee,
  179. items: data.items.filter((item) => ({
  180. goods_id: item.goods_id,
  181. goods_title: item.goods_title,
  182. goods_image: item.goods_image,
  183. goods_price: item.goods_price
  184. })),
  185. status_text: data.status_text
  186. }
  187. }
  188. };
  189. break;
  190. }
  191. if (msg) {
  192. socketSendMsg(msg, () => {
  193. scrollBottom();
  194. });
  195. chat.showTools = false;
  196. chat.showSelect = false;
  197. chat.selectMode = "";
  198. }
  199. }
  200. function onSendMessage() {
  201. if (!socketState.value.isConnect) {
  202. sheep_index.sheep.$helper.toast(socketState.value.tip || "您已掉线!请返回重试");
  203. return;
  204. }
  205. if (!chat.msg)
  206. return;
  207. const data = {
  208. from: "customer",
  209. mode: "text",
  210. date: (/* @__PURE__ */ new Date()).getTime(),
  211. content: {
  212. text: chat.msg
  213. }
  214. };
  215. socketSendMsg(data, () => {
  216. scrollBottom();
  217. });
  218. chat.showTools = false;
  219. setTimeout(() => {
  220. chat.msg = "";
  221. }, 100);
  222. }
  223. function onTemplateList(e) {
  224. if (!socketState.value.isConnect) {
  225. sheep_index.sheep.$helper.toast(socketState.value.tip || "您已掉线!请返回重试");
  226. return;
  227. }
  228. const data = {
  229. from: "customer",
  230. mode: "text",
  231. date: (/* @__PURE__ */ new Date()).getTime(),
  232. content: {
  233. text: e.title
  234. },
  235. customData: {
  236. question_id: e.id
  237. }
  238. };
  239. socketSendMsg(data, () => {
  240. scrollBottom();
  241. });
  242. }
  243. function onEmoji(item) {
  244. chat.msg += item.name;
  245. }
  246. function selEmojiFile(name) {
  247. for (let index in pages_chat_emoji.emojiList) {
  248. if (pages_chat_emoji.emojiList[index].name === name) {
  249. return pages_chat_emoji.emojiList[index].file;
  250. }
  251. }
  252. return false;
  253. }
  254. function replaceEmoji(data) {
  255. let newData = data;
  256. if (typeof newData !== "object") {
  257. let reg = /\[(.+?)\]/g;
  258. let zhEmojiName = newData.match(reg);
  259. if (zhEmojiName) {
  260. zhEmojiName.forEach((item) => {
  261. let emojiFile = selEmojiFile(item);
  262. newData = newData.replace(
  263. item,
  264. `<image class="chat-img" style="width: 24px;height: 24px;margin: 0 3px;" src="${sheep_index.sheep.$url.cdn(
  265. "/static/img/chat/emoji/" + emojiFile
  266. )}"/></image>`
  267. );
  268. });
  269. }
  270. }
  271. return newData;
  272. }
  273. function scrollBottom() {
  274. let timeout = null;
  275. chat.scrollInto = "";
  276. clearTimeout(timeout);
  277. timeout = setTimeout(() => {
  278. chat.scrollInto = "scrollBottom";
  279. }, 100);
  280. }
  281. common_vendor.onLoad(async () => {
  282. const { error } = await getUserToken();
  283. if (error === 0) {
  284. socketInit(chatConfig.value, () => {
  285. scrollBottom();
  286. });
  287. } else {
  288. socketState.value.isConnect = false;
  289. }
  290. });
  291. return (_ctx, _cache) => {
  292. return common_vendor.e({
  293. a: common_vendor.t(common_vendor.unref(socketState).isConnect ? common_vendor.unref(customerServiceInfo).title : "网络已断开,请检查网络后刷新重试"),
  294. b: common_vendor.unref(sys_navBar) + "px",
  295. c: common_vendor.unref(chatList).length && common_vendor.unref(chatHistoryPagination).lastPage > 1 && loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].title
  296. }, common_vendor.unref(chatList).length && common_vendor.unref(chatHistoryPagination).lastPage > 1 && loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].title ? {
  297. d: common_vendor.t(loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].title),
  298. e: common_vendor.n(loadingMap[common_vendor.unref(chatHistoryPagination).loadStatus].icon),
  299. f: common_vendor.o(onLoadMore)
  300. } : {}, {
  301. g: common_vendor.f(common_vendor.unref(chatList), (item, index, i0) => {
  302. var _a;
  303. return common_vendor.e({
  304. a: item.from !== "system" && common_vendor.unref(showTime)(item, index)
  305. }, item.from !== "system" && common_vendor.unref(showTime)(item, index) ? {
  306. b: common_vendor.t(common_vendor.unref(formatTime)(item.date))
  307. } : {}, {
  308. c: item.from === "system"
  309. }, item.from === "system" ? {
  310. d: common_vendor.t(item.content.text)
  311. } : {}, {
  312. e: item.mode === "template" && item.content.list.length
  313. }, item.mode === "template" && item.content.list.length ? {
  314. f: common_vendor.f(item.content.list, (item2, index2, i1) => {
  315. return {
  316. a: common_vendor.t(item2.title),
  317. b: index2,
  318. c: common_vendor.o(($event) => onTemplateList(item2), index2)
  319. };
  320. })
  321. } : {}, {
  322. g: item.from === "customer_service" && item.mode !== "template" || item.from === "customer"
  323. }, item.from === "customer_service" && item.mode !== "template" || item.from === "customer" ? common_vendor.e({
  324. h: item.from === "customer_service",
  325. i: common_vendor.unref(sheep_index.sheep).$url.cdn((_a = item == null ? void 0 : item.sender) == null ? void 0 : _a.avatar) || common_vendor.unref(sheep_index.sheep).$url.static("/static/images/default.png"),
  326. j: item.from === "customer" && index == common_vendor.unref(chatData).chatList.length - 1 && common_vendor.unref(chatData).isSendSucces !== 0
  327. }, item.from === "customer" && index == common_vendor.unref(chatData).chatList.length - 1 && common_vendor.unref(chatData).isSendSucces !== 0 ? common_vendor.e({
  328. k: common_vendor.unref(chatData).isSendSucces == -1
  329. }, common_vendor.unref(chatData).isSendSucces == -1 ? {
  330. l: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/loading.png")
  331. } : {}) : {}, {
  332. m: item.mode === "text"
  333. }, item.mode === "text" ? {
  334. n: replaceEmoji(item.content.text),
  335. o: common_vendor.o((...args) => _ctx.onRichtext && _ctx.onRichtext(...args), index),
  336. p: common_vendor.n(item.from)
  337. } : {}, {
  338. q: item.mode === "image"
  339. }, item.mode === "image" ? {
  340. r: "5a559478-1-" + i0 + ",5a559478-0",
  341. s: common_vendor.p({
  342. isPreview: true,
  343. previewList: [common_vendor.unref(sheep_index.sheep).$url.cdn(item.content.url)],
  344. current: 0,
  345. src: common_vendor.unref(sheep_index.sheep).$url.cdn(item.content.url),
  346. height: 200,
  347. width: 200,
  348. mode: "aspectFill"
  349. }),
  350. t: common_vendor.n(item.from)
  351. } : {}, {
  352. v: item.mode === "goods"
  353. }, item.mode === "goods" ? {
  354. w: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  355. id: item.content.item.id
  356. }), index),
  357. x: "5a559478-2-" + i0 + ",5a559478-0",
  358. y: common_vendor.p({
  359. goodsData: item.content.item
  360. })
  361. } : {}, {
  362. z: item.mode === "order"
  363. }, item.mode === "order" ? {
  364. A: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/order/detail", {
  365. id: item.content.item.id
  366. }), index),
  367. B: "5a559478-3-" + i0 + ",5a559478-0",
  368. C: common_vendor.p({
  369. from: "msg",
  370. orderData: item.content.item
  371. })
  372. } : {}, {
  373. D: item.from === "customer",
  374. E: common_vendor.unref(sheep_index.sheep).$url.cdn(common_vendor.unref(customerUserInfo).avatar),
  375. F: common_vendor.n(item.from === "customer_service" ? `ss-row-left` : item.from === "customer" ? `ss-row-right` : "")
  376. }) : {}, {
  377. G: index
  378. });
  379. }),
  380. h: pageHeight + "px",
  381. i: chat.scrollInto,
  382. j: pageHeight + "px",
  383. k: common_vendor.o(($event) => chat.msg = $event),
  384. l: common_vendor.p({
  385. inputBorder: false,
  386. clearable: false,
  387. placeholder: "请输入你要咨询的问题",
  388. modelValue: chat.msg
  389. }),
  390. m: common_vendor.o(($event) => onTools("emoji")),
  391. n: !chat.msg
  392. }, !chat.msg ? {
  393. o: chat.toolsMode == "tools" ? 1 : "",
  394. p: common_vendor.o(($event) => onTools("tools"))
  395. } : {}, {
  396. q: chat.msg
  397. }, chat.msg ? {
  398. r: common_vendor.o(onSendMessage)
  399. } : {}, {
  400. s: common_vendor.p({
  401. bottom: true
  402. }),
  403. t: common_vendor.o(($event) => chat.msg = $event),
  404. v: common_vendor.p({
  405. inputBorder: false,
  406. clearable: false,
  407. placeholder: "请输入你要咨询的问题",
  408. modelValue: chat.msg
  409. }),
  410. w: common_vendor.o(($event) => onTools("emoji")),
  411. x: !chat.msg
  412. }, !chat.msg ? {
  413. y: chat.toolsMode == "tools" ? 1 : "",
  414. z: common_vendor.o(($event) => onTools("tools"))
  415. } : {}, {
  416. A: chat.msg
  417. }, chat.msg ? {
  418. B: common_vendor.o(onSendMessage)
  419. } : {}, {
  420. C: chat.toolsMode == "emoji"
  421. }, chat.toolsMode == "emoji" ? {
  422. D: common_vendor.f(common_vendor.unref(pages_chat_emoji.emojiPage), (emoji, k0, i0) => {
  423. return {
  424. a: common_vendor.f(emoji, (item, k1, i1) => {
  425. return {
  426. a: common_vendor.unref(sheep_index.sheep).$url.cdn(`/static/img/chat/emoji/${item.file}`),
  427. b: common_vendor.o(($event) => onEmoji(item), item),
  428. c: item
  429. };
  430. }),
  431. b: emoji
  432. };
  433. })
  434. } : {
  435. E: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/image.png"),
  436. F: common_vendor.o(($event) => onSelect({
  437. type: "image",
  438. data: $event
  439. })),
  440. G: common_vendor.p({
  441. ["file-mediatype"]: "image",
  442. imageStyles: {
  443. width: 50,
  444. height: 50,
  445. border: false
  446. }
  447. }),
  448. H: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/goods.png"),
  449. I: common_vendor.o(($event) => onShowSelect("goods")),
  450. J: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/order.png"),
  451. K: common_vendor.o(($event) => onShowSelect("order"))
  452. }, {
  453. L: common_vendor.o(($event) => {
  454. chat.showTools = false;
  455. chat.toolsMode = "";
  456. }),
  457. M: common_vendor.p({
  458. show: chat.showTools
  459. }),
  460. N: common_vendor.o(onSelect),
  461. O: common_vendor.o(($event) => chat.showSelect = false),
  462. P: common_vendor.p({
  463. mode: chat.selectMode,
  464. show: chat.showSelect
  465. }),
  466. Q: common_vendor.p({
  467. title: "客服",
  468. navbar: "inner"
  469. })
  470. });
  471. };
  472. }
  473. };
  474. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5a559478"], ["__file", "D:/zx/mall-front-app/pages/chat/index.vue"]]);
  475. wx.createPage(MiniProgramPage);