index.js 19 KB

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